Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
ST3b: the rest of the frameworks as lenses: Campbell (call, aid, threshold, the ordeal as the lowest point before the boon, the boon lifting above it), Vogler (twelve stages; masks checked by what they do: a herald brings the call, a shadow acts against the hero), Harmon (the price after the getting, the change), Save the Cat (positions as shares of the telling, so an ad and a feature hold the same shape), Kishotenketsu (a late turn, no conflict asked for), Propp (lack, the donor's test, struggle, the lack made good) and Bernays (proof the audience has seen by the claim, a witness besides the brand, the customer's want; invented proof is an error). Read over 619 corpus stories with none failing to read.
shinyobjectzf6af08fd6933
diff --git a/docs/story.feature b/docs/story.featureindex 0bc123cd..0dacddd5 100644--- a/docs/story.feature+++ b/docs/story.feature@@ -109,6 +109,17 @@ Feature: Story: a story as ECS data, read through many frameworks, generated witGiven campbell, vogler, harmon, save-the-cat, kishotenketsu, propp and bernays as lensesThen each has its stages, checks and proposals, and bernays only arranges true proof (a claim with no fact behindit is a finding)+ And the plan:+ | crate | file | lines | job |+ | sdk | sdk/story/src/lenses/common.ts | 40 | who acts where, masks, the lowest beat |+ | sdk | sdk/story/src/lenses/campbell.ts | 60 | call, aid, threshold, ordeal, boon, return |+ | sdk | sdk/story/src/lenses/vogler.ts | 60 | twelve stages; masks checked by what they do |+ | sdk | sdk/story/src/lenses/harmon.ts | 50 | the circle: the price and the change |+ | sdk | sdk/story/src/lenses/save-the-cat.ts | 50 | the beat sheet as shares of the telling |+ | sdk | sdk/story/src/lenses/kishotenketsu.ts | 40 | the late turn, no conflict asked for |+ | sdk | sdk/story/src/lenses/propp.ts | 50 | lack, test, gift, struggle, the lack made good |+ | sdk | sdk/story/src/lenses/bernays.ts | 60 | proof seen, a witness, the customer's want; never invented |+ | sdk | sdk/story/src/lens.ts | 110 | levels and between in the structure |Rule: ST4. Generation without a fixed answerdiff --git a/sdk/story/src/index.ts b/sdk/story/src/index.tsindex 8d9e2ab8..76c68079 100644--- a/sdk/story/src/index.ts+++ b/sdk/story/src/index.ts@@ -11,7 +11,7 @@ export { tension } from "./systems/tension.ts";export { analyze, derive, checkStory, checkWorld, type Finding, type Level } from "./checks.ts";export { mutants, sampleMutants, type Mutant, type Label, type Kind } from "./mutate.ts";export { lens, readThrough, structure, labelled, type Lens, type LensResult, type Proposal, type Reading, type StageMap, type Structure } from "./lens.ts";-export { LENSES, mckee, pas, pixar, storynomics } from "./lenses/index.ts";+export { LENSES, bernays, campbell, harmon, kishotenketsu, mckee, pas, pixar, propp, saveTheCat, storynomics, vogler } from "./lenses/index.ts";export { sample, samples, matrix, judge, type Sampled, type SampleOptions, type MatrixResult, type MatrixRow } from "./sample.ts";export { compileScript, compileStorylets, dramaManager, toInk, toYarn, onScreenOf, type Storylet } from "./compile.ts";export { resolved, type RStory } from "./load.ts";diff --git a/sdk/story/src/lens.ts b/sdk/story/src/lens.tsindex 4e172f5a..72ae4547 100644--- a/sdk/story/src/lens.ts+++ b/sdk/story/src/lens.ts@@ -18,7 +18,7 @@ export const lens = (l: Lens): Lens => l;/** What every lens reads: the structure inferred once per world. */export type Structure = {- beats: { key: string; beat: RBeat; index: number; turns: Record<string, number>; tension: number; linked: boolean }[];+ beats: { key: string; beat: RBeat; index: number; turns: Record<string, number>; level: Record<string, number>; tension: number; linked: boolean }[];events: { key: string; ev: REvent; order: number }[];focus: string | undefined;hero: string | undefined;@@ -31,12 +31,16 @@ export type Structure = {firstShowing: (event: string | undefined) => string | undefined;lastShowing: (event: string | undefined) => string | undefined;focusTurn: (turns: Record<string, number>) => number;+ /** the focus value's level after a beat (its sum over values when the story names no focus) */+ focusLevel: (key: string | undefined) => number;+ /** the beats from one key to another, both left out */+ between: (from: string | undefined, to: string | undefined) => string[];};const size = (t: Partial<Record<string, number>> | undefined) => Object.values(t ?? {}).reduce<number>((a, d) => a + Math.abs(d ?? 0), 0);export function structure(w: World): Structure {- const beats = beatsOf(w).map((b) => ({ key: b.key, beat: b.beat, index: b.index, turns: w.must<Record<string, number>>(b.e, "Turns"), tension: w.must<number>(b.e, "Tension"), linked: w.must<boolean>(b.e, "Linked") }));+ const beats = beatsOf(w).map((b) => ({ key: b.key, beat: b.beat, index: b.index, turns: w.must<Record<string, number>>(b.e, "Turns"), level: w.must<Record<string, number>>(b.e, "Level"), tension: w.must<number>(b.e, "Tension"), linked: w.must<boolean>(b.e, "Linked") }));const events = eventsOf(w).sort((a, b) => a.order - b.order).map(({ key, ev, order }) => ({ key, ev, order }));const agents = Object.fromEntries(Object.entries(keysOf(w).agents).map(([k, e]) => [k, w.must<RAgent>(e, "Agent")]));const hero = Object.keys(agents).find((a) => agents[a].role === "customer" || agents[a].mask === "hero") ?? events[0]?.ev.who;@@ -51,7 +55,10 @@ export function structure(w: World): Structure {const climax = after.length ? after.reduce((best, x) => (Math.abs(focusTurn(x.ev.turns as Record<string, number> ?? {})) > Math.abs(focusTurn(best.ev.turns as Record<string, number> ?? {})) ? x : best)).key : undefined;const firstShowing = (ev: string | undefined) => (ev ? beats.find((b) => b.beat.shows.includes(ev))?.key : undefined);const lastShowing = (ev: string | undefined) => (ev ? [...beats].reverse().find((b) => b.beat.shows.includes(ev))?.key : undefined);- return { beats, events, focus, hero, brand, agents, inciting, crisis, climax, firstShowing, lastShowing, focusTurn };+ const focusLevel = (k: string | undefined) => { const b = beats.find((x) => x.key === k); return b ? focusTurn(b.level) : 0; };+ const idx = (k: string | undefined) => beats.find((x) => x.key === k)?.index;+ const between = (a: string | undefined, b: string | undefined) => beats.filter((x) => x.index > (idx(a) ?? -1) && x.index < (idx(b) ?? beats.length)).map((x) => x.key);+ return { beats, events, focus, hero, brand, agents, inciting, crisis, climax, firstShowing, lastShowing, focusTurn, focusLevel, between };}/** A beat's own label for this lens's stage, when it has one. */diff --git a/sdk/story/src/lenses/bernays.ts b/sdk/story/src/lenses/bernays.tsnew file mode 100644index 00000000..51a94fd7--- /dev/null+++ b/sdk/story/src/lenses/bernays.ts@@ -0,0 +1,45 @@+// Bernays's Propaganda (1928, public domain), in our words and on our terms. He described persuasion as arranging+// circumstances that make a claim evident (an event the public sees), carried by voices the audience already trusts,+// and tied to what people already want. raea keeps the craft and refuses the rest: a claim is only ever arranged proof,+// never invented. So this lens checks that every claim's proof is an event shown on screen, not a line said; that+// someone besides the brand carries or witnesses it; and that it meets the customer's own want.+import { beatsOf } from "../load.ts";+import { finding, lens } from "../lens.ts";+import type { Audience } from "../systems/know.ts";+import type { Finding } from "../checks.ts";+import { at } from "./common.ts";++export const bernays = lens({+ name: "bernays",+ about: "Proof arranged as an event the audience sees, carried by a voice they trust, tied to what they already want. Never invented.",+ stages: ["desire", "circumstance", "witness", "claim"],+ read: (w, s) => {+ // the first beat by which the audience knows every fact given+ const knownBy = (facts: string[]) => beatsOf(w).find(({ e }) => facts.every((x) => w.must<Audience>(e, "Audience").knows.includes(x)))?.key;+ const f: Finding[] = [];+ const claims = s.events.filter((x) => x.ev.claim);+ const customer = Object.keys(s.agents).find((a) => s.agents[a].role === "customer") ?? s.hero;+ const map: Record<string, string[]> = { desire: [], circumstance: [], witness: [], claim: [] };+ for (const c of claims) {+ // where the claim lands: its last showing (a hook can show it early, as a promise)+ const claimBeat = s.lastShowing(c.key);+ if (claimBeat) map.claim.push(claimBeat);+ const proof = c.ev.proof ?? [];+ const setters = s.events.filter((x) => x.order <= c.order && (x.ev.sets ?? []).some((p) => proof.includes(p)));+ if (proof.length && !setters.length) {+ f.push(finding("bernays:invented", "error", c.key, `the claim "${c.ev.claim}" rests on proof no event makes true: that's invented, not arranged`, "show the event that makes the proof true, or cut the claim"));+ continue;+ }+ const seen = proof.length ? knownBy(proof) : undefined;+ if (seen) map.circumstance.push(seen);+ if (proof.length && (!seen || at(s, seen) > at(s, claimBeat))) f.push(finding("bernays:circumstance", "warn", claimBeat ?? c.key, `the claim "${c.ev.claim}" is said before its proof is ever seen`, "show the proof's event on screen at or before the claim"));+ const voices = new Set(setters.flatMap((x) => [x.ev.who, ...(x.ev.with ?? [])]));+ if (s.brand && voices.size && [...voices].every((v) => v === s.brand)) f.push(finding("bernays:witness", "warn", c.key, `only ${s.brand} carries the proof of "${c.ev.claim}"`, "let the customer, or someone they trust, make or witness it"));+ else for (const x of setters) if (x.ev.who !== s.brand) { const b = s.lastShowing(x.key); if (b) map.witness.push(b); }+ const meetsWant = customer && s.events.some((x) => x.order >= c.order - 1 && x.ev.ends?.[customer] && (x.key === c.key || setters.some((y) => y.key === x.key) || x.order === c.order));+ if (customer && s.agents[customer]?.want && !meetsWant) f.push(finding("bernays:desire", "note", c.key, `the claim "${c.ev.claim}" doesn't meet ${customer}'s want (${s.agents[customer].want})`, "tie the claim to the event that settles what the customer wants"));+ }+ if (customer) { const b = s.beats[0]?.key; if (b) map.desire.push(b); }+ return { map, findings: f, proposals: [] };+ },+});diff --git a/sdk/story/src/lenses/campbell.ts b/sdk/story/src/lenses/campbell.tsnew file mode 100644index 00000000..7a8f8aea--- /dev/null+++ b/sdk/story/src/lenses/campbell.ts@@ -0,0 +1,42 @@+// Campbell's monomyth (The Hero with a Thousand Faces, 1949), in our words: a hero is called out of the known world,+// may refuse, is helped across a threshold, goes down through trials to an ordeal at the bottom, takes what they came+// for, and brings it back. raea reads it as a value curve: the ordeal is the lowest point after the threshold, and the+// boon must lift the story above it. The stage names follow the book's three movements, shortened.+import { finding, lens, type Proposal } from "../lens.ts";+import type { Finding } from "../checks.ts";+import { at, beatsWith, lowest, mentorOf } from "./common.ts";++export const campbell = lens({+ name: "campbell",+ about: "Called out of the known world, helped across a threshold, down through trials to an ordeal, back with a boon.",+ stages: ["call", "refusal", "aid", "threshold", "trials", "ordeal", "boon", "return"],+ read: (_w, s) => {+ const f: Finding[] = [];+ const p: Proposal[] = [];+ const call = s.firstShowing(s.inciting);+ const mentor = mentorOf(s);+ const aid = beatsWith(s, mentor).find((b) => b.index >= at(s, call))?.key ?? beatsWith(s, mentor)[0]?.key;+ const heroActs = beatsWith(s, s.hero).filter((b) => b.index > Math.max(at(s, call), at(s, aid)));+ const threshold = heroActs.find((b) => b.linked)?.key;+ const boon = s.lastShowing(s.climax);+ // the abyss: the lowest beat before the boon, from the threshold when it comes first, else from the call+ const from = threshold && at(s, threshold) < at(s, boon) ? threshold : call;+ const ordeal = lowest(s, (from ? [from] : []).concat(s.between(from, boon)));+ const refusal = s.between(call, aid ?? threshold).filter((k) => s.focusTurn(s.beats.find((b) => b.key === k)!.turns) < 0);+ const map = {+ call: call ? [call] : [], refusal, aid: aid ? [aid] : [], threshold: threshold ? [threshold] : [],+ trials: s.between(threshold, ordeal), ordeal: ordeal && ordeal !== threshold && ordeal !== call ? [ordeal] : [], boon: boon ? [boon] : [],+ return: boon ? s.beats.filter((b) => b.index > at(s, boon)).map((b) => b.key) : [],+ };+ if (!call) f.push(finding("campbell:call", "error", "story", "no call: nothing pulls the hero out of the known world", "give the hero an event that turns their world by 2 or more"));+ if (!mentor || !aid) {+ f.push(finding("campbell:aid", "warn", "story", "the hero crosses alone: no mentor or gift helps", "let a mentor or gift (mask) act with the hero before the threshold"));+ p.push({ stage: "aid", after: call, onScreen: `someone or something gives ${s.hero ?? "the hero"} what they need to go on`, feel: "hope", why: "the aid makes the crossing possible and names what's at stake" });+ }+ if (from === threshold && threshold && ordeal && s.focusLevel(ordeal) >= s.focusLevel(threshold) && s.between(threshold, boon).length)+ f.push(finding("campbell:ordeal", "warn", ordeal, "no descent: after the threshold the story never goes lower", "let the hero lose something on the way to the boon"));+ if (boon && ordeal && s.focusLevel(boon) <= s.focusLevel(ordeal)) f.push(finding("campbell:boon", "error", boon, "the hero brings nothing back: the boon doesn't lift the story above the ordeal", "turn the focus value up in the climax"));+ if (!map.return.length) f.push(finding("campbell:return", "note", "story", "no return: we never see the boon brought home", "end on the known world, changed"));+ return { map, findings: f, proposals: p };+ },+});diff --git a/sdk/story/src/lenses/common.ts b/sdk/story/src/lenses/common.tsnew file mode 100644index 00000000..a81fb29a--- /dev/null+++ b/sdk/story/src/lenses/common.ts@@ -0,0 +1,19 @@+// What several lenses read the same way: who's in an event, the beats an agent acts in, the lowest beat in a stretch.+import type { Structure } from "../lens.ts";++type B = Structure["beats"][number];+/** Whether an agent acts in an event (as who, or with). */+export const actsIn = (s: Structure, ev: string, agent: string | undefined) => {+ const e = s.events.find((x) => x.key === ev)?.ev;+ return !!agent && !!e && (e.who === agent || (e.with ?? []).includes(agent));+};+/** The beats where an agent acts. */+export const beatsWith = (s: Structure, agent: string | undefined): B[] => s.beats.filter((b) => b.beat.shows.some((e) => actsIn(s, e, agent)));+/** The agent wearing a mask (the first, when several do). */+export const masked = (s: Structure, mask: string) => Object.keys(s.agents).find((a) => s.agents[a].mask === mask);+/** The beat whose focus level is lowest among these keys (the earliest of equals). */+export const lowest = (s: Structure, keys: string[]) => keys.reduce<string | undefined>((lo, k) => (lo === undefined || s.focusLevel(k) < s.focusLevel(lo) ? k : lo), undefined);+/** A beat's place, or -1. */+export const at = (s: Structure, k: string | undefined) => s.beats.find((b) => b.key === k)?.index ?? -1;+/** The mentor: a mentor or gift mask, else the brand. */+export const mentorOf = (s: Structure) => masked(s, "mentor") ?? masked(s, "gift") ?? s.brand;diff --git a/sdk/story/src/lenses/harmon.ts b/sdk/story/src/lenses/harmon.tsnew file mode 100644index 00000000..b440d932--- /dev/null+++ b/sdk/story/src/lenses/harmon.ts@@ -0,0 +1,33 @@+// Dan Harmon's story circle (his writing on Channel 101 and after), in our words: a character in a zone of comfort+// wants something, goes into an unfamiliar situation, adapts, gets what they wanted, pays a heavy price for it, returns+// to the familiar, and has changed. raea checks the price (a fall after the getting) and the change (the need or the+// lie settled, and the story not ending where it began).+import { finding, lens } from "../lens.ts";+import type { Finding } from "../checks.ts";+import { at, beatsWith } from "./common.ts";++export const harmon = lens({+ name: "harmon",+ about: "You, need, go, search, find, take, return, change: a circle that comes home changed.",+ stages: ["you", "need", "go", "search", "find", "take", "return", "change"],+ read: (_w, s) => {+ const f: Finding[] = [];+ const inc = s.firstShowing(s.inciting);+ const go = beatsWith(s, s.hero).find((b) => b.index > at(s, inc) && b.linked)?.key;+ const wantMet = s.events.find((x) => s.hero && x.ev.ends?.[s.hero] === "want")?.key;+ const peak = s.beats.filter((b) => b.index > at(s, go)).reduce<string | undefined>((hi, b) => (hi === undefined || s.focusLevel(b.key) > s.focusLevel(hi) ? b.key : hi), undefined);+ const find = s.firstShowing(wantMet) ?? peak;+ const take = s.beats.find((b) => b.index > at(s, find) && s.focusTurn(b.turns) < 0)?.key;+ const last = s.beats.at(-1)?.key;+ const map = {+ you: s.between(undefined, inc), need: inc ? [inc] : [], go: go ? [go] : [], search: s.between(go, find),+ find: find ? [find] : [], take: take ? [take] : [], return: take ? s.between(take, last) : [], change: last && last !== find && last !== take ? [last] : [],+ };+ if (!go) f.push(finding("harmon:go", "warn", "story", "the hero never goes anywhere new: no step out of the comfort zone after the change", "show the hero acting in an unfamiliar situation"));+ if (find && !take) f.push(finding("harmon:take", "warn", find, "they get what they wanted at no cost", "make the getting cost something: a turn down after it"));+ const settled = s.events.some((x) => s.hero && (x.ev.ends?.[s.hero] === "need" || x.ev.ends?.[s.hero] === "lie"));+ if (!settled) f.push(finding("harmon:change", "warn", s.hero ?? "story", "the circle closes but the hero hasn't changed: no need met or lie dropped", "end an event with the hero's need or lie (ends)"));+ if (last && s.focusLevel(last) === 0 && s.beats.length > 2) f.push(finding("harmon:change", "note", last, "the story ends at the level it began", "let the return land somewhere different"));+ return { map, findings: f, proposals: [] };+ },+});diff --git a/sdk/story/src/lenses/index.ts b/sdk/story/src/lenses/index.tsindex 0f87ba93..9fb34553 100644--- a/sdk/story/src/lenses/index.ts+++ b/sdk/story/src/lenses/index.ts@@ -1,9 +1,16 @@// The lenses raea ships, by name (docs/story.feature ST3a, ST3b).import type { Lens } from "../lens.ts";+import { bernays } from "./bernays.ts";+import { campbell } from "./campbell.ts";+import { harmon } from "./harmon.ts";+import { kishotenketsu } from "./kishotenketsu.ts";import { mckee } from "./mckee.ts";import { pas } from "./pas.ts";import { pixar } from "./pixar.ts";+import { propp } from "./propp.ts";+import { saveTheCat } from "./save-the-cat.ts";import { storynomics } from "./storynomics.ts";+import { vogler } from "./vogler.ts";-export { mckee, pas, pixar, storynomics };-export const LENSES: Record<string, Lens> = { mckee, pixar, storynomics, pas };+export { bernays, campbell, harmon, kishotenketsu, mckee, pas, pixar, propp, saveTheCat, storynomics, vogler };+export const LENSES: Record<string, Lens> = { mckee, pixar, storynomics, pas, campbell, vogler, harmon, "save-the-cat": saveTheCat, kishotenketsu, propp, bernays };diff --git a/sdk/story/src/lenses/kishotenketsu.ts b/sdk/story/src/lenses/kishotenketsu.tsnew file mode 100644index 00000000..3eb412af--- /dev/null+++ b/sdk/story/src/lenses/kishotenketsu.ts@@ -0,0 +1,28 @@+// Kishōtenketsu (the four-part form of Chinese and Japanese poetry and of yonkoma comics), in our words: ki introduces,+// shō develops, ten turns (something new that makes the rest read differently), ketsu brings them together. It needs no+// conflict, so this lens never asks for a crisis or a villain; it asks for the turn, and for it to come late.+import { finding, lens } from "../lens.ts";+import type { Finding } from "../checks.ts";+import { at } from "./common.ts";++export const kishotenketsu = lens({+ name: "kishotenketsu",+ about: "Introduction, development, a turn that makes the rest read differently, a conclusion that joins them. No conflict needed.",+ stages: ["ki", "sho", "ten", "ketsu"],+ read: (_w, s) => {+ const f: Finding[] = [];+ const n = s.beats.length;+ const turnish = (b: (typeof s.beats)[number]) => b.beat.surprise === "meant" || (b.beat.reveals?.length ?? 0) > 0 || Object.values(b.turns).some((d) => Math.abs(d) >= 2);+ const ten = s.beats.filter((b) => b.index >= Math.floor(n / 2) && b.index < n).find(turnish)?.key ?? s.beats.find(turnish)?.key;+ const t = at(s, ten);+ const map = {+ ki: s.beats.filter((b) => b.index < Math.max(1, Math.floor((t < 0 ? n : t) / 2))).map((b) => b.key),+ sho: s.beats.filter((b) => b.index >= Math.max(1, Math.floor((t < 0 ? n : t) / 2)) && b.index < (t < 0 ? n : t)).map((b) => b.key),+ ten: ten ? [ten] : [], ketsu: ten ? s.beats.filter((b) => b.index > t).map((b) => b.key) : [],+ };+ if (!ten) f.push(finding("kishotenketsu:ten", "error", "story", "no ten: nothing new arrives to make the rest read differently", "add a late beat that reveals a fact or turns hard, or mark one surprise: \"meant\""));+ else if (t < Math.floor(n / 2)) f.push(finding("kishotenketsu:ten", "warn", ten, "the turn comes in the first half, before there's anything for it to change", "develop first; turn in the third quarter"));+ if (ten && !map.ketsu.length) f.push(finding("kishotenketsu:ketsu", "warn", ten, "the story stops on the turn: no ketsu brings the parts together", "add a closing beat that shows the first parts in the turn's light"));+ return { map, findings: f, proposals: [] };+ },+});diff --git a/sdk/story/src/lenses/propp.ts b/sdk/story/src/lenses/propp.tsnew file mode 100644index 00000000..e97d83bf--- /dev/null+++ b/sdk/story/src/lenses/propp.ts@@ -0,0 +1,36 @@+// Propp's Morphology of the Folktale (1928), in our words: a tale is a sequence of functions (what a character does for+// the plot) carried by a few roles: villain, donor, helper, the sought-for person, dispatcher, hero, false hero. raea+// reads the spine every tale shares: a villainy or a lack, a departure, a donor who tests the hero before giving, a+// struggle, and the lack made good. Masks carry the roles: shadow the villain, mentor or gift the donor, herald the+// dispatcher, shapeshifter the false hero.+import { finding, lens } from "../lens.ts";+import type { Finding } from "../checks.ts";+import { actsIn, at, beatsWith, masked, mentorOf } from "./common.ts";++export const propp = lens({+ name: "propp",+ about: "Villainy or lack, departure, the donor's test and gift, struggle, the lack made good, return and recognition.",+ stages: ["lack", "departure", "test", "gift", "struggle", "liquidation", "return", "recognition"],+ read: (_w, s) => {+ const f: Finding[] = [];+ const lackEv = s.events.find((x) => s.focusTurn((x.ev.turns ?? {}) as Record<string, number>) < 0)?.key;+ const lack = s.firstShowing(lackEv);+ const donor = mentorOf(s), villain = masked(s, "shadow");+ const departure = beatsWith(s, s.hero).find((b) => b.index > at(s, lack) && b.linked)?.key;+ const donorBeats = beatsWith(s, donor);+ const gift = donorBeats.find((b) => b.index > at(s, lack))?.key;+ const test = gift ? s.beats.filter((b) => b.index < at(s, gift) && b.index > at(s, lack) && b.beat.shows.some((e) => s.events.find((x) => x.key === e)?.ev.dilemma?.length)).map((b) => b.key) : [];+ const struggle = villain ? beatsWith(s, villain).filter((b) => b.beat.shows.some((e) => actsIn(s, e, s.hero))).map((b) => b.key) : [];+ const liq = s.beats.find((b) => b.index > at(s, lack) && s.focusLevel(b.key) >= 0 && s.focusTurn(b.turns) > 0)?.key;+ const recog = s.beats.filter((b) => b.index > at(s, liq) && (b.beat.reveals?.length ?? 0) > 0).map((b) => b.key);+ const map = {+ lack: lack ? [lack] : [], departure: departure ? [departure] : [], test, gift: gift ? [gift] : [], struggle,+ liquidation: liq ? [liq] : [], return: liq ? s.beats.filter((b) => b.index > at(s, liq)).map((b) => b.key) : [], recognition: recog,+ };+ if (!lack) f.push(finding("propp:lack", "error", "story", "no villainy and no lack: nothing is taken or missing", "open with what the hero lacks or loses (a turn down)"));+ if (lack && !liq) f.push(finding("propp:liquidation", "error", lack, "the lack is never made good", "end with the focus value back at or above where it started"));+ if (gift && !test.length) f.push(finding("propp:test", "note", gift, "the donor gives without testing: the hero earns nothing", "put a dilemma before the gift"));+ if (villain && !struggle.length) f.push(finding("propp:struggle", "warn", villain, `${villain} is the villain but never meets the hero`, `show ${villain} and ${s.hero ?? "the hero"} in one event`));+ return { map, findings: f, proposals: [] };+ },+});diff --git a/sdk/story/src/lenses/save-the-cat.ts b/sdk/story/src/lenses/save-the-cat.tsnew file mode 100644index 00000000..317143e3--- /dev/null+++ b/sdk/story/src/lenses/save-the-cat.ts@@ -0,0 +1,35 @@+// Blake Snyder's beat sheet (Save the Cat!, 2005), in our words: an opening image and a final image that mirror it, a+// catalyst early, a debate, a break into the new world, a midpoint that raises the stakes (a false win or a false+// loss), the bad guys closing in, an all-is-lost moment and a dark night, then a break into the finale. raea reads its+// positions as shares of the telling, so a 30-second ad and a feature are held to the same shape.+import { finding, lens } from "../lens.ts";+import type { Finding } from "../checks.ts";+import { at, lowest } from "./common.ts";++export const saveTheCat = lens({+ name: "save-the-cat",+ about: "Opening and final images that mirror, a catalyst early, a midpoint that raises the stakes, all is lost, then the finale.",+ stages: ["opening-image", "catalyst", "debate", "break-into-two", "midpoint", "bad-guys-close-in", "all-is-lost", "finale", "final-image"],+ read: (_w, s) => {+ const f: Finding[] = [];+ const n = s.beats.length;+ if (!n) return { map: {}, findings: f, proposals: [] };+ const share = (k: string | undefined) => (at(s, k) + 0.5) / n;+ const first = s.beats[0].key, last = s.beats[n - 1].key;+ const catalyst = s.firstShowing(s.inciting);+ const mid = s.beats.filter((b) => b.index > 0 && b.index < n - 1).sort((a, b) => Math.abs((a.index + 0.5) / n - 0.5) - Math.abs((b.index + 0.5) / n - 0.5))+ .find((b) => Object.values(b.turns).some((d) => Math.abs(d) >= 2))?.key;+ const finale = s.lastShowing(s.climax);+ const lost = lowest(s, s.between(catalyst, finale));+ const brk = s.beats.find((b) => b.index > at(s, catalyst) && b.linked && s.focusTurn(b.turns) !== 0)?.key;+ const map = {+ "opening-image": [first], catalyst: catalyst ? [catalyst] : [], debate: s.between(catalyst, brk), "break-into-two": brk ? [brk] : [],+ midpoint: mid ? [mid] : [], "bad-guys-close-in": s.between(mid, lost), "all-is-lost": lost ? [lost] : [], finale: finale ? [finale] : [], "final-image": [last],+ };+ if (catalyst && share(catalyst) > 0.34) f.push(finding("save-the-cat:catalyst", "warn", catalyst, `the catalyst comes ${Math.round(share(catalyst) * 100)}% of the way in`, "bring it into the first third"));+ if (n >= 5 && !mid) f.push(finding("save-the-cat:midpoint", "note", "story", "no midpoint: nothing near the middle raises the stakes", "give a middle beat a big turn, a false win or a false loss"));+ if (lost && share(lost) < 0.5 && n >= 4) f.push(finding("save-the-cat:all-is-lost", "warn", lost, "the lowest point comes in the first half: the story peaks downward too soon", "move the worst moment just before the finale"));+ if (s.focusLevel(last) === s.focusLevel(first) && n >= 3) f.push(finding("save-the-cat:final-image", "warn", last, "the final image is where the opening image was: nothing changed between them", "end on the opening world, changed"));+ return { map, findings: f, proposals: [] };+ },+});diff --git a/sdk/story/src/lenses/vogler.ts b/sdk/story/src/lenses/vogler.tsnew file mode 100644index 00000000..a159d0dd--- /dev/null+++ b/sdk/story/src/lenses/vogler.ts@@ -0,0 +1,42 @@+// Vogler's Writer's Journey (1992, from his memo on Campbell for Disney), in our words: twelve stages in three acts, and+// the archetypes as masks a character wears for a beat, not types. raea checks the masks by what they do: a herald+// brings the call, a shadow acts against the hero, a mentor helps; and the journey's late test, the resurrection, as a+// second fall after the reward.+import { finding, lens } from "../lens.ts";+import type { Finding } from "../checks.ts";+import { actsIn, at, beatsWith, lowest, masked, mentorOf } from "./common.ts";++export const vogler = lens({+ name: "vogler",+ about: "Twelve stages from the ordinary world to the return with the elixir; archetypes as masks that act.",+ stages: ["ordinary-world", "call", "refusal", "mentor", "threshold", "tests", "approach", "ordeal", "reward", "road-back", "resurrection", "return"],+ read: (_w, s) => {+ const f: Finding[] = [];+ const call = s.firstShowing(s.inciting);+ const mentor = mentorOf(s);+ const meet = beatsWith(s, mentor).find((b) => b.index >= at(s, call))?.key;+ const threshold = beatsWith(s, s.hero).find((b) => b.index > Math.max(at(s, call), at(s, meet)) && b.linked)?.key;+ const climax = s.lastShowing(s.climax);+ const from = threshold ?? call;+ const ordeal = lowest(s, s.between(from, climax));+ const reward = s.beats.find((b) => b.index > at(s, ordeal) && b.index < at(s, climax) && s.focusTurn(b.turns) > 0)?.key;+ const map = {+ "ordinary-world": s.between(undefined, call), call: call ? [call] : [],+ refusal: s.between(call, meet ?? threshold).filter((k) => s.focusTurn(s.beats.find((b) => b.key === k)!.turns) < 0),+ mentor: meet ? [meet] : [], threshold: threshold ? [threshold] : [],+ tests: s.between(from, ordeal).slice(0, -1), approach: s.between(from, ordeal).slice(-1),+ ordeal: ordeal ? [ordeal] : [], reward: reward ? [reward] : [], "road-back": s.between(reward ?? ordeal, climax),+ resurrection: climax ? [climax] : [], return: climax ? s.beats.filter((b) => b.index > at(s, climax)).map((b) => b.key) : [],+ };+ if (!s.hero || !s.agents[s.hero]?.mask) f.push(finding("vogler:hero", "note", "story", "no one wears the hero's mask", "mask the protagonist hero"));+ const herald = masked(s, "herald");+ if (herald && s.inciting && !actsIn(s, s.inciting, herald)) f.push(finding("vogler:herald", "warn", herald, `${herald} wears the herald's mask but doesn't bring the call`, `let ${herald} act in ${s.inciting}`));+ const shadow = masked(s, "shadow");+ if (shadow && !s.events.some((x) => (x.ev.who === shadow || (x.ev.with ?? []).includes(shadow)) && s.focusTurn((x.ev.turns ?? {}) as Record<string, number>) < 0))+ f.push(finding("vogler:shadow", "warn", shadow, `${shadow} wears the shadow's mask but never acts against the hero`, `give ${shadow} an event that turns the focus value down`));+ if (!reward && ordeal) f.push(finding("vogler:reward", "warn", ordeal, "nothing is won after the ordeal before the climax", "show the hero seizing something after the low point"));+ if (reward && climax && !s.between(reward, climax).some((k) => s.focusTurn(s.beats.find((b) => b.key === k)!.turns) < 0) && s.focusTurn(s.beats.find((b) => b.key === climax)!.turns) <= 0)+ f.push(finding("vogler:resurrection", "note", climax, "no resurrection: the hero is never tested a last time", "let the road back cost something before the final turn"));+ return { map, findings: f, proposals: [] };+ },+});diff --git a/sdk/story/test/lenses.test.ts b/sdk/story/test/lenses.test.tsindex 891cdd9e..6999fcf5 100644--- a/sdk/story/test/lenses.test.ts+++ b/sdk/story/test/lenses.test.ts@@ -30,3 +30,23 @@ test("a story with no dilemma gets a crisis proposed from the hero's want and neexpect(r.findings.some((f) => f.check === "mckee:crisis" && f.level === "error")).toBe(true);expect(r.proposals.find((p) => p.stage === "crisis")?.onScreen).toBe("kid must choose: win the race, or learn to lose");});++test("the ST3b lenses read the launch story", () => {+ const r = Object.fromEntries(readThrough(launch, ["campbell", "vogler", "harmon", "save-the-cat", "kishotenketsu", "propp", "bernays"].map((k) => LENSES[k]), "30s").map((x) => [x.lens, x]));+ expect(r.campbell.map.call).toEqual(["b1"]);+ expect(r.campbell.map.boon).toEqual(["b3"]);+ expect(r.vogler.map.ordeal).toEqual(["b2"]);+ expect(r.harmon.findings.map((f) => f.check)).toContain("harmon:take");+ expect(r.kishotenketsu.map.ten).toEqual(["b3"]);+ expect(r.propp.map.lack).toEqual(["b1"]);+ expect(r.propp.map.liquidation).toEqual(["b3"]);+ expect(r.bernays.map).toMatchObject({ circumstance: ["b3"], witness: ["b3"], claim: ["b3"] });+ for (const x of Object.values(r)) expect(x.passes).toBe(true);+});++test("bernays refuses invented proof", () => {+ const bad = { ...launch, world: { ...launch.world, ships: { ...launch.world.ships, sets: [] } } };+ const r = readThrough(bad as typeof launch, [LENSES.bernays], "30s")[0];+ expect(r.findings.map((f) => f.check)).toContain("bernays:invented");+ expect(r.passes).toBe(false);+});