Technical DocumentationWhat Data Feeds Into Generation

What Data Feeds Into Generation

When Writan generates or analyses content, it composites data from across the node tree to build a complete picture. The context composition logic exists in lib/context/inheritedContext.ts but is not yet wired into the generation API.

The code described on this page exists and is functional — it just isn’t connected to the generation endpoint yet.

Data Sources

From the Current Node

  • Beat notes — what this moment should achieve
  • Data blocks — characters, locations, objects, and freeform data attached to this node
  • Existing prose — any output already written (for revision or continuation)

From Parent Nodes (walking up the tree)

The getInheritedContext() function walks from the target node up to the root, collecting from each ancestor:

  • Node title and type — for structural context
  • Beat notes — the overview at that level
  • Data blocks — characters (with name, role, motivation, secret, fear), locations (with atmosphere), objects, and freeform blocks

Context is ordered root-first (Book → Act → Chapter → Scene → Beat) so the prompt presents broadest context first.

Not Yet Connected

The following are planned but not yet part of the data flow:

  • Sibling/adjacent nodes — preceding beats for continuity
  • Active ruleset — writing rules are embedded in the system prompt, not sourced dynamically from the rules engine

How Composition Works

Data flows downward through the tree:

Book (premise, themes, characters, locations)
  └── Act (dramatic arc, beat notes)
        └── Chapter (narrative purpose)
              └── Scene (objective, conflict, scene-level characters/locations)
                    └── Beat (beat notes + all inherited context)

Each level contributes its data blocks and overviews to the composite. This means a beat inherits the full context of its story without the writer needing to repeat information.

Formatted Output

The formatContextForPrompt() function produces structured text like:

## BOOK: Sleeping Dogs
Character: Jack Calloway (protagonist)
  Description: A retired detective...
  Motivation: To protect his daughter
Location: The Mill House
  Atmosphere: Damp stone, low ceilings...

## SCENE: The Confrontation
Notes: Jack finally faces his former partner...

## BEAT: The Accusation
Notes: Jack reveals what he knows about the cover-up