tangl.story.fabula¶
Compilation and materialization APIs for turning authored scripts into runtime story graphs.
Related design docs
Related notes
Compilation¶
- class StoryCompiler[source]¶
Validate and normalize authored story script data into a
StoryTemplateBundle.Why¶
Authored story scripts are intentionally lightweight. The compiler turns that loose authoring shape into a typed, scoped template tree that runtime materialization and provisioning can trust.
Key Features¶
Accepts raw dicts or validated
StoryScriptinstances.Builds scene and block template hierarchy used by runtime scope matching.
Canonicalizes action references so authored shorthand and qualified references resolve into a stable form.
Attempts to resolve authored
kindreferences during compilation when an override cannot be imported.
API¶
compile()is the supported public entry point.
- class StoryTemplateBundle[source]¶
Canonical output of
StoryCompiler.Why¶
Separating compilation from materialization lets one validated script bundle produce many independent story graphs without reparsing authored input.
Key Features¶
Carries the validated
TemplateRegistrytree used by the materializer.Preserves
metadata, storylocals, source mapping, and codec state alongside the template hierarchy.Records
entry_template_idsso materialization can resolve the graph’s initial cursor positions deterministically.Stores structured compiler diagnostics for cheap bundle-local integrity problems without forcing materialization first.
API¶
metadatastores story-level metadata used by runtime setup.localsstores authored top-level namespace values.template_registrycontains the validated template hierarchy.entry_template_idslists the template ids used for initial cursor resolution.issuesstores structured compile diagnostics for later inspection.source_map,codec_state, andcodec_idpreserve compile-time provenance and codec context.
- class CompileIssue(code, severity, message, phase='compile', subject_label=None, source_ref=None, related_identifiers=<factory>, details=<factory>)[source]¶
Structured compiler diagnostic stored on a compiled story bundle.
Notes
detailsis reserved for JSON-like payloads only. The compiler module documents allowed keys per issue code near its diagnostics helpers.
- class CompileSeverity(*values)[source]¶
Severity for compile diagnostics.
Notes
v1 of compiler diagnostics emits only
errorissues.warningexists so the surface can align with later authoring-integrity diagnostics work.
- class AuthoredRef(path=None, story_key=None, authored_path=None, label=None, note=None)[source]¶
Best-effort authored provenance for compile diagnostics.
Notes
This surface intentionally stays coarse in v1. File-level provenance plus compiler-known authored paths are sufficient for bundle preflight without blocking on line/column mapping.
Materialization¶
- class StoryMaterializer[source]¶
Story-policy helper for runtime graph wiring and compatibility delegation.
Why¶
World.create_story(...)now owns graph creation directly by layering overTraversableGraphFactory.StoryMaterializerremains as the focused helper that applies story-specific topology, eager prelink policy, and runtime materialization hooks on top of that lower-layer graph creation.Key Features¶
Wires story-specific topology onto an already-materialized graph.
Supports eager prelink/report passes once generic graph creation completes.
Preserves template-to-entity lineage for runtime scope lookup.
Finalizes scene contracts and wires node destinations after instantiation.
Uses vm resolver semantics instead of reimplementing provisioning logic.
API¶
create_story()delegates to a bound world for compatibility.make_state()builds story wiring state from direct runtime authorities.
- class World(label: str)[source]¶
Unitary story authority over templates, runtime graph creation, and world adjunct providers.
Why¶
Worldis the canonical story-layer authority object. It owns the story template bundle, runtime behavior authorities, and compatible accessors for loader/service surfaces while delegating generic graph materialization toTraversableGraphFactory.Key Features¶
Acts as the singleton shape and behavior authority for
StoryGraph.Preserves bundle-derived metadata, locals, entries, and compile provenance directly on the world.
Keeps compatibility alias views for one phase of the world cutover.
API¶
create_story()is the public story initialization entry point.get_authorities()exposes world-owned dispatch registries.get_story_info_projector()returns the world-owned projector when present.find_template()andfind_templates()resolve directly against the world’s template registry.
Init result types¶
- class InitReport(mode, materialized_counts=<factory>, prelinked_counts=<factory>, unresolved_hard=<factory>, unresolved_soft=<factory>, warnings=<factory>)[source]¶
Structured diagnostics emitted during story graph initialization.
Tracks materialized entity counts, dependency prelink results, and any hard or soft unresolved requirements discovered during initialization.
- class StoryInitResult(graph, report, entry_ids, source_map=<factory>, codec_state=<factory>, codec_id=None)[source]¶
Final result of materializing a runtime story graph.
Packages the graph, initialization report, resolved entry ids, and optional source/codec metadata carried forward from compilation.
Selected methods¶
- StoryCompiler.compile(script_data, *, source_map=None, codec_state=None, codec_id=None)[source]¶
Compile authored story data into a reusable template bundle.
Accepts raw script dictionaries or validated
StoryScriptobjects.Raw dicts are compiled directly. Use
validate_ir()separately when authored near-native data should be linted against the IR schema.