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 (claude + codex): guard pov-switch undrafted-gap + gate cliffhanger terminal-chapter exemption on finalPart (#1298)
Adam Eivyb96eeae15601
diff --git a/data.reference/prompts/stages/pipeline-editorial-endings-cliffhanger.md b/data.reference/prompts/stages/pipeline-editorial-endings-cliffhanger.mdindex a3547949d1..c8143b9ed4 100644--- a/data.reference/prompts/stages/pipeline-editorial-endings-cliffhanger.md+++ b/data.reference/prompts/stages/pipeline-editorial-endings-cliffhanger.md@@ -25,13 +25,22 @@ carry the reader on — is **medium**.Do NOT flag:-- The **final** chapter / issue of the whole story — a terminal ending is allowed- (and expected) to resolve. If the manuscript below clearly ends the series, leave- its last chapter alone.- A chapter that already ends on an open beat, a turn, or an unanswered question —that is exactly what the rule wants.- A deliberate quiet "breather" beat that still leaves a larger thread open.+{{#finalPart}}+- The **final** chapter / issue of the whole story — a terminal ending is allowed+ (and expected) to resolve. This is the LAST part of the manuscript, so if the text+ below clearly ends the series, leave its last chapter alone.+{{/finalPart}}+{{^finalPart}}+**You are reading the manuscript in PARTS and have not yet seen the later parts.**+The last chapter shown below is NOT the end of the story — do not treat it as a+terminal ending. Judge every chapter ending here, including the last one visible,+by the soft-landing rule.+{{/finalPart}}+{{#authoredCliffhangers}}## Cliffhangers the writer has already planneddiff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex c97469e80d..a00126bf07 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -2219,7 +2219,12 @@ export const EDITORIAL_CHECKS = [stage: ENDINGS_CLIFFHANGER_STAGE,category: 'pacing',overheadTokens: EDITORIAL_PROMPT_OVERHEAD_TOKENS + estimateTokens(authoredCliffhangers),- buildVars: (manuscript) => ({ manuscript, authoredCliffhangers }),+ // `finalPart` gates the "leave the terminal chapter alone" exemption (#1298):+ // on a chunked manuscript, only the LAST part can contain the series finale,+ // so an earlier part must NOT treat its last visible chapter as terminal+ // (that would false-negative a soft landing at a chunk boundary). A+ // single-chunk run is its own final part. Mirrors the Chekhov check.+ buildVars: (manuscript, meta) => ({ manuscript, authoredCliffhangers, finalPart: meta?.isFinal ? 'true' : '' }),});},},@@ -2273,6 +2278,12 @@ export const EDITORIAL_CHECKS = [// to cut to — and the final chapter is allowed to resolve).if (idx === -1 || idx === orderedIssues.length - 1) continue;const nextIssue = orderedIssues[idx + 1];+ // Only judge the cut when the IMMEDIATELY-following chapter is the next one+ // in the outline. If issue endIssue+1 is undrafted / not yet segmented (the+ // outline jumps to a later issue), there's no adjacent chapter to cut away+ // to — comparing across the gap would mis-attribute the cliffhanger to a+ // non-adjacent chapter, so skip (favor under-flagging).+ if (nextIssue !== endIssue + 1) continue;const ending = lastPovScene(byIssue.get(endIssue));const opening = firstPovScene(byIssue.get(nextIssue));if (!ending || !opening) continue;diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.jsindex bff2f663c9..b53e35e021 100644--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@ -502,6 +502,25 @@ describe('endings.cliffhanger — LLM check (#1298)', () => {await getCheck(ENDINGS_CLIFF).run(ctx);expect(seenVars.authoredCliffhangers).toBe('');});++ it('marks a single-chunk run as the final part so the terminal-chapter exemption applies', async () => {+ let seenVars = null;+ const ctx = wholeCtx({+ callStagedLLM: async (_stage, vars) => { seenVars = vars; return { content: { findings: [] } }; },+ });+ await getCheck(ENDINGS_CLIFF).run(ctx);+ expect(seenVars.finalPart).toBe('true');+ });++ it('flags only the LAST part as final so an earlier chunk does not treat its last chapter as terminal (#1298)', async () => {+ const finals = [];+ const ctx = wholeCtx({+ planManuscriptChunks: async () => ['# Issue 1\n\npart one', '# Issue 2\n\npart two', '# Issue 3\n\npart three'],+ callStagedLLM: async (_stage, vars) => { finals.push(vars.finalPart); return { content: { findings: [] } }; },+ });+ await getCheck(ENDINGS_CLIFF).run(ctx);+ expect(finals).toEqual(['', '', 'true']);+ });});describe('authoredCliffhangerSummary (#1298)', () => {@@ -594,6 +613,20 @@ describe('endings.pov-switch — deterministic check (#1298)', () => {expect(runSwitch(scenes, [{ atIssueBoundary: 2 }])).toEqual([]);});+ it('skips a cliffhanger whose boundary matches no outlined issue', () => {+ const scenes = [scene('Aria', 1), scene('Aria', 2), scene('Bram', 3)];+ // No issue 7 in the outline — nothing to resolve, no finding.+ expect(runSwitch(scenes, [{ atIssueBoundary: 7 }])).toEqual([]);+ });++ it('does not flag across an undrafted gap (next outlined issue is not endIssue+1)', () => {+ // Issue 2 is undrafted/unsegmented: the outline jumps 1 → 3. A cliffhanger+ // ending issue 1 has no adjacent chapter to cut to, so it must NOT compare+ // issue 1's ending POV against issue 3's opening POV.+ const scenes = [scene('Aria', 1), scene('Aria', 3), scene('Bram', 4)];+ expect(runSwitch(scenes, [{ atIssueBoundary: 1 }])).toEqual([]);+ });+it('emits one finding per ending issue even if multiple cliffhangers share the boundary', () => {const scenes = [scene('Aria', 1), scene('Aria', 2), scene('Bram', 3)];const findings = runSwitch(scenes, [