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: overlay FableLoom contract fields from the outline and name mismatched fields (#13184)
Adam Eivyf14c9ede4b8a
diff --git a/server/lib/fableLoomOutline.js b/server/lib/fableLoomOutline.jsindex 7cdfa4889b..15d64d2629 100644--- a/server/lib/fableLoomOutline.js+++ b/server/lib/fableLoomOutline.js@@ -455,21 +455,34 @@ export function analyzeStoryOutlineTeleplaySync(episode, outline, {&& node.playbackMode !== 'cut'? 'offscreen': 'onscreen');- const semanticFieldsMatch = scene.title === node.title- && (scene.plotPointId || null) === (node.plotPointId || null)- && (scene.challengePhase || null) === (node.challengePhase || null)- && scene.playbackMode === node.playbackMode- && scene.audienceConnection === node.audienceConnection- && scene.protagonistPresence === expectedProtagonistPresence- && scene.isEnding === node.isEnding- && (scene.endingLabel || '') === (node.endingLabel || '');+ // An ending has no outgoing paths, so its playbackMode carries no meaning.+ const comparePlayback = !scene.isEnding || !node.isEnding;+ const fieldChecks = [+ ['title', scene.title, node.title],+ ['plotPointId', scene.plotPointId || null, node.plotPointId || null],+ ['challengePhase', scene.challengePhase || null, node.challengePhase || null],+ ['playbackMode', comparePlayback ? scene.playbackMode : null, comparePlayback ? node.playbackMode : null],+ ['audienceConnection', scene.audienceConnection, node.audienceConnection],+ ['protagonistPresence', scene.protagonistPresence, expectedProtagonistPresence],+ ['isEnding', scene.isEnding, node.isEnding],+ ['endingLabel', scene.endingLabel || '', node.endingLabel || ''],+ ];+ const differingFields = fieldChecks+ .filter(([, expected, actual]) => expected !== actual)+ .map(([field, expected, actual]) => ({ field, outline: expected, teleplay: actual }));const outlineTransitions = sortedTransitionContract(scene.transitions, 'targetKey');const nodeTransitions = sortedTransitionContract(node.transitions, 'targetNodeId');- if (!semanticFieldsMatch || JSON.stringify(outlineTransitions) !== JSON.stringify(nodeTransitions)) {+ if (JSON.stringify(outlineTransitions) !== JSON.stringify(nodeTransitions)) {+ differingFields.push({ field: 'transitions', outline: outlineTransitions.length, teleplay: nodeTransitions.length });+ }+ if (differingFields.length) {+ const detail = differingFields+ .map(({ field, outline: o, teleplay: t }) => `${field}: outline=${JSON.stringify(o)}, teleplay=${JSON.stringify(t)}`)+ .join('; ');push(OUTLINE_ISSUE_CODES.TELEPLAY_SCENE_CONTRACT_MISMATCH,- `Beat "${scene.title || scene.key}" no longer matches its expanded teleplay scene contract.`,- { sceneKey: node.id },+ `Beat "${scene.title || scene.key}" no longer matches its expanded teleplay scene contract (${detail}).`,+ { sceneKey: node.id, fields: differingFields },);}}diff --git a/server/lib/fableLoomOutline.test.js b/server/lib/fableLoomOutline.test.jsindex 8755861745..a9001f2147 100644--- a/server/lib/fableLoomOutline.test.js+++ b/server/lib/fableLoomOutline.test.js@@ -220,6 +220,36 @@ describe('FableLoom story beat outlines', () => {expect(series.stats).toMatchObject({ ready: false, readyEpisodeCount: 0 });});+ it('ignores playbackMode on endings and names differing fields in the mismatch message', () => {+ const storyOutline = sanitizeStoryOutline({+ ...validOutline,+ scenes: validOutline.scenes.map((scene) => {+ if (!scene.isEnding) return scene;+ const { playbackMode: _omitted, ...rest } = scene;+ return rest;+ }),+ });+ expect(storyOutline.scenes.find((scene) => scene.isEnding).playbackMode).toBe('decision');+ const nodes = storyOutline.scenes.map((scene) => ({+ id: scene.key,+ title: scene.title,+ playbackMode: scene.isEnding ? 'cut' : scene.playbackMode,+ audienceConnection: scene.audienceConnection,+ protagonistPresence: scene.protagonistPresence,+ isEnding: scene.isEnding,+ endingLabel: scene.endingLabel,+ transitions: scene.transitions.map((item) => ({ targetNodeId: item.targetKey, intent: item.intent })),+ }));+ const episode = { id: 'ep-1', number: 1, startNodeId: storyOutline.startKey, storyOutline, nodes };+ expect(analyzeStoryOutlineTeleplaySync(episode, storyOutline).stats.matches).toBe(true);++ const other = nodes.find((node) => !node.isEnding);+ other.audienceConnection = other.audienceConnection === 'connected' ? 'disconnected' : 'connected';+ const sync = analyzeStoryOutlineTeleplaySync(episode, storyOutline);+ expect(sync.issues[0].message).toContain('audienceConnection: outline=');+ expect(sync.issues[0]).toMatchObject({ sceneKey: other.id, fields: [expect.objectContaining({ field: 'audienceConnection' })] });+ });+it('allows one structurally sound outline to replace its older teleplay explicitly', () => {const storyOutline = {...sanitizeStoryOutline(validOutline),diff --git a/server/services/fableLoom/weave.js b/server/services/fableLoom/weave.jsindex 1e71baf8ba..8ad697c443 100644--- a/server/services/fableLoom/weave.js+++ b/server/services/fableLoom/weave.js@@ -606,6 +606,11 @@ export async function weaveEpisode(loomId, episodeId, {endingLabel: outlineScene.endingLabel || '',plotPointId: outlineScene.plotPointId || null,challengePhase: outlineScene.challengePhase || null,+ // The validated outline owns the contract; the model owns prose and prompts.+ playbackMode: outlineScene.playbackMode,+ audienceConnection: outlineScene.audienceConnection,+ protagonistPresence: outlineScene.protagonistPresence,+ isEnding: outlineScene.isEnding,transitions: node.transitions.map((transition) => {const paths = outlineScene.transitions.filter((path) => path.targetKey === transition.targetNodeId);const planned = paths.find((path) => path.intent === transition.intent) || (paths.length === 1 ? paths[0] : null);diff --git a/server/services/fableLoom/weave.test.js b/server/services/fableLoom/weave.test.jsindex da971ddb03..ce12bf86fe 100644--- a/server/services/fableLoom/weave.test.js+++ b/server/services/fableLoom/weave.test.js@@ -297,6 +297,41 @@ describe('weaveEpisode', () => {expect(runStagedLLM.mock.calls[1][1].outlineDigest).toContain('[s1] Signal');});+ it('overlays contract fields from the outline when the model drifts (ending emitted as a cut)', async () => {+ const { loomId, episodeId } = await setup();+ runStagedLLM.mockResolvedValueOnce({ content: generatedOutline(), runId: 'outline-run' });+ await generateEpisodeOutline(loomId, episodeId, {});+ await validateEpisodeOutline(loomId, episodeId);+ const graph = generatedGraphFromOutline();+ graph.nodes[2].playbackMode = 'cut';+ graph.nodes[1].audienceConnection = 'connected';+ runStagedLLM.mockResolvedValueOnce({ content: graph, runId: 'drift-expand' });++ const result = await weaveEpisode(loomId, episodeId, { expandFromOutline: true });+ const episode = result.loom.episodes[0];+ const scenes = episode.storyOutline.scenes;+ episode.nodes.forEach((node, i) => {+ expect(node.playbackMode).toBe(scenes[i].playbackMode);+ expect(node.audienceConnection).toBe(scenes[i].audienceConnection);+ expect(node.protagonistPresence).toBe(scenes[i].protagonistPresence);+ expect(node.isEnding).toBe(scenes[i].isEnding);+ });+ expect(episode.nodes[2].playbackMode).toBe('decision');+ });++ it('still rejects a changed transition target and names the scene and field', async () => {+ const { loomId, episodeId } = await setup();+ runStagedLLM.mockResolvedValueOnce({ content: generatedOutline(), runId: 'outline-run' });+ await generateEpisodeOutline(loomId, episodeId, {});+ await validateEpisodeOutline(loomId, episodeId);+ const graph = generatedGraphFromOutline();+ graph.nodes[0].transitions[0].targetKey = 's3';+ runStagedLLM.mockResolvedValueOnce({ content: graph, runId: 'broken-expand' });++ await expect(weaveEpisode(loomId, episodeId, { expandFromOutline: true }))+ .rejects.toThrow(/Signal.*transitions: outline=/);+ });+it('replaces an old teleplay after a structurally valid outline rewrite', async () => {const { loomId, episodeId } = await setup();runStagedLLM.mockResolvedValueOnce({ content: generatedOutline(), runId: 'outline-run' });