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): seed snippets honor per-type keys; restore selection on failed delete

[._.]/ Adam Eivyf9119257c947
diff --git a/client/src/pages/Catalog.jsx b/client/src/pages/Catalog.jsx
index 7928e92485..2bc1588047 100644
--- a/client/src/pages/Catalog.jsx
+++ b/client/src/pages/Catalog.jsx
@@ -181,13 +181,18 @@ export default function Catalog() {
const confirmDelete = async (it) => {
setArmedId(null);
// A deleted ingredient can't be remixed — drop it from the selection so the
- // action bar count stays honest.
- setSelectedIds((prev) => {
- if (!prev.has(it.id)) return prev;
- const next = new Set(prev);
- next.delete(it.id);
- return next;
- });
+ // action bar count stays honest. Remember whether it WAS selected so a failed
+ // delete can restore it (otherwise a still-live ingredient silently vanishes
+ // from the selection and a later Remix omits it).
+ const wasSelected = selectedIds.has(it.id);
+ if (wasSelected) {
+ setSelectedIds((prev) => {
+ if (!prev.has(it.id)) return prev;
+ const next = new Set(prev);
+ next.delete(it.id);
+ return next;
+ });
+ }
// Capture the original index so a failed delete restores in place rather
// than jumping the row to the top of the list.
const originalIdx = items.findIndex((x) => x.id === it.id);
@@ -200,6 +205,8 @@ export default function Catalog() {
next.splice(Math.max(0, originalIdx), 0, it);
return next;
});
+ // Roll the selection back too — the ingredient still exists.
+ if (wasSelected) setSelectedIds((prev) => (prev.has(it.id) ? prev : new Set(prev).add(it.id)));
});
loadStats();
};
diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsx
index 4403395228..4de59f45a0 100644
--- a/client/src/pages/StoryBuilder.jsx
+++ b/client/src/pages/StoryBuilder.jsx
@@ -31,7 +31,7 @@ import {
import ArcCanvas from '../components/pipeline/ArcCanvas';
import { useArcCanvasSync } from '../hooks/useArcCanvasSync';
import { BEAT_KIND_COLORS, getBeatKindColor } from '../lib/beatColors';
-import { getCatalogType } from '../lib/catalogTypes';
+import { getCatalogType, payloadSnippet } from '../lib/catalogTypes';
// Mirror Importer.jsx's commit picker — only these arc fields are sent on commit.
const ARC_FIELDS_TO_COMMIT = ['logline', 'summary', 'protagonistArc', 'themes', 'shape'];
@@ -55,10 +55,10 @@ const CONTENT_TYPE_LABELS = {
// Compose a starter-idea prefill from a set of catalog ingredients (the Catalog
// "Remix into… → Story Builder" handoff). Ingredients are grouped by type, with
// a header line per group (e.g. `Characters:`) and one bullet per ingredient
-// (`- {name}: {summary}`) where the summary is the first ~120 chars of the
-// payload's description/summary/text. The whole composed text is capped at 4000
-// chars to match the seedIdea field. Pure — unit-tested in StoryBuilder.test.jsx.
-const SEED_SUMMARY_KEYS = ['description', 'summary', 'text'];
+// (`- {name}: {summary}`) where the summary comes from payloadSnippet — the
+// type's snippetFallbackKeys, so a character's `physicalDescription` is included.
+// The whole composed text is capped at 4000 chars to match the seedIdea field.
+// Pure — unit-tested in StoryBuilder.test.jsx; mirrors the server composer.
const SEED_MAX_CHARS = 4000;
const SEED_SUMMARY_CHARS = 120;
@@ -88,9 +88,7 @@ export function composeSeedFromIngredients(ingredients) {
lines.push(`${seedGroupHeading(type)}:`);
for (const ing of members) {
const name = (ing.name || '').trim() || '(untitled)';
- const payload = ing.payload || {};
- const rawKey = SEED_SUMMARY_KEYS.find((k) => typeof payload[k] === 'string' && payload[k].trim());
- const summary = rawKey ? payload[rawKey].trim().slice(0, SEED_SUMMARY_CHARS) : '';
+ const summary = payloadSnippet(ing.payload, ing.type, SEED_SUMMARY_CHARS);
lines.push(summary ? `- ${name}: ${summary}` : `- ${name}`);
}
lines.push('');
diff --git a/client/src/pages/StoryBuilder.test.jsx b/client/src/pages/StoryBuilder.test.jsx
index 3e9e4be89d..e6e979710d 100644
--- a/client/src/pages/StoryBuilder.test.jsx
+++ b/client/src/pages/StoryBuilder.test.jsx
@@ -116,7 +116,7 @@ describe('composeSeedFromIngredients', () => {
const out = composeSeedFromIngredients([
{ id: 'c1', name: 'Echo Saint', type: 'character', payload: { description: 'A wiry figure in a long coat.' } },
{ id: 'c2', name: 'Mara', type: 'character', payload: { summary: 'Loyal to a fault.' } },
- { id: 'p1', name: 'Old Harbor', type: 'place', payload: { text: 'Brine and rust.' } },
+ { id: 'p1', name: 'Old Harbor', type: 'place', payload: { description: 'Brine and rust.' } },
]);
expect(out).toContain('Characters:');
expect(out).toContain('- Echo Saint: A wiry figure in a long coat.');
@@ -125,12 +125,21 @@ describe('composeSeedFromIngredients', () => {
expect(out).toContain('- Old Harbor: Brine and rust.');
});
+ it('uses a character\'s physicalDescription (its primary content key), not just description', () => {
+ // A normal Catalog character stores its body prose under physicalDescription;
+ // payloadSnippet follows the type's snippetFallbackKeys so it is included.
+ const out = composeSeedFromIngredients([
+ { id: 'c1', name: 'Vance', type: 'character', payload: { physicalDescription: 'Scarred, silver-eyed, never still.' } },
+ ]);
+ expect(out).toContain('- Vance: Scarred, silver-eyed, never still.');
+ });
+
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 } }]);
- // 120-char summary cap.
- expect(out).toContain(`- Big: ${'x'.repeat(120)}`);
- expect(out).not.toContain('x'.repeat(121));
+ // payloadSnippet caps at 120 with an ellipsis (117 chars + '…').
+ expect(out).toContain(`- Big: ${'x'.repeat(117)}…`);
+ expect(out).not.toContain('x'.repeat(118));
expect(out.length).toBeLessThanOrEqual(4000);
});
diff --git a/server/lib/catalogTypes.js b/server/lib/catalogTypes.js
index d9f8a92ebd..659015fc21 100644
--- a/server/lib/catalogTypes.js
+++ b/server/lib/catalogTypes.js
@@ -215,6 +215,39 @@ export function getCatalogType(id) {
return BY_ID[id];
}
+// Ordered union of every type's snippet keys — the unknown-type fallback so a
+// row whose type isn't in the registry still gets a snippet. Mirrors the client.
+const UNION_SNIPPET_KEYS = (() => {
+ const out = [];
+ for (const t of CATALOG_TYPES) {
+ for (const k of t.snippetFallbackKeys) {
+ if (!out.includes(k)) out.push(k);
+ }
+ }
+ return out;
+})();
+
+/**
+ * First non-empty payload value along a type's `snippetFallbackKeys` chain,
+ * trimmed/whitespace-collapsed and truncated to `max` (ellipsis on overflow).
+ * Honors each type's primary content key — e.g. a character's body text lives
+ * under `physicalDescription`, not `description`. Mirror of the client helper in
+ * `client/src/lib/catalogTypes.js`; keep the two in sync. `resolveType` lets a
+ * caller fold in user-defined types (defaults to the built-in registry).
+ */
+export function payloadSnippet(payload, typeId, max = 120, resolveType = null) {
+ if (!payload || typeof payload !== 'object') return '';
+ const typeDef = (resolveType && resolveType(typeId)) || BY_ID[typeId];
+ const keys = typeDef?.snippetFallbackKeys || UNION_SNIPPET_KEYS;
+ let raw = '';
+ for (const k of keys) {
+ if (payload[k]) { raw = payload[k]; break; }
+ }
+ const text = String(raw).trim().replace(/\s+/g, ' ');
+ if (text.length <= max) return text;
+ return `${text.slice(0, max - 3)}…`;
+}
+
// --- User-defined types (runtime layer) ----------------------------------
// User types are persisted in PostgreSQL (`catalog_user_types`, #1001 — they
// lived in `data/settings.json` `catalogUserTypes: []` before that) and merged
diff --git a/server/lib/catalogTypes.test.js b/server/lib/catalogTypes.test.js
index d8d2f2a3ad..45b6b7c722 100644
--- a/server/lib/catalogTypes.test.js
+++ b/server/lib/catalogTypes.test.js
@@ -21,6 +21,7 @@ import {
INGREDIENT_TYPE_IDS,
FTS_PAYLOAD_FIELDS,
getCatalogType,
+ payloadSnippet,
ingredientIdPrefix,
currentPayloadSchemaVersion,
upgradePayload,
@@ -370,3 +371,31 @@ describe('catalogTypes — media kinds', () => {
}
});
});
+
+describe('payloadSnippet', () => {
+ it('follows a type\'s snippetFallbackKeys — character body text lives under physicalDescription', () => {
+ // A character's primary prose key is physicalDescription, NOT description.
+ expect(payloadSnippet({ physicalDescription: 'Scarred and silver-eyed.' }, 'character'))
+ .toBe('Scarred and silver-eyed.');
+ // Falls through the chain to description/summary when the primary is absent.
+ expect(payloadSnippet({ summary: 'Loyal to a fault.' }, 'character')).toBe('Loyal to a fault.');
+ });
+
+ it('collapses whitespace and truncates to max with an ellipsis', () => {
+ expect(payloadSnippet({ description: 'a b\n c' }, 'place')).toBe('a b c');
+ const out = payloadSnippet({ description: 'x'.repeat(200) }, 'idea', 120);
+ expect(out).toBe(`${'x'.repeat(117)}…`); // 117 chars + 1-char ellipsis
+ expect(out.length).toBeLessThanOrEqual(120);
+ });
+
+ it('returns empty for a non-object payload or no matching key', () => {
+ expect(payloadSnippet(null, 'character')).toBe('');
+ expect(payloadSnippet({ unrelated: 'x' }, 'character')).toBe('');
+ });
+
+ it('mirrors the client helper output', async () => {
+ const client = await import('../../client/src/lib/catalogTypes.js');
+ const payload = { physicalDescription: 'A wiry figure in a long coat, never still.' };
+ expect(payloadSnippet(payload, 'character')).toBe(client.payloadSnippet(payload, 'character'));
+ });
+});
diff --git a/server/services/storyBuilder.js b/server/services/storyBuilder.js
index b52c004732..15cde1da46 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 } from '../lib/catalogTypes.js';
+import { getCatalogType, payloadSnippet } from '../lib/catalogTypes.js';
import { createUniverse, deleteUniverse, getUniverse, updateUniverse } from './universeBuilder.js';
import { expandWorldTemplate } from './universeBuilderExpand.js';
import { refineWorldPrompts } from './universeBuilderRefine.js';
@@ -90,9 +90,9 @@ function seedGroupHeading(type) {
// Compose a fallback seed string from resolved catalog ingredients (#1761),
// used when the user supplies ingredients but no seedIdea so the minted
// universe/series shells aren't empty. Groups by type with a header line per
-// group and one `- {name}: {summary}` bullet per ingredient (summary = first
-// ~120 chars of the payload's description/summary/text; omitted, with the
-// `: `, when empty). Capped at SEED_MAX with a trailing ellipsis on overflow.
+// group and one `- {name}: {summary}` bullet per ingredient (summary via
+// payloadSnippet — the type's snippetFallbackKeys, ~120 chars; omitted, with
+// the `: `, when empty). Capped at SEED_MAX with a trailing ellipsis on overflow.
function composeSeedFromIngredients(ingredients) {
const byType = new Map();
for (const ing of ingredients) {
@@ -104,11 +104,9 @@ function composeSeedFromIngredients(ingredients) {
for (const [type, list] of byType) {
lines.push(`${seedGroupHeading(type)}:`);
for (const ing of list) {
- const p = ing.payload && typeof ing.payload === 'object' ? ing.payload : {};
- const raw = isStr(p.description) ? p.description
- : isStr(p.summary) ? p.summary
- : isStr(p.text) ? p.text : '';
- const summary = raw.trim().slice(0, 120).trim();
+ // 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);
lines.push(summary ? `- ${ing.name}: ${summary}` : `- ${ing.name}`);
}
}