ordinary_app_local_fields.bend
bendvy-ecs-core@0.1.0.0 · 183 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.0/ordinary_app_execution_recipe.bend as Exec
3import bendvy-ecs-core@0.1.0.0/ordinary_app_execution_run.bend as ExecuteRun
4import bendvy-ecs-core@0.1.0.0/execution_context.bend as Ctx
5import bendvy-ecs-core@0.1.0.0/trace_facts.bend as Facts
6import bendvy-ecs-core@0.1.0.0/system.bend as Sys
7import bendvy-ecs-core@0.1.0.0/schedule.bend as Sch
8import bendvy-ecs-core@0.1.0.0/schedule_provision.bend as SP
9import bendvy-ecs-core@0.1.0.0/captured_schedule_composition.bend as Choice
10import bendvy-ecs-core@0.1.0.0/ordinary_app_composer.bend as Build
11import bendvy-ecs-core@0.1.0.0/ordinary_app_records.bend as Pair
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/local.bend as Local
15import bendvy-ecs-core@0.1.0.0/world.bend as W
16import bendvy-ecs-core@0.1.0.0/ordinary_app_registration_fields.bend as Fields
17import bendvy-ecs-core@0.1.0.0/ordinary_query_declaration.bend as Query
18import bendvy-ecs-core@0.1.0.0/ordinary_resource_system.bend as P
19import bendvy-ecs-core@0.1.0.0/transaction.bend as T
20import bendvy-ecs-core@0.1.0.0/commands.bend as Cmd
21import bendvy-ecs-core@0.1.0.0/capabilities.bend as Cap
22# One ordinary declaration indexes the runner and registration owner. Local is
23# returned separately from body Out on both transaction success and failure.
24def returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Error:Data,~Out:Type,local:L,output:Out,result:T.Returned<W.World<S,C,R,E>,Error>) -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>:
25 match result:
26 case T.Returned{world,T.Success{}}:Local.Succeeded{world,local,output}
27 case T.Returned{world,T.Failure{error}}:Local.Failed{world,local,error}
28def finished(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Error:Data,~Out:Type,result:T.Tx<W.World<S,C,R,E>,E> & (L & (T.Outcome<Error> & Out))) -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>:
29 match result:
30 case (tx,(local,(outcome,output))):returned(~S,~C,~R,~E,~L,~Error,~Out,local,output,Cmd.tx_finish(~S,~C,~R,~E,~Error,tx,outcome))
31# Execute one resource declaration/body with opaque Tx capabilities and actual L.
32# Finish the ECS transaction using the returned outcome. Body-returned Local
33# persists on success AND failure; failed Out is discarded, not returned as recovery.
34# Args is consumed by the callback. This is Local execution, not captured-query
35# state rollback, and arbitrary external callback effects are not transactional.
36def runner(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),world:W.World<S,C,R,E>,local:L,args:Args) -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>:
37 finished(~S,~C,~R,~E,~L,~Error,~Out,body(T.Tx<W.World<S,C,R,E>,E>,P.grant(~S,~R,~T.Tx<W.World<S,C,R,E>,E>,~Ops(T.Tx<W.World<S,C,R,E>,E>),declaration),local,args,T.begin(~W.World<S,C,R,E>,~E,world)))
38# Affine owner of the actual Local.Instance, indexed by declaration and body.
39# No copied Local payload is retained in registration metadata.
40type Owner<-S:Data,-C:Type,-R:Type,-E:Data,-L:Type,-Args:Type,-Error:Data,-Out:Type,-Ops:Type -> Type,-declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,-body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out))> is Type:
41 Owner{instance:Local.Instance<S,C,R,E,L,Args,Error,Out,runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)>}
42# Registration success retains Local in owner; refusal returns actual World and
43# incoming L separately, without running the callback.
44type Registration<-World:Type,-Owned:Type,-L:Type> is Type:
45 Registered{world:World,owner:Owned}
46 Rejected{world:World,local:L}
47def registered(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),result:Local.Registered<S,C,R,E,L,Args,Error,Out,runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)>) -> Registration<W.World<S,C,R,E>,Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,L>:
48 match result:
49 case Local.Registered{world,instance}:Registered{world,Owner{instance}}
50 case Local.RegistrationRejected{world,local}:Rejected{world,local}
51# Register the Local runner using access derived from the same resource declaration.
52# Returns Registration with actual owners; does not execute the body or fabricate
53# a query reader. Closed declarations/projections remain trusted provisioning.
54def define(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),world:W.World<S,C,R,E>,name:String,local:L) -> Registration<W.World<S,C,R,E>,Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,L>:
55 registered(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,Local.register(~S,~C,~R,~E,~L,~Args,~Error,~Out,~runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body),world,name,P.access(~S,P.clause(~S,~R,~T.Tx<W.World<S,C,R,E>,E>,~Ops(T.Tx<W.World<S,C,R,E>,E>),declaration)),local))
56# Run the retained Local instance after actual registration/World validation.
57# Completed returns the updated instance and Done(Out) or Fail(Error); callback
58# failure still retains its returned Local. Refused returns World, instance and
59# unconsumed Args. No implicit barrier, skip processing or disposal is performed.
60def run(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),value:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,world:W.World<S,C,R,E>,args:Args) -> Local.Run<S,C,R,E,L,Args,Error,Out,runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)>:
61 match value:
62 case Owner{instance}:Local.run(~S,~C,~R,~E,~L,~Args,~Error,~Out,~runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body),instance,world,args)
63def field_values(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),instance:Local.Instance<S,C,R,E,L,Args,Error,Out,runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)>,clause:Query.Clause<S>) -> Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Fields.Fields<S>:
64 match instance clause:
65 case Local.Instance{+namespace,+id,+name,+access,local} Query.Clause{+slot,+mode}:(Owner{Local.Instance{namespace,id,name,access,local}},Fields.Fields{namespace,id,name,access,None{},slot,[Query.Clause{slot,mode}],Fields.ResourceKind{mode}})
66# Local has no retained query reader cursor; None marks this nonreader metadata.
67# Project registration fields while returning Owner. Resource slot/mode/access
68# come from the operational declaration; Local payload remains opaque. The absent cursor
69# is metadata, not a live lifecycle/event reader position.
70def fields(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),value:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Fields.Fields<S>:
71 match value:
72 case Owner{instance}:field_values(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,instance,P.clause(~S,~R,~T.Tx<W.World<S,C,R,E>,E>,~Ops(T.Tx<W.World<S,C,R,E>,E>),declaration))
73def fields_list_returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),result:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Fields.Fields<S>) -> Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & List<&2,Fields.Fields<S>>:
74 match result:
75 case (value,field):(value,[field])
76# Advanced singleton registration fold retaining Owner and its actual Local.
77# Produces metadata only, not an additional resource grant or gameplay invocation.
78def fold(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),value:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & List<&2,Fields.Fields<S>>:
79 fields_list_returned(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,fields(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,value))
80# Registration into an App either returns the extended App or the prior App shape
81# with actual incoming Local. No automatic destructor runs on AppendRejected.
82type Appended<-Before:Type,-After:Type,-L:Type> is Type:
83 Appended{app:After}
84 AppendRejected{app:Before,local:L}
85# Ordinary registration composes the derived fold itself; application authors
86# provide only operational declaration/body and Local, never metadata adapters.
87def appended(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,previous:Previous,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,debug:Bool,result:Registration<W.World<S,C,R,E>,Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,L>) -> Appended<Build.Registered<S,W.World<S,C,R,E>,Previous,Rows,observe,previousFold>,Build.Registered<S,W.World<S,C,R,E>,Previous & Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,Rows,observe,Pair.fold_pair(~S,~Previous,~Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~previousFold,~fold(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body))>,L>:
88 match result:
89 case Rejected{world,local}:AppendRejected{Build.Registered{world,previous,recipe,debug},local}
90 case Registered{world,owner}:Appended{Build.Registered{world,(previous,owner),recipe,debug}}
91# Register into a composer App, deriving the metadata fold and retaining prior
92# owners/observer/debug. On refusal return prior App shape and Local; does not run
93# body. See test-fixtures/public-schedules/named-app-v1/matched-feature-v1/fixture.bend.
94def register(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Type,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,app:Build.Registered<S,W.World<S,C,R,E>,Previous,Rows,observe,previousFold>,name:String,local:L) -> Appended<Build.Registered<S,W.World<S,C,R,E>,Previous,Rows,observe,previousFold>,Build.Registered<S,W.World<S,C,R,E>,Previous & Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,Rows,observe,Pair.fold_pair(~S,~Previous,~Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~previousFold,~fold(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body))>,L>:
95 match app:
96 case Build.Registered{world,previous,recipe,debug}:appended(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,~Previous,~Rows,~observe,~previousFold,previous,recipe,debug,define(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,world,name,local))
97
98# Schedule-facing distinction between callback transaction failure and refused
99# registration/routing. Neither branch implies Local was rolled back.
100type ExecutionError<Error:Data> is Data:
101 CallbackFailure{error:Error}
102 RegistrationRefused{}
103# Executable invocation retaining actual Local owner and reusable Data Args.
104# It stores no Out: schedule execution discards successful Out after completion.
105type Invocation<-S:Data,-C:Type,-R:Type,-E:Data,-L:Type,-Args:Data,-Error:Data,-Out:Type,-Ops:Type -> Type,-declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,-body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out))> is Type:
106 Invocation{owner:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,args:Args}
107def execution_folded(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),args:Args,result:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & List<&2,Fields.Fields<S>>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & List<&2,Fields.Fields<S>>:
108 match result:
109 case (owner,fields):(Invocation{owner,args},fields)
110# Advanced owner-returning fold of invocation metadata, retaining stored Args.
111def execution_fields(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),value:Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & List<&2,Fields.Fields<S>>:
112 match value:
113 case Invocation{owner,args}:execution_folded(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,args,fold(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,owner))
114def execution_planned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),args:Args,result:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Fields.Fields<S>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & SP.Plan<S>:
115 match result:
116 case (owner,Fields.Fields{_,id,_,_,_,_,_,_}):(Invocation{owner,args},SP.Entry{Sch.System{id,0},[]})
117# Advanced owner-returning single-id plan at condition slot zero with no explicit
118# requirements. Does not derive requirements from field metadata or run Local.
119def execution_plan(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),value:Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & SP.Plan<S>:
120 match value:
121 case Invocation{owner,args}:execution_planned(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,args,fields(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,owner))
122def execution_returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),args:Args,trace:Facts.State,result:Local.Run<S,C,R,E,L,Args,Error,Out,runner(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,ExecutionError<Error>,Unit>:
123 match result:
124 case Local.Completed{world,instance,Done{_},_}:(Invocation{Owner{instance},args},Sys.Succeeded{Ctx.Context{world,trace},Unit{}})
125 case Local.Completed{world,instance,Fail{error},_}:(Invocation{Owner{instance},args},Sys.Failed{Ctx.Context{world,trace},CallbackFailure{error}})
126 case Local.Refused{world,instance,_}:(Invocation{Owner{instance},args},Sys.Failed{Ctx.Context{world,trace},RegistrationRefused{}})
127def execution_allowed(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),valid:Bool,owner:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,args:Args,context:Ctx.Context<W.World<S,C,R,E>>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,ExecutionError<Error>,Unit>:
128 match valid context:
129 case False{} context:(Invocation{owner,args},Sys.Failed{context,RegistrationRefused{}})
130 case True{} Ctx.Context{world,trace}:
131 +actual=args
132 execution_returned(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,actual,trace,run(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,owner,world,actual))
133def execution_selected(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),args:Args,context:Ctx.Context<W.World<S,C,R,E>>,id:U32,result:Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Fields.Fields<S>) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,ExecutionError<Error>,Unit>:
134 match result:
135 case (owner,fields):execution_allowed(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,U32.is_eq(id,Exec.registration_id(~S,fields)),owner,args,context)
136# Advanced id-routed dispatch. Mismatched id returns invocation/context unchanged
137# with RegistrationRefused. Matched execution preserves reusable Data Args and
138# retains the returned Local instance; callback failure maps to CallbackFailure,
139# while successful Out is discarded. Trace context is carried separately.
140# This adapter installs no skip/cursor-advance or Local disposal callback.
141def execution_run(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),value:Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,context:Ctx.Context<W.World<S,C,R,E>>,id:U32) -> Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body> & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,ExecutionError<Error>,Unit>:
142 match value:
143 case Invocation{owner,args}:execution_selected(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,args,context,id,fields(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,owner))
144# Advanced execution-enabled App type with prior owners plus Local invocation.
145# Uses prior observation unchanged and adds registration fields/plan/dispatch;
146# this does not expose Local to unrelated systems or reset it on failed execution.
147def Executable(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> Type:
148 Exec.Registered<S,W.World<S,C,R,E>,Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,Rows,observe,Pair.fold_pair(~S,~Previous,~Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~previousFold,~execution_fields(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)),Choice.Choice<PriorError,ExecutionError<Error>>,Exec.plan_pair(~S,~Previous,~Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~priorPlan,~execution_plan(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)),Exec.dispatch_pair(~S,~W.World<S,C,R,E>,~Previous,~Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~PriorError,~ExecutionError<Error>,~previousFold,~priorDispatch,~execution_run(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body)),Exec.provision_pair(~S,~W.World<S,C,R,E>,~priorProvide,~Exec.empty_provide(~S,~W.World<S,C,R,E>))>
149def execution_added(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>,args:Args,previous:Previous,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,debug:Bool,result:Registration<W.World<S,C,R,E>,Owner<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,L>) -> Appended<Exec.Registered<S,W.World<S,C,R,E>,Previous,Rows,observe,previousFold,PriorError,priorPlan,priorDispatch,priorProvide>,Executable(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,~Previous,~Rows,~observe,~previousFold,~PriorError,~priorPlan,~priorDispatch,~priorProvide),L>:
150 match result:
151 case Rejected{world,local}:AppendRejected{Exec.Registered{Build.Registered{world,previous,recipe,debug},Exec.Recipe{}},local}
152 case Registered{world,owner}:Appended{Exec.Registered{Build.Registered{world,(previous,Invocation{owner,args}),recipe,debug},Exec.Recipe{}}}
153# Register Local and Data Args into an execution-enabled App, deriving composition
154# from the declaration. Refusal returns prior App and actual L; success retains
155# L and Args for later dispatch. No run, condition skip or disposal happens here.
156# Explicit lifecycle cleanup remains in local.bend rather than an implicit finalizer.
157def add(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>,value:Exec.Registered<S,W.World<S,C,R,E>,Previous,Rows,observe,previousFold,PriorError,priorPlan,priorDispatch,priorProvide>,name:String,local:L,args:Args) -> Appended<Exec.Registered<S,W.World<S,C,R,E>,Previous,Rows,observe,previousFold,PriorError,priorPlan,priorDispatch,priorProvide>,Executable(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,~Previous,~Rows,~observe,~previousFold,~PriorError,~priorPlan,~priorDispatch,~priorProvide),L>:
158 match value:
159 case Exec.Registered{Build.Registered{world,previous,recipe,debug},_}:execution_added(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,~Previous,~Rows,~observe,~previousFold,~PriorError,~priorPlan,~priorDispatch,~priorProvide,args,previous,recipe,debug,define(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body,world,name,local))
160# Advanced type projection of prior owners paired with actual Local invocation.
161def execution_owners(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> Type:
162 Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>
163# Advanced detached row projection: Local adds metadata, not observation rows.
164def execution_rows(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> Data:
165 Rows
166# Advanced observer projection retaining the prior observer exactly; Local is
167# not automatically rendered or inspected by this adapter.
168def execution_observe(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>:
169 observe
170# Advanced closed fold of prior fields followed by Local invocation metadata.
171def execution_fold(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> (Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> (Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) & List<&2,Fields.Fields<S>>:
172 Pair.fold_pair(~S,~Previous,~Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~previousFold,~execution_fields(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body))
173# Advanced closed plan composition: prior plan then Local id, retaining owners.
174def composed_plan(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> (Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> (Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) & SP.Plan<S>:
175 Exec.plan_pair(~S,~Previous,~Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~priorPlan,~execution_plan(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body))
176# Advanced closed routing to prior or Local invocation with tagged error branches.
177# Dispatch preserves actual owners; it is not a shared Local or capture transaction.
178def execution_dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> (Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> (Previous & Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>) & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,Choice.Choice<PriorError,ExecutionError<Error>>,Unit>:
179 Exec.dispatch_pair(~S,~W.World<S,C,R,E>,~Previous,~Invocation<S,C,R,E,L,Args,Error,Out,Ops,declaration,body>,~PriorError,~ExecutionError<Error>,~previousFold,~priorDispatch,~execution_run(~S,~C,~R,~E,~L,~Args,~Error,~Out,~Ops,~declaration,~body))
180# Advanced provisioning composition: preserve prior provisioning and add no
181# extra requirements for this Local registration.
182def execution_provide(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~Ops:Type -> Type,~declaration:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome<Error> & Out)),~Previous:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~previousFold:Previous -> Previous & List<&2,Fields.Fields<S>>,~PriorError:Data,~priorPlan:Previous -> Previous & SP.Plan<S>,~priorDispatch:Previous -> Ctx.Context<W.World<S,C,R,E>> -> U32 -> Previous & Sys.Outcome<Ctx.Context<W.World<S,C,R,E>>,PriorError,Unit>,~priorProvide:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>) -> W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,SP.Requirement<S>>:
183 Exec.provision_pair(~S,~W.World<S,C,R,E>,~priorProvide,~Exec.empty_provide(~S,~W.World<S,C,R,E>))