import Base import ./world.bend as W import ./ordinary_app_schedule.bend as Schedule import ./ordinary_app_schema.bend as SchemaApp import ./ordinary_app_composer.bend as Build import ./ordinary_schema.bend as Schema import ./ordinary_app_recipe.bend as Tree import ./ordinary_app_observation_data.bend as DTO import ./ordinary_app_registration_fields.bend as Fields import ./ordinary_app_access.bend as Access import ./schedule.bend as Sch import ./schedule_provision.bend as SP # Retained operational Plan selects actual registry identity; no parallel catalog. # Detached grouped declared accesses for the retained schedule's actual # namespace/name. This is a diagnostic index, not a runtime grant or payload view. type Index is Data: Index{namespace:U32,name:String,entries:List<&2,Access.Entry>} def selected(~S:Data,found:Bool,record:Fields.Fields,rest:List<&2,Fields.Fields>) -> List<&2,Fields.Fields>: match found: case True{}:record <> rest case False{}:rest def identified(~S:Data,namespace:U32,id:U32,+record:Fields.Fields,rest:List<&2,Fields.Fields>) -> List<&2,Fields.Fields>: match record: case Fields.Fields{otherNamespace,otherId,_,_,_,_,_,_}:selected(~S,Bool.and(U32.is_eq(namespace,otherNamespace),U32.is_eq(id,otherId)),record,rest) def matching(~S:Data,+namespace:U32,+id:U32,records:List<&2,Fields.Fields>) -> List<&2,Fields.Fields>: match records: case []:[] case +record <> rest:identified(~S,namespace,id,record,matching(~S,namespace,id,rest)) def step(~S:Data,namespace:U32,records:List<&2,Fields.Fields>,planned:Schedule.PlannedStep) -> List<&2,Fields.Fields>: match planned: case Schedule.PlannedStep{Sch.System{id,_},_}:matching(~S,namespace,id,records) case _ :[] # Advanced metadata selector: keep registration fields matching each System # placement's exact namespace/id in step order; phase/barrier entries add no fields. # No unmatched registration is invented and no capability is derived from strings. def placed(~S:Data,steps:List<&2,Schedule.PlannedStep>,+namespace:U32,+records:List<&2,Fields.Fields>) -> List<&2,Fields.Fields>: match steps: case []:[] case first <> rest:List.append(&2,Fields.Fields,step(~S,namespace,records,first),placed(~S,rest,namespace,records)) def folded(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Fields.Fields>,schema:Schema.Schema,world:W.World,recipe:Tree.Recipe,Rows,observe>,+plan:SP.Plan,+namespace:U32,+name:String,steps:List<&2,Sch.Step>,needs:List<&2,SP.Requirement>,result:H & List<&2,Fields.Fields>) -> Schedule.Application & Maybe<&2,Index>: match result: case (owners,records):(Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,True{}}},plan,namespace,name,steps,needs},Some{Index{namespace,name,Access.grouped(Access.fields(~S,placed(~S,Schedule.planned(~S,plan),namespace,records)),[])}}) # Return the same scheduled App and optional grouped declared-access index. # Disabled returns None before folding owners; enabled selects fields using the # retained operational plan. Does not run systems, inspect payloads, advance # readers or apply pending commands; arbitrary fold adapters remain trusted. def index(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Fields.Fields>,value:Schedule.Application) -> Schedule.Application & Maybe<&2,Index>: match value: case Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,False{}}},plan,namespace,name,steps,needs}:(Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,False{}}},plan,namespace,name,steps,needs},None{}) case Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,True{}}},plan,namespace,name,steps,needs}:folded(~S,~C,~R,~E,~H,~Rows,~observe,~fold,schema,world,recipe,plan,namespace,name,steps,needs,fold(owners))