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(world-builder): simplify holistic refine helpers

[._.]/ Adam Eivy38e0f599f863
diff --git a/client/src/components/worldBuilder/WorldPromptRefineModal.jsx b/client/src/components/worldBuilder/WorldPromptRefineModal.jsx
index 034c938b44..2f787d08f3 100644
--- a/client/src/components/worldBuilder/WorldPromptRefineModal.jsx
+++ b/client/src/components/worldBuilder/WorldPromptRefineModal.jsx
@@ -474,26 +474,28 @@ function diffItems(orig, fresh) {
return rows;
}
+const DIFF_ACCENTS = {
+ added: 'border-port-success/40 bg-port-success/5',
+ removed: 'border-port-error/40 bg-port-error/5',
+ changed: 'border-port-accent/40 bg-port-accent/5',
+ locked: 'border-port-accent/20 bg-port-bg',
+ unchanged: 'border-port-border bg-port-bg',
+};
+
+const DIFF_BADGES = {
+ added: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-success"><Plus className="w-3 h-3" /> Added</span>,
+ removed: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-error"><Minus className="w-3 h-3" /> Removed</span>,
+ changed: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-accent">Changed</span>,
+ locked: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-accent"><Lock className="w-3 h-3" /> Locked</span>,
+ unchanged: <span className="text-[10px] uppercase tracking-wide text-gray-500">Unchanged</span>,
+};
+
function DiffRow({ status, current, previous }) {
- const accents = {
- added: 'border-port-success/40 bg-port-success/5',
- removed: 'border-port-error/40 bg-port-error/5',
- changed: 'border-port-accent/40 bg-port-accent/5',
- locked: 'border-port-accent/20 bg-port-bg',
- unchanged: 'border-port-border bg-port-bg',
- };
- const badges = {
- added: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-success"><Plus className="w-3 h-3" /> Added</span>,
- removed: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-error"><Minus className="w-3 h-3" /> Removed</span>,
- changed: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-accent">Changed</span>,
- locked: <span className="inline-flex items-center gap-1 text-[10px] uppercase tracking-wide text-port-accent"><Lock className="w-3 h-3" /> Locked</span>,
- unchanged: <span className="text-[10px] uppercase tracking-wide text-gray-500">Unchanged</span>,
- };
return (
- <div className={`border rounded p-2 ${accents[status]}`}>
+ <div className={`border rounded p-2 ${DIFF_ACCENTS[status]}`}>
<div className="flex items-center justify-between gap-2 mb-1">
<div className="text-xs font-medium text-white truncate">{current.label}</div>
- {badges[status]}
+ {DIFF_BADGES[status]}
</div>
{status === 'changed' && (
<div className="text-[11px] text-gray-500 whitespace-pre-wrap line-clamp-2 line-through">
diff --git a/server/services/worldBuilderRefine.js b/server/services/worldBuilderRefine.js
index 25b76a92e2..2078426061 100644
--- a/server/services/worldBuilderRefine.js
+++ b/server/services/worldBuilderRefine.js
@@ -18,7 +18,6 @@ import { resolveEffectiveModel } from "../lib/promptRunner.js";
import {
COMPOSITE_PROMPT_MAX,
COMPOSITE_SHEETS_MAX,
- COMPOSITE_SHEET_KINDS,
LOCKABLE_FIELDS,
LOCKABLE_FIELD_LABELS,
LOGLINE_MAX,
@@ -308,9 +307,13 @@ const mergeCategoriesWithLocks = (originalCategories, llmCategories) => {
const fresh = (llmCategories && typeof llmCategories === "object") ? llmCategories : {};
const merged = {};
- for (const [rawKey, origCat] of Object.entries(orig)) {
- const key = normalizeCategoryKey(rawKey) || rawKey;
- const origVars = Array.isArray(origCat?.variations) ? origCat.variations : [];
+ const allKeys = new Set([
+ ...Object.keys(orig).map((k) => normalizeCategoryKey(k) || k),
+ ...Object.keys(fresh).map((k) => normalizeCategoryKey(k) || k),
+ ]);
+
+ for (const key of allKeys) {
+ const origVars = Array.isArray(orig?.[key]?.variations) ? orig[key].variations : [];
const llmVars = Array.isArray(fresh?.[key]?.variations) ? fresh[key].variations : [];
const lockedOrig = origVars.filter((v) => v?.locked === true);
const lockedLabels = new Set(lockedOrig.map((v) => normalizeLabelKey(v.label)));
@@ -325,13 +328,6 @@ const mergeCategoriesWithLocks = (originalCategories, llmCategories) => {
merged[key] = { variations: out };
}
- for (const [rawKey, cat] of Object.entries(fresh)) {
- const key = normalizeCategoryKey(rawKey) || rawKey;
- if (merged[key]) continue;
- if (!cat || typeof cat !== "object") continue;
- merged[key] = { variations: Array.isArray(cat.variations) ? cat.variations : [] };
- }
-
return sanitizeCategories(merged);
};
@@ -346,11 +342,7 @@ const mergeCompositesWithLocks = (originalSheets, llmSheets) => {
if (!s || typeof s !== "object") continue;
const label = typeof s.label === "string" ? s.label.trim() : "";
if (!label || lockedLabels.has(normalizeLabelKey(label))) continue;
- merged.push({
- kind: COMPOSITE_SHEET_KINDS.includes(s.kind) ? s.kind : "reference_sheet",
- label,
- prompt: typeof s.prompt === "string" ? s.prompt : "",
- });
+ merged.push({ kind: s.kind, label, prompt: s.prompt });
}
return sanitizeCompositeSheets(merged);
};