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
feat: carry clean cross-chunk setup into chunked editorial checks (#1403)
[._.]/ Adam Eivyf4f05d5ea33f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex d67830949a..2c4179911d 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -138,3 +138,5 @@- **[issue-1383] Chunked LLM editorial checks now carry cross-chapter continuity between chunks.** When a manuscript is too long for the provider's context window, the manuscript-consuming LLM checks review it chunk-by-chunk and merge findings first-wins (#1340). But a per-chunk view is blind to problems that span chapters: `style.conformance` couldn't see that chapter 1 established past-tense when judging chapter 3, and `objects.unmotivated-interaction` could flag a "missing setup" for an object that an earlier chunk already accounted for. Those two checks now opt into a rolling **prior-findings digest** (`editorialPriorFindingsDigest`) — each chunk after the first is prefixed with a capped, first-wins summary of the findings gathered so far, riding INSIDE the manuscript var so no stage-prompt template changes (mirrors the completeness pass's `priorFindingsDigest`). The digest instructs the model not to repeat prior findings and to flag only new problems plus cross-chapter continuity issues the earlier findings reveal; exact repeats are still deduped by `editorialFindingKey`. The chunk planner reserves `EDITORIAL_PRIOR_DIGEST_TOKENS` so prepending the digest can't overrun the window, and `prose.info-dumping` deliberately stays per-chunk (its problems are localized). The shared chunk loop is factored into one `runChunkedManuscriptCheck` helper used by both the staged and custom-check paths. (`server/lib/editorial/checkRegistry.js`, #1383)- **[issue-1395] Universe canon section-local renders now persist durably even if the page unmounts mid-render.** A single reference/clean-plate render fired from the Universe canon section round-tripped a client `updateUniverse` PATCH to append the new filename onto the entry's `imageRefs[]` — so a render that completed *after* the user navigated away, refreshed, or switched universes silently lost its attachment (the image reached the media library, but no `imageRefs[]` row was ever written). These renders now carry the same durable `universeRun.entryRef` job tag the batch path uses, so the server-side completion hook (`universeBuilderCollectionHook`) appends `imageRefs[]` independent of any mounted client — converging the section-local and batch surfaces onto one durable path (mirrors the catalog hook from #1359). The hook fires the `appendEntryImageRef` even when the render carries no collection (and the route preserves `entryRef` through a gallery-collection provisioning failure, so the imageRefs append never depends on the collection existing). The client `handleRefCompleted` keeps its optimistic/immediate-refresh role (no PATCH); the hook is idempotent against it (`mapAppendImageRef` dedupes by filename). Backbone the durable path depends on: `updateUniverse` now preserves canon-entry `imageRefs[]` per-id across a stale whole-array PATCH (an inline canon edit/add/lock that round-trips a snapshot loaded before the render landed no longer clobbers the freshly-appended filename — the same guard variations and composite sheets already had); `purgeImageRefFromAllUniverses` switches to the trusted mutator form so its intentional ref-removal isn't undone by that guard; and the route rejects an `entryRef` missing its locating key (canon→`kindKey`, variation→`categoryKey`) instead of silently no-opping the append. (`server/services/universeBuilderCollectionHook.js`, `server/routes/imageGen.js`, `server/services/universeBuilder.js`, `server/services/universeCanon.js`, `client/src/components/universe/UniverseCanonSection.jsx`, #1395)++- **[issue-1403] Chunked LLM editorial checks now also carry clean cross-chapter *setup* between chunks, not just prior findings.** The #1383 prior-findings digest stops a later chunk from re-flagging a problem an earlier chunk recorded — but clean setup produces no finding, so a payoff in chunk 2 could still be mis-flagged "missing setup" when chunk 1 cleanly established it, and `style.conformance` had no signal of which tense/POV chapter 1 set when judging chapter 3. `objects.unmotivated-interaction` and `style.conformance` now additionally opt into a **cross-chunk clean-setup digest** (`crossChunkSetup` + a per-check `setupFocus`): after each non-final chunk, one extra inline summarization call (`ctx.callInlineLLM`, tagged `pipeline-editorial-setup-digest`, built by `buildSetupDigestPrompt`) rolls a short "setup so far" summary forward, and `editorialSetupDigest` prepends it to later chunks alongside the findings digest — riding INSIDE the manuscript var (no stage-prompt change). Both digests **yield to manuscript coverage**: the setup digest is fitted *after* the findings digest into whatever spare room remains, so a tight chunk drops the digest rather than the manuscript. A single-chunk (whole-fits) run never summarizes, so the common case pays nothing; a summarizer failure keeps the prior summary and never aborts the check. When the reverse-outline (#1349) or continuity-bible (#1305) artifacts land, either could feed this context more cheaply than a per-chunk call. (`server/lib/editorial/checkRegistry.js`, #1403)diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.mdindex 5e49469a48..7fe897e7c5 100644--- a/server/lib/editorial/README.md+++ b/server/lib/editorial/README.md@@ -30,6 +30,20 @@ window (a chunk packed to the budget just runs without a digest).`objects.unmotivated-interaction` (setup/payoff across chapters) opt in;`prose.info-dumping` stays per-chunk (its problems are localized).+The findings digest carries prior *problems* forward but not clean prior *setup*+— a payoff in a later chunk can be mis-flagged "missing setup" when the earlier+chunk established it without producing a finding. A check can additionally opt+into a **cross-chunk clean-setup digest** (#1403): pass `crossChunkSetup: true`+(plus a per-check `setupFocus` string) to `runManuscriptLlmCheck`, and after each+non-final chunk one extra inline summarization call (`ctx.callInlineLLM`, tagged+`EDITORIAL_SETUP_DIGEST_SOURCE`, built by `buildSetupDigestPrompt`) rolls a short+"setup so far" summary forward. `editorialSetupDigest` wraps it and prepends it to+later chunks alongside the findings digest — also yielding to spare budget, and+fitted *after* the findings digest so manuscript coverage and the findings digest+both win when budget is tight. A single-chunk (whole-fits) run never summarizes,+so it pays nothing. When the reverse-outline (#1349) or continuity-bible (#1305)+artifacts land, either could feed this context more cheaply than a per-chunk call.+## Discovery ruleBefore adding an editorial rule, check whether an existing registry entry coversdiff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex 6cb7d123aa..a5e815a468 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -278,6 +278,77 @@ export function editorialPriorFindingsDigest(findings) {return `${EDITORIAL_PRIOR_DIGEST_HEADER}${body}${EDITORIAL_PRIOR_DIGEST_SEPARATOR}`;}+// Cross-chunk CLEAN-SETUP digest (#1403). The findings digest above carries prior+// problems forward, but it cannot tell a later chunk that an earlier chunk+// *cleanly* established context (an object's motivation, a tense/POV/rating) —+// clean setup produces no finding, so a payoff in a later chunk can be mis-flagged+// "missing setup". This digest threads a short rolling summary of established+// setup alongside the findings digest, generated by one extra summarization LLM+// call per chunk (see `runManuscriptLlmCheck`'s `crossChunkSetup` path).+//+// (When the reverse-outline (#1349) or continuity-bible (#1305) artifacts land,+// either could supply this cross-chunk context more cheaply than a per-chunk+// summary call — they already condense the manuscript. Until then this is the+// self-contained source.)+//+// Free-form run tag so /runs can filter the setup-summary calls apart from the+// named-stage editorial checks and custom-check calls.+export const EDITORIAL_SETUP_DIGEST_SOURCE = 'pipeline-editorial-setup-digest';+// Body cap for the rolling setup summary (a touch smaller than the findings+// digest — it is condensed prose, not a bounded findings list). Header + trailing+// `---` are appended AFTER the cap so the delimiter always survives truncation+// (the next manuscript chunk concatenates right after, same contract as the+// findings digest).+export const EDITORIAL_SETUP_DIGEST_BODY_CHARS = 1_500;+const EDITORIAL_SETUP_DIGEST_HEADER =+ '# Setup already established in EARLIER parts of this manuscript (clean context — these are NOT problems)\n'+ + 'Use this when judging the text below: do NOT flag a payoff as missing setup, or a tense/POV/rating as a '+ + 'drift, if it was already established here.\n\n';+const EDITORIAL_SETUP_DIGEST_SEPARATOR = '\n\n---\n\n';+// Whole-digest char ceiling = fixed wrapper + capped body. Like the findings+// digest, the setup digest is prepended only when it fits the chunk's spare+// budget, so it never grows a chunk past the provider window.+export const EDITORIAL_SETUP_DIGEST_CHARS =+ EDITORIAL_SETUP_DIGEST_HEADER.length + EDITORIAL_SETUP_DIGEST_BODY_CHARS + EDITORIAL_SETUP_DIGEST_SEPARATOR.length;++// Wrap an accumulated "setup so far" summary in the fixed header + trailing `---`+// so it rides INSIDE the next chunk's manuscript var (no prompt template change,+// mirrors editorialPriorFindingsDigest). Returns '' for an empty/non-string+// summary so the first chunk (no prior setup yet) is untouched.+export function editorialSetupDigest(summary) {+ if (typeof summary !== 'string' || !summary.trim()) return '';+ const body = summary.trim().slice(0, EDITORIAL_SETUP_DIGEST_BODY_CHARS);+ return `${EDITORIAL_SETUP_DIGEST_HEADER}${body}${EDITORIAL_SETUP_DIGEST_SEPARATOR}`;+}++// Build the inline summarization prompt that maintains the rolling "setup so far"+// summary. Pure + deterministic so it's unit-testable and so the caller can pin a+// per-check `focus` (the objects check tracks item motivations; the style check+// tracks tense/POV/rating). Asks for terse merged setup text only — no JSON, no+// commentary — since the result rides verbatim into the next chunk's digest.+export function buildSetupDigestPrompt({ focus, priorSummary, manuscript }) {+ const trackDefault = 'Items/objects introduced and any motivation or significance established for them; '+ + 'the narrative tense, point-of-view person, and content rating in force.';+ return [+ 'You are tracking established narrative SETUP across a long manuscript reviewed in parts.',+ 'Maintain a SHORT running summary of the setup so far — only the facts a later part needs to judge payoffs and continuity.',+ '',+ '# What to track',+ String(focus || '').trim() || trackDefault,+ '',+ '# Setup recorded so far (from earlier parts)',+ String(priorSummary || '').trim() || '(none yet)',+ '',+ '# New manuscript part',+ String(manuscript || ''),+ '',+ '# How to respond',+ 'Return an updated running summary that MERGES the prior setup with any new setup established in this part.',+ 'Be terse: short bullet lines, no preamble, no commentary — only the established facts, dropping nothing important from the prior summary.',+ 'Respond with the summary text only: no JSON, no section headers, no explanation.',+ ].join('\n');+}+// Shared chunk loop for the manuscript-consuming LLM checks: run `callChunk` on// each provider-sized chunk, normalize + merge findings first-wins (capped at// `max` across the whole run). When `crossChunkDigest` is set, each chunk after@@ -293,10 +364,21 @@ export function editorialPriorFindingsDigest(findings) {// the provider window — a chunk packed up to the budget simply runs without a// digest rather than dropping its tail. When the chunker doesn't report a budget// (a fits-in-one-call provider, or a test stub), there is unbounded headroom.-async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunk, crossChunkDigest = false }) {+//+// `summarizeChunk` (#1403) opts in the CLEAN-SETUP digest: when provided, after+// each non-final chunk it is called `(priorSummary, chunkText) => nextSummary` to+// roll forward a short "setup so far" summary, and that summary's `editorialSetupDigest`+// is prepended (alongside the findings digest, after it in the budget) to later+// chunks — also yielding to spare room. It is a no-op for a single-chunk run (no+// later chunk consumes a summary), so the common fits-in-one-call provider pays+// nothing.+async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunk, crossChunkDigest = false, summarizeChunk = null }) {const usableChars = Number.isFinite(chunks?.usableChars) ? chunks.usableChars : Infinity;const merged = new Map();- for (const manuscript of chunks) {+ const crossChunkSetup = typeof summarizeChunk === 'function';+ let setupSummary = '';+ for (let i = 0; i < chunks.length; i++) {+ const manuscript = chunks[i];// Stop launching further chunk calls once the run is cancelled — the runner// only checks the signal around the whole check, so without this a multi-// chunk check keeps paying for LLM calls whose results will be discarded.@@ -306,7 +388,13 @@ async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunkconst digest = editorialPriorFindingsDigest([...merged.values()]);// Only prepend when the digest fits the chunk's spare room — never trim the// manuscript (would drop review coverage) or overflow the window.- if (digest && digest.length <= usableChars - manuscript.length) text = `${digest}${manuscript}`;+ if (digest && digest.length <= usableChars - text.length) text = `${digest}${manuscript}`;+ }+ if (crossChunkSetup && setupSummary) {+ const setup = editorialSetupDigest(setupSummary);+ // Fits into whatever spare room remains AFTER the findings digest — manuscript+ // coverage and the findings digest both win over the setup digest if budget is tight.+ if (setup && setup.length <= usableChars - text.length) text = `${setup}${text}`;}const content = await callChunk(text);for (const f of mapLlmFindings(content?.findings, {@@ -318,6 +406,14 @@ async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunkconst k = editorialFindingKey(f);if (!merged.has(k)) merged.set(k, f);}+ // Roll the setup summary forward for the NEXT chunk — skip after the last chunk+ // (nothing consumes it) and on cancellation (its result would be discarded).+ // Summarize the RAW chunk, never the digest-prefixed text. A summarizer failure+ // must not abort the check — keep the prior summary and continue.+ if (crossChunkSetup && i < chunks.length - 1 && !ctx.signal?.aborted) {+ const next = await summarizeChunk(setupSummary, manuscript).catch(() => setupSummary);+ if (typeof next === 'string' && next.trim()) setupSummary = next.trim();+ }}return [...merged.values()].slice(0, Math.max(0, max));}@@ -335,17 +431,29 @@ async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunk// etc.) on top of EDITORIAL_PROMPT_OVERHEAD_TOKENS — those vars ride alongside// the chunked manuscript, so under-counting them lets a chunk overrun the// provider window.-async function runManuscriptLlmCheck(ctx, { stage, category, overheadTokens = 0, buildVars, crossChunkDigest = false }) {+async function runManuscriptLlmCheck(ctx, { stage, category, overheadTokens = 0, buildVars, crossChunkDigest = false, crossChunkSetup = false, setupFocus = '' }) {const max = ctx.config?.maxFindings ?? 12;// Chunks are planned at the full usable budget; the digest is fitted into each// later chunk's spare room inside runChunkedManuscriptCheck (it yields to the// manuscript), so no budget is reserved or carved out here.const chunks = await ctx.planManuscriptChunks(stage, { overheadTokens });+ // Clean-setup digest (#1403): roll a short "setup so far" summary forward via an+ // inline summarization call. Only wired when the check opts in AND the runner+ // injected an inline LLM caller — absent it (unit tests of the findings-digest+ // path), the check degrades to findings-only with no extra calls.+ const summarizeChunk = crossChunkSetup && typeof ctx.callInlineLLM === 'function'+ ? async (priorSummary, manuscript) => {+ const prompt = buildSetupDigestPrompt({ focus: setupFocus, priorSummary, manuscript });+ const { content } = await ctx.callInlineLLM(prompt, { source: EDITORIAL_SETUP_DIGEST_SOURCE });+ return typeof content === 'string' ? content : '';+ }+ : null;return runChunkedManuscriptCheck(ctx, {chunks,category,max,crossChunkDigest,+ summarizeChunk,callChunk: async (manuscript) => {const { content } = await ctx.callStagedLLM(stage, buildVars(manuscript), { returnsJson: true, source: stage });return content;@@ -833,6 +941,12 @@ export const EDITORIAL_CHECKS = [// later; without the digest a later chunk may flag a "missing setup" an// earlier chunk already accounted for (#1383).crossChunkDigest: true,+ // …and a CLEANLY established motivation produces no finding, so the findings+ // digest alone can't carry it forward — roll a setup summary of the objects+ // and their established significance so a later payoff isn't mis-flagged (#1403).+ crossChunkSetup: true,+ setupFocus: 'Objects/items characters interact with, and any motivation, emotional significance, '+ + 'or backstory the prose or canon has established for that object (so a later payoff is recognized as motivated).',});},},@@ -1023,6 +1137,12 @@ export const EDITORIAL_CHECKS = [// Tense/POV drift is inherently cross-chapter — a per-chunk view can't see// that chapter 1 established past-tense when judging chapter 3 (#1383).crossChunkDigest: true,+ // A chunk with no tense/POV finding leaves a later chunk blind to what+ // chapter 1 established — the findings digest carries problems, not the clean+ // baseline. Roll a setup summary of the tense/POV/rating in force forward (#1403).+ crossChunkSetup: true,+ setupFocus: 'The narrative tense (past/present), the point-of-view person (first/third/etc.), '+ + 'and the content rating / profanity / violence level in force.',});},},diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.jsindex 29d93a741f..5f62384c73 100644--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@ -22,6 +22,11 @@ import {editorialPriorFindingsDigest,EDITORIAL_PRIOR_DIGEST_MAX,EDITORIAL_PRIOR_DIGEST_CHARS,+ editorialSetupDigest,+ buildSetupDigestPrompt,+ EDITORIAL_SETUP_DIGEST_BODY_CHARS,+ EDITORIAL_SETUP_DIGEST_CHARS,+ EDITORIAL_SETUP_DIGEST_SOURCE,} from './checkRegistry.js';const NAMING = 'naming.dissimilar-names';@@ -709,6 +714,181 @@ describe('cross-chunk continuity digest (#1383)', () => {});});+describe('cross-chunk clean-setup digest (#1403)', () => {+ describe('editorialSetupDigest formatter', () => {+ it('returns empty string for empty / non-string summaries', () => {+ expect(editorialSetupDigest('')).toBe('');+ expect(editorialSetupDigest(' ')).toBe('');+ expect(editorialSetupDigest(null)).toBe('');+ expect(editorialSetupDigest(undefined)).toBe('');+ });++ it('wraps the summary in the clean-setup header + trailing separator', () => {+ const digest = editorialSetupDigest('- past tense, first person\n- Watch = grief over father');+ expect(digest).toMatch(/Setup already established in EARLIER parts/);+ expect(digest).toContain('past tense, first person');+ expect(digest).toContain('Watch = grief over father');+ expect(digest.endsWith('\n\n---\n\n')).toBe(true);+ });++ it('caps the whole digest and keeps the trailing --- separator after a body overflow', () => {+ const digest = editorialSetupDigest('x'.repeat(EDITORIAL_SETUP_DIGEST_BODY_CHARS + 500));+ expect(digest.length).toBeLessThanOrEqual(EDITORIAL_SETUP_DIGEST_CHARS);+ expect(digest.endsWith('\n\n---\n\n')).toBe(true);+ // A following chunk stays clearly separated from the digest body.+ expect(`${digest}NEXT_CHUNK`).toContain('---\n\nNEXT_CHUNK');+ });+ });++ describe('buildSetupDigestPrompt', () => {+ it('embeds the focus, the prior summary, and the new chunk; asks for summary-only output', () => {+ const prompt = buildSetupDigestPrompt({+ focus: 'tense/POV/rating in force',+ priorSummary: '- past tense established',+ manuscript: 'CHAPTER TWO TEXT',+ });+ expect(prompt).toContain('tense/POV/rating in force');+ expect(prompt).toContain('- past tense established');+ expect(prompt).toContain('CHAPTER TWO TEXT');+ expect(prompt).toMatch(/summary text only/i);+ });++ it('falls back to a default focus + "(none yet)" prior summary', () => {+ const prompt = buildSetupDigestPrompt({ manuscript: 'CHAPTER ONE' });+ expect(prompt).toContain('(none yet)');+ expect(prompt).toMatch(/narrative tense, point-of-view person, and content rating/);+ });+ });++ // Drive a two-chunk run with an inline LLM caller wired so the clean-setup digest+ // path activates. Returns the manuscript text each findings call saw + the inline+ // prompts the summarizer was given.+ const runTwoChunksWithSetup = async (checkId, ctxExtras, { usableChars } = {}) => {+ const seen = [];+ const setupPrompts = [];+ await getCheck(checkId).run({+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ planManuscriptChunks: async () => {+ const chunks = ['CHUNK_ONE', 'CHUNK_TWO'];+ if (Number.isFinite(usableChars)) chunks.usableChars = usableChars;+ return chunks;+ },+ callStagedLLM: async (_stage, vars) => {+ seen.push(vars.manuscript);+ return { content: { findings: [] } }; // no findings → isolate the setup digest+ },+ callInlineLLM: async (prompt) => {+ setupPrompts.push(prompt);+ return { content: '- SETUP: past tense, first person' };+ },+ ...ctxExtras,+ });+ return { seen, setupPrompts };+ };++ it('style.conformance rolls a setup summary forward into the next chunk', async () => {+ const { seen, setupPrompts } = await runTwoChunksWithSetup('style.conformance', {+ series: { styleGuide: { tense: 'past', povPerson: 'first' } },+ });+ // First chunk untouched (no prior setup yet).+ expect(seen[0]).toBe('CHUNK_ONE');+ // The summarizer ran once (after chunk one, before chunk two) and saw chunk one.+ expect(setupPrompts).toHaveLength(1);+ expect(setupPrompts[0]).toContain('CHUNK_ONE');+ // The second chunk is prefixed with the clean-setup digest, then its text.+ expect(seen[1]).toContain('Setup already established in EARLIER parts');+ expect(seen[1]).toContain('past tense, first person');+ expect(seen[1].endsWith('CHUNK_TWO')).toBe(true);+ });++ it('objects.unmotivated-interaction rolls a setup summary forward', async () => {+ const { seen, setupPrompts } = await runTwoChunksWithSetup('objects.unmotivated-interaction', {+ canon: {+ objects: [{ id: 'o1', name: 'Watch', attachments: [{ characterId: 'c1', emotion: 'grief' }] }],+ characters: [{ id: 'c1', name: 'Mara' }],+ },+ });+ expect(seen[0]).toBe('CHUNK_ONE');+ expect(setupPrompts).toHaveLength(1);+ expect(seen[1]).toContain('Setup already established in EARLIER parts');+ expect(seen[1].endsWith('CHUNK_TWO')).toBe(true);+ });++ it('uses the dedicated run source tag for setup-summary calls', async () => {+ let source = null;+ await getCheck('style.conformance').run({+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ series: { styleGuide: { tense: 'past', povPerson: 'first' } },+ planManuscriptChunks: async () => ['CHUNK_ONE', 'CHUNK_TWO'],+ callStagedLLM: async () => ({ content: { findings: [] } }),+ callInlineLLM: async (_prompt, opts) => {+ source = opts?.source;+ return { content: 'summary' };+ },+ });+ expect(source).toBe(EDITORIAL_SETUP_DIGEST_SOURCE);+ });++ it('does not summarize a single-chunk run (no later chunk consumes it)', async () => {+ let inlineCalls = 0;+ const seen = [];+ await getCheck('style.conformance').run({+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ series: { styleGuide: { tense: 'past', povPerson: 'first' } },+ planManuscriptChunks: async () => ['ONLY_CHUNK'],+ callStagedLLM: async (_stage, vars) => { seen.push(vars.manuscript); return { content: { findings: [] } }; },+ callInlineLLM: async () => { inlineCalls += 1; return { content: 'summary' }; },+ });+ expect(seen).toEqual(['ONLY_CHUNK']);+ expect(inlineCalls).toBe(0);+ });++ it('skips the setup digest when it would not fit the chunk budget (manuscript coverage wins)', async () => {+ const { seen } = await runTwoChunksWithSetup(+ 'style.conformance',+ { series: { styleGuide: { tense: 'past', povPerson: 'first' } } },+ { usableChars: 'CHUNK_TWO'.length }, // no spare room for any digest+ );+ expect(seen[1]).toBe('CHUNK_TWO');+ expect(seen[1]).not.toContain('Setup already established in EARLIER parts');+ });++ it('degrades to findings-only when no inline LLM caller is injected (no setup digest, no crash)', async () => {+ // No callInlineLLM in ctx → the setup-summary path stays off entirely.+ const seen = [];+ await getCheck('style.conformance').run({+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ series: { styleGuide: { tense: 'past', povPerson: 'first' } },+ planManuscriptChunks: async () => ['CHUNK_ONE', 'CHUNK_TWO'],+ callStagedLLM: async (_stage, vars) => { seen.push(vars.manuscript); return { content: { findings: [] } }; },+ });+ expect(seen).toEqual(['CHUNK_ONE', 'CHUNK_TWO']);+ expect(seen[1]).not.toContain('Setup already established in EARLIER parts');+ });++ it('keeps the prior summary when the summarizer throws (a bad call must not abort the check)', async () => {+ const seen = [];+ let inlineCalls = 0;+ await getCheck('style.conformance').run({+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ series: { styleGuide: { tense: 'past', povPerson: 'first' } },+ planManuscriptChunks: async () => ['CHUNK_ONE', 'CHUNK_TWO'],+ callStagedLLM: async (_stage, vars) => { seen.push(vars.manuscript); return { content: { findings: [] } }; },+ callInlineLLM: async () => { inlineCalls += 1; throw new Error('summarizer down'); },+ });+ // The summarizer was attempted but threw → no setup digest, and the run still+ // processed both chunks to completion.+ expect(inlineCalls).toBe(1);+ expect(seen).toEqual(['CHUNK_ONE', 'CHUNK_TWO']);+ expect(seen[1]).not.toContain('Setup already established in EARLIER parts');+ });+});+describe('objects.backstory-consistency — LLM check (#1288)', () => {const canonWithRow = () => ({objects: [{ id: 'o1', name: 'Watch', attachments: [{ characterId: 'c1', emotion: 'grief', origin: 'gift from her father in 1990' }] }],