auto-coder-web 0.1.69__py3-none-any.whl → 0.1.71__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,16 +2,64 @@ import os
2
2
  import shutil
3
3
  import aiofiles
4
4
  import aiofiles.os
5
- from fastapi import APIRouter, Request, HTTPException, Depends
5
+ import asyncio
6
+ from fastapi import APIRouter, Request, HTTPException, Depends, Query
6
7
  from auto_coder_web.file_manager import (
7
8
  get_directory_tree_async,
8
9
  read_file_content_async,
9
10
  )
10
11
  from pydantic import BaseModel
11
- from typing import List
12
+ from typing import List, Optional
13
+ import pathspec
12
14
 
13
15
  router = APIRouter()
14
16
 
17
+ DEFAULT_IGNORED_DIRS = ['.git', '.auto-coder', 'node_modules', '.mvn', '.idea', '__pycache__', '.venv', 'venv', 'dist', 'build', '.gradle']
18
+
19
+ def load_ignore_spec(source_dir: str) -> Optional[pathspec.PathSpec]:
20
+ """
21
+ Loads .autocoderignore file from the source_dir if it exists.
22
+ Returns a PathSpec object or None if no ignore file.
23
+ """
24
+ ignore_file_path = os.path.join(source_dir, ".autocoderignore")
25
+ if not os.path.isfile(ignore_file_path):
26
+ return None
27
+ try:
28
+ with open(ignore_file_path, "r") as f:
29
+ ignore_patterns = f.read().splitlines()
30
+ spec = pathspec.PathSpec.from_lines("gitwildmatch", ignore_patterns)
31
+ return spec
32
+ except Exception:
33
+ return None
34
+
35
+
36
+ def should_ignore(path: str, ignore_spec: Optional[pathspec.PathSpec], ignored_dirs: List[str], source_dir: str) -> bool:
37
+ """
38
+ Determine if a given path should be ignored based on ignore_spec and ignored_dirs.
39
+ - path: absolute path
40
+ - ignore_spec: PathSpec object or None
41
+ - ignored_dirs: list of directory names to ignore
42
+ - source_dir: root source directory absolute path
43
+ """
44
+ rel_path = os.path.relpath(path, source_dir)
45
+ parts = rel_path.split(os.sep)
46
+
47
+ # Always ignore if any part matches ignored_dirs
48
+ for part in parts:
49
+ if part in ignored_dirs:
50
+ return True
51
+
52
+ # If ignore_spec exists, use it to check
53
+ if ignore_spec:
54
+ # pathspec expects posix style paths
55
+ rel_path_posix = rel_path.replace(os.sep, "/")
56
+ # Check both file and dir ignoring
57
+ if ignore_spec.match_file(rel_path_posix):
58
+ return True
59
+
60
+ return False
61
+
62
+
15
63
  class FileInfo(BaseModel):
16
64
  name: str
17
65
  path: str
@@ -145,4 +193,42 @@ async def list_files_in_directory(
145
193
  except Exception:
146
194
  continue # ignore errors per file
147
195
 
148
- return result
196
+ return result
197
+
198
+
199
+ @router.get("/api/search-in-files")
200
+ async def search_in_files(
201
+ query: str = Query(..., description="Search text"),
202
+ project_path: str = Depends(get_project_path)
203
+ ):
204
+ """
205
+ Search for files under the project path containing the given query string.
206
+ Returns list of file paths.
207
+ """
208
+ matched_files = []
209
+ ignore_spec = load_ignore_spec(project_path)
210
+
211
+ for root, dirs, files in os.walk(project_path):
212
+ # Filter ignored directories in-place to avoid descending into them
213
+ dirs[:] = [d for d in dirs if not should_ignore(os.path.join(root, d), ignore_spec, DEFAULT_IGNORED_DIRS, project_path)]
214
+
215
+ for file in files:
216
+ file_path = os.path.join(root, file)
217
+ if should_ignore(file_path, ignore_spec, DEFAULT_IGNORED_DIRS, project_path):
218
+ continue
219
+ try:
220
+ async def read_and_check(fp):
221
+ try:
222
+ async with aiofiles.open(fp, mode='r', encoding='utf-8', errors='ignore') as f:
223
+ content = await f.read()
224
+ return query in content
225
+ except Exception:
226
+ return False
227
+
228
+ found = await read_and_check(file_path)
229
+ if found:
230
+ matched_files.append(os.path.relpath(file_path, project_path))
231
+ except Exception:
232
+ continue # ignore read errors
233
+
234
+ return {"files": matched_files}
auto_coder_web/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.69"
1
+ __version__ = "0.1.71"