A context compiler for long-form fiction. Structured creative intent (characters, voice rules, scene contracts) is compiled into optimized LLM context payloads, enabling gated chunk-by-chunk prose generation.
The author never writes prompts. They fill in structured fields, write anchor lines, and edit generated prose. The app handles all context assembly, budget management, and constraint injection.
Bible + Scene Plan + Previous Chunks + Config
→ Ring Builder (system / chapter / scene context)
→ Budget Enforcer (token counting, priority trim)
→ Linter (priming risk, missing voice, budget health)
→ Assembler → LLM → Generated Chunk
→ Human Review (accept / edit / reject)
→ Auditor (kill list, variance, subtext, epistemic)
→ Learner (diff analysis → pattern proposals)
The context compiler builds prompts in three concentric rings:
- Ring 1 (system): Project voice, tone, kill list, global rules
- Ring 2 (chapter): Chapter arc, character states, active setups
- Ring 3 (scene): Scene plan, voice fingerprints, continuity bridge, anchor lines
When over budget, rings compress in priority order. Scene context always gets at least 60% of the token budget.
- Node.js 20+
- pnpm
- An Anthropic API key
git clone https://github.com/2389-research/word-compiler.git
cd word-compiler
pnpm installCreate a .env file:
ANTHROPIC_API_KEY=your-key-here
pnpm dev:all # Starts frontend (localhost:5173) + API server (localhost:3001)- Bootstrap — Paste a synopsis or build a bible manually (characters, locations, style guide, narrative rules)
- Plan — Author scene plans with chapter arcs, beat sheets, and continuity tracking
- Draft — Generate prose chunk by chunk with compiled context; review, edit, accept or reject
- Audit — Run quality checks: kill list violations, sentence variance, subtext compliance
- Complete — Mark scenes done, extract narrative IR for cross-scene analysis
- Export — Output to markdown or plaintext
See the Quickstart Guide for a detailed walkthrough, or docs/workflow.md for the full workflow reference.
pnpm test # Unit tests (Vitest)
pnpm e2e # E2E tests (Playwright)
pnpm check-all # Lint + typecheck + unit tests
pnpm storybook # Component docs (localhost:6006)
pnpm eval:mock # Evaluation suite (no LLM calls)Pre-commit hooks enforce lint, typecheck, and tests via Husky.
See CONTRIBUTING.md for development setup details.
The core compiler logic is pure TypeScript with no framework dependencies. The UI is a Svelte 5 app.
src/
compiler/ Ring 1/2/3 builders, budget enforcer, assembler
auditor/ Kill list, sentence variance, epistemic leaks, subtext
bootstrap/ Synopsis → draft bible, scene generation, genre templates
learner/ Diff analysis, pattern accumulation, bible proposals
ir/ Narrative IR extraction and parsing
types/ All interfaces (single source of truth)
server/
api/ REST routes (Express)
db/ SQLite schema + repository modules
Full architecture documentation lives in docs/architecture/, covering:
- Overview — System map and design philosophy
- Theory of Operation — How the compilation pipeline works
- Context Compiler — Ring building and budget enforcement
- Auditor & Linter — Quality gate details
- Narrative IR — Structured extraction format
- Gates & Workflow — Stage progression logic
- Bible Versioning — Version control for story bibles
- Revision Learner — Pattern learning from edits
- Export Pipeline — Output formats
- Bootstrap & Genres — Synopsis-to-bible generation
- Persistence Layer — SQLite + repository pattern
- UI Architecture — Svelte 5 component design
- Evaluation System — Automated quality metrics
- Protocols — Inter-module contracts
- Personalization — Voice profiling and adaptation
Word Compiler is designed as a self-hosted, single-user, localhost application. The API server binds to 127.0.0.1 by default and CORS is restricted to http://localhost:5173 and http://127.0.0.1:5173.
Do not expose the server to the public internet or untrusted networks. The API endpoints include an unauthenticated proxy to the Anthropic API using your configured API key. There is no authentication, no rate limiting, and no input validation — this is by design for a local tool.
To override the defaults (not recommended for untrusted networks):
HOST=0.0.0.0— bind to all interfacesCORS_ORIGIN=http://example.com— allow a different origin