@@ -505,24 +505,27 @@ def classify_agent_level(
505505
506506 if normalized_type == "metaswarm-swarm" :
507507 return "other"
508- if normalized_type == "metaswarm-division" or "division" in haystack or "div-" in haystack :
509- return "division_commanders"
510- if (
511- normalized_type in {"metaswarm-commander" , "swarm-command" , "stampede-commander" }
512- or "commander" in haystack
513- or "cmd-" in haystack
514- or "hive-auth-" in haystack
515- or "hive1k" in haystack
516- ):
517- return "commanders"
518- if normalized_type in {"metaswarm-squad" } or "squad" in haystack :
519- return "squad_leads"
520- if normalized_type in {"metaswarm-reviewer" , "code-review" } or "reviewer" in haystack or "code-review" in haystack :
521- return "reviewers"
522508 if normalized_type in {"metaswarm-sub-agent" , "metaswarm-worker" , "stampede-agent" , "dispatch-worker" }:
523509 return "workers"
524510 if normalized_type in {"task" , "explore" }:
525511 return "workers"
512+ if normalized_type in {"metaswarm-squad" }:
513+ return "squad_leads"
514+ if normalized_type in {"metaswarm-reviewer" , "code-review" }:
515+ return "reviewers"
516+ if normalized_type == "metaswarm-division" :
517+ return "division_commanders"
518+ if normalized_type in {"metaswarm-commander" , "swarm-command" , "stampede-commander" }:
519+ return "commanders"
520+
521+ if "division" in haystack or "div-" in haystack :
522+ return "division_commanders"
523+ if "commander" in haystack or "cmd-" in haystack or "hive-auth-" in haystack or "hive1k" in haystack :
524+ return "commanders"
525+ if "squad" in haystack :
526+ return "squad_leads"
527+ if "reviewer" in haystack or "code-review" in haystack :
528+ return "reviewers"
526529 if "worker" in haystack or "sub-agent" in haystack or "subagent" in haystack or "leaf" in haystack or "validator" in haystack :
527530 return "workers"
528531 if "lead" in haystack :
@@ -1095,6 +1098,36 @@ def run_sort_key(path: Path) -> Tuple[int, float]:
10951098
10961099 return sorted (runs .values (), key = run_sort_key , reverse = True )[: self ._RUN_DIR_LIMIT ]
10971100
1101+ @staticmethod
1102+ def _run_id_ts (run_id : str ) -> Optional [int ]:
1103+ match = re .match (r"run-(\d{8})-(\d{6})$" , run_id )
1104+ if not match :
1105+ return None
1106+ try :
1107+ return int (datetime .strptime ("" .join (match .groups ()), "%Y%m%d%H%M%S" ).replace (tzinfo = timezone .utc ).timestamp ())
1108+ except Exception :
1109+ return None
1110+
1111+ def _commander_launch_ts (self , run_dir : Path , run_id : str , commander_id : str , run_state : Dict , commander_state : Dict ) -> int :
1112+ for value in (
1113+ commander_state .get ("created_at" ),
1114+ run_state .get ("created_at" ),
1115+ run_state .get ("started_at" ),
1116+ commander_state .get ("claimed_at" ),
1117+ commander_state .get ("last_heartbeat_at" ),
1118+ commander_state .get ("updated_at" ),
1119+ ):
1120+ parsed = parse_iso_ts (value )
1121+ if parsed :
1122+ return parsed
1123+ parsed_run_id = self ._run_id_ts (run_id )
1124+ if parsed_run_id :
1125+ return parsed_run_id
1126+ try :
1127+ return int (run_dir .stat ().st_ctime )
1128+ except OSError :
1129+ return now_ts ()
1130+
10981131 def _poll_ledger_events (self , ledger : Path , run_id : str , commander_id : str ) -> None :
10991132 key = f"stampede-ledger:{ ledger } "
11001133 try :
@@ -1125,7 +1158,16 @@ def _poll_ledger_events(self, ledger: Path, run_id: str, commander_id: str) -> N
11251158 if not isinstance (data , dict ):
11261159 continue
11271160
1128- child_id = str (data .get ("child_id" ) or data .get ("agent_id" ) or data .get ("id" ) or "sub-agent" )
1161+ child_id_value = (
1162+ data .get ("child_id" )
1163+ or data .get ("agent_id" )
1164+ or data .get ("id" )
1165+ or data .get ("name" )
1166+ or data .get ("task_id" )
1167+ )
1168+ if not child_id_value :
1169+ continue
1170+ child_id = str (child_id_value )
11291171 event = str (data .get ("event" ) or "" ).lower ()
11301172 if event in _REQUEST_ONLY_CHILD_EVENTS :
11311173 requested [child_id ] = data
@@ -1264,6 +1306,7 @@ def poll(self) -> List[MetaswarmRun]:
12641306 if isinstance (line , str ) and line .strip ()
12651307 ][:5 ] if isinstance (commentary_lines , list ) else []
12661308 commanders : List [MetaswarmCommander ] = []
1309+ commander_launch_events : List [AgentEvent ] = []
12671310
12681311 def metric_int (* values : object , default : int = 0 ) -> int :
12691312 for value in values :
@@ -1292,6 +1335,22 @@ def metric_int(*values: object, default: int = 0) -> int:
12921335 fleet_meta = fleet .get (commander_id , {}) if isinstance (fleet , dict ) else {}
12931336 if not isinstance (fleet_meta , dict ):
12941337 fleet_meta = {}
1338+ commander_model = (
1339+ commander_state .get ("model" )
1340+ if isinstance (commander_state .get ("model" ), str )
1341+ else fleet_meta .get ("model" )
1342+ if isinstance (fleet_meta .get ("model" ), str )
1343+ else None
1344+ )
1345+ commander_launch_events .append (
1346+ AgentEvent (
1347+ ts = self ._commander_launch_ts (run_dir , run_id , commander_id , state , commander_state ),
1348+ agent_type = "stampede-commander" ,
1349+ name = commander_id ,
1350+ model = commander_model ,
1351+ source = f"stampede-commander:{ run_id } :{ commander_id } " ,
1352+ )
1353+ )
12951354
12961355 ledger = commander_dir / "child-agents.jsonl"
12971356 if ledger .exists ():
@@ -1331,13 +1390,7 @@ def metric_int(*values: object, default: int = 0) -> int:
13311390 MetaswarmCommander (
13321391 run_id = run_id ,
13331392 commander_id = commander_id ,
1334- model = (
1335- commander_state .get ("model" )
1336- if isinstance (commander_state .get ("model" ), str )
1337- else fleet_meta .get ("model" )
1338- if isinstance (fleet_meta .get ("model" ), str )
1339- else None
1340- ),
1393+ model = commander_model ,
13411394 status = status_text or "unknown" ,
13421395 phase = str (commander_state .get ("phase" ) or "unknown" ),
13431396 pid_status = pid_status ,
@@ -1455,6 +1508,7 @@ def metric_int(*values: object, default: int = 0) -> int:
14551508 )
14561509
14571510 if commanders :
1511+ self .store .insert_agent_events (commander_launch_events )
14581512 runs .append (
14591513 MetaswarmRun (
14601514 run_id = run_id ,
@@ -2902,9 +2956,10 @@ def update_rows(self, rows: List[Tuple[int, str, Optional[str], Optional[str]]])
29022956 for ts , typ , name , model in rows :
29032957 age = human_age (max (0 , now - ts ))
29042958 color = TYPE_COLOR .get (typ , TYPE_COLOR ["custom" ])
2959+ label = display_agent_type (typ )
29052960 self .add_row (
29062961 Text (age , style = "#8D99AE" ),
2907- Text (typ , style = f"bold { color } " ),
2962+ Text (label , style = f"bold { color } " ),
29082963 Text (name or "—" , style = "#C7F9CC" if name else "#8D99AE" ),
29092964 Text (model or "—" , style = "#8D99AE" ),
29102965 )
0 commit comments