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: address FableLoom audience review gaps

Adam Eivyf0acab0f133e
diff --git a/client/src/components/fableloom/LoomPlayPanel.jsx b/client/src/components/fableloom/LoomPlayPanel.jsx
index a78024397a..b6fca8ad78 100644
--- a/client/src/components/fableloom/LoomPlayPanel.jsx
+++ b/client/src/components/fableloom/LoomPlayPanel.jsx
@@ -67,8 +67,8 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
const ended = !!scene && (scene.isEnding || !scene.choices?.length);
const audienceConnected = audienceCanParticipate(loom, scene);
const automaticCut = !!scene && !scene.isEnding
- && (scene.playbackMode === 'cut' || !audienceConnected)
- && scene.choices?.length === 1;
+ && scene.choices?.length > 0
+ && (!audienceConnected || (scene.playbackMode === 'cut' && scene.choices.length === 1));
const restart = () => {
setScene(start);
@@ -177,8 +177,9 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
if (turn.role === 'scene') {
if (previewMode === 'video' || i === latestSceneTurnIndex) return null;
const historicalCut = !turn.node.isEnding
- && turn.node.playbackMode === 'cut'
- && turn.node.choices?.length === 1;
+ && turn.node.choices?.length > 0
+ && (!audienceCanParticipate(loom, turn.node)
+ || (turn.node.playbackMode === 'cut' && turn.node.choices.length === 1));
return (
<SceneCard
key={i}
@@ -186,6 +187,7 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
format={loom.format}
previewMode={previewMode}
automaticCut={historicalCut}
+ helperMode={loom.participationMode === 'helper'}
/>
);
}
@@ -210,6 +212,7 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
previewMode={previewMode}
onCutEnded={advanceCut}
automaticCut={automaticCut}
+ helperMode={loom.participationMode === 'helper'}
videoFailed={failedVideoId === scene.videoHistoryId}
onVideoError={() => setFailedVideoId(scene.videoHistoryId)}
/>
@@ -303,7 +306,7 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
function SceneCard({
node, isOpening = false, format, previewMode, onCutEnded, automaticCut,
- videoFailed = false, onVideoError,
+ helperMode = false, videoFailed = false, onVideoError,
}) {
if (!node) return null;
const showVideo = previewMode === 'video' && node.videoHistoryId && !videoFailed;
@@ -343,7 +346,11 @@ function SceneCard({
<p className="mt-2 text-xs text-port-text-muted">
{automaticCut
? 'Automatic cut'
- : node.audienceConnection === 'connected' ? 'Audience connected — waits for input' : 'Decision loop — waits for viewer input'}
+ : helperMode && node.audienceConnection !== 'connected'
+ ? 'Canon path — audience disconnected'
+ : node.audienceConnection === 'connected'
+ ? 'Audience connected — waits for input'
+ : 'Decision loop — waits for viewer input'}
</p>
)}
</div>
diff --git a/client/src/components/fableloom/LoomPlayPanel.test.jsx b/client/src/components/fableloom/LoomPlayPanel.test.jsx
index a3fe9f32e2..ef7c5c1576 100644
--- a/client/src/components/fableloom/LoomPlayPanel.test.jsx
+++ b/client/src/components/fableloom/LoomPlayPanel.test.jsx
@@ -37,18 +37,29 @@ describe('LoomPlayPanel', () => {
expect(screen.getByRole('button', { name: 'Take path: enter the gate' })).toBeInTheDocument();
});
- it('keeps a helper audience passive until the configured channel connects', () => {
+ it('keeps a helper audience passive and follows the first canon path until the channel connects', async () => {
+ const user = userEvent.setup();
const helperEpisode = {
id: 'ep-helper', startNodeId: 'opening', nodes: [{
id: 'opening', title: 'Opening', prose: 'The protagonist walks alone.',
playbackMode: 'cut', audienceConnection: 'disconnected',
- transitions: [{ id: 'continue', targetNodeId: 'radio', intent: 'Continue' }],
+ transitions: [
+ { id: 'continue', targetNodeId: 'radio', intent: 'Continue' },
+ { id: 'legacy-choice', targetNodeId: 'other', intent: 'Legacy choice' },
+ ],
}, {
id: 'radio', title: 'Radio', prose: 'The radio crackles.',
playbackMode: 'decision', audienceConnection: 'connected',
transitions: [{ id: 'answer', targetNodeId: 'end', intent: 'warn them' }],
}],
};
+ playLoomTurn.mockResolvedValue({
+ action: 'move', resolvedBy: 'graph', narration: '', ended: false,
+ node: {
+ id: 'radio', title: 'Radio', prose: 'The radio crackles.',
+ playbackMode: 'decision', audienceConnection: 'connected', choices: [],
+ },
+ });
render(<LoomPlayPanel
loom={{
...loom,
@@ -63,6 +74,10 @@ describe('LoomPlayPanel', () => {
expect(screen.queryByLabelText('Your action')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Take path: Continue' })).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Next cut' })).toBeEnabled();
+ await user.click(screen.getByRole('button', { name: 'Next cut' }));
+ await waitFor(() => expect(playLoomTurn).toHaveBeenCalledWith(
+ 'loom-1', 'ep-helper', expect.objectContaining({ transitionId: 'continue' }), { silent: true },
+ ));
});
it('sends a tapped path as a transition id, not as free text to match', async () => {
diff --git a/client/src/components/fableloom/LoomSettingsDrawer.jsx b/client/src/components/fableloom/LoomSettingsDrawer.jsx
index fd5d292e34..89add9ee3c 100644
--- a/client/src/components/fableloom/LoomSettingsDrawer.jsx
+++ b/client/src/components/fableloom/LoomSettingsDrawer.jsx
@@ -16,7 +16,7 @@
* all, so this only governs typed input.
*/
-import { useRef, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { Loader2, Sparkles } from 'lucide-react';
import Drawer from '../Drawer';
import ProviderModelSelector from '../ProviderModelSelector';
@@ -53,6 +53,11 @@ export default function LoomSettingsDrawer({ open, onClose, loom, onLoomUpdate,
const format = loom.format || 'prose';
const [participationMode, setParticipationMode] = useState(loom.participationMode || 'protagonist');
const [communicationMedium, setCommunicationMedium] = useState(loom.audienceCommunicationMedium || '');
+ useEffect(() => {
+ if (open) return;
+ setParticipationMode(loom.participationMode || 'protagonist');
+ setCommunicationMedium(loom.audienceCommunicationMedium || '');
+ }, [open, loom.participationMode, loom.audienceCommunicationMedium]);
const play = loom.playSettings || {};
const playProvider = providers.find((p) => p.id === play.providerId);
// Only scenes not already in the target format are sent, so this is what the
@@ -191,6 +196,11 @@ export default function LoomSettingsDrawer({ open, onClose, loom, onLoomUpdate,
}}
placeholder="How the protagonist hears the audience: radio, telepathy, magic device, phone…"
/>
+ {!communicationMedium.trim() && (
+ <p className="text-xs text-port-warning mt-1">
+ Helper stories need a communication medium before the role can be saved.
+ </p>
+ )}
</FormField>
)}
</section>
diff --git a/client/src/components/fableloom/LoomSettingsDrawer.test.jsx b/client/src/components/fableloom/LoomSettingsDrawer.test.jsx
index 6e76cadfc4..0f09e1bdc7 100644
--- a/client/src/components/fableloom/LoomSettingsDrawer.test.jsx
+++ b/client/src/components/fableloom/LoomSettingsDrawer.test.jsx
@@ -171,6 +171,7 @@ describe('LoomSettingsDrawer audience participation', () => {
renderDrawer({ ...makeLoom([]), participationMode: 'protagonist' });
await user.selectOptions(screen.getByLabelText('Audience role'), 'helper');
+ expect(screen.getByText(/need a communication medium before the role can be saved/i)).toBeInTheDocument();
await user.type(screen.getByLabelText('Communication medium'), 'A silver mirror.');
await user.tab();
@@ -179,4 +180,23 @@ describe('LoomSettingsDrawer audience participation', () => {
audienceCommunicationMedium: 'A silver mirror.',
}, { silent: true }));
});
+
+ it('resets an unsaved helper selection when the drawer closes', async () => {
+ const user = userEvent.setup();
+ const loom = { ...makeLoom([]), participationMode: 'protagonist' };
+ const props = {
+ loom,
+ onClose: () => {},
+ onLoomUpdate: vi.fn(),
+ onRewritten: vi.fn(),
+ };
+ const { rerender } = render(<LoomSettingsDrawer open {...props} />);
+
+ await user.selectOptions(screen.getByLabelText('Audience role'), 'helper');
+ expect(updateLoom).not.toHaveBeenCalled();
+ rerender(<LoomSettingsDrawer open={false} {...props} />);
+ rerender(<LoomSettingsDrawer open {...props} />);
+
+ expect(screen.getByLabelText('Audience role')).toHaveValue('protagonist');
+ });
});
diff --git a/server/lib/fableLoomGraph.js b/server/lib/fableLoomGraph.js
index ee4d5e002d..970d98ca70 100644
--- a/server/lib/fableLoomGraph.js
+++ b/server/lib/fableLoomGraph.js
@@ -197,7 +197,9 @@ export function analyzeEpisodeGraph(episode, {
* `proseLimit` truncates each node's prose so a large graph stays inside the
* stage's context window.
*/
-export function describeGraphForPrompt(episode, { proseLimit = 400 } = {}) {
+export function describeGraphForPrompt(episode, {
+ proseLimit = 400, participationMode = 'protagonist',
+} = {}) {
const nodes = asArray(episode?.nodes);
const lines = [];
for (const node of nodes) {
@@ -205,7 +207,9 @@ export function describeGraphForPrompt(episode, { proseLimit = 400 } = {}) {
node.id === episode?.startNodeId ? 'START' : null,
node?.isEnding ? `ENDING${isStr(node?.endingLabel) ? `: ${node.endingLabel}` : ''}` : null,
node?.isEnding ? null : (node?.playbackMode === 'cut' ? 'AUTO CUT' : 'DECISION LOOP'),
- node?.audienceConnection === 'connected' ? 'AUDIENCE CONNECTED' : 'AUDIENCE DISCONNECTED',
+ participationMode === 'helper'
+ ? (node?.audienceConnection === 'connected' ? 'AUDIENCE CONNECTED' : 'AUDIENCE DISCONNECTED')
+ : null,
].filter(Boolean);
lines.push(`[${node.id}] ${node.title || 'Untitled scene'}${flags.length ? ` (${flags.join(') (')})` : ''}`);
const prose = typeof node.prose === 'string' ? node.prose.trim() : '';
diff --git a/server/lib/fableLoomGraph.test.js b/server/lib/fableLoomGraph.test.js
index 4c51a9a0fb..488184c097 100644
--- a/server/lib/fableLoomGraph.test.js
+++ b/server/lib/fableLoomGraph.test.js
@@ -135,6 +135,25 @@ describe('analyzeEpisodeGraph', () => {
expect(connectedCodes).not.toContain(GRAPH_ISSUE_CODES.DISCONNECTED_DECISION);
});
+ it('warns when a helper audience is not connected until after the opening sequence', () => {
+ const nodes = Array.from({ length: 6 }, (_, index) => ({
+ id: `n${index}`,
+ title: `Scene ${index}`,
+ playbackMode: index < 4 ? 'cut' : 'decision',
+ audienceConnection: index === 4 ? 'connected' : 'disconnected',
+ isEnding: index === 5,
+ transitions: index === 5 ? [] : [tr(`t${index}`, `n${index + 1}`, 'Continue')],
+ }));
+ const { issues } = analyzeEpisodeGraph({ startNodeId: 'n0', nodes }, {
+ participationMode: 'helper', requireAudienceIntroduction: true,
+ });
+ expect(issues).toContainEqual(expect.objectContaining({
+ code: GRAPH_ISSUE_CODES.LATE_AUDIENCE_CONNECTION,
+ severity: 'warning',
+ nodeId: 'n4',
+ }));
+ });
+
it('warns on unreachable nodes and errors when no ending is reachable', () => {
const ep = soundEpisode();
ep.nodes.push({ id: 'n9', title: 'Orphan', transitions: [tr('t9', 'n4', 'onward')] });
@@ -197,4 +216,13 @@ describe('describeGraphForPrompt', () => {
ep.nodes[0].transitions[0].triggers = ['go in', 'open the gate'];
expect(describeGraphForPrompt(ep)).toContain('(triggers: go in; open the gate)');
});
+
+ it('renders connection flags only for helper stories', () => {
+ const ep = soundEpisode();
+ ep.nodes[0].audienceConnection = 'connected';
+ expect(describeGraphForPrompt(ep, { participationMode: 'helper' }))
+ .toContain('(START) (DECISION LOOP) (AUDIENCE CONNECTED)');
+ expect(describeGraphForPrompt(ep)).not.toContain('AUDIENCE CONNECTED');
+ expect(describeGraphForPrompt(ep)).not.toContain('AUDIENCE DISCONNECTED');
+ });
});
diff --git a/server/services/fableLoom/records.js b/server/services/fableLoom/records.js
index b621227999..c9119eb3c8 100644
--- a/server/services/fableLoom/records.js
+++ b/server/services/fableLoom/records.js
@@ -423,6 +423,11 @@ export function addNode(loomId, episodeId, fields = {}) {
throw new ServerError('Scene limit reached', { status: 400, code: 'LIMIT_REACHED' });
}
const node = { id: `node-${randomUUID()}`, ...fields };
+ if (asFableLoomParticipationMode(loom.participationMode) === 'helper'
+ && asFableLoomAudienceConnection(fields.audienceConnection) !== 'connected'
+ && !('playbackMode' in fields)) {
+ node.playbackMode = 'cut';
+ }
episode.nodes.push(node);
if (!episode.startNodeId) episode.startNodeId = node.id;
// Optionally wire the new node in as a branch of an existing one. The
diff --git a/server/services/fableLoom/records.test.js b/server/services/fableLoom/records.test.js
index 55d3b83a09..670e0d207b 100644
--- a/server/services/fableLoom/records.test.js
+++ b/server/services/fableLoom/records.test.js
@@ -242,8 +242,13 @@ describe('audience participation round-trip', () => {
audienceCommunicationMedium: 'A hand-cranked radio carried by the protagonist.',
});
loom = await addEpisode(loom.id, { title: 'Pilot' });
+ loom = await addNode(loom.id, loom.episodes[0].id);
+ expect(loom.episodes[0].nodes[0]).toMatchObject({
+ audienceConnection: 'disconnected',
+ playbackMode: 'cut',
+ });
loom = await addNode(loom.id, loom.episodes[0].id, { audienceConnection: 'connected' });
- expect(loom.episodes[0].nodes[0].audienceConnection).toBe('connected');
+ expect(loom.episodes[0].nodes[1].audienceConnection).toBe('connected');
await expect(updateLoom(loom.id, { audienceCommunicationMedium: '' }))
.rejects.toMatchObject({ code: 'AUDIENCE_MEDIUM_REQUIRED' });
diff --git a/server/services/fableLoom/weave.js b/server/services/fableLoom/weave.js
index f5fc0017c8..8b3ab53967 100644
--- a/server/services/fableLoom/weave.js
+++ b/server/services/fableLoom/weave.js
@@ -38,7 +38,6 @@ const TRANSCRIPT_TURNS_MAX = 12;
const AUDIENCE_GRAPH_ERROR_CODES = new Set([
GRAPH_ISSUE_CODES.NO_AUDIENCE_CONNECTION,
GRAPH_ISSUE_CODES.DISCONNECTED_DECISION,
- GRAPH_ISSUE_CODES.CUT_TRANSITION_COUNT,
]);
const clamp = (value, min, max, fallback) =>
@@ -219,7 +218,7 @@ export async function weaveEpisode(loomId, episodeId, {
canonDigest: canonDigest || '(none — invent what the story needs)',
guidance: guidance || '(none)',
existingGraph: episode.nodes.length
- ? describeGraphForPrompt(episode, { proseLimit: 1200 })
+ ? describeGraphForPrompt(episode, { proseLimit: 1200, participationMode: loom.participationMode })
: '(none — create the episode from the story context)',
cameraMovementCatalog: fableLoomCameraMovementCatalogForPrompt(),
sceneFormatContract: sceneFormatContract(loom.format),
@@ -234,7 +233,11 @@ export async function weaveEpisode(loomId, episodeId, {
participationMode: 'helper',
requireAudienceIntroduction: requiresAudienceIntroduction(loom, episode),
},
- ).issues.filter((issue) => issue.severity === 'error' && AUDIENCE_GRAPH_ERROR_CODES.has(issue.code));
+ ).issues.filter((issue) => issue.severity === 'error' && (
+ AUDIENCE_GRAPH_ERROR_CODES.has(issue.code)
+ || (issue.code === GRAPH_ISSUE_CODES.CUT_TRANSITION_COUNT
+ && nodes.find((node) => node.id === issue.nodeId)?.audienceConnection !== 'connected')
+ ));
if (audienceErrors.length) {
throw aiShapeError(`The model returned an invalid audience connection graph: ${audienceErrors[0].message}`);
}
@@ -271,7 +274,10 @@ export async function branchNode(loomId, episodeId, nodeId, {
const { content, runId } = await runStagedLLM('fableloom-branch-node', {
storyContext: storyContext(loom, episode),
canonDigest: canonDigest || '(none — invent what the story needs)',
- graphDigest: describeGraphForPrompt(episode, { proseLimit: 200 }),
+ graphDigest: describeGraphForPrompt(episode, {
+ proseLimit: 200,
+ participationMode: loom.participationMode,
+ }),
sceneTitle: node.title || 'Untitled scene',
sceneProse: node.prose || '(no prose yet)',
branchCount: String(count),
@@ -330,7 +336,7 @@ export async function reviewEpisode(loomId, episodeId, { providerId, model, effo
});
const { content, runId } = await runStagedLLM('fableloom-review', {
storyContext: storyContext(loom, episode),
- graphDigest: describeGraphForPrompt(episode),
+ graphDigest: describeGraphForPrompt(episode, { participationMode: loom.participationMode }),
structuralDigest: structural.issues.length
? structural.issues.map((i) => `- [${i.severity}] ${i.message}`).join('\n')
: '(no structural issues)',
@@ -447,7 +453,10 @@ export async function feedbackEpisode(loomId, episodeId, {
const { content, runId } = await runStagedLLM('fableloom-feedback-episode', {
storyContext: storyContext(loom, episode),
canonDigest: canonDigest || '(none)',
- graphDigest: describeGraphForPrompt(episode, { proseLimit: 1200 }),
+ graphDigest: describeGraphForPrompt(episode, {
+ proseLimit: 1200,
+ participationMode: loom.participationMode,
+ }),
cameraMovementCatalog: fableLoomCameraMovementCatalogForPrompt(),
feedback: instruction,
}, llmOptions({ providerId, model, effort }, 'fableloom-feedback'));
@@ -674,13 +683,16 @@ export async function playTurn(loomId, episodeId, {
}
if (transitionId) {
- const taken = node.transitions.find((t) => t.id === transitionId);
+ const interactive = audienceCanParticipate(loom, node);
+ const taken = interactive
+ ? node.transitions.find((t) => t.id === transitionId)
+ : node.transitions[0];
if (!taken) {
throw new ServerError('That path is not on this scene', { status: 400, code: 'INVALID_TRANSITION' });
}
return moveResult(episode, node, taken, {
narration: '',
- resolvedBy: audienceCanParticipate(loom, node) ? 'choice' : 'graph',
+ resolvedBy: interactive ? 'choice' : 'graph',
});
}
diff --git a/server/services/fableLoom/weave.test.js b/server/services/fableLoom/weave.test.js
index 34cb158669..8849a4b9f8 100644
--- a/server/services/fableLoom/weave.test.js
+++ b/server/services/fableLoom/weave.test.js
@@ -371,19 +371,25 @@ describe('playTurn', () => {
});
it('locks typed audience input out while a helper channel is disconnected but permits canon advance', async () => {
- const { loomId, episodeId, gate, insideId } = await playSetup();
+ const { loomId, episodeId, gate: originalGate, insideId } = await playSetup();
await updateLoom(loomId, {
participationMode: 'helper',
audienceCommunicationMedium: 'A pocket radio.',
});
- await updateNode(loomId, episodeId, gate.id, {
+ await updateNode(loomId, episodeId, originalGate.id, {
playbackMode: 'cut', audienceConnection: 'disconnected',
});
+ await mutateLoom(loomId, (loom) => {
+ const gate = loom.episodes[0].nodes.find((node) => node.id === originalGate.id);
+ gate.transitions.push({ id: 'alternate-path', targetNodeId: insideId, intent: 'Choose a different route' });
+ return loom;
+ });
+ const gate = (await getLoom(loomId)).episodes[0].nodes.find((node) => node.id === originalGate.id);
await expect(playTurn(loomId, episodeId, { nodeId: gate.id, message: 'Can you hear me?' }))
.rejects.toMatchObject({ code: 'AUDIENCE_DISCONNECTED' });
const advanced = await playTurn(loomId, episodeId, {
- nodeId: gate.id, transitionId: gate.transitions[0].id,
+ nodeId: gate.id, transitionId: 'alternate-path',
});
expect(advanced).toMatchObject({ action: 'move', resolvedBy: 'graph' });
expect(advanced.node.id).toBe(insideId);