Migrate to ripgrep for glob_files

This commit is contained in:
2026-01-31 12:30:11 -08:00
parent 64e375e960
commit 35616d3e3e

View File

@@ -101,6 +101,8 @@ def edit_file(path: str, old: str, new: str, replace_all: bool = False) -> str:
def glob_files(pattern: str, path: str = ".") -> str: def glob_files(pattern: str, path: str = ".") -> str:
"""Find files matching a glob pattern, sorted by modification time. """Find files matching a glob pattern, sorted by modification time.
Respects .gitignore files automatically via ripgrep.
Args: Args:
pattern: Glob pattern to match (e.g., '**/*.py') pattern: Glob pattern to match (e.g., '**/*.py')
path: Base directory to search in path: Base directory to search in
@@ -110,14 +112,20 @@ def glob_files(pattern: str, path: str = ".") -> str:
""" """
print(f"{MAGENTA}⏺ Glob: {pattern}{RESET}") print(f"{MAGENTA}⏺ Glob: {pattern}{RESET}")
full_pattern = (path + "/" + pattern).replace("//", "/") cmd = ["rg", "--files", "-g", pattern, path]
files = globlib.glob(full_pattern, recursive=True) try:
files = sorted( result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
files, files = result.stdout.strip().split("\n") if result.stdout.strip() else []
key=lambda f: os.path.getmtime(f) if os.path.isfile(f) else 0, files = sorted(
reverse=True, files,
) key=lambda f: os.path.getmtime(f) if os.path.isfile(f) else 0,
return "\n".join(files) or "no files found" reverse=True,
)
return "\n".join(files) or "no files found"
except FileNotFoundError:
return "error: ripgrep (rg) not installed - install with 'brew install ripgrep'"
except subprocess.TimeoutExpired:
return "error: search timed out after 30s"
def grep_files(pattern: str, path: str = ".", glob: str = None, max_results: int = 50) -> str: def grep_files(pattern: str, path: str = ".", glob: str = None, max_results: int = 50) -> str:
@@ -382,7 +390,7 @@ if __name__ == "__main__":
for branch in branches: for branch in branches:
agent.push_to_hub( agent.push_to_hub(
MODAIC_REPO_PATH, MODAIC_REPO_PATH,
commit_message="Fix config override bug by recreating LMs after load_state", commit_message="Migrate to ripgrep for glob_files",
branch=branch, branch=branch,
) )