import os import sys def generate_graph_index(root_path=".hmcmkit"): index_content = ["# HMCMkit Knowledge Graph Index", "", "> Automatically generated index of all knowledge assets.", ""] # Simple tree walk for root, dirs, files in os.walk(root_path): # Filter hidden dirs[:] = [d for d in dirs if not d.startswith('.')] files = [f for f in files if not f.startswith('.')] rel_path = os.path.relpath(root, root_path) if rel_path == ".": level = 0 rel_path = "" else: level = rel_path.count(os.sep) + 1 indent = " " * level folder_name = os.path.basename(root) if folder_name != ".hmcmkit" and rel_path != "": index_content.append(f"{indent}- 📂 **{folder_name}/**") sub_indent = " " * (level + 1) for f in files: if f.endswith(".md") or f.endswith(".json") or f.endswith(".py"): link_path = os.path.join(root, f).replace("\\", "/") # POSIX style for links # Make link relative to where _GRAPH-INDEX.md will be (in system/) # Actually, let's just use the path from project root for clarity in Antigravity context index_content.append(f"{sub_indent}- [{f}]({link_path})") output_path = os.path.join(root_path, "system", "_GRAPH-INDEX.md") os.makedirs(os.path.dirname(output_path), exist_ok=True) with open(output_path, 'w', encoding='utf-8') as f: f.write("\n".join(index_content)) print(f"✅ Generated Graph Index at: {output_path}") if __name__ == "__main__": target = sys.argv[1] if len(sys.argv) > 1 else ".hmcmkit" generate_graph_index(target)