Migrate to ripgrep for glob_files
This commit is contained in:
14
nanocode.py
14
nanocode.py
@@ -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:
|
||||
"""Find files matching a glob pattern, sorted by modification time.
|
||||
|
||||
Respects .gitignore files automatically via ripgrep.
|
||||
|
||||
Args:
|
||||
pattern: Glob pattern to match (e.g., '**/*.py')
|
||||
path: Base directory to search in
|
||||
@@ -110,14 +112,20 @@ def glob_files(pattern: str, path: str = ".") -> str:
|
||||
"""
|
||||
print(f"{MAGENTA}⏺ Glob: {pattern}{RESET}")
|
||||
|
||||
full_pattern = (path + "/" + pattern).replace("//", "/")
|
||||
files = globlib.glob(full_pattern, recursive=True)
|
||||
cmd = ["rg", "--files", "-g", pattern, path]
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
||||
files = result.stdout.strip().split("\n") if result.stdout.strip() else []
|
||||
files = sorted(
|
||||
files,
|
||||
key=lambda f: os.path.getmtime(f) if os.path.isfile(f) else 0,
|
||||
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:
|
||||
@@ -382,7 +390,7 @@ if __name__ == "__main__":
|
||||
for branch in branches:
|
||||
agent.push_to_hub(
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user