Add list_files tool

This commit is contained in:
2026-01-31 12:36:10 -08:00
parent 35616d3e3e
commit fb5aa0070f
2 changed files with 24 additions and 2 deletions

View File

@@ -98,6 +98,27 @@ def edit_file(path: str, old: str, new: str, replace_all: bool = False) -> str:
return "ok"
def list_files(path: str = ".") -> str:
"""List all files in a directory, respecting .gitignore.
Args:
path: Directory to list files from
Returns:
Newline-separated list of files
"""
print(f"{MAGENTA}⏺ List: {path}{RESET}")
cmd = ["rg", "--files", path]
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
return result.stdout.strip() 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 glob_files(pattern: str, path: str = ".") -> str:
"""Find files matching a glob pattern, sorted by modification time.
@@ -235,6 +256,7 @@ class RLMCodingProgram(PrecompiledProgram):
"read_file": read_file,
"write_file": write_file,
"edit_file": edit_file,
"list_files": list_files,
"glob_files": glob_files,
"grep_files": grep_files,
"run_bash": run_bash,
@@ -390,7 +412,7 @@ if __name__ == "__main__":
for branch in branches:
agent.push_to_hub(
MODAIC_REPO_PATH,
commit_message="Migrate to ripgrep for glob_files",
commit_message="Add list_files tool",
branch=branch,
)