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

Merge remote-tracking branch 'origin/main' into next/issue-1511

Adam Eivy01e8c5f18a1b
diff --cc server/lib/universePromptRenderers.js
index 53b4550e1d,0a00754c25..fd8edb0e62
--- a/server/lib/universePromptRenderers.js
+++ b/server/lib/universePromptRenderers.js
@@@ -178,25 -178,23 +178,35 @@@ 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.
++// stages render the roster with the WHOLE non-scoped 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 } = {}) {
+ // `excludeCharacterNames` (a Set of lower-cased names) drops characters already
+ // rendered in full elsewhere in the same prompt — e.g. the per-issue text stages
-// list the series-canon characters as full bible records, so re-listing them in
-// this terse roster is pure duplication. Places/objects are never excluded (they
-// have no full-record block to overlap with). The exclusion happens BEFORE the
-// top-N slice so the "+N more" count reflects what's actually withheld.
++// list the SCOPED characters as full bible records, so re-listing them in this
++// terse roster is pure duplication. Places/objects are never excluded (they have
++// no full-record block to overlap with). The exclusion happens BEFORE the top-N
++// slice so the "+N more" count reflects what's actually withheld.
+ export function renderEntitiesSummary(world, { maxPerKind = ENTITIES_SUMMARY_MAX_PER_KIND, excludeCharacterNames = null } = {}) {
if (!world || typeof world !== 'object') return '';
+ const exclude = excludeCharacterNames instanceof Set ? excludeCharacterNames : null;
const lines = [];
for (const { field, header, formatEntry } of SUMMARY_SECTIONS) {
- const entries = Array.isArray(world[field]) ? world[field] : [];
+ let entries = Array.isArray(world[field]) ? world[field] : [];
+ if (field === 'characters' && exclude && exclude.size) {
+ entries = entries.filter((e) => !exclude.has((e?.name || '').trim().toLowerCase()));
+ }
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 --cc server/services/pipeline/textStages.js
index 1147928acd,76800abecc..128b063c12
--- a/server/services/pipeline/textStages.js
+++ b/server/services/pipeline/textStages.js
@@@ -309,28 -228,22 +322,31 @@@ function buildStageContext({ series, ca
// backfill the beat sheet from finished prose.
const sourceMaterials = resolveSourceStageIds({ issue, stageId, sourceStageIds })
.map((id) => ({ stageId: id, label: STAGE_LABELS[id] || id, content: stageContentOf(issue.stages?.[id]) }));
- // Compact one-line-per-kind synopsis of the linked universe's canon. Lets
- // 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. 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, { 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 for the principals plus characters
- // named in the issue's source text; the compact roster above keeps the rest of
- // the cast known for naming/continuity. Only the roster-backed stages are scoped
++ // named in the issue's source text. Only the roster-backed stages are scoped
+ // (see ROSTER_BACKED_STAGES); the idea stage keeps the full cast.
+ const scopedCharacters = ROSTER_BACKED_STAGES.has(stageId)
+ ? scopeCharactersForIssue(canon?.characters || [], buildIssueScopeText(issue, sourceMaterials, seedInput))
+ : (canon?.characters || []);
+ // Compact one-line-per-kind synopsis of the linked universe's canon. Lets
+ // per-issue text prompts reference named entities without paying the full
- // canon-block token cost — `series.characters` already covers the bible-
- // sized character context, this adds places/objects + other characters not
- // pulled into the series-canon for continuity anchors.
- // Exclude the series-canon characters from the terse roster — they're already
- // rendered in full in the bible's "### Characters" block above, so re-listing
- // them in "Universe at a glance" duplicates every character in the prompt. The
- // roster then does what its comment intends: adds places/objects + any OTHER
- // characters not pulled into the series canon.
- const seriesCharacterNames = new Set(
- (canon?.characters || []).map((c) => (c?.name || '').trim().toLowerCase()).filter(Boolean),
++ // canon-block token cost. The roster carries the REST of the cast — everyone
++ // NOT rendered as a full record in `series.characters` — plus places/objects,
++ // so a scoped-out character is still represented for naming/continuity and is
++ // never duplicated (excludeCharacterNames drops the scoped set). Characters are
++ // uncapped here (`maxPerKind: { characters: Infinity }`) because the roster is
++ // the ONLY place the non-scoped cast appears: the default top-8 cap would make
++ // a large-cast series silently drop mid-bible characters from the prompt.
++ const scopedCharacterNames = new Set(
++ scopedCharacters.map((c) => (c?.name || '').trim().toLowerCase()).filter(Boolean),
+ );
+ const worldEntitiesSummary = world
- ? (renderEntitiesSummary(world, { excludeCharacterNames: seriesCharacterNames }) || '(none)')
++ ? (renderEntitiesSummary(world, {
++ maxPerKind: { characters: Infinity },
++ excludeCharacterNames: scopedCharacterNames,
++ }) || '(none)')
+ : NO_LINKED_UNIVERSE_PLACEHOLDER;
return {
series: {
name: series.name,