4444
4545# Per-step roles, used by TracingMiddleware to narrate the pipeline.
4646STEP_ROLES : dict [str , str ] = {
47- "context_creation" : "create execution context, set global deadline" ,
48- "call_chain_guard" : "check call depth & repeat limits" ,
49- "module_lookup" : "resolve module from registry" ,
50- "acl_check" : "enforce access control (default-deny)" ,
51- "approval_gate" : "human approval gate (if required)" ,
47+ "context_creation" : "create execution context, set global deadline" ,
48+ "call_chain_guard" : "check call depth & repeat limits" ,
49+ "module_lookup" : "resolve module from registry" ,
50+ "acl_check" : "enforce access control (default-deny)" ,
51+ "approval_gate" : "human approval gate (if required)" ,
5252 "middleware_before" : "run before-middleware chain (in order)" ,
53- "input_validation" : "validate inputs against schema" ,
54- "execute" : "invoke the module" ,
53+ "input_validation" : "validate inputs against schema" ,
54+ "execute" : "invoke the module" ,
5555 "output_validation" : "validate output against schema" ,
56- "middleware_after" : "run after-middleware chain (reverse order)" ,
57- "return_result" : "finalize and return output" ,
56+ "middleware_after" : "run after-middleware chain (reverse order)" ,
57+ "return_result" : "finalize and return output" ,
5858}
5959
6060
@@ -80,16 +80,12 @@ def before_step(self, step_name: str, state: PipelineState) -> None:
8080 role = "CUSTOM step inserted via insert_after / replace"
8181 print (f" { label } { step_name :<19} — { role } " )
8282
83- def after_step (
84- self , step_name : str , state : PipelineState , result : StepResult
85- ) -> None :
83+ def after_step (self , step_name : str , state : PipelineState , result : StepResult ) -> None :
8684 elapsed_ms = (time .perf_counter () - self ._starts .pop (step_name , time .perf_counter ())) * 1000
8785 detail = self ._summarize (step_name , state .context , result )
8886 print (f" ✓ { elapsed_ms :>6.2f} ms · { detail } " )
8987
90- def on_step_error (
91- self , step_name : str , state : PipelineState , error : Exception
92- ) -> None :
88+ def on_step_error (self , step_name : str , state : PipelineState , error : Exception ) -> None :
9389 print (f" ✗ { type (error ).__name__ } : { error } " )
9490 # Returning None lets the original exception propagate.
9591
@@ -177,8 +173,7 @@ def add(a: int, b: int) -> int:
177173 banner ("Section 3: Orchestration — insert_after + replace" )
178174 strategy .insert_after ("output_validation" , AuditLogStep ())
179175 custom = [n for n in strategy .step_names () if n not in CANONICAL_STEPS ]
180- print (f"after insert_after: 11 standard + { len (custom )} custom = "
181- f"{ len (strategy .steps )} steps" )
176+ print (f"after insert_after: 11 standard + { len (custom )} custom = " f"{ len (strategy .steps )} steps" )
182177 for i , name in enumerate (strategy .step_names (), start = 1 ):
183178 marker = " ← CUSTOM (inserted)" if name not in CANONICAL_STEPS else ""
184179 print (f" { i :>2} . { name } { marker } " )
@@ -187,8 +182,10 @@ def add(a: int, b: int) -> int:
187182 client .call ("math.add" , {"a" : 2 , "b" : 3 })
188183
189184 strategy .replace ("audit_log" , QuietAuditLogStep ())
190- print (f"\n after replace: { len (strategy .steps )} steps "
191- f"(audit_log still at index { strategy .step_names ().index ('audit_log' )} )" )
185+ print (
186+ f"\n after replace: { len (strategy .steps )} steps "
187+ f"(audit_log still at index { strategy .step_names ().index ('audit_log' )} )"
188+ )
192189
193190 print ("\n calling with the quiet replacement:" )
194191 client .call ("math.add" , {"a" : 7 , "b" : 9 })
0 commit comments