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

fix([issue-731]): fingerprint full cast + season editorial content for staleness

[._.]/ Adam Eivye50bbf2ffdc7
diff --git a/server/services/storyBuilder.js b/server/services/storyBuilder.js
index eb37fa2e40..30d24271b7 100644
--- a/server/services/storyBuilder.js
+++ b/server/services/storyBuilder.js
@@ -21,7 +21,7 @@ import { join } from 'path';
import { randomUUID } from 'crypto';
import { PATHS } from '../lib/fileUtils.js';
import { createCollectionStore } from '../lib/collectionStore.js';
-import { isStr, trimTo } from '../lib/storyBible.js';
+import { isStr, trimTo, pickPromptFields, BIBLE_KIND } from '../lib/storyBible.js';
import { sanitizeOrigin } from '../lib/sharingOrigin.js';
import { sanitizeSoftDeleteFields } from '../lib/syncWire.js';
import { runStagedLLM } from '../lib/stageRunner.js';
@@ -295,14 +295,38 @@ function projectArc(series) {
shape: arc.shape || null,
};
}
+// Project the SEMANTIC content of each canon character — the same prompt-field
+// whitelist the bible extractor / evaluator use (`physicalDescription`,
+// `personality`, `role`, etc.), which excludes ids/timestamps/source churn by
+// construction. A bare `{ name, descriptor }` would only change on add / remove
+// / rename — canon characters carry no `descriptor` field, so editing a locked
+// character's body fields out-of-band (the #731 case) would never flag stale.
function projectCast(universe) {
return (Array.isArray(universe?.characters) ? universe.characters : [])
- .map((c) => ({ name: c?.name || '', descriptor: c?.descriptor ?? null }));
+ .map((c) => pickPromptFields(BIBLE_KIND.CHARACTER, c));
+}
+// The plotArc step generates AND persists the season breakdown, so a locked
+// plotArc must fingerprint the seasons' editorial content alongside the arc
+// core — editing a season title/logline/synopsis/episode-count out-of-band
+// otherwise leaves the lock un-flagged. Excludes render slots (cover/backCover)
+// and operational churn (id/status/timestamps) — only the editorial fields the
+// step produces and the user reviews.
+function projectSeasons(series) {
+ return (Array.isArray(series?.seasons) ? series.seasons : []).map((s) => ({
+ number: s?.number ?? 0,
+ title: s?.title || '',
+ logline: s?.logline || '',
+ synopsis: s?.synopsis || '',
+ episodeCountTarget: s?.episodeCountTarget ?? 0,
+ themes: Array.isArray(s?.themes) ? s.themes : [],
+ endingHook: s?.endingHook || '',
+ }));
}
function buildUpstreamInputs(session, universe, series) {
const aesthetic = projectAesthetic(universe);
const arc = projectArc(series);
+ const seasons = projectSeasons(series);
const readerMap = series?.arc?.readerMap || null;
const cast = projectCast(universe);
// The idea step expands seedIdea into universe.starterPrompt + series
@@ -329,7 +353,7 @@ function buildUpstreamInputs(session, universe, series) {
return {
idea: { intakeMode: session.intakeMode, seedIdea: session.seedIdea || '', ownOutputs: ideaOutputs },
universeAesthetic: { seedIdea: session.seedIdea || '', ideaOutputs, ownOutputs: aesthetic },
- plotArc: { aesthetic, seedIdea: session.seedIdea || '', ideaOutputs, ownOutputs: arc },
+ plotArc: { aesthetic, seedIdea: session.seedIdea || '', ideaOutputs, ownOutputs: { arc, seasons } },
readerMap: { arc, ownOutputs: readerMap },
characters: { readerMap, arcSummary: arc.summary, aesthetic, ownOutputs: cast },
issues: { arc, readerMap, cast },
diff --git a/server/services/storyBuilder.test.js b/server/services/storyBuilder.test.js
index c8b3c7842e..b439a65aab 100644
--- a/server/services/storyBuilder.test.js
+++ b/server/services/storyBuilder.test.js
@@ -258,20 +258,64 @@ describe('storyBuilder — integrity / staleness', () => {
expect(view.staleSteps).toContain('plotArc');
});
- it('flags a locked characters step stale when the cast is edited out-of-band (#731)', async () => {
+ it('flags a locked characters step stale when a character is added out-of-band (#731)', async () => {
const s = await sb.createStorySession({ title: 'X' });
await universeSvc.updateUniverse(s.universeId, {
- characters: [{ name: 'Ada', descriptor: 'the foundry forewoman' }],
+ characters: [{ name: 'Ada', physicalDescription: 'the foundry forewoman' }],
});
await sb.lockStep(s.id, 'characters');
let view = await sb.getStorySessionView(s.id);
expect(view.staleSteps).not.toContain('characters');
await universeSvc.updateUniverse(s.universeId, {
- characters: [{ name: 'Ada', descriptor: 'the foundry forewoman' }, { name: 'Rook', descriptor: 'the rival' }],
+ characters: [
+ { name: 'Ada', physicalDescription: 'the foundry forewoman' },
+ { name: 'Rook', physicalDescription: 'the rival' },
+ ],
+ });
+ view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).toContain('characters');
+ });
+
+ it('flags a locked characters step stale when a character body field is edited out-of-band (#731)', async () => {
+ // The cast fingerprint must track the canon body fields (physicalDescription,
+ // personality, role, …), not just name — editing a locked character's
+ // description in Universe Builder is exactly the out-of-band case #731 targets.
+ const s = await sb.createStorySession({ title: 'X' });
+ await universeSvc.updateUniverse(s.universeId, {
+ characters: [{ name: 'Ada', physicalDescription: 'tall, soot-streaked', personality: 'guarded' }],
+ });
+ await sb.lockStep(s.id, 'characters');
+ let view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).not.toContain('characters');
+ // Same name + count, only the body changes.
+ await universeSvc.updateUniverse(s.universeId, {
+ characters: [{ name: 'Ada', physicalDescription: 'CHANGED — gaunt, grease-stained', personality: 'guarded' }],
});
view = await sb.getStorySessionView(s.id);
expect(view.staleSteps).toContain('characters');
});
+
+ it('flags a locked plotArc step stale when a season is edited out-of-band (#731)', async () => {
+ // The plotArc step persists the season breakdown, so editing a season's
+ // editorial content (here its synopsis) must flag the locked step stale even
+ // though the arc core fields are untouched.
+ const s = await sb.createStorySession({ title: 'X' });
+ await seriesSvc.updateSeries(s.seriesId, {
+ arc: { logline: 'spine', summary: 'sum' },
+ seasons: [{ number: 1, title: 'Vol 1', synopsis: 'the foundry goes silent' }],
+ });
+ await sb.lockStep(s.id, 'plotArc');
+ let view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).not.toContain('plotArc');
+ // Edit only the season synopsis (arc core unchanged); the arc lock that
+ // lockStep set is cleared so updateSeries accepts the season edit.
+ await seriesSvc.updateSeries(s.seriesId, {
+ arc: { logline: 'spine', summary: 'sum' }, locked: {},
+ seasons: [{ number: 1, title: 'Vol 1', synopsis: 'CHANGED — the foundry roars back to life' }],
+ });
+ view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).toContain('plotArc');
+ });
});
describe('storyBuilder — generate delegation', () => {