Spaces:
Sleeping
Sleeping
fix: tool resolution for directories (list_files now shows folders/)
Browse files
tools.py
CHANGED
|
@@ -75,22 +75,30 @@ def list_files(repo_path, path="."):
|
|
| 75 |
return f"Error: '{path}' is not a directory."
|
| 76 |
|
| 77 |
try:
|
| 78 |
-
|
|
|
|
| 79 |
for root, dirs, filenames in os.walk(abs_target):
|
| 80 |
-
#
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
|
|
|
|
| 84 |
rel_path = os.path.relpath(os.path.join(root, f), abs_repo)
|
| 85 |
-
if
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
break
|
| 89 |
|
| 90 |
-
if not
|
| 91 |
-
return f"No relevant files found in '{path}'."
|
| 92 |
|
| 93 |
# Group result for LLM
|
| 94 |
-
return f"
|
| 95 |
except Exception as e:
|
| 96 |
return f"Error listing files in '{path}': {e}"
|
|
|
|
| 75 |
return f"Error: '{path}' is not a directory."
|
| 76 |
|
| 77 |
try:
|
| 78 |
+
items = []
|
| 79 |
+
# Get immediate children (files and dirs)
|
| 80 |
for root, dirs, filenames in os.walk(abs_target):
|
| 81 |
+
# Show directories with a trailing slash
|
| 82 |
+
# Filter out hidden/junk dirs
|
| 83 |
+
visible_dirs = [d for d in dirs if not d.startswith('.') and d not in ('node_modules', '__pycache__', 'vendor', 'dist', 'build', '.git')]
|
| 84 |
+
for d in sorted(visible_dirs):
|
| 85 |
+
items.append(f"{d}/")
|
| 86 |
|
| 87 |
+
# Show files
|
| 88 |
+
for f in sorted(filenames):
|
| 89 |
rel_path = os.path.relpath(os.path.join(root, f), abs_repo)
|
| 90 |
+
# Show filename only if inside the target dir
|
| 91 |
+
if os.path.dirname(os.path.join(root, f)) == abs_target:
|
| 92 |
+
if smart_file_filter(f): # Filter only the filename for listing
|
| 93 |
+
items.append(f)
|
| 94 |
+
|
| 95 |
+
# Only show top level of the requested path
|
| 96 |
break
|
| 97 |
|
| 98 |
+
if not items:
|
| 99 |
+
return f"No relevant files or directories found in '{path}'."
|
| 100 |
|
| 101 |
# Group result for LLM
|
| 102 |
+
return f"Contents of '{path}':\n" + "\n".join(items[:30]) # Limit for brief summary
|
| 103 |
except Exception as e:
|
| 104 |
return f"Error listing files in '{path}': {e}"
|