Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ agent_file_system/TASK_HISTORY.md
!build_template.py
docs/LIVING_UI_DEVELOPER_GUIDE.md
agent_file_system/ACTIONS.md
agent_bundle/
agent_bundle/
**/.craftbot/
67 changes: 26 additions & 41 deletions app/data/action/find_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
from agent_core import action


def _find_files_impl(base_directory: str, file_pattern: str, recursive: bool) -> dict:
import glob
import os

from app.utils import file_index

if not recursive:
matches = []
for path in glob.glob(os.path.join(base_directory, file_pattern)):
if os.path.isfile(path):
matches.append(os.path.abspath(path))
else:
file_index.start_watcher(base_directory)
matches = file_index.search(base_directory, file_pattern)
Comment on lines +10 to +17

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be differing results depending on the value of recursive. For example, let's search for .test.txt. When recursive = False, the code uses Python's glob method to match filenames which ignores files that start with '.', so .test.txt will never match. On the other hand, if recursive = True, the code uses the fnmatch via SQLite index to match filenames, which will include .test.txt.

I think we should just stick with recursive = True. recursive = False just needs to look at one folder instead of multiple.


return {
"status": "success",
"matches": matches,
"message": ""
if matches
else f"No files matching '{file_pattern}' were found in '{base_directory}'.",
}


@action(
name="find_files",
description="Finds files by name or pattern across the system. Supports wildcards and recursive search. Use absolute paths for base_directory.",
Expand Down Expand Up @@ -45,7 +69,6 @@
)
def find_file_by_name(input_data: dict) -> dict:
import os
import fnmatch

pattern = (input_data.get("pattern") or "").strip()
recursive = bool(input_data.get("recursive", True))
Expand Down Expand Up @@ -85,26 +108,7 @@ def find_file_by_name(input_data: dict) -> dict:
else pattern
)

matches = []
for root, dirs, files in os.walk(base_directory):
try:
for name in files:
if fnmatch.fnmatch(name, file_pattern):
matches.append(os.path.abspath(os.path.join(root, name)))
except PermissionError:
# Skip directories we don't have access to
continue

if not recursive:
break

return {
"status": "success",
"matches": matches,
"message": ""
if matches
else f"No files matching '{file_pattern}' were found in '{base_directory}'.",
}
return _find_files_impl(base_directory, file_pattern, recursive)


@action(
Expand Down Expand Up @@ -151,7 +155,6 @@ def find_file_by_name(input_data: dict) -> dict:
)
def find_file_by_name_windows(input_data: dict) -> dict:
import os
import fnmatch

pattern = (input_data.get("pattern") or "").strip()
recursive = bool(input_data.get("recursive", True))
Expand Down Expand Up @@ -194,22 +197,4 @@ def find_file_by_name_windows(input_data: dict) -> dict:
else pattern
)

matches = []
for root, dirs, files in os.walk(base_directory):
try:
for name in files:
if fnmatch.fnmatch(name, file_pattern):
matches.append(os.path.abspath(os.path.join(root, name)))
except PermissionError:
continue

if not recursive:
break

return {
"status": "success",
"matches": matches,
"message": ""
if matches
else f"No files matching '{file_pattern}' were found in '{base_directory}'.",
}
return _find_files_impl(base_directory, file_pattern, recursive)
Loading