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

address review (codex): remix seed honors user-defined catalog types

[._.]/ Adam Eivy6ceba799efbf
diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsx
index 4de59f45a0..0573b43cbe 100644
--- a/client/src/pages/StoryBuilder.jsx
+++ b/client/src/pages/StoryBuilder.jsx
@@ -32,6 +32,7 @@ import ArcCanvas from '../components/pipeline/ArcCanvas';
import { useArcCanvasSync } from '../hooks/useArcCanvasSync';
import { BEAT_KIND_COLORS, getBeatKindColor } from '../lib/beatColors';
import { getCatalogType, payloadSnippet } from '../lib/catalogTypes';
+import { useCatalogTypes } from '../hooks/useCatalogTypes.jsx';
// Mirror Importer.jsx's commit picker — only these arc fields are sent on commit.
const ARC_FIELDS_TO_COMMIT = ['logline', 'summary', 'protagonistArc', 'themes', 'shape'];
@@ -64,15 +65,19 @@ const SEED_SUMMARY_CHARS = 120;
// "character" → "Characters:" — prefer the catalog registry's canonical label
// (so idea/scene/concept get proper plurals), naive-pluralizing a user-defined
-// type's id as a fallback. Mirrors `seedGroupHeading` in server storyBuilder.js
-// so the prefill the user sees matches the server's fallback composition.
-function seedGroupHeading(type) {
- const label = getCatalogType(type)?.label;
- const base = label || (type ? `${type.charAt(0).toUpperCase()}${type.slice(1)}` : 'Other');
+// type's id as a fallback. `resolveType` (the merged useCatalogTypes registry)
+// covers user-defined types; falls back to the built-in registry. Mirrors
+// `seedGroupHeading` in server storyBuilder.js.
+function seedGroupHeading(type, resolveType) {
+ const typeDef = (resolveType && resolveType(type)) || getCatalogType(type);
+ const base = typeDef?.label || (type ? `${type.charAt(0).toUpperCase()}${type.slice(1)}` : 'Other');
return base.endsWith('s') ? base : `${base}s`;
}
-export function composeSeedFromIngredients(ingredients) {
+// `resolveType` is the merged catalog-type registry (useCatalogTypes().getType)
+// so a user-defined type's label + snippetFallbackKeys are honored; without it
+// the built-in six are used.
+export function composeSeedFromIngredients(ingredients, resolveType = null) {
const list = Array.isArray(ingredients) ? ingredients : [];
if (list.length === 0) return '';
// Preserve first-seen group order so the prefill reads in selection order.
@@ -85,10 +90,10 @@ export function composeSeedFromIngredients(ingredients) {
}
const lines = [];
for (const [type, members] of groups) {
- lines.push(`${seedGroupHeading(type)}:`);
+ lines.push(`${seedGroupHeading(type, resolveType)}:`);
for (const ing of members) {
const name = (ing.name || '').trim() || '(untitled)';
- const summary = payloadSnippet(ing.payload, ing.type, SEED_SUMMARY_CHARS);
+ const summary = payloadSnippet(ing.payload, ing.type, SEED_SUMMARY_CHARS, resolveType);
lines.push(summary ? `- ${name}: ${summary}` : `- ${name}`);
}
lines.push('');
@@ -142,6 +147,9 @@ function StoryBuilderIndex() {
const navigate = useNavigate();
const location = useLocation();
const [searchParams] = useSearchParams();
+ // Merged catalog-type registry (system + user-defined) so the remix seed
+ // prefill honors a user-defined type's snippetFallbackKeys, not just the six.
+ const { getType } = useCatalogTypes();
// The "Start a Story" onramp can deep-link here with a pre-chosen universe
// (?universeId=…); pass it through so the new session attaches to it instead
// of auto-creating a fresh universe. The create schema already accepts it.
@@ -175,7 +183,7 @@ function StoryBuilderIndex() {
const list = Array.isArray(res) ? res : (Array.isArray(res?.items) ? res.items : []);
setRemixIngredients(list);
// Prefill only if the user hasn't already typed a seed — don't clobber.
- setSeedIdea((prev) => (prev.trim() ? prev : composeSeedFromIngredients(list)));
+ setSeedIdea((prev) => (prev.trim() ? prev : composeSeedFromIngredients(list, getType)));
})
.catch(() => {});
// Clear the handoff state so a refresh doesn't re-seed (ids already captured).
diff --git a/client/src/pages/StoryBuilder.test.jsx b/client/src/pages/StoryBuilder.test.jsx
index e6e979710d..8f84f0d40c 100644
--- a/client/src/pages/StoryBuilder.test.jsx
+++ b/client/src/pages/StoryBuilder.test.jsx
@@ -47,6 +47,12 @@ const api = vi.hoisted(() => ({
}));
vi.mock('../services/api', () => api);
+// useCatalogTypes fetches the merged registry; mock it to "no user types" so the
+// hook resolves deterministically to the built-in six (its static fallback).
+vi.mock('../services/apiCatalogTypes', () => ({
+ listCatalogTypes: vi.fn().mockResolvedValue({ types: [] }),
+}));
+
// Spy on toast so the rejection tests can prove the catch-path notice fired —
// the success path never toasts, so a specific toast.error message uniquely
// pins the rejection branch (a bare reload-count check can't, since onSuccess
@@ -134,6 +140,20 @@ describe('composeSeedFromIngredients', () => {
expect(out).toContain('- Vance: Scarred, silver-eyed, never still.');
});
+ it('honors a user-defined type resolver (custom label + snippetFallbackKeys)', () => {
+ // A user-defined `faction` type whose body field is `creed` — the resolver
+ // (useCatalogTypes().getType) carries its snippetFallbackKeys + label.
+ const resolve = (id) => (id === 'faction'
+ ? { id: 'faction', label: 'Faction', snippetFallbackKeys: ['creed', 'description'] }
+ : undefined);
+ const out = composeSeedFromIngredients(
+ [{ id: 'f1', name: 'The Tide', type: 'faction', payload: { creed: 'The sea remembers.' } }],
+ resolve,
+ );
+ expect(out).toContain('Factions:');
+ expect(out).toContain('- The Tide: The sea remembers.');
+ });
+
it('truncates each summary to ~120 chars and the whole text to 4000', () => {
const long = 'x'.repeat(500);
const out = composeSeedFromIngredients([{ id: 'c1', name: 'Big', type: 'idea', payload: { description: long } }]);
diff --git a/server/services/storyBuilder.js b/server/services/storyBuilder.js
index 15cde1da46..8d6fdef44d 100644
--- a/server/services/storyBuilder.js
+++ b/server/services/storyBuilder.js
@@ -47,7 +47,7 @@ import {
import { hashUpstream, computeStaleSteps, computeSyncDrift } from '../lib/storyBuilderIntegrity.js';
import { getStoryBuilderStore } from './storyBuilderStore/store.js';
import { listIngredients, linkIngredientsToSeries } from './catalogDB.js';
-import { getCatalogType, payloadSnippet } from '../lib/catalogTypes.js';
+import { getActiveCatalogType, payloadSnippet } from '../lib/catalogTypes.js';
import { createUniverse, deleteUniverse, getUniverse, updateUniverse } from './universeBuilder.js';
import { expandWorldTemplate } from './universeBuilderExpand.js';
import { refineWorldPrompts } from './universeBuilderRefine.js';
@@ -77,12 +77,13 @@ export const TITLE_MAX = 200;
export const SEED_MAX = 4000;
export const INTAKE_MODES = Object.freeze(['seed', 'import']);
-// Group → header label for the composed fallback seed. Prefer the catalog
-// registry's canonical label (so idea/scene/concept get proper plurals and
-// match the client's prefill), naive-pluralizing a user-defined type's id as a
-// fallback. Mirrors `seedGroupHeading` in client StoryBuilder.jsx.
+// Group → header label for the composed fallback seed. Prefer the ACTIVE
+// registry's canonical label (getActiveCatalogType covers user-defined types
+// too, so idea/scene/concept + custom types get proper plurals and match the
+// client's prefill), naive-pluralizing an unknown type's id as a fallback.
+// Mirrors `seedGroupHeading` in client StoryBuilder.jsx.
function seedGroupHeading(type) {
- const label = getCatalogType(type)?.label;
+ const label = getActiveCatalogType(type)?.label;
const base = label || (isStr(type) && type ? `${type.charAt(0).toUpperCase()}${type.slice(1)}` : 'Other');
return base.endsWith('s') ? base : `${base}s`;
}
@@ -104,9 +105,10 @@ function composeSeedFromIngredients(ingredients) {
for (const [type, list] of byType) {
lines.push(`${seedGroupHeading(type)}:`);
for (const ing of list) {
- // payloadSnippet follows the type's snippetFallbackKeys, so a character's
- // body text (under `physicalDescription`, not `description`) is included.
- const summary = payloadSnippet(ing.payload, ing.type, 120);
+ // payloadSnippet follows the type's snippetFallbackKeys (getActiveCatalogType
+ // resolves user-defined types too), so a character's body text — under
+ // `physicalDescription`, not `description` — is included.
+ const summary = payloadSnippet(ing.payload, ing.type, 120, getActiveCatalogType);
lines.push(summary ? `- ${ing.name}: ${summary}` : `- ${ing.name}`);
}
}