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

feat: let FableLoom honor finite and renewable series designs (#7204)

[._.]/ Adam Eivy923e36322c35
diff --git a/client/src/components/fableloom/LoomSeriesPlan.jsx b/client/src/components/fableloom/LoomSeriesPlan.jsx
index def97c3e7c..fc4f07bd00 100644
--- a/client/src/components/fableloom/LoomSeriesPlan.jsx
+++ b/client/src/components/fableloom/LoomSeriesPlan.jsx
@@ -30,6 +30,7 @@ import LoomAiRunStatus from './LoomAiRunStatus';
import LoomEditorialAutomation from './LoomEditorialAutomation';
import { fableLoomPlotPointKind } from '../../../../server/lib/fableLoomOutline.js';
import CharacterEvolutionLens from '../character/CharacterEvolutionLens';
+import SeriesDesignEditor from '../pipeline/arcCanvas/SeriesDesignEditor.jsx';
import { EVOLUTION_STAGES, isDeclaredEvolution } from '../../lib/characterEvolution.js';
const PLAN_SECTIONS = [
@@ -51,6 +52,7 @@ const normalizeDeliveryOptions = (options) => ({
});
const normalizePlan = (plan) => ({
+ seriesDesign: plan?.seriesDesign || null,
storyArc: plan?.storyArc || '',
plotPoints: Array.isArray(plan?.plotPoints)
? plan.plotPoints.map((item) => ({ ...item, kind: fableLoomPlotPointKind(item) }))
@@ -69,15 +71,17 @@ const normalizePlan = (plan) => ({
/**
* The plan body the save PATCH actually sends.
*
- * `characterEvolutions` is OMITTED when nothing is authored, so a plan that
- * never opted into the lens produces a request body byte-identical to the
- * pre-lens one (the server sanitizer omits the key on exactly that rule). An
- * absent key on this WHOLESALE-`seriesPlan` PATCH is itself the clear, so
- * removing the last lens still persists as a clear rather than a no-op.
+ * Optional author-owned fields are OMITTED when nothing is authored, so a
+ * legacy plan produces the same request body as before either field existed.
+ * An absent key on this WHOLESALE-`seriesPlan` PATCH is itself the clear, so
+ * removing the last lens or series brief persists as a clear rather than a
+ * no-op.
*/
-const planSavePayload = ({ characterEvolutions, ...rest }) => (
- characterEvolutions?.length ? { ...rest, characterEvolutions } : rest
-);
+const planSavePayload = ({ characterEvolutions, seriesDesign, ...rest }) => ({
+ ...rest,
+ ...(characterEvolutions?.length ? { characterEvolutions } : {}),
+ ...(seriesDesign?.mode ? { seriesDesign } : {}),
+});
const episodeBoundaryKey = (fromEpisodeId, toEpisodeId) => `${fromEpisodeId}::${toEpisodeId}`;
@@ -205,9 +209,14 @@ export default function LoomSeriesPlan({ loom, universe, onLoomUpdate }) {
<div ref={contentRef} className="min-h-0 flex-1 overflow-y-auto p-4 md:p-6">
<div className="max-w-5xl mx-auto">
<div hidden={requestedSection !== 'arc'} role="tabpanel" aria-labelledby="tab-arc" id="series-section-arc" tabIndex={-1} className="rounded-lg border border-port-border bg-port-card p-4 focus:outline-none">
+ <SeriesDesignEditor
+ value={plan.seriesDesign}
+ onChange={(seriesDesign) => changePlan((current) => ({ ...current, seriesDesign }))}
+ />
<FormField
label="Story arc"
hint="The beginning-to-end dramatic movement, central conflict, and intended resolution."
+ className="mt-4"
labelClassName={labelClass}
>
<textarea
diff --git a/client/src/components/fableloom/LoomSeriesPlan.test.jsx b/client/src/components/fableloom/LoomSeriesPlan.test.jsx
index b56aaf8bf7..942915e90d 100644
--- a/client/src/components/fableloom/LoomSeriesPlan.test.jsx
+++ b/client/src/components/fableloom/LoomSeriesPlan.test.jsx
@@ -68,6 +68,31 @@ describe('LoomSeriesPlan', () => {
expect(onLoomUpdate).toHaveBeenCalledWith(updated);
});
+ it('authors and clears the shared series-design brief without adding it to legacy saves', async () => {
+ const user = userEvent.setup();
+ api.updateLoom.mockImplementation(async (_id, { seriesPlan }) => loom({ seriesPlan }));
+ render(<RouterProvider router={createMemoryRouter([
+ { path: '/', element: <StatefulPlan initial={loom()} /> },
+ ], { initialEntries: ['/'] })} />);
+
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Story intent' }), 'renewable');
+ await user.type(screen.getByRole('textbox', { name: 'Episode activity' }), 'Decode a dangerous signal.');
+ await user.type(screen.getByRole('textbox', { name: 'Continuing tensions' }), 'Each relay hides another sender.');
+ await user.click(screen.getByRole('button', { name: /save plan/i }));
+
+ await waitFor(() => expect(api.updateLoom).toHaveBeenCalledTimes(1));
+ expect(api.updateLoom.mock.calls[0][1].seriesPlan.seriesDesign).toEqual(expect.objectContaining({
+ mode: 'renewable',
+ episodeActivity: 'Decode a dangerous signal.',
+ continuingTensions: 'Each relay hides another sender.',
+ }));
+
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Story intent' }), '');
+ await user.click(screen.getByRole('button', { name: /save plan/i }));
+ await waitFor(() => expect(api.updateLoom).toHaveBeenCalledTimes(2));
+ expect(api.updateLoom.mock.calls[1][1].seriesPlan).not.toHaveProperty('seriesDesign');
+ });
+
it('adds a playable challenge as an episode-mapped plot-point contract', async () => {
const user = userEvent.setup();
api.updateLoom.mockResolvedValue(loom());
diff --git a/data.reference/prompts/stages/fableloom-editorial-remediate.md b/data.reference/prompts/stages/fableloom-editorial-remediate.md
index 6d7c7b8157..be5abd5fc1 100644
--- a/data.reference/prompts/stages/fableloom-editorial-remediate.md
+++ b/data.reference/prompts/stages/fableloom-editorial-remediate.md
@@ -56,6 +56,7 @@ author explained is not a deficiency.
## Editorial contract
- Preserve every episode id, scene id, transition id, and all episode/scene/transition membership. Do not add or remove an episode, scene, or transition.
+- `seriesDesign`, when present, is author-owned and read-only. Never return or patch it. Honor finite stories that earn their declared ending and renewable stories that retain their recurring activity and continuing tensions. Do not flatten mutually exclusive paths into one sequence or reopen a valid local ending merely to manufacture more episodes. Anchor related findings to supplied episode, scene, and path ids. Keep voicemail and teaser handoffs independent.
- A missing field preserves its current value. A present empty string or `null` intentionally clears a field where the schema permits it.
- When an expanded episode has no valid beat outline, return its complete `storyOutline`. It must use every existing scene id exactly once as its scene keys, use the teleplay `startNodeId` as `startKey`, and match every scene's playback/audience/protagonist/ending flags plus every transition target and intent.
- If you change an episode title, synopsis, opening scene, scene title, playback/audience/protagonist/ending flags, or transition target/intent, include that episode's complete synchronized `storyOutline` in the same patch. A stale previously-valid outline is never acceptable.
@@ -94,7 +95,7 @@ Return ONLY valid JSON — no prose, markdown fence, or commentary. The followin
Optional patch keys are:
- top level: `clears`, `seriesPlan`, `episodes`
-- `seriesPlan`: `storyArc`, `plotPoints`, `sideQuests`, `deliveryOptions`, `interEpisodeVoicemails`, `nextSeasonTeaser`
+- `seriesPlan`: `storyArc`, `plotPoints`, `sideQuests`, `deliveryOptions`, `interEpisodeVoicemails`, `nextSeasonTeaser` (`seriesDesign` is never editable here)
- episode: `id`, `title`, `synopsis`, `startNodeId`, `storyOutline`, `scenes`
- scene: `id`, `title`, `prose`, `imagePrompt`, `videoPrompt`, `cameraMovement`, `playbackMode`, `audienceConnection`, `protagonistPresence`, `isEnding`, `endingLabel`, `visualCanon`, `transitions`
- transition: `id`, `targetNodeId`, `intent`, `triggers`, `description`
diff --git a/data.reference/prompts/stages/fableloom-feedback-series-plan.md b/data.reference/prompts/stages/fableloom-feedback-series-plan.md
index ebcbdb6238..bee2661aa6 100644
--- a/data.reference/prompts/stages/fableloom-feedback-series-plan.md
+++ b/data.reference/prompts/stages/fableloom-feedback-series-plan.md
@@ -20,6 +20,7 @@ You are the story editor for an interactive branching series. Apply the author's
## Editing contract
+- `seriesDesign`, when present in the current plan, is author-owned and read-only. Honor its finite or renewable intent, but never return or rewrite it. Keep mutually exclusive branch outcomes as alternatives rather than combining them into one compulsory sequence.
- Make the smallest coherent change that fully satisfies the instruction.
- A missing field preserves it. A present empty string or `null` intentionally clears it.
- Return sparse item edits. Preserve existing item ids; new items omit `id`; removal uses `remove: true`.
diff --git a/data.reference/prompts/stages/fableloom-generate-series-plan.md b/data.reference/prompts/stages/fableloom-generate-series-plan.md
index a10c725dc5..896d055b4e 100644
--- a/data.reference/prompts/stages/fableloom-generate-series-plan.md
+++ b/data.reference/prompts/stages/fableloom-generate-series-plan.md
@@ -16,6 +16,8 @@ You are the series architect for an interactive branching story. Draft the compl
## Planning contract
+- `seriesDesign`, when present in the current plan, is an author-owned brief. Honor it and never return or rewrite it. A renewable design must retain a recognizable source of further episode stories without making every local branch identical. A finite design may bring its declared problem to a complete ending and must not manufacture continuation after that ending.
+- Treat mutually exclusive branch outcomes as alternatives, not events that all happen. A local ending may satisfy its own promise even when another planned branch or later episode continues.
- Write a clear beginning-to-end `storyArc`: protagonist pressure, escalation, irreversible midpoint, climax, resolution, and thematic movement. Account for meaningful local branches while keeping the series-level promises and payoffs legible.
- Draft 6–12 ordered `plotPoints`. Give each a durable `kind`: `"beat"` for a fixed tentpole or `"challenge"` for a blockade the viewer helps solve. Include several concrete playable challenges when the premise supports them. Each item needs a concise title and a description of what happens, why it matters, and what changes.
- A `kind: "challenge"` description must name the planted clue or capability, the viewer decision loop, distinct success and failure consequences, and the recovery/payoff that lets failure continue with a visible cost.
diff --git a/data.reference/prompts/stages/fableloom-outline-episode.md b/data.reference/prompts/stages/fableloom-outline-episode.md
index fb8a850c94..6b570726bc 100644
--- a/data.reference/prompts/stages/fableloom-outline-episode.md
+++ b/data.reference/prompts/stages/fableloom-outline-episode.md
@@ -32,6 +32,7 @@ You are the story architect for one episode of an interactive branching series.
## Planning contract
+- Honor any Series design in the Story section. Renewable series keep their declared recurring activity and continuing tensions available beyond a local episode outcome; finite series may complete the declared ending condition. Do not flatten mutually exclusive outcomes into events that all happen, and do not rewrite a valid ending merely to keep the series running. Judge each ending against its local promise and the supplied episode order.
- The first episode must establish a person before a puzzle: show the protagonist doing their everyday role, pursuing a concrete immediate want, and encountering a disruption with a legible personal cost. Put these observable actions in the opening summaries; the synopsis does not count as on-screen setup. Introduce unfamiliar systems through their effect on that person before naming their mechanisms. Do not spend the opening on evidence administration or future branch bookkeeping.
- Plan the complete dramatic job of this episode, including setup, escalation, a meaningful turn, branch consequences, and distinct endings that hand off cleanly to the next episode when one exists.
- Use one beat per eventual camera-cut scene. Keep each `summary` to 1–3 sentences describing what changes, what the protagonist wants, and why the beat matters.
diff --git a/data.reference/prompts/stages/fableloom-review-episode-outline.md b/data.reference/prompts/stages/fableloom-review-episode-outline.md
index 8e086ec519..f8dfc92f35 100644
--- a/data.reference/prompts/stages/fableloom-review-episode-outline.md
+++ b/data.reference/prompts/stages/fableloom-review-episode-outline.md
@@ -26,6 +26,8 @@ When Story requests a cold opening review, evaluate ONLY the supplied opening an
For a full outline review, evaluate whether the episode has a clear dramatic job, escalation, protagonist agency, branch consequences, meaningful and distinct endings, continuity with adjacent episodes, side-quest movement, and a compelling handoff. Check that choices are legible from their preceding beat and that the audience connection rules are dramatized rather than merely technical. Check that off-screen protagonist beats are reserved for direct audience conversations and that visible beats keep the canonical wardrobe. Flag only concrete risks that a writer can fix before teleplay expansion.
+Honor any Series design in the Story section. Renewable intent requires a credible source of further stories, while finite intent may reach its declared ending condition. Do not treat mutually exclusive branches as events that all occur or rewrite a valid ending solely to prolong the series. Anchor each design-related risk to the supplied episode and outline scene key. Judge an ending by its local branch promise and the stated later continuation; voicemail and teaser handoffs remain independent.
+
Return ONLY valid JSON matching this shape — no prose, markdown fence, or commentary:
```json
diff --git a/data.reference/prompts/stages/fableloom-review-playthroughs.md b/data.reference/prompts/stages/fableloom-review-playthroughs.md
index 4aebf017fb..df652088eb 100644
--- a/data.reference/prompts/stages/fableloom-review-playthroughs.md
+++ b/data.reference/prompts/stages/fableloom-review-playthroughs.md
@@ -28,6 +28,7 @@ You are the final narrative quality reviewer for an interactive FableLoom series
Evaluate:
+- any author-owned `seriesDesign`: renewable stories retain the declared recurring activity and a source of varied episodes, while finite stories may end completely when the ending condition is earned. Treat mutually exclusive paths as alternatives and never require a valid deliberate ending to reopen solely to keep the series running. Judge local ending promises separately from explicit later-series continuation; configured voicemail and teaser handoffs remain independent;
- whether every choice is understandable before it is made and creates a causally legible consequence;
- whether branch-specific knowledge, relationships, objects, injuries, promises, and emotional state remain coherent after convergence;
- whether the protagonist retains agency and the audience participation contract is honored;
@@ -36,7 +37,7 @@ Evaluate:
- whether episode handoffs, side quests, visual continuity, and character voices remain consistent across all variations;
- whether the writing is specific, emotionally credible, paced for play, and strong enough to ship.
-Anchor each finding to the most specific supplied episode, path, and scene ids. Do not invent ids. A score of 8 or higher means polished, coherent, high-quality interactive storytelling. Set `passed` to true only when the score is at least 8, no high-severity finding remains, and the deterministic harness reports no failure.
+Anchor each finding to the most specific supplied episode, path, and scene ids. Do not invent ids. A satisfied series-design brief contributes no finding. A score of 8 or higher means polished, coherent, high-quality interactive storytelling. Set `passed` to true only when the score is at least 8, no high-severity finding remains, and the deterministic harness reports no failure.
Return ONLY valid JSON matching this shape — no prose, markdown fence, or commentary:
diff --git a/data.reference/prompts/stages/fableloom-review-series-plan.md b/data.reference/prompts/stages/fableloom-review-series-plan.md
index 8aff1de22c..1a660deba8 100644
--- a/data.reference/prompts/stages/fableloom-review-series-plan.md
+++ b/data.reference/prompts/stages/fableloom-review-series-plan.md
@@ -16,6 +16,8 @@ You are a senior story editor analyzing the complete plan for an interactive bra
Evaluate the long-form dramatic arc, escalation and payoff of the ordered plot points, pacing across episodes, integration and resolution of side quests, continuity, thematic coherence, and whether the plan leaves each episode a distinct dramatic job. When beat outlines are present in the episode outline, review their scene-by-scene progression as one continuous teleplay series: check that each episode inherits the previous episode's consequences, that the protagonist and world remain consistent, that branch outcomes reconverge honestly, and that the finale's configured voicemail/teaser handoffs are earned. Account for branching storytelling: meaningful paths can vary locally, but the series-level promises and payoffs still need to remain legible.
+When `seriesDesign` is present, treat it as author-owned intent. A renewable plan must preserve its declared recurring activity and a credible source of varied future episodes. A finite plan may fulfill its ending condition completely; do not call that completion a defect or demand another season. Treat mutually exclusive outcomes as alternatives. Anchor every design-related risk to a supplied episode, plot-point id, or outline scene key, and judge a local ending against what that branch promises plus any explicit later continuation. Configured voicemail and teaser handoffs remain independent requirements. A satisfied brief contributes no risk; an empty `risks` array is valid.
+
{{#characterEvolutions}}
## Authored character evolution (five-stage lens)
diff --git a/data.reference/prompts/stages/fableloom-review-series-teleplay.md b/data.reference/prompts/stages/fableloom-review-series-teleplay.md
index 0b11d64f63..c48538e069 100644
--- a/data.reference/prompts/stages/fableloom-review-series-teleplay.md
+++ b/data.reference/prompts/stages/fableloom-review-series-teleplay.md
@@ -22,6 +22,8 @@ You are the senior story editor on a complete interactive teleplay series. Revie
Evaluate the full series for protagonist continuity, character and place consistency, escalation, midpoint reversal, climax and resolution, episode-to-episode causality, branch consequences, choice clarity, side-quest payoff, scene-level pacing, distinct endings, and the configured overnight voicemail/finale teaser handoffs. Treat the image-preview/player experience as part of the review: every scene should have a clear visual beat and every decision should be available only when the audience channel is active. Flag concrete issues with the smallest useful fix; do not pad the review with generic advice.
+When `seriesDesign` is present, treat it as author-owned intent. Renewable stories must retain their declared recurring activity and continuing source of varied episodes; finite stories may conclude when their ending condition is earned. Do not combine mutually exclusive outcomes into one chronology or demand that a valid deliberate ending be reopened merely to continue. Anchor each design-related risk to an exact supplied episode and scene/path. Judge local ending promises separately from explicit later-series continuation, and keep voicemail/teaser handoffs independent. A fully satisfied brief requires no risk.
+
Return ONLY valid JSON matching this shape — no prose, markdown fence, or commentary:
```json
diff --git a/data.reference/prompts/stages/fableloom-weave-episode.md b/data.reference/prompts/stages/fableloom-weave-episode.md
index d2dc6e25c7..5c0c2f6514 100644
--- a/data.reference/prompts/stages/fableloom-weave-episode.md
+++ b/data.reference/prompts/stages/fableloom-weave-episode.md
@@ -32,6 +32,7 @@ When a validated beat outline is present, it is the authoritative story plan for
## Design contract
+- Honor any Series design in the Story section. Preserve its author-owned finite or renewable intent without copying it into story fields. Mutually exclusive paths are alternatives, not a checklist of events every path must contain. Preserve a deliberate finite ending when it fulfills its branch promise; for renewable intent, retain the declared source of further stories without flattening local outcomes. Configured voicemail and teaser handoffs remain independent requirements.
- Choose the node count and ending count yourself from the story's pacing, dramatic coverage, and branching needs. Never compress multiple camera cuts into one node to hit an arbitrary count.
- Each node is exactly ONE continuous shot with one primary framing and one camera movement. Split every change of angle, framing, location, time, or camera movement into another node.
- Set `playbackMode: "cut"` on setup/action nodes that play once and automatically feed the next camera cut. They must have exactly one `Continue` transition.
diff --git a/scripts/migrations/288-fableloom-scene-format.js b/scripts/migrations/288-fableloom-scene-format.js
index fa44f56fc2..5a7b564acb 100644
--- a/scripts/migrations/288-fableloom-scene-format.js
+++ b/scripts/migrations/288-fableloom-scene-format.js
@@ -32,7 +32,7 @@ export const ACCEPTED_OLD_MD5 = {
// Post-change shipped hashes (format contract rendered from the loom record).
export const NEW_SHIPPED_MD5 = {
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e', // post-324 challenge mapping
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71', // post-384 series design
'fableloom-branch-node.md': '39a208c8cc593d0531af50760e3cf0da',
'fableloom-play-turn.md': 'e35ad91aae263e3adf28d1e047a46661',
};
diff --git a/scripts/migrations/310-fableloom-camera-cuts.js b/scripts/migrations/310-fableloom-camera-cuts.js
index 17d9b1ad96..4d2506619b 100644
--- a/scripts/migrations/310-fableloom-camera-cuts.js
+++ b/scripts/migrations/310-fableloom-camera-cuts.js
@@ -17,7 +17,7 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e', // post-324 challenge mapping
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71', // post-384 series design
'fableloom-branch-node.md': '39a208c8cc593d0531af50760e3cf0da',
'fableloom-feedback-episode.md': '1aaa6f17acad6a3215e48dcce14e8670',
};
diff --git a/scripts/migrations/311-fableloom-audience-participation.js b/scripts/migrations/311-fableloom-audience-participation.js
index ea7fd47fdd..5eb2c52b7c 100644
--- a/scripts/migrations/311-fableloom-audience-participation.js
+++ b/scripts/migrations/311-fableloom-audience-participation.js
@@ -17,7 +17,7 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e', // post-324 challenge mapping
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71', // post-384 series design
'fableloom-branch-node.md': '39a208c8cc593d0531af50760e3cf0da',
'fableloom-feedback-episode.md': '1aaa6f17acad6a3215e48dcce14e8670',
'fableloom-review.md': 'c26a641f6d0530caef7d1186c3b09937',
diff --git a/scripts/migrations/319-fableloom-protagonist-continuity.js b/scripts/migrations/319-fableloom-protagonist-continuity.js
index ca035a9fe6..c28c733bc3 100644
--- a/scripts/migrations/319-fableloom-protagonist-continuity.js
+++ b/scripts/migrations/319-fableloom-protagonist-continuity.js
@@ -12,9 +12,9 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e',
- 'fableloom-outline-episode.md': '2ff6fb72777ff0c6fc70f3afd0ddfd53',
- 'fableloom-review-episode-outline.md': '0f549ed25dea8566ce2d3c515968783b',
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71',
+ 'fableloom-outline-episode.md': '76f5211b851de7a0a23d9c11c5969b25',
+ 'fableloom-review-episode-outline.md': '3e548d8de54dd23312a6f1024910fedc',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/321-fableloom-outline-expansion-contract.js b/scripts/migrations/321-fableloom-outline-expansion-contract.js
index d7f84f79a4..9d22837aec 100644
--- a/scripts/migrations/321-fableloom-outline-expansion-contract.js
+++ b/scripts/migrations/321-fableloom-outline-expansion-contract.js
@@ -7,7 +7,7 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e',
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/324-fableloom-playable-challenge-contract.js b/scripts/migrations/324-fableloom-playable-challenge-contract.js
index 4a26bdafef..23cad52035 100644
--- a/scripts/migrations/324-fableloom-playable-challenge-contract.js
+++ b/scripts/migrations/324-fableloom-playable-challenge-contract.js
@@ -9,9 +9,9 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-generate-series-plan.md': '27336d8c64e6193aecd1ba697f52315e',
- 'fableloom-outline-episode.md': '2ff6fb72777ff0c6fc70f3afd0ddfd53',
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e',
+ 'fableloom-generate-series-plan.md': 'ab912a52879d8ce78e9998dec19ddaa8',
+ 'fableloom-outline-episode.md': '76f5211b851de7a0a23d9c11c5969b25',
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/349-fableloom-plan-synopsis-sync.js b/scripts/migrations/349-fableloom-plan-synopsis-sync.js
index e002ef891b..a1390e69c7 100644
--- a/scripts/migrations/349-fableloom-plan-synopsis-sync.js
+++ b/scripts/migrations/349-fableloom-plan-synopsis-sync.js
@@ -5,7 +5,7 @@ export const ACCEPTED_OLD_MD5 = {
'fableloom-feedback-series-plan.md': ['6c4f6c846acc6186eaa8da297080b9d9'],
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-feedback-series-plan.md': '2d1b40041223baa02a1517a102f103c2',
+ 'fableloom-feedback-series-plan.md': 'ece17ecf3ee0d6018f3ca350794d8d52',
};
const { applyMigration, up } = makePromptReplaceMigration({
accepted: ACCEPTED_OLD_MD5,
diff --git a/scripts/migrations/350-fableloom-opening-comprehension.js b/scripts/migrations/350-fableloom-opening-comprehension.js
index a9935e6c83..ebb4492442 100644
--- a/scripts/migrations/350-fableloom-opening-comprehension.js
+++ b/scripts/migrations/350-fableloom-opening-comprehension.js
@@ -10,8 +10,8 @@ export const ACCEPTED_OLD_MD5 = {
]
};
export const NEW_SHIPPED_MD5 = {
- "fableloom-outline-episode.md": "2ff6fb72777ff0c6fc70f3afd0ddfd53",
- "fableloom-review-episode-outline.md": "0f549ed25dea8566ce2d3c515968783b"
+ "fableloom-outline-episode.md": "76f5211b851de7a0a23d9c11c5969b25",
+ "fableloom-review-episode-outline.md": "3e548d8de54dd23312a6f1024910fedc"
};
const { applyMigration, up } = makePromptReplaceMigration({
accepted: ACCEPTED_OLD_MD5, current: NEW_SHIPPED_MD5,
diff --git a/scripts/migrations/365-fableloom-editorial-cast-integrity.js b/scripts/migrations/365-fableloom-editorial-cast-integrity.js
index 48e75d9dc1..b3ea4c58f1 100644
--- a/scripts/migrations/365-fableloom-editorial-cast-integrity.js
+++ b/scripts/migrations/365-fableloom-editorial-cast-integrity.js
@@ -21,7 +21,7 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-editorial-remediate.md': 'c0cce5cfe63ec4e94047415bbe83881b',
+ 'fableloom-editorial-remediate.md': '75f23d18fdf3b4ca3f329db8c61aec9d',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/368-fableloom-plan-review-evolution.js b/scripts/migrations/368-fableloom-plan-review-evolution.js
index 959e1f84b8..e84e97bc39 100644
--- a/scripts/migrations/368-fableloom-plan-review-evolution.js
+++ b/scripts/migrations/368-fableloom-plan-review-evolution.js
@@ -28,7 +28,7 @@ export const ACCEPTED_OLD_MD5 = {
};
export const NEW_SHIPPED_MD5 = {
- 'fableloom-review-series-plan.md': '588c82fafd733581490f24cb6fb4bfa7',
+ 'fableloom-review-series-plan.md': 'd82ff6df1d41c3e53fb0cc7ea49f8dc5',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/384-fableloom-series-design.js b/scripts/migrations/384-fableloom-series-design.js
new file mode 100644
index 0000000000..c3363222d7
--- /dev/null
+++ b/scripts/migrations/384-fableloom-series-design.js
@@ -0,0 +1,35 @@
+import { makePromptReplaceMigration } from './_lib.js';
+
+export const ACCEPTED_OLD_MD5 = {
+ 'fableloom-editorial-remediate.md': ['c0cce5cfe63ec4e94047415bbe83881b'],
+ 'fableloom-feedback-series-plan.md': ['2d1b40041223baa02a1517a102f103c2'],
+ 'fableloom-generate-series-plan.md': ['27336d8c64e6193aecd1ba697f52315e'],
+ 'fableloom-outline-episode.md': ['2ff6fb72777ff0c6fc70f3afd0ddfd53'],
+ 'fableloom-review-episode-outline.md': ['0f549ed25dea8566ce2d3c515968783b'],
+ 'fableloom-review-playthroughs.md': ['27843c9a77dc9dcfb8a9b12102253541'],
+ 'fableloom-review-series-plan.md': ['588c82fafd733581490f24cb6fb4bfa7'],
+ 'fableloom-review-series-teleplay.md': ['fc87fe58f599be451d245ce4f26d9691'],
+ 'fableloom-weave-episode.md': ['abea2442af2be2039b70deee4919c00e'],
+};
+
+export const NEW_SHIPPED_MD5 = {
+ 'fableloom-editorial-remediate.md': '75f23d18fdf3b4ca3f329db8c61aec9d',
+ 'fableloom-feedback-series-plan.md': 'ece17ecf3ee0d6018f3ca350794d8d52',
+ 'fableloom-generate-series-plan.md': 'ab912a52879d8ce78e9998dec19ddaa8',
+ 'fableloom-outline-episode.md': '76f5211b851de7a0a23d9c11c5969b25',
+ 'fableloom-review-episode-outline.md': '3e548d8de54dd23312a6f1024910fedc',
+ 'fableloom-review-playthroughs.md': 'c24c3799c8ef9050c16a3fa4b56920e2',
+ 'fableloom-review-series-plan.md': 'd82ff6df1d41c3e53fb0cc7ea49f8dc5',
+ 'fableloom-review-series-teleplay.md': '10a3289dd0824539f7ccbcd4a579c865',
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71',
+};
+
+const { applyMigration, up } = makePromptReplaceMigration({
+ accepted: ACCEPTED_OLD_MD5,
+ current: NEW_SHIPPED_MD5,
+ label: 'FableLoom series design',
+ customizedHint: (filename) => ` Merge the series-design guidance from data.reference/prompts/stages/${filename} into your customized prompt.`,
+});
+
+export { applyMigration };
+export default { up };
diff --git a/scripts/migrations/384-fableloom-series-design.test.js b/scripts/migrations/384-fableloom-series-design.test.js
new file mode 100644
index 0000000000..a211eb9e36
--- /dev/null
+++ b/scripts/migrations/384-fableloom-series-design.test.js
@@ -0,0 +1,13 @@
+import { describe } from 'vitest';
+import { runPromptMigrationTests } from './_testHelpers.js';
+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './384-fableloom-series-design.js';
+
+describe('migration 384 — FableLoom series design', () => {
+ runPromptMigrationTests({
+ migration,
+ applyMigration,
+ ACCEPTED_OLD_MD5,
+ NEW_SHIPPED_MD5,
+ prefix: 'migration-384-',
+ });
+});
diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.js
index 94a1388057..7001ba9ed1 100644
--- a/scripts/setup-data-drift.test.js
+++ b/scripts/setup-data-drift.test.js
@@ -58,19 +58,21 @@ const EXPECTED_STAGE_OLD = {
'pipeline-judge-foundation.md': ['75714f0e41c77ff5c8b9623cb4fb0a25', '74c0244e641dcf7a73e9c83123ebdee9', '4c0bd349ff4d329048c9f4ac068745d4', 'edf7850d0c724c63761bc9fb667227d9', '02a8e9215ba534b333f3a29f11f3ac4f', 'e44b6c50d741bbd21fc86f481684c410'],
'pipeline-observer.md': ['f3dc51ac077050a887c2161ee7438181'],
'pipeline-self-improve.md': ['ed0b0df42e0690d515b8dd88911931e4'],
- 'fableloom-editorial-remediate.md': ['d73329e2341e7bea9935a96043ed045f'],
- 'fableloom-weave-episode.md': ['1fea11b8c4269008561ac22a30494d46', '1b27f5b0073a304c21079aa6e2c71447', '4c9454d1537c4ebb3becbfa04fae3ed8', '18a442e39b973e4074a0d595928a665d', 'e0f8d864caa8746912b56cd567f1c09d', 'b4d363db94fd8a9928fa977745c76ff9'],
+ 'fableloom-editorial-remediate.md': ['d73329e2341e7bea9935a96043ed045f', 'c0cce5cfe63ec4e94047415bbe83881b'],
+ 'fableloom-weave-episode.md': ['1fea11b8c4269008561ac22a30494d46', '1b27f5b0073a304c21079aa6e2c71447', '4c9454d1537c4ebb3becbfa04fae3ed8', '18a442e39b973e4074a0d595928a665d', 'e0f8d864caa8746912b56cd567f1c09d', 'b4d363db94fd8a9928fa977745c76ff9', 'abea2442af2be2039b70deee4919c00e'],
'fableloom-branch-node.md': ['f558e4804b056a5961af1ea74fdef2ba', '6279b1c9912c300363a727245d22fe84', 'c14e2b9c435e43a8c3b134a62cd66d08'],
'fableloom-play-turn.md': ['bb33dc9bc483668d88196ca972d5f364'],
'fableloom-feedback-episode.md': ['43d1525fcedce99b933ae5b003516a36', 'd09bb405478d24c294b0c658ef365cd1'],
'fableloom-review.md': ['2802f269f246e00ec5a8937637d42de6'],
- 'fableloom-outline-episode.md': ['3f5144103b2ab6203fa071ff5026251b', '513b2b5b8fa98766852cdde7b87198c9', '820b8c157c1977b34eb317e44236519e'],
- 'fableloom-review-episode-outline.md': ['96d631104155ff11be08bcc5144cca1c', '8154b4c289b10268df8fd3c625bcdac2'],
- 'fableloom-review-series-plan.md': ['1c1ab552f6f6a4d9d51f1d3bacd89122'],
- 'fableloom-feedback-series-plan.md': ['6c4f6c846acc6186eaa8da297080b9d9'],
+ 'fableloom-outline-episode.md': ['3f5144103b2ab6203fa071ff5026251b', '513b2b5b8fa98766852cdde7b87198c9', '820b8c157c1977b34eb317e44236519e', '2ff6fb72777ff0c6fc70f3afd0ddfd53'],
+ 'fableloom-review-episode-outline.md': ['96d631104155ff11be08bcc5144cca1c', '8154b4c289b10268df8fd3c625bcdac2', '0f549ed25dea8566ce2d3c515968783b'],
+ 'fableloom-review-series-plan.md': ['1c1ab552f6f6a4d9d51f1d3bacd89122', '588c82fafd733581490f24cb6fb4bfa7'],
+ 'fableloom-feedback-series-plan.md': ['6c4f6c846acc6186eaa8da297080b9d9', '2d1b40041223baa02a1517a102f103c2'],
+ 'fableloom-review-playthroughs.md': ['27843c9a77dc9dcfb8a9b12102253541'],
+ 'fableloom-review-series-teleplay.md': ['fc87fe58f599be451d245ce4f26d9691'],
'fableloom-plan-shots.md': ['4cf0fb96d4e9a17a8ae8285ec134f37f'],
'fableloom-review-shots.md': ['699ba1189f67338728b74834269759a9'],
- 'fableloom-generate-series-plan.md': ['2591cf4ca6cc160765f029fcc497dc35'],
+ 'fableloom-generate-series-plan.md': ['2591cf4ca6cc160765f029fcc497dc35', '27336d8c64e6193aecd1ba697f52315e'],
'pipeline-editorial-character-consistency.md': ['69bbee3a1bb126b2675d8b00f5aef48c'],
'pipeline-editorial-secondary-arc.md': ['8a96ce93f6592fed3d30e221497739a4'],
'pipeline-editorial-arc-transitions.md': ['72e27707f0dc82eab84eed74e9707587'],
@@ -112,19 +114,21 @@ const EXPECTED_STAGE_NEW = {
'pipeline-judge-foundation.md': 'd4abf4ddafbf84a2903e6d70d14adea1',
'pipeline-observer.md': '29e0212d2252b1be3278f20e2959eb8e',
'pipeline-self-improve.md': '95b378832ff78e5976a6a63fcf328090',
- 'fableloom-editorial-remediate.md': 'c0cce5cfe63ec4e94047415bbe83881b',
- 'fableloom-weave-episode.md': 'abea2442af2be2039b70deee4919c00e',
+ 'fableloom-editorial-remediate.md': '75f23d18fdf3b4ca3f329db8c61aec9d',
+ 'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71',
'fableloom-branch-node.md': '39a208c8cc593d0531af50760e3cf0da',
'fableloom-play-turn.md': 'e35ad91aae263e3adf28d1e047a46661',
'fableloom-feedback-episode.md': '1aaa6f17acad6a3215e48dcce14e8670',
'fableloom-review.md': 'c26a641f6d0530caef7d1186c3b09937',
- 'fableloom-outline-episode.md': '2ff6fb72777ff0c6fc70f3afd0ddfd53',
- 'fableloom-review-episode-outline.md': '0f549ed25dea8566ce2d3c515968783b',
- 'fableloom-review-series-plan.md': '588c82fafd733581490f24cb6fb4bfa7',
- 'fableloom-feedback-series-plan.md': '2d1b40041223baa02a1517a102f103c2',
+ 'fableloom-outline-episode.md': '76f5211b851de7a0a23d9c11c5969b25',
+ 'fableloom-review-episode-outline.md': '3e548d8de54dd23312a6f1024910fedc',
+ 'fableloom-review-series-plan.md': 'd82ff6df1d41c3e53fb0cc7ea49f8dc5',
+ 'fableloom-feedback-series-plan.md': 'ece17ecf3ee0d6018f3ca350794d8d52',
+ 'fableloom-review-playthroughs.md': 'c24c3799c8ef9050c16a3fa4b56920e2',
+ 'fableloom-review-series-teleplay.md': '10a3289dd0824539f7ccbcd4a579c865',
'fableloom-plan-shots.md': '9b1cd4b406ee327d6dc3fcbd57b48483',
'fableloom-review-shots.md': '8cf5fe685cc5f75537caddea1d272a00',
- 'fableloom-generate-series-plan.md': '27336d8c64e6193aecd1ba697f52315e',
+ 'fableloom-generate-series-plan.md': 'ab912a52879d8ce78e9998dec19ddaa8',
'pipeline-editorial-character-consistency.md': 'bbefd9b033cc7830752acf87722659a0',
'pipeline-editorial-secondary-arc.md': 'a9bd4dd9a06bc571f0363e0031d9a5d7',
'pipeline-editorial-arc-transitions.md': '46cb5444f41d05fb7bdbc219d62619b2',
diff --git a/server/lib/fableLoomValidation.js b/server/lib/fableLoomValidation.js
index 80f27a2879..62fb5b042e 100644
--- a/server/lib/fableLoomValidation.js
+++ b/server/lib/fableLoomValidation.js
@@ -33,6 +33,7 @@ import { FABLELOOM_PLAYTEST_LIMITS } from './fableLoomPlaytest.js';
import { EFFORT_LEVELS } from './providerModels.js';
import { QUEUEABLE_IMAGE_MODES, VIDEO_GEN_MODES } from './generationModes.js';
import { llmRoutePinSchema } from './llmRoutePin.js';
+import { seriesDesignSchema } from './sharedSchemas.js';
const name = z.string().trim().min(1).max(LOOM_LIMITS.NAME_MAX);
const logline = z.string().max(LOOM_LIMITS.LOGLINE_MAX);
@@ -120,6 +121,9 @@ const seriesPlan = z.object({
// wholesale-`seriesPlan` PATCH (the sync path is where an absent key
// preserves — see preserveLegacyCharacterEvolutions).
characterEvolutions: characterEvolutionListSchema.optional(),
+ // Omission clears on the wholesale plan PATCH; null is also accepted as an
+ // explicit clear and is preserved on current-version sync payloads.
+ seriesDesign: seriesDesignSchema.nullable().optional(),
});
const outlineTransitionSchema = z.object({
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index 181b3e3b00..9650d6dcfc 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -408,7 +408,11 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({
// restores local lenses from a <v8 sender that omits the key
// (`preserveLegacyCharacterEvolutions`), the same belt-and-braces the
// delivery plan got at v4.
- fableLoom: 8,
+ // v9 = `seriesPlan.seriesDesign` — the optional shared finite/renewable
+ // author brief. A <=v8 peer would strip it during an unrelated whole-record
+ // edit, so newer transfers are gated and legacy omissions restore the local
+ // value through `preserveLegacySeriesDesign`.
+ fableLoom: 9,
// v1 = Creative Director projects (PostgreSQL `creative_director_projects`)
// federated via the per-record peer-sync push pipeline (record kind
// `creativeDirectorProject`, sync category `creativeDirectorProjects`, #1564).
diff --git a/server/lib/schemaVersions.test.js b/server/lib/schemaVersions.test.js
index ac38168cf2..248c2b92a0 100644
--- a/server/lib/schemaVersions.test.js
+++ b/server/lib/schemaVersions.test.js
@@ -45,10 +45,11 @@ describe('PORTOS_SCHEMA_VERSIONS', () => {
it('version-gates the persisted FableLoom shot and reference shape', () => {
// v7 adds timed shots and draft character image anchors; v8 adds the
- // optional per-character five-stage evolution lens on the series plan.
+ // optional per-character five-stage evolution lens on the series plan; v9
+ // adds the shared finite/renewable series-design brief.
// Older peers stay behind the full render contract until they advertise
// support for the additive fields.
- expect(PORTOS_SCHEMA_VERSIONS.fableLoom).toBe(8);
+ expect(PORTOS_SCHEMA_VERSIONS.fableLoom).toBe(9);
});
it('version-gates the additive Creative Commission taste brief shape', () => {
diff --git a/server/routes/fableLoom.test.js b/server/routes/fableLoom.test.js
index 7e1fc5ea43..db7a1d1d49 100644
--- a/server/routes/fableLoom.test.js
+++ b/server/routes/fableLoom.test.js
@@ -241,6 +241,11 @@ describe('FableLoom routes', () => {
it('validates and forwards structured series-plan patches', async () => {
const seriesPlan = {
+ seriesDesign: {
+ mode: 'finite',
+ episodeActivity: 'The courier decodes one dangerous signal.',
+ endingCondition: 'The source is identified and silenced.',
+ },
storyArc: 'A courier becomes a leader.',
plotPoints: [{ id: 'plot-1', title: 'The choice', description: 'She stays.', episodeId: 'ep-1' }],
sideQuests: [{ id: 'quest-1', title: 'Lost map', description: 'Recover it.', status: 'active', startEpisodeId: 'ep-1', endEpisodeId: null }],
@@ -249,6 +254,15 @@ describe('FableLoom routes', () => {
const response = await request(makeApp()).patch('/api/fableloom/loom-1').send({ seriesPlan });
expect(response.status).toBe(200);
expect(fableLoom.updateLoom).toHaveBeenCalledWith('loom-1', { seriesPlan });
+
+ fableLoom.updateLoom.mockResolvedValueOnce({ id: 'loom-1', seriesPlan: { ...seriesPlan, seriesDesign: null } });
+ const cleared = await request(makeApp()).patch('/api/fableloom/loom-1').send({
+ seriesPlan: { ...seriesPlan, seriesDesign: null },
+ });
+ expect(cleared.status).toBe(200);
+ expect(fableLoom.updateLoom).toHaveBeenLastCalledWith('loom-1', {
+ seriesPlan: { ...seriesPlan, seriesDesign: null },
+ });
});
it('episode + node CRUD dispatches with route params', async () => {
diff --git a/server/services/fableLoom/editorial.js b/server/services/fableLoom/editorial.js
index 3205f6b195..1125e2dbb8 100644
--- a/server/services/fableLoom/editorial.js
+++ b/server/services/fableLoom/editorial.js
@@ -33,6 +33,7 @@ import {
FABLELOOM_PROTAGONIST_PRESENCE,
} from '../../lib/fableLoomPlayback.js';
import { renderStoryCanonDigest } from '../../lib/universePromptRenderers.js';
+import { renderSeriesDesign } from '../../lib/storyArc.js';
import { normalizeFableLoomCameraMovement } from '../../lib/fableLoomCameraMovements.js';
import { startAIOp } from '../aiStatusEvents.js';
import { buildPrompt } from '../promptService.js';
@@ -165,6 +166,7 @@ const storyContext = (loom) => [
loom.protagonistWardrobeId
? `Canonical protagonist wardrobe id: ${loom.protagonistWardrobeId}`
: '',
+ renderSeriesDesign(loom.seriesPlan?.seriesDesign),
].filter(Boolean).join('\n');
const withoutTemporalMetadata = (value) => {
@@ -229,6 +231,9 @@ const assertEditorialDependenciesUnchanged = (current, fingerprint, { code, mess
};
const seriesPlanDigest = (loom) => JSON.stringify({
+ ...(Object.prototype.hasOwnProperty.call(loom.seriesPlan || {}, 'seriesDesign')
+ ? { seriesDesign: loom.seriesPlan.seriesDesign }
+ : {}),
storyArc: loom.seriesPlan?.storyArc || '',
plotPoints: asArray(loom.seriesPlan?.plotPoints),
sideQuests: asArray(loom.seriesPlan?.sideQuests),
@@ -1273,6 +1278,7 @@ export const __testing = {
sanitizeEvaluation,
sanitizePlaythroughReview,
seriesPlanDigest,
+ storyContext,
teleplayDigest,
withCompletePlaythroughDigest,
};
diff --git a/server/services/fableLoom/editorial.test.js b/server/services/fableLoom/editorial.test.js
index 0ba2a7c0fd..510daf5a09 100644
--- a/server/services/fableLoom/editorial.test.js
+++ b/server/services/fableLoom/editorial.test.js
@@ -150,6 +150,40 @@ const completeOutline = () => ({
});
describe('editorial prompt graph contract', () => {
+ it('carries the exact optional series brief through branching editorial context without making it editable', () => {
+ const plain = makeLoom();
+ const designed = sanitizeLoom({
+ ...plain,
+ seriesPlan: {
+ ...plain.seriesPlan,
+ seriesDesign: {
+ mode: 'finite',
+ episodeActivity: 'Trace one fork of the divided signal.',
+ endingCondition: 'The sender is identified and the beacon is silenced.',
+ },
+ },
+ });
+
+ expect(JSON.parse(__testing.seriesPlanDigest(plain))).not.toHaveProperty('seriesDesign');
+ expect(JSON.parse(__testing.seriesPlanDigest(designed)).seriesDesign).toEqual(designed.seriesPlan.seriesDesign);
+ expect(__testing.storyContext(designed)).toContain('Series design (author-owned; do not rewrite this brief):');
+ expect(__testing.teleplayDigest(designed)).toContain('transition=take-left sourceNode=opening targetNode=left');
+ expect(__testing.teleplayDigest(designed)).toContain('transition=take-right sourceNode=opening targetNode=right');
+ expect(__testing.editorialFingerprint(designed)).not.toBe(__testing.editorialFingerprint(plain));
+ expect(() => __testing.assertEditorialSnapshotUnchanged(
+ designed,
+ __testing.editorialFingerprint(plain),
+ { code: 'STALE', message: 'Series design changed' },
+ )).toThrow(/series design changed/i);
+
+ const remediated = applyFableLoomEditorialPatch(designed, {
+ seriesPlan: { storyArc: 'Both exclusive routes reveal one source.' },
+ }).loom;
+ expect(remediated.seriesPlan.seriesDesign).toEqual(designed.seriesPlan.seriesDesign);
+ expect(remediated.episodes[0].nodes.map((node) => node.id))
+ .toEqual(['opening', 'left', 'right', 'ending']);
+ });
+
it('gives the editor exact transition, source, and target ids for safe patches', () => {
const digest = __testing.teleplayDigest(makeLoom());
diff --git a/server/services/fableLoom/records.js b/server/services/fableLoom/records.js
index 152ac7d145..bd6191fc55 100644
--- a/server/services/fableLoom/records.js
+++ b/server/services/fableLoom/records.js
@@ -16,6 +16,7 @@ import { randomUUID } from 'crypto';
import { ServerError } from '../../lib/errorHandler.js';
import { sanitizeLlmRoutePin } from '../../lib/llmRoutePin.js';
import { sanitizeCharacterEvolutionList } from '../../lib/characterEvolution.js';
+import { sanitizeSeriesDesign } from '../../lib/storyArc.js';
import { compareNewerWins } from '../../lib/lwwTimestamp.js';
import { sanitizeSoftDeleteFields } from '../../lib/syncWire.js';
import {
@@ -245,6 +246,7 @@ function sanitizeSeriesPlan(raw, episodes) {
// the same way `sanitizeStoryOutline` keeps an unknown `targetKey` so
// DANGLING_TRANSITION can report it. Absent on every pre-#6440 plan.
const characterEvolutions = sanitizeCharacterEvolutionList(source.characterEvolutions);
+ const seriesDesign = sanitizeSeriesDesign(source.seriesDesign);
return {
storyArc: trimTo(source.storyArc, LOOM_LIMITS.STORY_ARC_MAX),
plotPoints: (Array.isArray(source.plotPoints) ? source.plotPoints : [])
@@ -278,6 +280,9 @@ function sanitizeSeriesPlan(raw, episodes) {
// above follows) and `preserveLegacyCharacterEvolutions` can tell "this
// sender cannot represent the field" from "the author cleared it".
...(characterEvolutions.length ? { characterEvolutions } : {}),
+ // Keep legacy omission byte-identical while preserving an explicit null as
+ // a clear on current-version records and sync payloads.
+ ...(source.seriesDesign !== undefined ? { seriesDesign } : {}),
};
}
@@ -737,14 +742,29 @@ const preserveLegacyCharacterEvolutions = (remotePlan, localPlan, senderVersion)
: {}
);
+// The shared author-owned series brief arrived with v9. A pre-v9 sender's
+// omission means it cannot represent the field; a v9 sender's omission is the
+// wholesale series-plan PATCH clear used by the local editor.
+const preserveLegacySeriesDesign = (remotePlan, localPlan, senderVersion) => (
+ senderVersion < 9
+ && localPlan
+ && Object.prototype.hasOwnProperty.call(localPlan, 'seriesDesign')
+ && !Object.prototype.hasOwnProperty.call(remotePlan || {}, 'seriesDesign')
+ ? { seriesDesign: localPlan.seriesDesign }
+ : {}
+);
+
// Everything an older sender cannot represent inside `seriesPlan`, in one
-// place: the v4 delivery plan, the v5 plot-point kinds, and the v8 evolution
-// lenses. Returns `remote` BY REFERENCE when there is nothing to restore, so
-// the common merge allocates no copy.
+// place: the v4 delivery plan, the v5 plot-point kinds, the v8 evolution
+// lenses, and the v9 series design. Returns `remote` BY REFERENCE when there is
+// nothing to restore, so the common merge allocates no copy.
const preserveLegacySeriesPlan = (remote, local, senderVersion) => {
const evolutions = preserveLegacyCharacterEvolutions(remote, local, senderVersion);
+ const seriesDesign = preserveLegacySeriesDesign(remote, local, senderVersion);
if (senderVersion >= 5) {
- return evolutions.characterEvolutions ? { ...remote, ...evolutions } : remote;
+ return evolutions.characterEvolutions || seriesDesign.seriesDesign !== undefined
+ ? { ...remote, ...evolutions, ...seriesDesign }
+ : remote;
}
const localPlotPoints = new Map((local?.plotPoints || []).map((item) => [item.id, item]));
return {
@@ -757,6 +777,7 @@ const preserveLegacySeriesPlan = (remote, local, senderVersion) => {
// Last, so the key lands where `sanitizeSeriesPlan` puts it — this merge
// result is persisted without a re-sanitize.
...evolutions,
+ ...seriesDesign,
};
};
@@ -766,9 +787,9 @@ const preserveLegacySeriesPlan = (remote, local, senderVersion) => {
// them. A sender at the current schema version's present null remains an
// intentional clear.
const preserveLegacyVisualProduction = (remote, local, senderVersion) => {
- if (!local || senderVersion >= 8) return remote;
+ if (!local || senderVersion >= 9) return remote;
const seriesPlan = preserveLegacySeriesPlan(remote.seriesPlan, local.seriesPlan, senderVersion);
- // A v7 sender's ONLY unrepresentable field is the evolution lens above —
+ // A v7/v8 sender's only unrepresentable plan fields are restored above —
// every branch below is gated at <7 or lower. Returning early keeps the
// dominant legacy path off the O(episodes x nodes) rebuild it would all skip.
if (senderVersion >= 7) {
@@ -849,7 +870,7 @@ export async function mergeLoomsFromSync(
remoteLooms,
{
source = { via: 'sync', peerId: null },
- senderSchemaVersions = { fableLoom: 8 },
+ senderSchemaVersions = { fableLoom: 9 },
} = {},
) {
if (!Array.isArray(remoteLooms)) return { applied: false, count: 0 };
diff --git a/server/services/fableLoom/records.test.js b/server/services/fableLoom/records.test.js
index 10168597d2..64c77725bf 100644
--- a/server/services/fableLoom/records.test.js
+++ b/server/services/fableLoom/records.test.js
@@ -1377,3 +1377,66 @@ describe('per-character evolution lens on the series plan (#6440)', () => {
});
});
});
+
+describe('author-owned series design on the series plan (#7204)', () => {
+ const renewableDesign = {
+ mode: 'renewable',
+ episodeActivity: 'Mara decodes one dangerous signal with the audience.',
+ conflictSource: 'Every sender needs a different sacrifice.',
+ audiencePromise: 'A choice changes who learns the truth.',
+ continuingTensions: 'The relay keeps revealing incompatible histories.',
+ endingCondition: '',
+ };
+
+ const seedLoomWithDesign = async () => {
+ const loom = await makeLoom({ name: 'The Signal Relay' });
+ return updateLoom(loom.id, {
+ seriesPlan: { ...loom.seriesPlan, seriesDesign: renewableDesign },
+ });
+ };
+
+ it('keeps a legacy plan byte-identical and does not inherit from a linked Pipeline series', async () => {
+ getSeriesMock.mockResolvedValueOnce({ id: 'series-1', arc: { seriesDesign: renewableDesign } });
+ const loom = await makeLoom({ name: 'Linked but independent', seriesId: 'series-1' });
+
+ expect(Object.prototype.hasOwnProperty.call(loom.seriesPlan, 'seriesDesign')).toBe(false);
+ expect(JSON.stringify(sanitizeLoom(loom).seriesPlan)).toBe(JSON.stringify(loom.seriesPlan));
+ });
+
+ it('round-trips the exact bounded brief and clears it through a wholesale plan patch', async () => {
+ const saved = await seedLoomWithDesign();
+ expect((await getLoom(saved.id)).seriesPlan.seriesDesign).toEqual(renewableDesign);
+
+ const { seriesDesign: _cleared, ...planWithoutDesign } = saved.seriesPlan;
+ const cleared = await updateLoom(saved.id, { seriesPlan: planWithoutDesign });
+ expect(Object.prototype.hasOwnProperty.call(cleared.seriesPlan, 'seriesDesign')).toBe(false);
+
+ const explicitClear = await updateLoom(saved.id, {
+ seriesPlan: { ...cleared.seriesPlan, seriesDesign: null },
+ });
+ expect(explicitClear.seriesPlan).toHaveProperty('seriesDesign', null);
+ });
+
+ it('preserves the brief from a v8 omission and lets a v9 sender clear it', async () => {
+ const loom = await seedLoomWithDesign();
+ const { seriesDesign: _dropped, ...planWithoutDesign } = loom.seriesPlan;
+
+ await mergeLoomsFromSync([{
+ ...loom,
+ name: 'Renamed by v8 peer',
+ updatedAt: '2099-01-01T00:00:00.000Z',
+ seriesPlan: planWithoutDesign,
+ }], { senderSchemaVersions: { fableLoom: 8 } });
+ expect((await getLoom(loom.id)).seriesPlan.seriesDesign).toEqual(renewableDesign);
+
+ await mergeLoomsFromSync([{
+ ...loom,
+ name: 'Cleared by v9 peer',
+ updatedAt: '2099-01-02T00:00:00.000Z',
+ seriesPlan: planWithoutDesign,
+ }], { senderSchemaVersions: { fableLoom: 9 } });
+ const cleared = await getLoom(loom.id);
+ expect(cleared.name).toBe('Cleared by v9 peer');
+ expect(Object.prototype.hasOwnProperty.call(cleared.seriesPlan, 'seriesDesign')).toBe(false);
+ });
+});
diff --git a/server/services/fableLoom/weave.js b/server/services/fableLoom/weave.js
index 17f8788fb7..b7a4b3ceb9 100644
--- a/server/services/fableLoom/weave.js
+++ b/server/services/fableLoom/weave.js
@@ -19,6 +19,7 @@ import { runStagedLLM } from '../stageRunner.js';
import { resolveLlmRoutePin } from '../../lib/llmRoutePin.js';
import { renderStoryCanonDigest } from '../../lib/universePromptRenderers.js';
import { renderCharacterEvolutionListForPrompt } from '../../lib/characterEvolution.js';
+import { renderSeriesDesign } from '../../lib/storyArc.js';
import { GRAPH_ISSUE_CODES, analyzeEpisodeGraph, describeGraphForPrompt } from '../../lib/fableLoomGraph.js';
import {
FABLELOOM_CAMERA_MOVEMENT_VALUES,
@@ -201,6 +202,7 @@ const seriesPlanContext = (loom, episode) => {
}
}
return [
+ renderSeriesDesign(plan.seriesDesign),
plan.storyArc ? `Series arc: ${plan.storyArc}` : '',
...plotPoints,
...sideQuests,
@@ -239,6 +241,9 @@ const storyContext = (loom, episode, { includeSeriesPlan = true } = {}) => [
].filter(Boolean).join('\n');
const seriesPlanDigest = (loom) => JSON.stringify({
+ ...(Object.prototype.hasOwnProperty.call(loom.seriesPlan || {}, 'seriesDesign')
+ ? { seriesDesign: loom.seriesPlan.seriesDesign }
+ : {}),
storyArc: loom.seriesPlan?.storyArc || '',
plotPoints: (loom.seriesPlan?.plotPoints || []).map((item) => ({
...item, description: item.description || '',
@@ -1142,6 +1147,7 @@ export async function feedbackSeriesPlan(loomId, {
throw new ServerError('Series-plan feedback is required', { status: 400, code: 'FEEDBACK_REQUIRED' });
}
const loom = await requireLoom(loomId);
+ const sourceFingerprint = seriesPlanGenerationFingerprint(loom);
const canonDigest = await buildCanonDigest(loom);
const { content, runId } = await runLoomAi('fableloom-feedback-series-plan', {
storyContext: storyContext(loom, undefined, { includeSeriesPlan: false }),
@@ -1162,6 +1168,12 @@ export async function feedbackSeriesPlan(loomId, {
if (!hasPlanEdit) throw aiShapeError('The model returned no usable series-plan edits');
const updated = await mutateLoom(loomId, (current) => {
+ if (seriesPlanGenerationFingerprint(current) !== sourceFingerprint) {
+ throw new ServerError('The story changed while its plan feedback was being applied', {
+ status: 409,
+ code: 'LOOM_CHANGED_DURING_GENERATION',
+ });
+ }
const plan = { ...current.seriesPlan };
if (hasOwn(content, 'storyArc') && typeof content.storyArc === 'string') plan.storyArc = content.storyArc;
plan.plotPoints = applyPlanItemEdits(plan.plotPoints, content.plotPointEdits, content.plotPointOrder, {
diff --git a/server/services/fableLoom/weave.test.js b/server/services/fableLoom/weave.test.js
index 652e1880e4..da971ddb03 100644
--- a/server/services/fableLoom/weave.test.js
+++ b/server/services/fableLoom/weave.test.js
@@ -157,6 +157,15 @@ const generatedChallengeGraph = () => ({
})),
});
+const finiteSeriesDesign = () => ({
+ mode: 'finite',
+ episodeActivity: 'Mara decodes one royal summons per episode.',
+ conflictSource: 'Every summons asks her to protect the crown at a personal cost.',
+ audiencePromise: 'A complete mystery and one irreversible choice each episode.',
+ continuingTensions: 'Mara distrusts the council that still needs her.',
+ endingCondition: 'Mara chooses whether the city deserves a restored crown.',
+});
+
describe('mapGeneratedGraph', () => {
it('mints server ids, remaps targets, and drops unknown-target transitions', () => {
const { nodes, startNodeId } = mapGeneratedGraph(generatedGraph());
@@ -1262,6 +1271,84 @@ describe('descriptive canon reveal gate at the FableLoom prompt boundary (#6426)
});
describe('series plan AI', () => {
+ it('passes the author-owned series design through every plan operation without rewriting it', async () => {
+ const { loomId } = await setup();
+ const seriesDesign = finiteSeriesDesign();
+ await updateLoom(loomId, { seriesPlan: { seriesDesign } });
+
+ runStagedLLM.mockResolvedValueOnce({
+ content: {
+ storyArc: 'Mara follows the summons to their source.',
+ plotPoints: [{ title: 'The first summons' }],
+ sideQuests: [{ title: 'The missing seal' }],
+ },
+ runId: 'design-draft',
+ });
+ const generated = await generateSeriesPlan(loomId);
+ expect(JSON.parse(runStagedLLM.mock.calls[0][1].seriesPlanJson).seriesDesign).toEqual(seriesDesign);
+ expect(generated.loom.seriesPlan.seriesDesign).toEqual(seriesDesign);
+
+ runStagedLLM.mockResolvedValueOnce({
+ content: { summary: 'The finite spine is coherent.', risks: [] },
+ runId: 'design-review',
+ });
+ await reviewSeriesPlan(loomId, { planningOnly: true });
+ expect(JSON.parse(runStagedLLM.mock.calls[1][1].seriesPlanJson).seriesDesign).toEqual(seriesDesign);
+
+ runStagedLLM.mockResolvedValueOnce({
+ content: { storyArc: 'Mara follows the summons and rejects the crown.', changes: ['Clarified the ending.'] },
+ runId: 'design-feedback',
+ });
+ const feedback = await feedbackSeriesPlan(loomId, { feedback: 'Clarify the ending.' });
+ expect(JSON.parse(runStagedLLM.mock.calls[2][1].seriesPlanJson).seriesDesign).toEqual(seriesDesign);
+ expect(feedback.loom.seriesPlan.seriesDesign).toEqual(seriesDesign);
+ });
+
+ it('rejects stale series-plan feedback when the author changes the series design in flight', async () => {
+ const { loomId } = await setup();
+ await updateLoom(loomId, { seriesPlan: { seriesDesign: finiteSeriesDesign() } });
+ let finishFeedback;
+ runStagedLLM.mockImplementationOnce(() => new Promise((resolve) => { finishFeedback = resolve; }));
+
+ const pending = feedbackSeriesPlan(loomId, { feedback: 'Tighten the arc.' });
+ await vi.waitFor(() => expect(runStagedLLM).toHaveBeenCalledOnce());
+ await updateLoom(loomId, { seriesPlan: {
+ seriesDesign: { ...finiteSeriesDesign(), endingCondition: 'Mara destroys the crown.' },
+ } });
+ finishFeedback({ content: { storyArc: 'A stale revision.' }, runId: 'stale-feedback' });
+
+ await expect(pending).rejects.toMatchObject({ code: 'LOOM_CHANGED_DURING_GENERATION' });
+ expect((await getLoom(loomId)).seriesPlan.seriesDesign.endingCondition).toBe('Mara destroys the crown.');
+ });
+
+ it('supplies the series design to outline, weave, outline review, and teleplay review', async () => {
+ const { loomId, episodeId } = await setup();
+ const seriesDesign = finiteSeriesDesign();
+ await updateLoom(loomId, { seriesPlan: { seriesDesign } });
+ const renderedDesign = 'Episode activity: Mara decodes one royal summons per episode.';
+
+ runStagedLLM.mockResolvedValueOnce({ content: generatedOutline(), runId: 'design-outline' });
+ await generateEpisodeOutline(loomId, episodeId);
+ expect(runStagedLLM.mock.calls[0][1].storyContext).toContain(renderedDesign);
+ await validateEpisodeOutline(loomId, episodeId);
+
+ runStagedLLM.mockResolvedValueOnce({ content: { summary: 'The opening is clear.', risks: [] }, runId: 'design-cold-review' });
+ runStagedLLM.mockResolvedValueOnce({ content: { summary: 'The outline fits.', risks: [] }, runId: 'design-outline-review' });
+ await reviewEpisodeOutline(loomId, episodeId, { planningGate: true });
+ expect(runStagedLLM.mock.calls[2][1].storyContext).toContain(renderedDesign);
+
+ runStagedLLM.mockResolvedValueOnce({ content: generatedGraphFromOutline(), runId: 'design-weave' });
+ await weaveEpisode(loomId, episodeId, { expandFromOutline: true });
+ expect(runStagedLLM.mock.calls[3][1].storyContext).toContain(renderedDesign);
+
+ runStagedLLM.mockResolvedValueOnce({
+ content: { summary: 'The finite series lands.', risks: [] },
+ runId: 'design-teleplay-review',
+ });
+ await reviewSeriesTeleplay(loomId);
+ expect(JSON.parse(runStagedLLM.mock.calls[4][1].seriesPlanJson).seriesDesign).toEqual(seriesDesign);
+ });
+
it('drafts and persists a complete scaffold while preserving episode records', async () => {
const { loomId, episodeId } = await setup();
getUniverseMock.mockResolvedValueOnce({