Persist the IDE agent's clustering result as the module tree.
(
arguments: Dict[str, Any],
store: SessionStore,
)
| 57 | }) |
| 58 | else: |
| 59 | order.append({ |
| 60 | "module": module_name, |
| 61 | "path": current_path, |
| 62 | "is_leaf": True, |
| 63 | "components": module_info.get("components", []), |
| 64 | }) |
| 65 | |
| 66 | _collect(module_tree, parent_path) |
| 67 | return order |
| 68 | |
| 69 | |
| 70 | def _collect_component_ids(module_tree: Dict[str, Any]) -> set[str]: |
| 71 | """Return the set of all component ids referenced across the module tree. |
| 72 | |
| 73 | Walks every module (and nested ``children``) and collects the entries of |
| 74 | each module's ``components`` list. |
| 75 | """ |
| 76 | ids: set[str] = set() |
| 77 | |
| 78 | def _walk(tree: Dict[str, Any]) -> None: |
| 79 | for module_info in tree.values(): |
| 80 | ids.update(module_info.get("components", []) or []) |
| 81 | children = module_info.get("children", {}) |
| 82 | if isinstance(children, dict): |
| 83 | _walk(children) |
| 84 | |
| 85 | _walk(module_tree) |
| 86 | return ids |
| 87 | |
| 88 | |
| 89 | def _validate_module_tree( |
| 90 | module_tree: Dict[str, Any], |
| 91 | known_ids: set[str], |
| 92 | candidate_ids: set[str], |
| 93 | ) -> Tuple[List[str], List[str]]: |
| 94 | """Check the tree's component ids against the analysis index. |
| 95 | |
| 96 | Returns ``(unmatched_ids, leftover_ids)``: |
| 97 | * ``unmatched_ids``: ids referenced by the tree that do not exist in the |
| 98 | index (typos / drift) -- they will be silently omitted from docs. |
| 99 | * ``leftover_ids``: clustering candidate ids (leaf nodes) that are not |
| 100 | assigned to any module -- a coverage gap for the current clustering. |
| 101 | Non-candidate components (excluded / non-essential) are intentionally |
| 102 | not reported as leftover. |
| 103 | """ |
| 104 | assigned = _collect_component_ids(module_tree) |
| 105 | unmatched = sorted(assigned - known_ids) |
| 106 | leftover = sorted(candidate_ids - assigned) |
| 107 | return unmatched, leftover |
| 108 | |
| 109 |
nothing calls this directly
no test coverage detected