ordinary_app_event_runtime.bend

bendvy-ecs-core@0.1.0.0 · 175 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/ordinary_schema_dump.bend as Presentation
3import bendvy-ecs-core@0.1.0.0/ordinary_app_dump.bend as Dump
4import bendvy-ecs-core@0.1.0.0/ordinary_app_population.bend as Population
5import bendvy-ecs-core@0.1.0.0/ordinary_dump_filter.bend as Filter
6import bendvy-ecs-core@0.1.0.0/world.bend as W
7import bendvy-ecs-core@0.1.0.0/event_runtime.bend as Ev
8import bendvy-ecs-core@0.1.0.0/ordinary_schema.bend as Schema
9import bendvy-ecs-core@0.1.0.0/ordinary_app_schema.bend as SchemaApp
10import bendvy-ecs-core@0.1.0.0/ordinary_app_composer.bend as Build
11import bendvy-ecs-core@0.1.0.0/ordinary_app_registration_fields.bend as Records
12import bendvy-ecs-core@0.1.0.0/ordinary_app_recipe.bend as Tree
13import bendvy-ecs-core@0.1.0.0/ordinary_app_observation_data.bend as DTO
14import bendvy-ecs-core@0.1.0.0/ordinary_app_access.bend as Access
15import bendvy-ecs-core@0.1.0.0/system.bend as Sys
16import bendvy-ecs-core@0.1.0.0/ordinary_event_declaration.bend as Event
17import bendvy-ecs-core@0.1.0.0/ordinary_app_event.bend as EventOwner
18# Sole World is inside Runtime; schema/operational owners/phantom recipe remain retained.
19# Schema App retaining one actual event Runtime, ordinary registration owners and
20# event-owner product. Events are detached Data here; affine payload logs require
21# the separate owned-event family APIs. Raw folds/adapters remain trusted setup.
22type Application<S:Data,C:Type,R:Type,E:Data,H:Type,Rows:Data,-observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,-fold:H -> H & List<&2,Records.Fields<S>>,Events:Type,-eventFold:Events -> Events & List<&2,Access.Entry>> is Type:
23  Application{schema:Schema.Schema<S,C,R>,runtime:Ev.Runtime<S,C,R,E>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,events:Events,debug:Bool}
24# Advanced Unit event-owner fold with an empty access inventory.
25def empty_events(unit:Unit) -> Unit & List<&2,Access.Entry>:(unit,[])
26# Wrap the schema App World in an event Runtime with the supplied retention
27# capacity and no event owners. Preserve schema/owners/recipe/debug; no reader
28# or writer is automatically registered.
29def start(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,capacity:Nat,value:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold>) -> Application<S,C,R,E,H,Rows,observe,fold,Unit,empty_events>:
30  match value:
31    case SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}}:Application{schema,Ev.start(~S,~C,~R,~E,world,capacity),owners,recipe,Unit{},debug}
32# Set App observation enablement without dispatch or retention/cursor changes.
33def enabled(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>,flag:Bool) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>:
34  match app:
35    case Application{schema,runtime,owners,recipe,events,_}:Application{schema,runtime,owners,recipe,events,flag}
36def indexed(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,schema:Schema.Schema<S,C,R>,runtime:Ev.Runtime<S,C,R,E>,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,prior:H & List<&2,Records.Fields<S>>,eventResult:Events & List<&2,Access.Entry>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,List<&2,Access.Entry>>:
37  match prior eventResult:
38    case (owners,records),(events,entries):(Application{schema,runtime,owners,recipe,events,True{}},Some{Access.grouped(List.append(&2,Access.Entry,Access.fields(~S,records),entries),[])})
39# Return App and optional grouped registration/event access inventory. Disabled
40# bypasses both folds; enabled threads actual owners through generated folds.
41# Inventory metadata is not a gameplay grant or an event acknowledgement.
42def index(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,List<&2,Access.Entry>>:
43  match app:
44    case Application{schema,runtime,owners,recipe,events,False{}}:(Application{schema,runtime,owners,recipe,events,False{}},None{})
45    case Application{schema,runtime,owners,recipe,events,True{}}:indexed(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,schema,runtime,recipe,fold(owners),eventFold(events))
46def pair_second(~L:Type,~R:Type,left:L,before:List<&2,Access.Entry>,right:R & List<&2,Access.Entry>) -> (L & R) & List<&2,Access.Entry>:
47  match right:
48    case (right,after):((left,right),List.append(&2,Access.Entry,before,after))
49def pair_first(~L:Type,~R:Type,~rightFold:R -> R & List<&2,Access.Entry>,right:R,left:L & List<&2,Access.Entry>) -> (L & R) & List<&2,Access.Entry>:
50  match left:
51    case (left,before):pair_second(~L,~R,left,before,rightFold(right))
52# Advanced left-before-right event-owner fold composition retaining both actual
53# owners and concatenating detached access entries in order.
54def pair(~L:Type,~R:Type,~leftFold:L -> L & List<&2,Access.Entry>,~rightFold:R -> R & List<&2,Access.Entry>,events:L & R) -> (L & R) & List<&2,Access.Entry>:
55  match events:
56    case (left,right):pair_first(~L,~R,~rightFold,right,leftFold(left))
57# Actual event reader token paired with its declaration/registry owner. Reader id
58# and system registry id are distinct identities; neither is copied to run a reader.
59type ReaderLeaf<S:Data,E:Data,Registry:Type> is Type:
60  ReaderLeaf{reader:Ev.Reader<S>,owner:EventOwner.Owner<S,E,Registry>}
61def writer_entry_returned(~S:Data,~C:Type,~R:Type,~E:Data,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> A -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,result:EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>> & Maybe<&2,Access.Entry>) -> EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>> & List<&2,Access.Entry>:
62  match result:
63    case (owner,None{}):(owner,[])
64    case (owner,Some{entry}):(owner,[entry])
65# Advanced owner-returning event-writer access description using its declaration
66# and actual registry. The owner's debug flag controls whether an entry is emitted.
67def writer_entry(~S:Data,~C:Type,~R:Type,~E:Data,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> A -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,leaf:EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>) -> EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>> & List<&2,Access.Entry>:
68  match leaf:
69    case EventOwner.Owner{declaration,registry,debug}:writer_entry_returned(~S,~C,~R,~E,~A,~Error,~O,~runner,EventOwner.described(~S,~C,~R,~E,~A,~Error,~O,~runner,declaration,registry,debug))
70def reader_entry_returned(~S:Data,~C:Type,~R:Type,~E:Data,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> Ev.Input<E,A> -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,reader:Ev.Reader<S>,result:EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>> & Maybe<&2,Access.Entry>) -> ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>> & List<&2,Access.Entry>:
71  match result:
72    case (owner,None{}):(ReaderLeaf{reader,owner},[])
73    case (owner,Some{entry}):(ReaderLeaf{reader,owner},[entry])
74# Advanced event-reader access description retaining the actual reader and registry.
75# Does not consume unread messages or advance stream positions.
76def reader_entry(~S:Data,~C:Type,~R:Type,~E:Data,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> Ev.Input<E,A> -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,leaf:ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>) -> ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>> & List<&2,Access.Entry>:
77  match leaf:
78    case ReaderLeaf{reader,EventOwner.Owner{declaration,registry,debug}}:reader_entry_returned(~S,~C,~R,~E,~A,~Error,~O,~runner,reader,EventOwner.described(~S,~C,~R,~E,~Ev.Input<E,A>,~Error,~O,~runner,declaration,registry,debug))
79def writer_registered_world(~S:Data,~C:Type,~R:Type,~E:Data,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> A -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,result:EventOwner.WriterRegistered<S,C,R,E,A,Error,O,runner>) -> W.World<S,C,R,E> & Maybe<EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>>:
80  match result:
81    case EventOwner.WriterFailed{world}:(world,None{})
82    case EventOwner.WriterRegistered{world,owner}:(world,Some{owner})
83def writer_appended(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> A -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,~Result:Type,done:Application<S,C,R,E,H,Rows,observe,fold,Events & EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>,pair(~Events,~EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>,~eventFold,~writer_entry(~S,~C,~R,~E,~A,~Error,~O,~runner))> -> Result,failed:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> -> Result,schema:Schema.Schema<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,events:Events,debug:Bool,result:Ev.Runtime<S,C,R,E> & Maybe<EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>>) -> Result:
84  match result:
85    case (runtime,None{}):failed(Application{schema,runtime,owners,recipe,events,debug})
86    case (runtime,Some{owner}):done(Application{schema,runtime,owners,recipe,(events,owner),debug})
87# Register a declared writer and append its actual owner on success. failed gets
88# the prior App shape with returned Runtime; done gets extended event owners.
89# No writer body runs. World registration adapter synchronizes through Ev.with_world.
90def register_writer(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> A -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,~Result:Type,done:Application<S,C,R,E,H,Rows,observe,fold,Events & EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>,pair(~Events,~EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>,~eventFold,~writer_entry(~S,~C,~R,~E,~A,~Error,~O,~runner))> -> Result,failed:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> -> Result,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>,declaration:Event.Declaration<S,E>,name:String) -> Result:
91  match app:
92    case Application{schema,runtime,owners,recipe,events,debug}:writer_appended(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~A,~Error,~O,~runner,~Result,done,failed,schema,owners,recipe,events,debug,Ev.with_world(~S,~C,~R,~E,~Maybe<EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>>,world => writer_registered_world(~S,~C,~R,~E,~A,~Error,~O,~runner,EventOwner.register_writer(~S,~C,~R,~E,~A,~Error,~O,~runner,world,declaration,name)),runtime))
93def reader_appended(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> Ev.Input<E,A> -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,~Result:Type,done:Application<S,C,R,E,H,Rows,observe,fold,Events & ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>,pair(~Events,~ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>,~eventFold,~reader_entry(~S,~C,~R,~E,~A,~Error,~O,~runner))> -> Result,failed:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> -> Result,schema:Schema.Schema<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,events:Events,debug:Bool,result:EventOwner.ReaderRegistered<S,C,R,E,A,Error,O,runner>) -> Result:
94  match result:
95    case EventOwner.ReaderFailed{runtime}:failed(Application{schema,runtime,owners,recipe,events,debug})
96    case EventOwner.ReaderRegistered{runtime,reader,owner}:done(Application{schema,runtime,owners,recipe,(events,ReaderLeaf{reader,owner}),debug})
97# Register a declared reader with its actual stream/registry ownership. done gets
98# the extended App; failed gets the prior App shape with returned Runtime. Does
99# not invoke the body or equate Reader id with Registry id.
100def register_reader(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> Ev.Input<E,A> -> Sys.Outcome<W.World<S,C,R,E>,Error,O>,~Result:Type,done:Application<S,C,R,E,H,Rows,observe,fold,Events & ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>,pair(~Events,~ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>,~eventFold,~reader_entry(~S,~C,~R,~E,~A,~Error,~O,~runner))> -> Result,failed:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> -> Result,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>,declaration:Event.Declaration<S,E>,name:String) -> Result:
101  match app:
102    case Application{schema,runtime,owners,recipe,events,debug}:reader_appended(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~A,~Error,~O,~runner,~Result,done,failed,schema,owners,recipe,events,debug,EventOwner.register_reader(~S,~C,~R,~E,~A,~Error,~O,~runner,runtime,declaration,name))
103
104# Internal owner-returning action transport, not an additional public App owner.
105type Previous<S:Data,C:Type,R:Type,E:Data,H:Type,Rows:Data,-observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,Out:Type> is Type:
106  Previous{schema:Schema.Schema<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,debug:Bool,output:Out}
107def previous_finished(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Out:Type,result:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Out) -> W.World<S,C,R,E> & Previous<S,C,R,E,H,Rows,observe,Out>:
108  match result:
109    case (SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}},output):(world,Previous{schema,owners,recipe,debug,output})
110def previous_returned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~Out:Type,events:Events,result:Ev.Runtime<S,C,R,E> & Previous<S,C,R,E,H,Rows,observe,Out>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Out:
111  match result:
112    case (runtime,Previous{schema,owners,recipe,debug,output}):(Application{schema,runtime,owners,recipe,events,debug},output)
113# Advanced schema-App action bridge retaining event owners and threading Runtime
114# through Ev.with_world synchronization/tick semantics. Arbitrary action effects
115# are trusted; this is not the observation-only bypass used by population/dump.
116def with_previous(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~Out:Type,action:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> -> SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Out,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Out:
117  match app:
118    case Application{schema,runtime,owners,recipe,events,debug}:previous_returned(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~Out,events,Ev.with_world(~S,~C,~R,~E,~Previous<S,C,R,E,H,Rows,observe,Out>,world => previous_finished(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Out,action(SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}})),runtime))
119# Advanced type projection of the App after appending one actual writer owner.
120def AfterWriter(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> A -> Sys.Outcome<W.World<S,C,R,E>,Error,O>) -> Type:Application<S,C,R,E,H,Rows,observe,fold,Events & EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>,pair(~Events,~EventOwner.Owner<S,E,Sys.Registry<S,C,R,E,A,Error,O,runner>>,~eventFold,~writer_entry(~S,~C,~R,~E,~A,~Error,~O,~runner))>
121# Advanced type projection after appending a ReaderLeaf with actual reader/owner.
122def AfterReader(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~A:Type,~Error:Data,~O:Type,~runner:W.World<S,C,R,E> -> Ev.Input<E,A> -> Sys.Outcome<W.World<S,C,R,E>,Error,O>) -> Type:Application<S,C,R,E,H,Rows,observe,fold,Events & ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>,pair(~Events,~ReaderLeaf<S,E,Sys.Registry<S,C,R,E,Ev.Input<E,A>,Error,O,runner>>,~eventFold,~reader_entry(~S,~C,~R,~E,~A,~Error,~O,~runner))>
123
124# Trusted internal action bridge: its arbitrary callback type does not imply read-only behavior.
125# Ordinary population/dump use only the concrete qualified generated observations.
126def internal_observation_returned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~Out:Type,namespace:U32,batches:List<&2,Ev.Batch<E>>,positions:List<&2,Ev.Position>,nextReader:U32,tick:Nat,frameStart:Nat,boundary:Nat,capacity:Nat,dropped:Nat,events:Events,result:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Out) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Out:
127  match result:
128    case (SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}},output):(Application{schema,Ev.Runtime{world,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped},owners,recipe,events,debug},output)
129def internal_observation_runtime(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~Out:Type,schema:Schema.Schema<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,events:Events,debug:Bool,action:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> -> SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Out,runtime:Ev.Runtime<S,C,R,E>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Out:
130  match runtime:
131    case Ev.Runtime{world,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped}:internal_observation_returned(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~Out,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped,events,action(SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}}))
132def internal_observation(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~Out:Type,action:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> -> SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Out,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Out:
133  match app:
134    case Application{schema,runtime,owners,recipe,events,debug}:internal_observation_runtime(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~Out,schema,owners,recipe,events,debug,action,runtime)
135# Observe generated ordinary component counts while preserving actual Runtime
136# fields, event owners and pending work. Disabled population bypasses counting.
137# No event synchronization/tick/frame/reader update is added by this observation.
138def population(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~count:C -> List<&2,W.Handle<S>> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,presentation:Presentation.Recipe<S,C,R,count,components,resources>,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,Population.Population>:
139  match presentation:
140    case Presentation.Recipe{}:internal_observation(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~Maybe<&2,Population.Population>,value => Population.schema_population(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,value),app)
141# Observe the generated filtered ordinary dump without advancing event Runtime.
142# Retain all actual owners; debug/filter/presenter behavior is that of App Dump,
143# with opaque presentation adapters trusted. Does not acknowledge event readers.
144def dump(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,~count:C -> List<&2,W.Handle<S>> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,presentation:Presentation.Recipe<S,C,R,count,components,resources>,criteria:Filter.Filter<S>,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,Dump.Dump<S>>:
145  match presentation:
146    case Presentation.Recipe{}:internal_observation(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,~Maybe<&2,Dump.Dump<S>>,value => Dump.schema_snapshot(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,criteria,value),app)
147
148# Descriptive values only. Position.id is the actual Reader ID, not a Registry ID.
149# Detached debug view of Data batches, actual reader positions and World event
150# log. Reader position ids are not registry ids; this is not a restorable checkpoint.
151type RuntimeView<E:Data> is Data:
152  RuntimeView{namespace:U32,batches:List<&2,Ev.Batch<E>>,positions:List<&2,Ev.Position>,nextReader:U32,tick:Nat,frameStart:Nat,boundary:Nat,capacity:Nat,droppedThrough:Nat,log:List<&2,E>}
153def runtime_view_returned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,schema:Schema.Schema<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,events:Events,+namespace:U32,+batches:List<&2,Ev.Batch<E>>,+positions:List<&2,Ev.Position>,+nextReader:U32,+tick:Nat,+frameStart:Nat,+boundary:Nat,+capacity:Nat,+dropped:Nat,result:W.World<S,C,R,E> & List<&2,E>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,RuntimeView<E>>:
154  match result:
155    case (world,log):(Application{schema,Ev.Runtime{world,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped},owners,recipe,events,True{}},Some{RuntimeView{namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped,log}})
156def runtime_view_enabled(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,schema:Schema.Schema<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,events:Events,runtime:Ev.Runtime<S,C,R,E>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,RuntimeView<E>>:
157  match runtime:
158    case Ev.Runtime{world,+namespace,+batches,+positions,+nextReader,+tick,+frameStart,+boundary,+capacity,+dropped}:runtime_view_returned(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,schema,owners,recipe,events,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped,W.events_view(~S,~C,~R,~E,world))
159# Return App and optional copied RuntimeView. Disabled bypasses log observation;
160# enabled preserves Runtime fields and owners, without sync/trim/frame or dispatch.
161def runtime_view(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~Events:Type,~eventFold:Events -> Events & List<&2,Access.Entry>,app:Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold>) -> Application<S,C,R,E,H,Rows,observe,fold,Events,eventFold> & Maybe<&2,RuntimeView<E>>:
162  match app:
163    case Application{schema,runtime,owners,recipe,events,False{}}:(Application{schema,runtime,owners,recipe,events,False{}},None{})
164    case Application{schema,runtime,owners,recipe,events,True{}}:runtime_view_enabled(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~Events,~eventFold,schema,owners,recipe,events,runtime)
165def runtime_batch_u32(batch:Ev.Batch<U32>) -> String:
166  match batch:
167    case Ev.Batch{tick,values}:Nat.show(tick) ++ ":" ++ List.show(~&2,~U32,~U32.show,values)
168def runtime_position(position:Ev.Position) -> String:
169  match position:
170    case Ev.Position{id,cursor,registeredAt}:"Reader" ++ U32.show(id) ++ ":" ++ Nat.show(cursor) ++ ":" ++ Nat.show(registeredAt)
171# Format a detached U32 RuntimeView only; no runtime access, cursor movement or IO.
172def runtime_text_u32(view:Maybe<&2,RuntimeView<U32>>) -> String:
173  match view:
174    case None{}:"runtime=None"
175    case Some{RuntimeView{namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped,log}}:"runtime=namespace:" ++ U32.show(namespace) ++ ";batches:" ++ List.show(~&2,~Ev.Batch<U32>,~runtime_batch_u32,batches) ++ ";readers:" ++ List.show(~&2,~Ev.Position,~runtime_position,positions) ++ ";nextReader:" ++ U32.show(nextReader) ++ ";tick:" ++ Nat.show(tick) ++ ";frameStart:" ++ Nat.show(frameStart) ++ ";boundary:" ++ Nat.show(boundary) ++ ";capacity:" ++ Nat.show(capacity) ++ ";droppedThrough:" ++ Nat.show(dropped) ++ ";log:" ++ List.show(~&2,~U32,~U32.show,log)