1 import Base 2 import ./ordinary_app_execution_recipe.bend as Exec 3 import ./execution_context.bend as Ctx 4 import ./schedule_provision.bend as SP 5 import ./captured_schedule_composition.bend as Choice 6 import ./ordinary_app_composer.bend as Build 7 import ./ordinary_app_registration_fields.bend as Records 8 import ./ordinary_app_records.bend as Leaf 9 import ./world.bend as W 10 import ./system.bend as Sys 11 import ./transaction.bend as T 12 import ./compose.bend as Q 13 import ./ordinary_capture_query.bend as O 14 import ./ordinary_query_declaration.bend as Decl 15 import ./ordinary_app_capture_query_fields.bend as Fields 16 import ./ordinary_app_observation_data.bend as DTO 17 import ./trace_facts.bend as Facts 18 import ./ordinary_app_recipe.bend as Tree 19 20 # The actual affine capture-query owner is the invocation token. Fields are 21 # refreshed from that owner after each execution, including its real cursor. 22 # The registered owner of a repeatable query with affine capture L. 23 # Retain the actual returned owner, including its capture and reader cursor; 24 # metadata alone cannot replace its authority. Normally stored in Invocation. 25 def Owned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> Type:O.Owner 26 # An App-owned captured-query invocation: registered owner, repeatable Args, 27 # and latest row outputs. Thread the returned invocation through every update; 28 # use arguments, outputs and with_arguments rather than reconstructing tokens. 29 def Invocation(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> Type:Exec.Invocation 30 # Failure of this captured App leaf. CallbackFailure wraps the query's access 31 # or user error; RegistrationRefused reports rejected execution authority. 32 # A failure result still returns the context and captured-query owner. 33 type ExecutionError is Data: 34 CallbackFailure{error:Q.Error} 35 RegistrationRefused{} 36 def execution_extracted(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),args:Args,outputs:List<&2,Out>,outcome:Sys.Outcome>,ExecutionError,Unit>,result:Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Records.Fields) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Sys.Outcome>,ExecutionError,Unit>: 37 match result: 38 case (owner,fields):(Exec.Invocation{Leaf.Record{owner,fields},args,outputs},outcome) 39 def execution_returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),args:Args,trace:Facts.State,result:O.Run,Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),Args,Q.Error,Out>) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Sys.Outcome>,ExecutionError,Unit>: 40 match result: 41 case O.Completed{world,owner,Done{outputs}}:execution_extracted(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,args,outputs,Sys.Succeeded{Ctx.Context{world,trace},Unit{}},Fields.fields(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,owner)) 42 case O.Completed{world,owner,Fail{error}}:execution_extracted(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,args,[],Sys.Failed{Ctx.Context{world,trace},CallbackFailure{error}},Fields.fields(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,owner)) 43 case O.Refused{world,owner,returnedArgs}:execution_extracted(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,returnedArgs,[],Sys.Failed{Ctx.Context{world,trace},RegistrationRefused{}},Fields.fields(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,owner)) 44 def execution_allowed(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),allowed:Bool,invocation:Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),context:Ctx.Context>) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Sys.Outcome>,ExecutionError,Unit>: 45 match allowed invocation context: 46 case False{} invocation context:(invocation,Sys.Failed{context,RegistrationRefused{}}) 47 case True{} Exec.Invocation{Leaf.Record{owner,_},+args,_} Ctx.Context{world,trace}:execution_returned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,args,trace,O.run(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,owner,world,args)) 48 def execution_run(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),invocation:Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),context:Ctx.Context>,id:U32) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Sys.Outcome>,ExecutionError,Unit>: 49 match invocation: 50 case Exec.Invocation{Leaf.Record{owner,+fields},args,outputs}:execution_allowed(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,U32.is_eq(id,Exec.registration_id(~S,fields)),Exec.Invocation{Leaf.Record{owner,fields},args,outputs},context) 51 # Executable App type after appending a query with retained affine capture. 52 # The new invocation is paired with prior owners; earlier inspection rows remain. 53 # The polymorphic body receives declared Ops and must return both its opaque 54 # frame and capture on every branch. Args, Error and Out are repeatable Data. 55 # See examples/captured-query/app.bend for named aliases and a complete App. 56 def Application(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> Type: 57 Exec.Registered,Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),Rows,observe,Leaf.fold_pair(~S,~Owners,~Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~fold,~Exec.invocation_fields(~S,~Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~Args,~Out)),Choice.Choice>,Exec.plan_pair(~S,~Owners,~Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~priorPlan,~Exec.invocation_plan(~S,~Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~Args,~Out)),Exec.dispatch_pair(~S,~W.World,~Owners,~Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~PriorError,~ExecutionError,~fold,~priorDispatch,~execution_run(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)),Exec.provision_pair(~S,~W.World,~priorProvide,~Exec.empty_provide(~S,~W.World))> 58 def added_extracted(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),~Output:Type,args:Args,done:Application(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~PriorError,~priorPlan,~priorDispatch,~priorProvide,~L,~Ops,~Args,~Error,~Out,~query,~body) -> Output,world:W.World,owners:Owners,result:Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Records.Fields,recipe:Tree.Recipe,Rows,observe>,debug:Bool) -> Output: 59 match result: 60 case (owner,fields):done(Exec.Registered{Build.Registered{world,(owners,Exec.Invocation{Leaf.Record{owner,fields},args,[]}),recipe,debug},Exec.Recipe{}}) 61 def added(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),~Output:Type,args:Args,done:Application(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~PriorError,~priorPlan,~priorDispatch,~priorProvide,~L,~Ops,~Args,~Error,~Out,~query,~body) -> Output,failed:Exec.Registered,Owners,Rows,observe,fold,PriorError,priorPlan,priorDispatch,priorProvide> -> L -> Output,result:Fields.Appended,Owners,Rows,observe,fold>,Build.Registered,Owners & Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),Rows,observe,Leaf.fold_pair(~S,~Owners,~Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~fold,~Fields.fold(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body))>,L>) -> Output: 62 match result: 63 case Fields.Appended{Build.Registered{world,(owners,owner),recipe,debug}}:added_extracted(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~PriorError,~priorPlan,~priorDispatch,~priorProvide,~L,~Ops,~Args,~Error,~Out,~query,~body,~Output,args,done,world,owners,Fields.fields(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,owner),recipe,debug) 64 case Fields.AppendRejected{app,capture}:failed(Exec.Registered{app,Exec.Recipe{}},capture) 65 # Register a captured query during App setup, consuming value and capture. 66 # On success done receives the extended App. On refusal failed receives the 67 # returned prior App AND capture, so the caller can recover or explicitly drop 68 # those affine owners. args is retained for future invocations; name follows 69 # the ordinary registry rules. No callback runs during this registration. 70 # During execution, failure rolls back transactional writes and clears row 71 # outputs, but retains the callback-returned capture: capture mutation is not 72 # ECS rollback. Failure/refusal do not advance the query reader cursor; success does. 73 # Deferred structural commands still need the ordinary explicit barrier. 74 # Runnable example: bash examples/captured-query/run.sh js (or native). 75 # Its app.bend:add_second shows add; body.bend returns all owners on failure. 76 def add(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),~Output:Type,done:Application(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~PriorError,~priorPlan,~priorDispatch,~priorProvide,~L,~Ops,~Args,~Error,~Out,~query,~body) -> Output,failed:Exec.Registered,Owners,Rows,observe,fold,PriorError,priorPlan,priorDispatch,priorProvide> -> L -> Output,value:Exec.Registered,Owners,Rows,observe,fold,PriorError,priorPlan,priorDispatch,priorProvide>,args:Args,name:String,capture:L) -> Output: 77 match value: 78 case Exec.Registered{app,_}:added(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~PriorError,~priorPlan,~priorDispatch,~priorProvide,~L,~Ops,~Args,~Error,~Out,~query,~body,~Output,args,done,failed,Fields.register(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body,~Owners,~Rows,~observe,~fold,app,name,capture)) 79 # Advanced App-composition type projection: prior owners plus this Invocation. 80 # Use the complete matching execution_* family to name a composed App. 81 def execution_owners(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> Type: 82 Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) 83 # Advanced App-composition type projection: prior inspection rows, unchanged. 84 # Captured row results are read with outputs, not added to inspection here. 85 def execution_rows(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> Data: 86 Rows 87 # Advanced App-composition projection: retain the prior World observer. 88 # This captured leaf does not add a separate inspection-query projection. 89 def execution_observe(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> W.World -> W.World & DTO.Observation: 90 observe 91 # Advanced App-composition projection: collect live registration fields while 92 # returning every owner, including this query's actual reader cursor. 93 def execution_fold(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> (Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) -> (Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) & List<&2,Records.Fields>: 94 Leaf.fold_pair(~S,~Owners,~Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~fold,~Exec.invocation_fields(~S,~Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~Args,~Out)) 95 # Advanced App-composition projection: build the combined registration plan 96 # without consuming or executing the retained captures. 97 def execution_plan(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> (Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) -> (Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) & SP.Plan: 98 Exec.plan_pair(~S,~Owners,~Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~priorPlan,~Exec.invocation_plan(~S,~Owned(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~Args,~Out)) 99 # Advanced App-composition projection: dispatch a registered ID and return all 100 # owners/context on success or failure. Prefer App schedule/run in gameplay; 101 # use the library-generated registration IDs and reader cursors. 102 def execution_dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> (Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) -> Ctx.Context> -> U32 -> (Owners & Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) & Sys.Outcome>,Choice.Choice>,Unit>: 103 Exec.dispatch_pair(~S,~W.World,~Owners,~Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),~PriorError,~ExecutionError,~fold,~priorDispatch,~execution_run(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) 104 # Advanced App-composition projection: combine prior provisioning requirements. 105 # This query leaf adds no host-service provisioner and returns the World owner. 106 def execution_provide(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~PriorError:Data,~priorPlan:Owners -> Owners & SP.Plan,~priorDispatch:Owners -> Ctx.Context> -> U32 -> Owners & Sys.Outcome>,PriorError,Unit>,~priorProvide:W.World -> W.World & List<&2,SP.Requirement>,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out))) -> W.World -> W.World & List<&2,SP.Requirement>: 107 Exec.provision_pair(~S,~W.World,~priorProvide,~Exec.empty_provide(~S,~W.World)) 108 109 # Read the repeatable arguments without losing the invocation. 110 # Returns (invocation, args); the affine capture remains inside the invocation. 111 def arguments(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),value:Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & Args: 112 match value: 113 case Exec.Invocation{record,+args,outputs}:(Exec.Invocation{record,args,outputs},args) 114 # Read this invocation's latest per-row outputs, preserving the invocation. 115 # A callback failure or Refused returned by the captured query runner clears 116 # outputs. An early ID-routing refusal returns the invocation and its previous 117 # outputs unchanged. Values are Data, not capture owners. 118 def outputs(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),value:Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body)) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body) & List<&2,Out>: 119 match value: 120 case Exec.Invocation{record,args,+outputs}:(Exec.Invocation{record,args,outputs},outputs) 121 # Replace repeatable invocation arguments, preserving capture, cursor and the 122 # stored output list. Does not run the query or reset failure visibility. 123 # See examples/captured-query/app.bend's retry path with Entry.update_owners. 124 def with_arguments(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~Args:Data,~Error:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> Args -> H -> H & (L & (T.Outcome & Out)),value:Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body),args:Args) -> Invocation(~S,~C,~R,~E,~L,~Ops,~Args,~Error,~Out,~query,~body): 125 match value: 126 case Exec.Invocation{record,_,outputs}:Exec.Invocation{record,args,outputs}