Skip to content

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

fix: measure episode graph audience-connection depth in dramatic scenes (#13207)

Adam Eivy91a176150a5c
diff --git a/server/lib/fableLoomGraph.js b/server/lib/fableLoomGraph.js
index 1e2d521b66..d128706a2e 100644
--- a/server/lib/fableLoomGraph.js
+++ b/server/lib/fableLoomGraph.js
@@ -69,6 +69,32 @@ export function computeGraphLayers(episode) {
return { layers, depthById };
}
+/**
+ * Depth measured in dramatic scenes: a transition between two shots of the same
+ * `shot.dramaticSceneId` adds no depth, matching `fableLoomOutline.js`, so a
+ * shot split never makes the audience introduction look narratively later.
+ */
+function computeDramaticDepths(episode, depthById) {
+ const nodes = asArray(episode?.nodes);
+ const byId = new Map(nodes.map((n) => [n.id, n]));
+ const groupOf = (id) => byId.get(id)?.shot?.dramaticSceneId || id;
+ const dramatic = new Map();
+ if (!depthById.has(episode?.startNodeId)) return dramatic;
+ dramatic.set(episode.startNodeId, 0);
+ const queue = [episode.startNodeId];
+ for (let i = 0; i < queue.length; i += 1) {
+ const id = queue[i];
+ for (const tr of asArray(byId.get(id)?.transitions)) {
+ const target = tr?.targetNodeId;
+ if (byId.has(target) && !dramatic.has(target)) {
+ dramatic.set(target, dramatic.get(id) + (groupOf(id) === groupOf(target) ? 0 : 1));
+ queue.push(target);
+ }
+ }
+ }
+ return dramatic;
+}
+
/**
* Deterministic structural validation of one episode graph. Returns
* `{ issues, stats }`; `issues` entries are
@@ -111,13 +137,14 @@ export function analyzeEpisodeGraph(episode, {
'The audience is never invited into the story through its communication medium.',
);
} else {
- const firstDepth = Math.min(...connected.map((node) => depthById.get(node.id)));
+ const dramaticDepth = computeDramaticDepths(episode, depthById);
+ const firstDepth = Math.min(...connected.map((node) => dramaticDepth.get(node.id)));
if (firstDepth > 3) {
push(
GRAPH_ISSUE_CODES.LATE_AUDIENCE_CONNECTION,
'warning',
'The audience communication channel is not activated until late in the opening sequence.',
- { nodeId: connected.find((node) => depthById.get(node.id) === firstDepth)?.id },
+ { nodeId: connected.find((node) => dramaticDepth.get(node.id) === firstDepth)?.id },
);
}
}
diff --git a/server/lib/fableLoomGraph.test.js b/server/lib/fableLoomGraph.test.js
index 488184c097..09e03c121b 100644
--- a/server/lib/fableLoomGraph.test.js
+++ b/server/lib/fableLoomGraph.test.js
@@ -135,6 +135,27 @@ describe('analyzeEpisodeGraph', () => {
expect(connectedCodes).not.toContain(GRAPH_ISSUE_CODES.DISCONNECTED_DECISION);
});
+ it('measures audience-connection depth in dramatic scenes, not split shots', () => {
+ // Two dramatic scenes split into 4 shots each; the connected shot is node 8 (dramatic depth 2).
+ const nodes = Array.from({ length: 10 }, (_, index) => ({
+ id: `n${index}`,
+ title: `Shot ${index}`,
+ playbackMode: 'cut',
+ audienceConnection: index === 8 ? 'connected' : 'disconnected',
+ isEnding: index === 9,
+ shot: { dramaticSceneId: index < 4 ? 'sceneA' : index < 8 ? 'sceneB' : 'sceneC' },
+ transitions: index === 9 ? [] : [tr(`t${index}`, `n${index + 1}`, 'Continue')],
+ }));
+ const { issues } = analyzeEpisodeGraph({ startNodeId: 'n0', nodes }, {
+ participationMode: 'helper', requireAudienceIntroduction: true,
+ });
+ expect(issues.map((issue) => issue.code)).not.toContain(GRAPH_ISSUE_CODES.LATE_AUDIENCE_CONNECTION);
+ for (const node of nodes) delete node.shot;
+ expect(analyzeEpisodeGraph({ startNodeId: 'n0', nodes }, {
+ participationMode: 'helper', requireAudienceIntroduction: true,
+ }).issues.map((issue) => issue.code)).toContain(GRAPH_ISSUE_CODES.LATE_AUDIENCE_CONNECTION);
+ });
+
it('warns when a helper audience is not connected until after the opening sequence', () => {
const nodes = Array.from({ length: 6 }, (_, index) => ({
id: `n${index}`,