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 (claude): keep whole character cast in roster so scoping never drops a non-featured character

Adam Eivy2f8b4db58306
diff --git a/server/lib/universePromptRenderers.js b/server/lib/universePromptRenderers.js
index 65d757c2f7..53b4550e1d 100644
--- a/server/lib/universePromptRenderers.js
+++ b/server/lib/universePromptRenderers.js
@@ -178,13 +178,25 @@ const SUMMARY_SECTIONS = [
* (prose/teleplay/comic-script) where the budget can't afford the full
* dump but the LLM still needs continuity anchors.
*/
+// `maxPerKind` accepts either a single number (applied to every kind) or a
+// per-kind map (`{ characters, places, objects }`) so a caller can lift the cap
+// on one kind while leaving the others at the default — e.g. the per-issue text
+// stages now scope the full-record character block, so they render the roster
+// with the WHOLE character cast (continuity safety net) while keeping
+// places/objects terse. A missing per-kind key falls back to the default cap.
+const capForKind = (maxPerKind, field) => (
+ typeof maxPerKind === 'object' && maxPerKind !== null
+ ? (maxPerKind[field] ?? ENTITIES_SUMMARY_MAX_PER_KIND)
+ : maxPerKind
+);
+
export function renderEntitiesSummary(world, { maxPerKind = ENTITIES_SUMMARY_MAX_PER_KIND } = {}) {
if (!world || typeof world !== 'object') return '';
const lines = [];
for (const { field, header, formatEntry } of SUMMARY_SECTIONS) {
const entries = Array.isArray(world[field]) ? world[field] : [];
if (!entries.length) continue;
- const shown = entries.slice(0, maxPerKind);
+ const shown = entries.slice(0, capForKind(maxPerKind, field));
const hidden = entries.length - shown.length;
const tags = shown.map(formatEntry).filter(Boolean);
if (!tags.length) continue;
diff --git a/server/lib/universePromptRenderers.test.js b/server/lib/universePromptRenderers.test.js
index d75125e46f..7828e0c95d 100644
--- a/server/lib/universePromptRenderers.test.js
+++ b/server/lib/universePromptRenderers.test.js
@@ -72,6 +72,18 @@ describe('renderEntitiesSummary', () => {
expect(out).toContain('(+2 more)');
});
+ it('honors a per-kind maxPerKind map, lifting one kind while defaulting the rest', () => {
+ const characters = Array.from({ length: ENTITIES_SUMMARY_MAX_PER_KIND + 5 }, (_, i) => ({ name: `C${i + 1}`, role: 'role' }));
+ const places = Array.from({ length: ENTITIES_SUMMARY_MAX_PER_KIND + 2 }, (_, i) => ({ name: `P${i + 1}` }));
+ const out = renderEntitiesSummary({ characters, places }, { maxPerKind: { characters: Infinity } });
+ // characters uncapped — every one listed, no "(+N more)" on the Characters line
+ expect(out).toContain(`C${ENTITIES_SUMMARY_MAX_PER_KIND + 5} (role)`);
+ expect(out).not.toMatch(/Characters:.*\(\+\d+ more\)/);
+ // places fall back to the default cap with a "(+2 more)" tag
+ expect(out).not.toContain(`P${ENTITIES_SUMMARY_MAX_PER_KIND + 1}`);
+ expect(out).toMatch(/Places:.*\(\+2 more\)/);
+ });
+
it(`truncates over-long descriptors at ${ENTITIES_SUMMARY_DESCRIPTOR_MAX} chars with an ellipsis`, () => {
const long = 'x'.repeat(ENTITIES_SUMMARY_DESCRIPTOR_MAX + 50);
const out = renderEntitiesSummary({
diff --git a/server/services/pipeline/textStages.js b/server/services/pipeline/textStages.js
index 538bdd8c0f..14afa913ae 100644
--- a/server/services/pipeline/textStages.js
+++ b/server/services/pipeline/textStages.js
@@ -264,9 +264,15 @@ function buildStageContext({ series, canon, world, issue, stageId, seedInput, so
// per-issue text prompts reference named entities without paying the full
// canon-block token cost — `series.characters` carries full records only for
// the issue-relevant cast (scoped below), and this compact roster covers the
- // rest of the cast plus places/objects for continuity anchors.
+ // rest of the cast plus places/objects for continuity anchors. Characters are
+ // rendered UNCAPPED here (`maxPerKind: { characters: Infinity }`): because the
+ // full-record block is now scoped, the roster is the only place a non-featured
+ // character is represented, so it must list the whole cast or a mid-bible
+ // character would vanish from the prompt entirely. Places/objects stay at the
+ // default cap — they were never full-record-injected, so their behavior is
+ // unchanged.
const worldEntitiesSummary = world
- ? (renderEntitiesSummary(world) || '(none)')
+ ? (renderEntitiesSummary(world, { maxPerKind: { characters: Infinity } }) || '(none)')
: NO_LINKED_UNIVERSE_PLACEHOLDER;
// Scope the heavyweight full-record character block to the cast this issue
// actually involves (#1511) — full records only for characters named in the
diff --git a/server/services/pipeline/textStages.test.js b/server/services/pipeline/textStages.test.js
index 4d2b6f6ed4..b5fac3ccbb 100644
--- a/server/services/pipeline/textStages.test.js
+++ b/server/services/pipeline/textStages.test.js
@@ -539,6 +539,31 @@ describe('pipeline text stage generator', () => {
expect(ctx.worldEntitiesSummary).toContain('Chandelier');
});
+ it('keeps the WHOLE cast in the roster even on a large bible, so a non-featured character never vanishes', async () => {
+ const { series } = await seed();
+ const world = await universeSvc.createUniverse({ name: 'Big Verse' });
+ // 12 characters (> the default roster cap of 8). Only "Mira" is named in the
+ // issue; "Tail" sits at bible-index 12 and is neither named nor a principal —
+ // it must still appear in the compact roster (its only representation now that
+ // the full-record block is scoped).
+ const cast = Array.from({ length: 11 }, (_, i) => ({ name: `Filler${i + 1}`, role: 'walk-on' }));
+ cast.unshift({ name: 'Mira', role: 'surveyor' });
+ cast.push({ name: 'Tail', role: 'background' });
+ await universeSvc.updateUniverse(world.id, { characters: cast });
+ await seriesSvc.updateSeries(series.id, { universeId: world.id });
+ const issue = await issuesSvc.createIssue({
+ seriesId: series.id, title: 'The Hush',
+ stages: { idea: { input: 'a quiet survey', output: 'Mira walks alone.', status: 'ready' } },
+ });
+ await textStages.generateStage(issue.id, 'prose');
+ const ctx = ctxFromCall(llmCalls[0]);
+ // Full records scoped to the named character only…
+ expect(ctx.series.characters.map((c) => c.name)).toEqual(['Mira']);
+ // …but the roster still lists the deep-bible character and shows no truncation.
+ expect(ctx.worldEntitiesSummary).toContain('Tail');
+ expect(ctx.worldEntitiesSummary).not.toMatch(/Characters:.*\(\+\d+ more\)/);
+ });
+
it('scopeCharactersForIssue: matched names win over principals', () => {
const cast = [
{ name: 'Mira', role: 'lead' },