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
fix: measure audience introduction along shortest dramatic paths (#13377)
[._.]/a1a165d2ab4c
diff --git a/server/lib/fableLoomOutline.js b/server/lib/fableLoomOutline.jsindex 970b626f98..6aebe884aa 100644--- a/server/lib/fableLoomOutline.js+++ b/server/lib/fableLoomOutline.js@@ -200,7 +200,6 @@ export function analyzeStoryOutline(outline, {if (byKey.has(startKey)) {const queue = [startKey];depthByKey.set(startKey, 0);- dramaticDepthByKey.set(startKey, 0);let cursor = 0;while (cursor < queue.length) {const key = queue[cursor];@@ -210,15 +209,33 @@ export function analyzeStoryOutline(outline, {for (const transition of asArray(byKey.get(key)?.transitions)) {if (byKey.has(transition.targetKey) && !depthByKey.has(transition.targetKey)) {depthByKey.set(transition.targetKey, depthByKey.get(key) + 1);- // Extra camera cuts do not make the audience introduction narratively later.- const sameScene = groupByKey.has(key) && groupByKey.get(key) === groupByKey.get(transition.targetKey);- dramaticDepthByKey.set(transition.targetKey, dramaticDepthByKey.get(key) + (sameScene ? 0 : 1));queue.push(transition.targetKey);}}}}+ // 0-1 BFS: extra camera cuts cost nothing; relax previously discovered+ // beats so a later same-scene shortcut can lower their dramatic depth.+ if (byKey.has(startKey)) {+ dramaticDepthByKey.set(startKey, 0);+ const deque = [startKey];+ while (deque.length) {+ const key = deque.shift();+ const base = dramaticDepthByKey.get(key);+ for (const transition of asArray(byKey.get(key)?.transitions)) {+ const target = transition.targetKey;+ if (!byKey.has(target)) continue;+ const sameScene = groupByKey.has(key) && groupByKey.get(key) === groupByKey.get(target);+ const cost = sameScene ? 0 : 1;+ if (!dramaticDepthByKey.has(target) || base + cost < dramaticDepthByKey.get(target)) {+ dramaticDepthByKey.set(target, base + cost);+ if (cost === 0) deque.unshift(target); else deque.push(target);+ }+ }+ }+ }+const endings = scenes.filter((scene) => scene.isEnding);if (scenes.length && !endings.length) {push(OUTLINE_ISSUE_CODES.NO_ENDINGS, 'error', 'The story outline has no ending beat.');diff --git a/server/lib/fableLoomOutline.test.js b/server/lib/fableLoomOutline.test.jsindex a9001f2147..f3dcc45635 100644--- a/server/lib/fableLoomOutline.test.js+++ b/server/lib/fableLoomOutline.test.js@@ -303,3 +303,40 @@ it('measures audience introduction in dramatic scenes after a shot split', () =>const nodes = scenes.map((scene, index) => ({ id: scene.key, shot: { dramaticSceneId: index < 4 ? 'opening' : 'invitation' } }));expect(analyzeStoryOutline(outline, { ...options, nodes }).issues.some((issue) => issue.code === 'LATE_AUDIENCE_CONNECTION')).toBe(false);});++it('uses a same-scene shortcut discovered after a multi-scene detour for audience introduction', () => {+ const edges = {+ opening: ['detour-1', 'cut-1'],+ 'detour-1': ['detour-2'],+ 'detour-2': ['detour-3'],+ 'detour-3': ['join'],+ 'cut-1': ['cut-2'],+ 'cut-2': ['cut-3'],+ 'cut-3': ['cut-4'],+ 'cut-4': ['join', 'cut-1'],+ join: ['invitation'],+ invitation: [],+ };+ const scenes = Object.entries(edges).map(([key, targets]) => ({+ key,+ title: key,+ summary: 'The signal travels through the opening sequence.',+ playbackMode: 'cut',+ audienceConnection: key === 'invitation' ? 'connected' : 'disconnected',+ isEnding: key === 'invitation',+ transitions: targets.map((targetKey) => ({ targetKey, intent: `Follow ${targetKey}` })),+ }));+ const outline = { startKey: 'opening', scenes };+ const options = { participationMode: 'helper', requireAudienceIntroduction: true };+ const ungrouped = analyzeStoryOutline(outline, options);+ expect(ungrouped.issues).toContainEqual(expect.objectContaining({ code: 'LATE_AUDIENCE_CONNECTION' }));++ const nodes = scenes.map(({ key }) => ({+ id: key,+ shot: { dramaticSceneId: key.startsWith('detour-') ? key : 'opening' },+ }));+ const result = analyzeStoryOutline(outline, { ...options, nodes });+ expect(result.issues).not.toContainEqual(expect.objectContaining({ code: 'LATE_AUDIENCE_CONNECTION' }));+ expect(result.stats.maxDepth).toBe(ungrouped.stats.maxDepth);+ expect(result.stats.reachableCount).toBe(ungrouped.stats.reachableCount);+});