Skip to content

KleinDigitalSolutions/EMBER

Repository files navigation

EMBER β€” AI-Powered Novel Writing Studio

Next.js TypeScript React OpenAI Anthropic Supabase License Status A structured writing environment for long-form fiction, powered by OpenAI and Anthropic. EMBER combines a scene-card pipeline, a memory backbone, and a stateful draft engine to help authors write consistently across chapters and books β€” not just generate text.


What is EMBER?

Most AI writing tools are stateless: each generation forgets what came before. EMBER is different. It maintains a persistent Memory Backbone β€” a living record of canon facts, character states, object tracking, open plot threads, and reader promises β€” and uses it to ensure every generated scene is consistent with everything that came before.

Built for commercial fiction. Designed for authors who want AI as a disciplined co-pilot, not an autocomplete.


Core Features

πŸ“‹ Scene Card Pipeline

Structured scene direction using YAML-like cards with hard (canon) and soft (guidance) fields. The writer reads the card but is not bound by its exact language.

🧠 Memory Backbone

  • Canon Ledger β€” locked facts that can never be contradicted
  • Character State Ledger β€” who knows what, who wants what, and how they've shifted
  • Object Ledger β€” tracks physical objects, their holders, and their locations across scenes
  • Knowledge Ledger β€” information asymmetry between characters and reader
  • Promise Ledger β€” setup/payoff tracking for mysteries, emotional arcs, and plot threads

πŸ”„ StateDiff Layer

After each draft is accepted, a typed BookStateDiff is extracted β€” a structured diff of what changed in the world (objects moved, knowledge revealed, promises reinforced). Human approval gates what enters the canon.

🎯 Draft Engine

  • Lean remote pipeline via OpenAI or Anthropic
  • length_control β†’ extract β†’ continuity β†’ quality_eval stages
  • Quality audit warns, never auto-rewrites
  • Human Edit Memory: accepted edits are stored and influence future prompts

πŸ“š Legacy Reader

A branching-fiction storefront and reader at public/legacy/, built in vanilla JS with localStorage-based progress resumption.

πŸ’¬ Studio Assistant

An in-studio chat assistant (OpenAI / Anthropic / local Gemma) scoped to project, act, chapter, or scene context.


Studio Impressions

πŸ–‹οΈ Manuscript Editor

Direct prose drafting with integrated scene context, word count tracking, and AI copilot selection. Studio Editor

πŸ“Š Blueprint & Memory Backbone

High-level project control across multiple phases, from foundation to market readiness. Blueprint Overview

βš–οΈ Writer Constitution

Fine-grained narrative rules and model orchestration instructions to maintain a consistent voice. Writer Constitution

πŸ“– Codex & World Bible

Centralized tracking of characters, locations, and objects with automated state updates. Codex & World Bible

πŸ€– Assistant Chat

Context-aware brainstorming and strategic feedback on manuscript chapters and scene cards. Assistant Chat


Tech Stack

Layer Technology
Framework Next.js 15, React 19
Language TypeScript 5
AI Providers OpenAI SDK, Anthropic SDK
Database Supabase (PostgreSQL)
Styling Vanilla CSS (globals.css)
Local AI MLX / Gemma 4 (optional)

Project Structure

ember-studio/
β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”œβ”€β”€ api/                # Route handlers (book jobs, assistant, etc.)
β”‚   β”œβ”€β”€ studio/             # Studio UI pages
β”‚   └── samples/            # Sample reader
β”œβ”€β”€ components/             # React components
β”‚   └── studio/             # All studio UI components
β”œβ”€β”€ lib/                    # Core engine logic
β”‚   β”œβ”€β”€ book-engine.ts      # Main draft pipeline (context β†’ draft β†’ extract β†’ quality)
β”‚   β”œβ”€β”€ story-schema.ts     # All TypeScript types + normalizers
β”‚   β”œβ”€β”€ book-locked-facts.ts# Genre-specific canon fact profiles
β”‚   β”œβ”€β”€ book-state-validator.ts # Deterministic StateDiff validation
β”‚   β”œβ”€β”€ book-genre-engine-*.ts  # Genre-specific prompt engines
β”‚   └── server/             # Supabase + provider integrations
β”œβ”€β”€ scripts/                # CLI tools
β”‚   β”œβ”€β”€ bootstrap-book-from-regie.ts  # Convert a Regie blueprint β†’ Supabase book
β”‚   └── book-state-validator.test.ts  # StateDiff test suite
β”œβ”€β”€ public/legacy/          # Vanilla JS storefront + branching reader
└── supabase/migrations/    # SQL schema

Getting Started

Prerequisites

  • Node.js 20+
  • A Supabase project (or local Supabase)
  • OpenAI API key and/or Anthropic API key

Setup

# 1. Clone and install
git clone https://github.com/KleinDigitalSolutions/EMBER.git
cd ember-studio
npm install

# 2. Configure environment
cp .env.example .env.local
# Fill in your API keys and Supabase credentials

# 3. Run database migrations
# Apply files in supabase/migrations/ to your Supabase project

# 4. Start the dev server
npm run dev

Open http://localhost:3000/studio.

Environment Variables

Variable Required Description
OPENAI_API_KEY Optional* For OpenAI draft jobs
ANTHROPIC_API_KEY Optional* For Anthropic draft jobs
NEXT_PUBLIC_SUPABASE_URL Yes Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY Yes Supabase anon key
SUPABASE_SERVICE_ROLE_KEY Yes Supabase service role key
LOCAL_GEMMA_SERVER_URL No Local Gemma/MLX for studio chat

*At least one AI provider key is needed for draft generation.


Architecture Notes

Book Pipeline (Remote)

Scene Card
    ↓
Context Pack (canon + character state + open threads)
    ↓
Draft (direct from Scene Intention β€” no separate beat_plan call)
    ↓
Length Control (expand/compress only for strong outliers)
    ↓
Extract (StateDiff + canon candidates)
    ↓
Continuity Guard
    ↓
Quality Eval (warns, never blocks)
    ↓
Human Review β†’ Accept / Reject
    ↓
StateDiff Approval β†’ Memory Backbone Update

Genre Engines

Pluggable genre engines extend the base pipeline with genre-specific locked facts, continuity rules, and prompt overlays. Current genres:

  • domestic_suspense_thriller
  • ya_superhero_origin

StateDiff (typed state tracking)

Every accepted draft produces a BookStateDiff with object changes, knowledge state updates, promise reinforcements, and proposed canon facts. Promotion into the canon ledger requires explicit human approval.


Scripts

# Run the StateDiff test suite
npm run test:book-state

# Type check
npm run typecheck

# Bootstrap a new book from a Regie blueprint
npx tsx scripts/bootstrap-book-from-regie.ts <path-to-regie.md>

Status

This is an active portfolio / research project. The core pipeline is functional and used for real manuscript drafting. The UI is a working studio, not a polished SaaS product.


License

MIT β€” see LICENSE for details.

Releases

No releases published

Packages

 
 
 

Contributors