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 — STYLE_ID constants, ALL_STYLE_IDS, surface migration parse errors

Adam Eivy322f580f56dc
diff --git a/client/src/components/writers-room/StoryboardPanel.jsx b/client/src/components/writers-room/StoryboardPanel.jsx
index 390c350d40..3d6b17dcd1 100644
--- a/client/src/components/writers-room/StoryboardPanel.jsx
+++ b/client/src/components/writers-room/StoryboardPanel.jsx
@@ -16,10 +16,10 @@ import {
WR_IMAGE_DEFAULTS,
buildCharByKey,
readWrImageSettings,
+ STYLE_ID,
+ EMPTY_IMAGE_STYLE,
} from './sceneCardHelpers';
-const EMPTY_STYLE = { presetId: 'none', prompt: '', negativePrompt: '' };
-
export default function StoryboardPanel({
work,
characters = [],
@@ -39,7 +39,7 @@ export default function StoryboardPanel({
const [stylePresets, setStylePresets] = useState([]);
const mountedRef = useMounted();
- const imageStyle = work.imageStyle || EMPTY_STYLE;
+ const imageStyle = work.imageStyle || EMPTY_IMAGE_STYLE;
useEffect(() => {
let cancelled = false;
@@ -113,7 +113,7 @@ export default function StoryboardPanel({
{scenes.length} scene{scenes.length === 1 ? '' : 's'} · {timeAgo(latestScript.completedAt || latestScript.createdAt, 'never')}
</span>
)}
- {imageStyle.presetId !== 'none' && (
+ {imageStyle.presetId !== STYLE_ID.NONE && (
<button
onClick={() => setShowSettings((v) => !v)}
className="text-port-accent/80 hover:text-port-accent flex items-center gap-1 text-[10px]"
@@ -230,8 +230,8 @@ function StaleBanner({ onRunAdapt, runningAdapt }) {
}
function styleChip(style, presets) {
- if (!style || style.presetId === 'none') return null;
- if (style.presetId === 'custom') return 'Custom style';
+ if (!style || style.presetId === STYLE_ID.NONE) return null;
+ if (style.presetId === STYLE_ID.CUSTOM) return 'Custom style';
const p = presets.find((x) => x.id === style.presetId);
return p?.label || style.presetId;
}
@@ -253,13 +253,13 @@ function WorldStyleRow({ value, presets, onChange }) {
}, [value.presetId, value.prompt, value.negativePrompt]);
const pickPreset = (presetId) => {
- if (presetId === 'none') {
- onChange?.({ presetId: 'none', prompt: '', negativePrompt: '' });
+ if (presetId === STYLE_ID.NONE) {
+ onChange?.(EMPTY_IMAGE_STYLE);
return;
}
- if (presetId === 'custom') {
+ if (presetId === STYLE_ID.CUSTOM) {
// Keep whatever's in the textarea — just flip the discriminator.
- onChange?.({ presetId: 'custom', prompt: draftPrompt, negativePrompt: draftNeg });
+ onChange?.({ presetId: STYLE_ID.CUSTOM, prompt: draftPrompt, negativePrompt: draftNeg });
return;
}
const preset = presets.find((p) => p.id === presetId);
@@ -276,7 +276,7 @@ function WorldStyleRow({ value, presets, onChange }) {
&& matchingPreset.prompt === draftPrompt
&& matchingPreset.negativePrompt === draftNeg;
onChange?.({
- presetId: stillMatchesPreset ? value.presetId : 'custom',
+ presetId: stillMatchesPreset ? value.presetId : STYLE_ID.CUSTOM,
prompt: draftPrompt,
negativePrompt: draftNeg,
});
@@ -288,10 +288,10 @@ function WorldStyleRow({ value, presets, onChange }) {
<span className="text-[9px] uppercase tracking-wider text-gray-500 flex items-center gap-1">
<Palette size={10} /> World style
</span>
- {value.presetId !== 'none' && (
+ {value.presetId !== STYLE_ID.NONE && (
<button
type="button"
- onClick={() => pickPreset('none')}
+ onClick={() => pickPreset(STYLE_ID.NONE)}
className="text-[9px] text-gray-500 hover:text-port-error"
title="Clear style"
>
@@ -304,19 +304,19 @@ function WorldStyleRow({ value, presets, onChange }) {
onChange={(e) => pickPreset(e.target.value)}
className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-[11px] text-gray-200"
>
- <option value="none">None — use scene visualPrompt only</option>
+ <option value={STYLE_ID.NONE}>None — use scene visualPrompt only</option>
<optgroup label="Presets">
{presets.map((p) => (
<option key={p.id} value={p.id}>{p.label}</option>
))}
</optgroup>
- <option value="custom">Custom</option>
+ <option value={STYLE_ID.CUSTOM}>Custom</option>
</select>
- {value.presetId !== 'none' && (
+ {value.presetId !== STYLE_ID.NONE && (
<>
<label className="block">
<span className="text-[9px] uppercase tracking-wider text-gray-500">
- Style prompt {value.presetId === 'custom' && <Check size={9} className="inline text-port-accent" />}
+ Style prompt {value.presetId === STYLE_ID.CUSTOM && <Check size={9} className="inline text-port-accent" />}
</span>
<textarea
value={draftPrompt}
diff --git a/client/src/components/writers-room/sceneCardHelpers.js b/client/src/components/writers-room/sceneCardHelpers.js
index 5b40ed11f9..65c93d8572 100644
--- a/client/src/components/writers-room/sceneCardHelpers.js
+++ b/client/src/components/writers-room/sceneCardHelpers.js
@@ -2,6 +2,13 @@
// (legacy) inline script result. Lives in its own module so SceneCard can be
// imported wherever scenes are rendered without dragging the whole AI panel.
+// Mirror of server/lib/writersRoomStylePresets.js — kept in sync manually
+// since client and server are separate bundles. Curated preset ids come from
+// the /api/writers-room/style-presets endpoint at runtime; only the two
+// special discriminators live here.
+export const STYLE_ID = { NONE: 'none', CUSTOM: 'custom' };
+export const EMPTY_IMAGE_STYLE = { presetId: STYLE_ID.NONE, prompt: '', negativePrompt: '' };
+
// Defaults for the per-scene image gen pipe. Klein-4B is the fastest FLUX.2
// variant on Apple Silicon, and 768×512 is a 3:2 aspect that suits scene work.
// steps + seed are stored as strings (or empty) so the form inputs can bind
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 1a66fc3a7f..983b3830ea 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -2,7 +2,7 @@ import { z } from 'zod';
import { ServerError } from './errorHandler.js';
import { ASPECT_RATIOS, QUALITIES, PROJECT_STATUSES, SCENE_STATUSES } from './creativeDirectorPresets.js';
import { WORK_KINDS, WORK_STATUSES, ANALYSIS_KINDS } from './writersRoomPresets.js';
-import { STYLE_PRESET_IDS, SPECIAL_STYLE_IDS } from './writersRoomStylePresets.js';
+import { ALL_STYLE_IDS, STYLE_ID } from './writersRoomStylePresets.js';
// =============================================================================
// AGENT PERSONALITY SCHEMAS
@@ -498,7 +498,7 @@ export const writersRoomImageStyleSchema = z.object({
// or one of the curated preset ids. The resolved prompt text lives on the
// work — picking a preset later doesn't retroactively change historical
// works' rendering.
- presetId: z.enum(['none', ...SPECIAL_STYLE_IDS.filter((id) => id !== 'none'), ...STYLE_PRESET_IDS]).default('none'),
+ presetId: z.enum(ALL_STYLE_IDS).default(STYLE_ID.NONE),
prompt: z.string().max(2000).default(''),
negativePrompt: z.string().max(2000).default(''),
}).strict();
diff --git a/server/lib/writersRoomStylePresets.js b/server/lib/writersRoomStylePresets.js
index 93b9a9760b..1c95b3f620 100644
--- a/server/lib/writersRoomStylePresets.js
+++ b/server/lib/writersRoomStylePresets.js
@@ -80,7 +80,10 @@ export const STYLE_PRESET_IDS = STYLE_PRESETS.map((p) => p.id);
// 'custom' = user wrote their own prompt without picking a preset.
// 'none' = no style applied (image-gen uses scene visualPrompt verbatim).
-export const SPECIAL_STYLE_IDS = ['none', 'custom'];
+export const STYLE_ID = { NONE: 'none', CUSTOM: 'custom' };
+export const ALL_STYLE_IDS = [STYLE_ID.NONE, STYLE_ID.CUSTOM, ...STYLE_PRESET_IDS];
+
+export const EMPTY_IMAGE_STYLE = { presetId: STYLE_ID.NONE, prompt: '', negativePrompt: '' };
export function findStylePreset(id) {
return STYLE_PRESETS.find((p) => p.id === id) || null;
diff --git a/server/services/writersRoom/evaluator.js b/server/services/writersRoom/evaluator.js
index 1bdcf11871..3aac7c0ce2 100644
--- a/server/services/writersRoom/evaluator.js
+++ b/server/services/writersRoom/evaluator.js
@@ -290,9 +290,10 @@ async function migrateLegacyAnalyses(workId) {
.filter((id) => LEGACY_ANALYSIS_ID_RE.test(id));
if (legacy.length === 0) return 0;
const loaded = (await Promise.all(legacy.map(async (id) => {
- const content = await readFile(join(dir, `${id}.json`), 'utf-8').catch(() => null);
+ const path = join(dir, `${id}.json`);
+ const content = await readFile(path, 'utf-8').catch(() => null);
if (content === null) return null;
- const parsed = safeJSONParse(content, null, { allowArray: false });
+ const parsed = safeJSONParse(content, null, { allowArray: false, logError: true, context: path });
return parsed ? { id, snapshot: parsed } : null;
}))).filter(Boolean);