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

refactor(writers-room): simplify pass

Adam Eivy6ab5526878f5
diff --git a/client/src/components/writers-room/WorkEditor.jsx b/client/src/components/writers-room/WorkEditor.jsx
index a0553bd117..30201b2aee 100644
--- a/client/src/components/writers-room/WorkEditor.jsx
+++ b/client/src/components/writers-room/WorkEditor.jsx
@@ -111,12 +111,13 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
// mirror their lists here so the storyboard's image-prompt enrichment picks
// up edits immediately.
useEffect(() => {
- listWritersRoomCharacters(work.id)
- .then((list) => setCharacters(list || []))
- .catch(() => setCharacters([]));
- listWritersRoomSettings(work.id)
- .then((list) => setSettings(list || []))
- .catch(() => setSettings([]));
+ Promise.all([
+ listWritersRoomCharacters(work.id).catch(() => []),
+ listWritersRoomSettings(work.id).catch(() => []),
+ ]).then(([chars, sets]) => {
+ setCharacters(chars || []);
+ setSettings(sets || []);
+ });
}, [work.id]);
const dirty = body !== savedBody;
@@ -263,11 +264,11 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
// reference. Bails on first failure (the failed step's toast already fired).
const runFullPipeline = useCallback(async () => {
if (runningKind) return;
- const okChars = await runAnalysis('characters');
+ const okChars = await runAnalysis(ANALYSIS_KIND.CHARACTERS);
if (!okChars || !mountedRef.current) return;
- const okSettings = await runAnalysis('settings');
+ const okSettings = await runAnalysis(ANALYSIS_KIND.SETTINGS);
if (!okSettings || !mountedRef.current) return;
- await runAnalysis('script');
+ await runAnalysis(ANALYSIS_KIND.SCRIPT);
}, [runAnalysis, runningKind]);
const applyFormatText = (text) => {
diff --git a/client/src/components/writers-room/sceneCardHelpers.js b/client/src/components/writers-room/sceneCardHelpers.js
index 955f18a503..ede394d3f3 100644
--- a/client/src/components/writers-room/sceneCardHelpers.js
+++ b/client/src/components/writers-room/sceneCardHelpers.js
@@ -66,7 +66,7 @@ export function matchSceneCharacters(sceneCharacterNames = [], charByKey) {
// Match server's normalizeSlugline in services/writersRoom/settings.js — the
// pair has to agree byte-for-byte or the bible's match keys won't line up
// with the live scene matching here.
-export const normSlugline = (s) => String(s || '')
+export const normalizeSlugline = (s) => String(s || '')
.toUpperCase()
.replace(/[—–-]/g, ' ')
.replace(/[.,:;]/g, '')
@@ -76,7 +76,7 @@ export const normSlugline = (s) => String(s || '')
export function buildSettingByKey(allSettings) {
const map = new Map();
for (const setting of allSettings || []) {
- const key = normSlugline(setting.slugline || setting.name);
+ const key = normalizeSlugline(setting.slugline || setting.name);
if (!key) continue;
map.set(key, setting);
}
@@ -85,7 +85,7 @@ export function buildSettingByKey(allSettings) {
export function matchSceneSetting(sceneSlugline, settingByKey) {
if (!sceneSlugline) return null;
- return settingByKey?.get(normSlugline(sceneSlugline)) || null;
+ return settingByKey?.get(normalizeSlugline(sceneSlugline)) || null;
}
const PROMPT_MAX = 1900;
@@ -149,9 +149,3 @@ export function buildScenePrompt(workTitle, scene, matchedCharacters, worldStyle
if (visual) segs.push(visual);
return segs.filter(Boolean).join(' ').slice(0, PROMPT_MAX);
}
-
-// Backward-compatible alias — older callers (and tests) used the previous
-// name. New code should use `buildScenePrompt` so the setting param is
-// discoverable.
-export const buildScenePromptWithCharacters = (workTitle, scene, matchedCharacters, worldStyle = '') =>
- buildScenePrompt(workTitle, scene, matchedCharacters, worldStyle, null);
diff --git a/server/services/writersRoom/evaluator.js b/server/services/writersRoom/evaluator.js
index c22cc2c32b..22529f0344 100644
--- a/server/services/writersRoom/evaluator.js
+++ b/server/services/writersRoom/evaluator.js
@@ -507,14 +507,16 @@ export async function runAnalysis(workId, { kind } = {}) {
weather: s.weather,
recurringDetails: s.recurringDetails,
});
- if (kind === 'characters' || kind === 'script') {
- const existing = await listCharacters(workId);
- variables.existingCharactersJson = JSON.stringify(existing.map(trimCharacter), null, 2);
- }
- if (kind === 'settings' || kind === 'script') {
- const existing = await listSettings(workId);
- variables.existingSettingsJson = JSON.stringify(existing.map(trimSetting), null, 2);
- }
+ // For 'script' both bibles load — fire them in parallel so the script
+ // pipeline doesn't pay two sequential disk reads. For 'characters' or
+ // 'settings' alone Promise.all is degenerate (one element) but the shape
+ // keeps the call site uniform.
+ const [existingChars, existingSets] = await Promise.all([
+ (kind === 'characters' || kind === 'script') ? listCharacters(workId) : null,
+ (kind === 'settings' || kind === 'script') ? listSettings(workId) : null,
+ ]);
+ if (existingChars) variables.existingCharactersJson = JSON.stringify(existingChars.map(trimCharacter));
+ if (existingSets) variables.existingSettingsJson = JSON.stringify(existingSets.map(trimSetting));
const temperature = kind === 'format' ? 0.2 : 0.4;
const { content, model: usedModel, providerId: usedProvider } = await callAI(stage, variables, temperature);