@@ -604,51 +604,82 @@ async def agent_detail(request: Request, agent_name: str):
604604 except (json .JSONDecodeError , OSError ):
605605 pass
606606
607- # Gather logs for this agent across all ideas
607+ # Gather logs for this agent — projection (instant) or filesystem (slow)
608608 bb = Blackboard (settings .blackboard_dir )
609+ projection = getattr (request .app .state , "projection" , None )
609610 agent_logs = []
610611 associated_ideas = {}
611- for idea_id in bb .list_ideas ():
612- log_dir = bb .idea_dir (idea_id ) / "agent-logs"
613- if not log_dir .is_dir ():
614- continue
615- idea_status = bb .get_status (idea_id )
616- for f in sorted (log_dir .iterdir (), reverse = True ):
617- if f .suffix != ".json" :
618- continue
619- try :
620- data = json .loads (f .read_text ())
621- except Exception :
622- continue
623- if data .get ("agent" ) != agent_name :
624- continue
625- associated_ideas [idea_id ] = idea_status .get ("title" , idea_id )
612+
613+ if projection and projection ._db :
614+ # Fast path: indexed query
615+ raw_logs = projection .get_agent_logs (agent_name )
616+ for log in raw_logs :
617+ idea_id = log .get ("idea_id" , "" )
618+ idea_proj = projection .get_idea (idea_id )
619+ title = idea_proj .get ("title" , idea_id ) if idea_proj else idea_id
620+ associated_ideas [idea_id ] = title
626621 agent_logs .append (
627622 {
628- "filename" : f . name ,
623+ "filename" : log . get ( "filename" , "" ) ,
629624 "idea_id" : idea_id ,
630- "idea_title" : idea_status . get ( " title" , idea_id ) ,
631- "timestamp" : data .get ("timestamp" , "" ),
632- "model" : data .get ("model" , "" ),
633- "transcript_len" : len ( data .get ("transcript " , []) ),
634- "run_status" : data .get ("run_status" , "" ),
625+ "idea_title" : title ,
626+ "timestamp" : log .get ("timestamp" , "" ),
627+ "model" : log .get ("model" , "" ),
628+ "transcript_len" : log .get ("transcript_len " , 0 ),
629+ "run_status" : log .get ("run_status" , "" ),
635630 }
636631 )
632+ else :
633+ # Slow path: scan all idea directories
634+ for idea_id in bb .list_ideas ():
635+ log_dir = bb .idea_dir (idea_id ) / "agent-logs"
636+ if not log_dir .is_dir ():
637+ continue
638+ idea_status = bb .get_status (idea_id )
639+ for f in sorted (log_dir .iterdir (), reverse = True ):
640+ if f .suffix != ".json" :
641+ continue
642+ try :
643+ data = json .loads (f .read_text ())
644+ except Exception :
645+ continue
646+ if data .get ("agent" ) != agent_name :
647+ continue
648+ associated_ideas [idea_id ] = idea_status .get ("title" , idea_id )
649+ agent_logs .append (
650+ {
651+ "filename" : f .name ,
652+ "idea_id" : idea_id ,
653+ "idea_title" : idea_status .get ("title" , idea_id ),
654+ "timestamp" : data .get ("timestamp" , "" ),
655+ "model" : data .get ("model" , "" ),
656+ "transcript_len" : len (data .get ("transcript" , [])),
657+ "run_status" : data .get ("run_status" , "" ),
658+ }
659+ )
637660
638661 # Sort logs by timestamp descending
639662 agent_logs .sort (key = lambda x : x ["timestamp" ], reverse = True )
640663
641- # Gather sandbox suggestions for this agent across all ideas
664+ # Gather sandbox suggestions — projection or filesystem
642665 sandbox_suggestions = []
643- for idea_id in bb . list_ideas () :
644- try :
645- st = bb . get_status ( idea_id )
646- for s in st .get ("sandbox_suggestions" , []):
666+ if projection and projection . _db :
667+ all_ideas = projection . get_ideas_for_home ()
668+ for idea in all_ideas :
669+ for s in idea .get ("sandbox_suggestions" , []):
647670 if s .get ("agent" ) == agent_name :
648- s ["idea_id" ] = idea_id
671+ s ["idea_id" ] = idea . get ( "id" , "" )
649672 sandbox_suggestions .append (s )
650- except Exception :
651- pass
673+ else :
674+ for idea_id in bb .list_ideas ():
675+ try :
676+ st = bb .get_status (idea_id )
677+ for s in st .get ("sandbox_suggestions" , []):
678+ if s .get ("agent" ) == agent_name :
679+ s ["idea_id" ] = idea_id
680+ sandbox_suggestions .append (s )
681+ except Exception :
682+ pass
652683
653684 ctx = _template_ctx (agent )
654685 ctx ["request" ] = request
0 commit comments