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 in lib/context/inheritedContext.ts walks the tree to collect all relevant information.

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.

From Sibling Nodes

The getSiblingContext() function collects data from preceding sibling nodes for narrative continuity:

  • Prior beat notes — what happened in earlier beats within the same scene
  • Prior prose — the actual text of preceding beats (for voice/style continuity)
  • Cross-scene bridging — the last beat of the previous scene, providing transition context

Sibling context is configurable via SiblingContextConfig:

SettingDefaultPurpose
maxSiblings3Maximum prior siblings to include
includeProsetrueWhether to include prior prose text
includeBeatNotestrueWhether to include prior beat notes
crossSceneBridgetrueInclude last beat from previous scene

Not Yet Connected

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

  • 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 + sibling 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...

## PRECEDING BEATS
Beat: The Warning
  Notes: Jack receives an anonymous phone call...
  Prose: The phone rang twice before Jack picked it up...

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