Spaces:
Sleeping
Sleeping
| # Author: Liam Grinstead | |
| # Multi-generation lineage tracking with mutation provenance | |
| from typing import Dict, List | |
| LINEAGE: Dict[str, List[dict]] = {} | |
| PARENT_OF: Dict[str, str] = {} | |
| def register_lineage(parent_id: str, child_id: str, mutation_profile: dict): | |
| entry = { | |
| "child_id": child_id, | |
| "tier": mutation_profile.get("tier_drift"), | |
| "overlay": mutation_profile.get("collapse_torque"), | |
| "operators": mutation_profile.get("symbolic_operators", []), | |
| } | |
| LINEAGE.setdefault(parent_id, []).append(entry) | |
| PARENT_OF[child_id] = parent_id | |
| def get_ancestors(agent_id: str) -> List[str]: | |
| chain = [] | |
| cur = agent_id | |
| while cur in PARENT_OF: | |
| p = PARENT_OF[cur] | |
| chain.append(p) | |
| cur = p | |
| return chain[::-1] | |
| def get_descendants(agent_id: str, depth: int = 6) -> Dict[int, List[dict]]: | |
| levels: Dict[int, List[dict]] = {} | |
| frontier = [agent_id] | |
| for d in range(1, depth + 1): | |
| nxt = [] | |
| for node in frontier: | |
| children = LINEAGE.get(node, []) | |
| if children: | |
| levels.setdefault(d, []).extend(children) | |
| nxt.extend([c["child_id"] for c in children]) | |
| frontier = nxt | |
| if not frontier: | |
| break | |
| return levels | |