{"slug": "show-hn-branching-story-kit-207-line-zero-dep-story-state-kernel-mit", "title": "Show HN: Branching-story-kit – 207-line zero-dep story-state kernel (MIT)", "summary": "Ouba Studio released branching-story-kit, a 207-line, zero-dependency MIT-licensed story-state kernel for branching interactive fiction that runs in Node ≥ 18 and modern browsers with `dependencies: {}`. The kit provides a JSON story graph with explicit state, relationship and flag tracking, a persistent memory log via `engine.remember()`, `{{state}}` prose interpolation, free-text steering through `set()` and `jump()`, save/restore via `exportSave()` and `StoryEngine.importSave()`, plus a static validator and JSON Schema, and is published on npm as @ouba-studio/branching-story-kit and on JSR. A four-scene rivals-to-lovers demo, \"The Midnight Bookshop,\" runs on the engine via GitHub Pages, itch.io, IFDB and a Hugging Face Space mirror.", "body_md": "**Zero-dependency branching narrative engine for interactive fiction, visual novels, and romance story apps** — story-graph state tracking, gated choices, a persistent memory log, save/restore, a static validator, and a JSON Schema. Native ESM, TypeScript declarations, MIT.\n\nBuilt in the open by **[Ouba Studio](https://www.ouba.art/)** — the team behind [Ouba](https://www.ouba.art/), free reader-first interactive fiction on **web, iOS, and Android**, and the [2026 AI Story Apps Benchmark](https://www.ouba.art/i-tested-ai-story-apps) (open data on [CERN Zenodo](https://doi.org/10.5281/zenodo.24511974), [Harvard Dataverse](https://doi.org/10.7910/DVN/YEBHQR), and [Figshare](https://doi.org/10.6084/m9.figshare.35110510.v1)).\n\nA four-scene rivals-to-lovers branching romance with relationship meters, an inventory item, a trust-gated choice, a free-text steering moment, and four endings. It is a plain JSON manifest played by the real engine — no framework, no build step.\n\n| Where | Link | \n|---|---|\n| **GitHub Pages (live, runs on this engine)** | [https://ouba-studio.github.io/branching-story-kit/](https://ouba-studio.github.io/branching-story-kit/) | \n| **itch.io (HTML5 build)** | [https://ouba-art.itch.io/the-midnight-bookshop](https://ouba-art.itch.io/the-midnight-bookshop) | \n| **IFDB — Interactive Fiction Database** | [https://ifdb.org/viewgame?id=ku32o1jvi5fnb95q](https://ifdb.org/viewgame?id=ku32o1jvi5fnb95q) | \n| **Hugging Face Space (mirror)** | [https://huggingface.co/spaces/oubaapp/the-midnight-bookshop](https://huggingface.co/spaces/oubaapp/the-midnight-bookshop) | \n| **Headless in your terminal** | `node examples/run.mjs --all` | \n\nWant full-length stories where your choices and typed lines carry across 20+ turns with real memory? **Read free on [Ouba](https://www.ouba.art/)** — web, iOS, and Android.\n\nMost \"interactive story\" tooling is either a full game engine or a blank chat box. This kit is the small, boring, reliable layer in between: **a JSON story graph with explicit state**, so that what a reader did in turn 2 is still true in turn 15.\n\n- **Zero dependencies** — one`.mjs` file, pure ESM, runs in Node ≥ 18 and every modern browser.`dependencies: {}` .\n- **Relationship & flag state** — numeric effects*add* , everything else*assigns* ;`requires` gates choices behind thresholds.\n- **Persistent memory log** —`engine.remember(\"My cat's name is Marmalade.\")` records reader-planted facts with turn numbers so long sessions don't drift.\n- **`{{state}}` interpolation** in prose, with unknown placeholders left intact.\n- **Free-text steering** —`set()` +`jump()` let typed input branch the plot without leaving the manifest.\n- **Save / restore** —`exportSave()` →`StoryEngine.importSave()` round-trips cursor, state, history, and memory.\n- **Static validator + JSON Schema** — catch broken`next` links before you publish; validate manifests in your editor or CI.\n- **TypeScript declarations** shipped in the box.\n\n```\nnpm install @ouba-studio/branching-story-kit\npnpm add @ouba-studio/branching-story-kit\n# or\nyarn add @ouba-studio/branching-story-kit\n```\n\n**JSR (Deno / Bun / Node with `jsr:` specifiers) — no `node_modules`, no build step:**\n\n``` python\ndeno add jsr:@ouba-studio/branching-story-kit\n# or import it directly:\n# import { StoryEngine, validateStory } from \"jsr:@ouba-studio/branching-story-kit@1\";\n```\n\nPackage page: [https://jsr.io/@ouba-studio/branching-story-kit](https://jsr.io/@ouba-studio/branching-story-kit)\n\nOne file, zero dependencies — drop it straight into a `<script type=\"module\">` tag or an\n`import()` call. jsDelivr serves the tagged GitHub release with a global CDN cache, so the\nsame URL works in a blog post, a CodePen, or a university writing-lab handout:\n\n``` js\n<script type=\"module\">\n  import { StoryEngine, validateStory } from\n    \"https://cdn.jsdelivr.net/gh/ouba-studio/branching-story-kit@v1.0.0/index.mjs\";\n\n  const story = {\n    id: \"two-scenes\",\n    start: \"door\",\n    initialState: { trust: 1 },\n    scenes: {\n      door: {\n        title: \"The Door\",\n        body: \"The lamp is still on.\",\n        choices: [{ label: \"Knock\", next: \"inside\", effects: { trust: 2 } }],\n      },\n      inside: { title: \"Inside\", body: \"Trust = {{trust}}.\", ending: true },\n    },\n  };\n\n  if (validateStory(story).valid) {\n    const engine = new StoryEngine(story);\n    engine.choose(0);\n    document.body.textContent = engine.current().body; // \"Trust = 3.\"\n  }\n</script>\n```\n\nPin the version for anything you ship: `@v1.0.0` is immutable, `@main` tracks `HEAD`.\n\n| Channel | Import specifier | \n|---|---|\n| **jsDelivr (GitHub release, pinned)** | `https://cdn.jsdelivr.net/gh/ouba-studio/branching-story-kit@v1.0.0/index.mjs` | \n| **jsDelivr (npm mirror)** | `https://cdn.jsdelivr.net/npm/@ouba-studio/branching-story-kit@1.0.0/index.mjs` | \n| **JSR** | `jsr:@ouba-studio/branching-story-kit@1` →[https://jsr.io/@ouba-studio/branching-story-kit](https://jsr.io/@ouba-studio/branching-story-kit) | \n| **npm** | `@ouba-studio/branching-story-kit` | \n| **GitHub Pages (live interactive demo)** | [https://ouba-studio.github.io/branching-story-kit/](https://ouba-studio.github.io/branching-story-kit/) | \n\n``` js\nimport { StoryEngine, validateStory } from \"@ouba-studio/branching-story-kit\";\n\nconst story = {\n  id: \"midnight-bookshop\",\n  start: \"arrival\",\n  initialState: { spark: 1, trust: 1, item: \"cardamom tea\" },\n  scenes: {\n    arrival: {\n      title: \"Rain on Bellweather Lane\",\n      body: \"Julian slides a warm mug of {{item}} across the counter.\",\n      choices: [\n        { label: \"Hold his gaze\", next: \"stacks\", effects: { spark: 2 } },\n        { label: \"Ask about the folio\", next: \"stacks\", effects: { trust: 2 }, requires: { trust: 2 } },\n      ],\n    },\n    stacks: {\n      title: \"Between the Stacks\",\n      body: \"The lantern glows amber as he opens the fourth folio. Spark = {{spark}}, trust = {{trust}}.\",\n      ending: true,\n      choices: [{ label: \"Continue on Ouba →\", href: \"https://www.ouba.art/\" }],\n    },\n  },\n};\n\nconsole.log(validateStory(story)); // { valid: true, errors: [] }\n\nconst engine = new StoryEngine(story);\nengine.remember(\"My cat's name is Marmalade.\"); // memory log\nconsole.log(engine.current().choices.length); // 1 — the trust-gated choice is hidden\n\nengine.choose(0); // apply effects, advance to \"stacks\"\nconsole.log(engine.current().body); // \"... Spark = 3, trust = 1.\"\nconsole.log(engine.exportSave()); // {\"storyId\":\"midnight-bookshop\",\"sceneId\":\"stacks\",...}\njs\nimport { StoryEngine, validateStory, type StoryManifest } from \"@ouba-studio/branching-story-kit\";\n\nconst story: StoryManifest = {\n  start: \"intro\",\n  scenes: {\n    intro: {\n      title: \"Rain on the Glass\",\n      body: \"Welcome back, {{reader}}.\",\n      choices: [{ label: \"Begin\", next: \"end\", effects: { trust: 1 } }],\n    },\n    end: { title: \"Shared Lamp\", body: \"Trust rose to {{trust}}.\", ending: true },\n  },\n};\n\nif (validateStory(story).valid) {\n  const engine = new StoryEngine(story, { reader: \"Clara\", trust: 0 });\n  const ending = engine.choose(0); // fully typed SceneView\n}\n```\n\nA manifest is `{ start, scenes }` plus optional metadata. Scene bodies are strings (paragraph breaks with `\\n\\n`); `{{key}}` placeholders interpolate from state. Choices may point to a `next` scene **or** an external `href`.\n\n```\n{\n  \"id\": \"the-midnight-bookshop\",\n  \"title\": \"The Midnight Bookshop\",\n  \"start\": \"start\",\n  \"initialState\": { \"spark\": 1, \"trust\": 1, \"item\": \"none\", \"customLine\": \"\" },\n  \"scenes\": {\n    \"start\": {\n      \"tag\": \"Scene 1 of 4\",\n      \"title\": \"Rain on Bellweather Lane\",\n      \"body\": \"The brass bell above Bellweather Rare Books chimes at 11:48 PM…\",\n      \"choices\": [\n        { \"label\": \"Take the mug and hold his gaze.\", \"next\": \"glimpse\", \"effects\": { \"spark\": 2, \"item\": \"Cardamom Tea\" } },\n        { \"label\": \"Open the full story on Ouba →\", \"href\": \"https://www.ouba.art/\" }\n      ]\n    },\n    \"glimpse\": { \"title\": \"Between the Stacks\", \"body\": \"…\", \"ending\": true }\n  }\n}\n```\n\nThe full contract lives in **[`story.schema.json`](https://github.com/ouba-studio/branching-story-kit/blob/main/story.schema.json)** (JSON Schema 2020-12). Import it in your editor with `@ouba-studio/branching-story-kit/story.schema.json`.\n\n| Field | Type | Meaning | \n|---|---|---|\n| `label` | `string` | Text shown to the reader (required). | \n| `next` | `string` | Scene id to advance to (required unless `href` is set). | \n| `requires` | `Record<string, number>` | Minimum numeric state values for the choice to be **visible** . | \n| `effects` | `Record<string, number \\| string \\| boolean>` | Applied when chosen — numbers **add** to the current value, strings/booleans**assign** . | \n| `href` | `string` | External link (store page, sequel, survey). `choose()` refuses it; your UI opens it. | \n\n| Member | Signature | Notes | \n|---|---|---|\n| `StoryEngine` | `new StoryEngine(story, initialState?)` | One instance per reader session; throws on invalid manifests. | \n| `engine.turn` | `number` | Scene visits so far (the start scene is turn 1). | \n| `engine.current()` | `SceneView` | `{ id, title, body, choices, ending, state }` with gated choices filtered out and`{{…}}` interpolated. | \n| `engine.choose(index)` | `SceneView` | Picks a **visible** choice by index; applies`effects` ; advances to`next` . | \n| `engine.jump(sceneId, effects?)` | `SceneView` | Direct navigation for free-text steering and scripted transitions. | \n| `engine.set(key, value)` | `StoryState` | Writes a single state value (player name, typed line, runtime flag). | \n| `engine.remember(fact)` | `MemoryEntry[]` | Appends `{ turn, fact }` to the memory log; blank facts are ignored. | \n| `engine.interpolate(text)` | `string` | Replaces `{{key}}` placeholders; unknown keys are left intact. | \n| `engine.exportSave()` | `string` | JSON with `storyId` ,`sceneId` ,`state` ,`history` ,`memory` . | \n| `StoryEngine.importSave(json, story)` | `StoryEngine` | Restores a session; validates the scene cursor exists. | \n| `validateStory(story)` | `{ valid, errors }` | Static check: start scene exists, every `next` resolves, choices are labelled, scenes have bodies. Never throws. | \n\n``` js\nconst json = engine.exportSave();               // persist anywhere (localStorage, your DB…)\nconst restored = StoryEngine.importSave(json, story);\nrestored.memory; // same facts, same turn numbers\nrestored.current(); // identical SceneView to the moment of export\nnpm test                      # node --test test.mjs  (21 tests, zero dependencies)\nnpm run example               # headless play-through of every route in the demo story\nnpm run build:docs            # refresh docs/engine.mjs + docs/story.mjs for GitHub Pages\n```\n\n`validateStory()` is designed for CI: run it over every manifest in your repo and fail the build on `valid === false`.\n\n`remember()` exists because of what the Ouba Studio research team measured in the open, reproducible [2026 AI Story Apps Benchmark](https://www.ouba.art/i-tested-ai-story-apps) (evaluation date `2026-11-15`): across 10 prominent AI story and companion apps, a trivial fact planted at turn 2 (*\"My cat's name is Marmalade.\"*) was **forgotten by turn 15** by several major products, and free-tier walls stopped others before turn 15 at all. Explicit story state plus a factual memory log is the deterministic fix for authored branching fiction.\n\n| Artifact | Persistent identifier | \n|---|---|\n| Primary dataset (CERN Zenodo) | [10.5281/zenodo.24511974](https://doi.org/10.5281/zenodo.24511974) | \n| Harvard Dataverse ( `.edu` ) | [10.7910/DVN/YEBHQR](https://doi.org/10.7910/DVN/YEBHQR) | \n| Figshare | [10.6084/m9.figshare.35110510.v1](https://doi.org/10.6084/m9.figshare.35110510.v1) | \n| Executive deck (CERN Zenodo) | [10.5281/zenodo.24511982](https://doi.org/10.5281/zenodo.24511982) | \n| Interactive benchmark site | [https://ai-story-benchmark-2026.vercel.app/](https://ai-story-benchmark-2026.vercel.app/) | \n| Hugging Face Datasets | [https://huggingface.co/datasets/oubaapp/ai-story-apps-benchmark-2026](https://huggingface.co/datasets/oubaapp/ai-story-apps-benchmark-2026) | \n| Benchmark source repository | [https://github.com/ouba-studio/ai-story-apps-benchmark-2026](https://github.com/ouba-studio/ai-story-apps-benchmark-2026) | \n\n```\nbranching-story-kit/\n├── index.mjs                  # the engine (zero dependencies)\n├── index.d.ts                 # TypeScript declarations\n├── story.schema.json          # JSON Schema for story manifests\n├── jsr.json                   # JSR (jsr.io) package manifest — @ouba-studio/branching-story-kit\n├── test.mjs                   # node --test suite (21 tests)\n├── examples/\n│   ├── midnight-bookshop.mjs  # the demo story as a manifest\n│   └── run.mjs                # headless play-through (npm run example)\n├── docs/                      # GitHub Pages showcase (docs/index.html)\n│   ├── engine.mjs             # generated copy of index.mjs (npm run build:docs)\n│   └── story.mjs              # generated copy of the demo manifest\n├── scripts/build-docs.mjs\n├── CITATION.cff · CHANGELOG.md · LICENSE\n└── .github/workflows/ci.yml   # node --test on Node 18/20/22/24\n```\n\nIf you use `branching-story-kit` in research, a product, or a game, cite:\n\nOuba Studio (2026). *branching-story-kit: A zero-dependency branching narrative engine for interactive fiction, visual novels, and romance story apps* (v1.0.0) [Computer software]. MIT License. [https://doi.org/10.5281/zenodo.24514910](https://doi.org/10.5281/zenodo.24514910)\n\n```\n@software{ouba_studio_2026_branching_story_kit,\n  author  = {{Ouba Studio}},\n  title   = {branching-story-kit: A zero-dependency branching narrative engine for interactive fiction, visual novels, and romance story apps},\n  year    = {2026},\n  version = {1.0.0},\n  publisher = {CERN Zenodo},\n  doi     = {10.5281/zenodo.24514910},\n  url     = {https://github.com/ouba-studio/branching-story-kit},\n  license = {MIT},\n  note    = {Ouba Studio, \\url{https://www.ouba.art/}}\n}\n```\n\nMachine-readable metadata: [`CITATION.cff`](https://github.com/ouba-studio/branching-story-kit/blob/main/CITATION.cff).\n\n| Artifact | Identifier | \n|---|---|\n| **This software (Zenodo, v1.0.0)** | [10.5281/zenodo.24514910](https://doi.org/10.5281/zenodo.24514910) | \n| npm package | [`@ouba-studio/branching-story-kit`](https://www.npmjs.com/package/@ouba-studio/branching-story-kit) | \n| JSR package | [`@ouba-studio/branching-story-kit`](https://jsr.io/@ouba-studio/branching-story-kit) | \n| GitHub release | [`v1.0.0`](https://github.com/ouba-studio/branching-story-kit/releases/tag/v1.0.0) | \n| Live demo | [https://ouba-studio.github.io/branching-story-kit/](https://ouba-studio.github.io/branching-story-kit/) | \n\n`branching-story-kit` is the engine behind the open writing-lab exercises on\n**[Ouba+ for Students](https://www.ouba.art/students)** — MIT-licensed, zero dependencies, and\nsmall enough to read in one sitting, which is the point: students edit a JSON manifest and watch\nstate, gating, and memory behave deterministically. Verified `.edu` / accredited-university\nstudents also get [Ouba+ free](https://www.ouba.art/students) for full-length reading.\n\n[MIT](https://github.com/ouba-studio/branching-story-kit/blob/main/LICENSE) © 2026 Ouba Studio. Use it in commercial games, embed it in apps, ship it — just keep the notice.\n\n- **Play interactive romance & fiction free** —[https://www.ouba.art/](https://www.ouba.art/) (web · iOS · Android)\n- **Ouba+ for Students** — verified`.edu` / accredited-university students get 100% free Ouba+ (no card, no auto-billing):[https://www.ouba.art/students](https://www.ouba.art/students)\n- **The 2026 AI Story Apps Benchmark** —[https://www.ouba.art/i-tested-ai-story-apps](https://www.ouba.art/i-tested-ai-story-apps)\n- **Cite this kit** — Zenodo DOI[10.5281/zenodo.24514910](https://doi.org/10.5281/zenodo.24514910)\n- **Contact** —[team@ouba.art](mailto:team@ouba.art)", "url": "https://wpnews.pro/news/show-hn-branching-story-kit-207-line-zero-dep-story-state-kernel-mit", "canonical_source": "https://github.com/ouba-studio/branching-story-kit", "published_at": "2026-11-26 02:36:13+00:00", "updated_at": "2026-11-26 02:42:30.557933+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools"], "entities": ["Ouba Studio", "branching-story-kit", "Ouba", "The Midnight Bookshop", "GitHub Pages", "itch.io", "Hugging Face", "JSR"], "also_reported_by": [], "takeaway": "branching-story-kit ships as a single zero-dependency ESM file with TypeScript declarations, a static validator and JSON Schema, so manifests with broken `next` links can be caught in CI before publishing.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-branching-story-kit-207-line-zero-dep-story-state-kernel-mit", "markdown": "https://wpnews.pro/news/show-hn-branching-story-kit-207-line-zero-dep-story-state-kernel-mit.md", "text": "https://wpnews.pro/news/show-hn-branching-story-kit-207-line-zero-dep-story-state-kernel-mit.txt", "jsonld": "https://wpnews.pro/news/show-hn-branching-story-kit-207-line-zero-dep-story-state-kernel-mit.jsonld"}}