@@ -14,7 +14,6 @@ use serde_json::{json, Map, Value};
1414
1515use crate :: identity:: artifact_identifier;
1616use crate :: pycompat:: { first_nonempty_line, py_casefold, read_text_universal} ;
17- use crate :: relationships:: corpus_items;
1817use crate :: spec:: spec_for;
1918
2019const DECISION_TYPE : & str = "decision" ;
@@ -179,9 +178,11 @@ fn is_live_decision(artifact: &crate::parse::Artifact) -> bool {
179178}
180179
181180/// `build_agent_rules_block(directory)` → ordered entries + digest.
182- fn build_projection ( directory : & str ) -> ( Vec < AgentRulesEntry > , String ) {
181+ fn build_projection ( directory : & str ) -> Result < ( Vec < AgentRulesEntry > , String ) , String > {
183182 let mut entries: Vec < AgentRulesEntry > = Vec :: new ( ) ;
184- for item in corpus_items ( directory, true ) {
183+ for item in crate :: federated_corpus:: local_writable_items ( directory, true )
184+ . map_err ( |error| error. to_string ( ) ) ?
185+ {
185186 let Some ( spec) = item. spec else { continue } ;
186187 if spec. name != DECISION_TYPE || !is_live_decision ( & item. artifact ) {
187188 continue ;
@@ -215,7 +216,7 @@ fn build_projection(directory: &str) -> (Vec<AgentRulesEntry>, String) {
215216 . collect ( ) ;
216217 let canonical = crate :: pyjson:: dumps_canonical_sorted ( & Value :: Array ( payload) ) ;
217218 let digest = crate :: sha256:: hexdigest ( canonical. as_bytes ( ) ) ;
218- ( entries, digest)
219+ Ok ( ( entries, digest) )
219220}
220221
221222/// `render_managed_block(projection)` — markers + distilled pointers, no
@@ -298,7 +299,7 @@ pub fn generate_agent_rules(
298299 root : & str ,
299300 clients : & [ String ] ,
300301) -> Result < AgentRulesResult , String > {
301- let ( entries, digest) = build_projection ( directory) ;
302+ let ( entries, digest) = build_projection ( directory) ? ;
302303 let block = render_managed_block ( & entries, & digest) ;
303304
304305 let mut files: Vec < AgentRulesFileResult > = Vec :: new ( ) ;
@@ -349,8 +350,12 @@ pub fn generate_agent_rules(
349350
350351/// `check_agent_rules(directory, root, clients)` — never writes; compares
351352/// each present target's embedded digest to the live projection.
352- pub fn check_agent_rules ( directory : & str , root : & str , clients : & [ String ] ) -> AgentRulesResult {
353- let ( _, digest) = build_projection ( directory) ;
353+ pub fn check_agent_rules (
354+ directory : & str ,
355+ root : & str ,
356+ clients : & [ String ] ,
357+ ) -> Result < AgentRulesResult , String > {
358+ let ( _, digest) = build_projection ( directory) ?;
354359
355360 let mut files: Vec < AgentRulesFileResult > = Vec :: new ( ) ;
356361 for target in targets_for ( clients) {
@@ -371,12 +376,12 @@ pub fn check_agent_rules(directory: &str, root: &str, clients: &[String]) -> Age
371376 } ) ;
372377 }
373378
374- AgentRulesResult {
379+ Ok ( AgentRulesResult {
375380 mode : "check" ,
376381 digest,
377382 root : root. to_string ( ) ,
378383 files,
379- }
384+ } )
380385}
381386
382387#[ cfg( test) ]
0 commit comments