nnsohamnn commited on
Commit
159caaa
·
1 Parent(s): c7ae96b

fix: tool resolution for directories (list_files now shows folders/)

Browse files
Files changed (1) hide show
  1. tools.py +18 -10
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
- files = []
 
79
  for root, dirs, filenames in os.walk(abs_target):
80
- # Prune directories to skip hidden or junk ones
81
- dirs[:] = [d for d in dirs if not d.startswith('.') and d not in ('node_modules', '__pycache__', 'vendor', 'dist', 'build')]
 
 
 
82
 
83
- for f in filenames:
 
84
  rel_path = os.path.relpath(os.path.join(root, f), abs_repo)
85
- if smart_file_filter(rel_path):
86
- files.append(rel_path)
87
- # Only go one level deep to avoid recursion overwhelming the context
 
 
 
88
  break
89
 
90
- if not files:
91
- return f"No relevant files found in '{path}'."
92
 
93
  # Group result for LLM
94
- return f"Files in '{path}':\n" + "\n".join(files[:20]) # Limit to 20 for brief summary
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}"