# tools/git_tool.py from pathlib import Path def scan_repository_structure(repo_path: str, max_depth: int = 2) -> str: """ Recursively scan and summarize the directory structure of a repo up to a max depth. """ repo_path = Path(repo_path) if not repo_path.exists(): return f"āŒ Error: Path {repo_path} does not exist." def _walk(path: Path, depth: int = 0): if depth > max_depth: return [] lines = [] for child in sorted(path.iterdir()): prefix = " " * depth + ("ā”œā”€ā”€ " if child.is_file() else "šŸ“‚ ") lines.append(f"{prefix}{child.name}") if child.is_dir(): lines.extend(_walk(child, depth + 1)) return lines structure_lines = _walk(repo_path) return f"\nšŸ“ Repository Structure ({repo_path.name}):\n" + "\n".join(structure_lines) def read_code_file(file_path: str) -> str: try: with open(file_path, "r", encoding="utf-8") as f: return f.read() except Exception as e: return f"Error reading file: {e}" # Optional: for LangChain Tool usage from langchain.tools import Tool git_scan_tool = Tool( name="ScanGitRepoStructure", func=scan_repository_structure, description="Scans a local Git repository and returns a summarized directory tree. Provide the full path." )