11import os
22from fnmatch import fnmatch
3- from typing import Any , Dict , List , Optional , Set , Tuple
3+ from typing import Any
44
55import tiktoken
66
1010MAX_TOTAL_SIZE_BYTES = 500 * 1024 * 1024 # 500 MB
1111
1212
13- def should_include (path : str , base_path : str , include_patterns : List [str ]) -> bool :
13+ def should_include (path : str , base_path : str , include_patterns : list [str ]) -> bool :
1414 rel_path = path .replace (base_path , "" ).lstrip (os .sep )
1515 include = False
1616 for pattern in include_patterns :
@@ -19,7 +19,7 @@ def should_include(path: str, base_path: str, include_patterns: List[str]) -> bo
1919 return include
2020
2121
22- def should_exclude (path : str , base_path : str , ignore_patterns : List [str ]) -> bool :
22+ def should_exclude (path : str , base_path : str , ignore_patterns : list [str ]) -> bool :
2323 rel_path = path .replace (base_path , "" ).lstrip (os .sep )
2424 for pattern in ignore_patterns :
2525 if pattern == '' :
@@ -60,11 +60,11 @@ def read_file_content(file_path: str) -> str:
6060
6161def scan_directory (
6262 path : str ,
63- query : Dict [str , Any ],
64- seen_paths : Optional [ Set [ str ]] = None ,
63+ query : dict [str , Any ],
64+ seen_paths : set [ str ] | None = None ,
6565 depth : int = 0 ,
66- stats : Optional [ Dict [ str , int ]] = None ,
67- ) -> Optional [ Dict [ str , Any ]] :
66+ stats : dict [ str , int ] | None = None ,
67+ ) -> dict [ str , Any ] | None :
6868 """Recursively analyzes a directory and its contents with safety limits."""
6969 if seen_paths is None :
7070 seen_paths = set ()
@@ -220,11 +220,11 @@ def scan_directory(
220220
221221
222222def extract_files_content (
223- query : Dict [str , Any ],
224- node : Dict [str , Any ],
223+ query : dict [str , Any ],
224+ node : dict [str , Any ],
225225 max_file_size : int ,
226- files : Optional [ List [ Dict [ str , Any ]]] = None ,
227- ) -> List [ Dict [str , Any ]]:
226+ files : list [ dict [ str , Any ]] | None = None ,
227+ ) -> list [ dict [str , Any ]]:
228228 """Recursively collects all text files with their contents."""
229229 if files is None :
230230 files = []
@@ -248,7 +248,7 @@ def extract_files_content(
248248 return files
249249
250250
251- def create_file_content_string (files : List [ Dict [str , Any ]]) -> str :
251+ def create_file_content_string (files : list [ dict [str , Any ]]) -> str :
252252 """Creates a formatted string of file contents with separators."""
253253 output = ""
254254 separator = "=" * 48 + "\n "
@@ -278,7 +278,7 @@ def create_file_content_string(files: List[Dict[str, Any]]) -> str:
278278 return output
279279
280280
281- def create_summary_string (query : Dict [str , Any ], nodes : Dict [str , Any ]) -> str :
281+ def create_summary_string (query : dict [str , Any ], nodes : dict [str , Any ]) -> str :
282282 """Creates a summary string with file counts and content size."""
283283 if "user_name" in query :
284284 summary = f"Repository: { query ['user_name' ]} /{ query ['repo_name' ]} \n "
@@ -297,7 +297,7 @@ def create_summary_string(query: Dict[str, Any], nodes: Dict[str, Any]) -> str:
297297 return summary
298298
299299
300- def create_tree_structure (query : Dict [str , Any ], node : Dict [str , Any ], prefix : str = "" , is_last : bool = True ) -> str :
300+ def create_tree_structure (query : dict [str , Any ], node : dict [str , Any ], prefix : str = "" , is_last : bool = True ) -> str :
301301 """Creates a tree-like string representation of the file structure."""
302302 tree = ""
303303
@@ -319,7 +319,7 @@ def create_tree_structure(query: Dict[str, Any], node: Dict[str, Any], prefix: s
319319 return tree
320320
321321
322- def generate_token_string (context_string : str ) -> Optional [ str ] :
322+ def generate_token_string (context_string : str ) -> str | None :
323323 """Returns the number of tokens in a text string."""
324324 formatted_tokens = ""
325325 try :
@@ -340,7 +340,7 @@ def generate_token_string(context_string: str) -> Optional[str]:
340340 return formatted_tokens
341341
342342
343- def ingest_single_file (path : str , query : Dict [str , Any ]) -> Tuple [str , str , str ]:
343+ def ingest_single_file (path : str , query : dict [str , Any ]) -> tuple [str , str , str ]:
344344 if not os .path .isfile (path ):
345345 raise ValueError (f"Path { path } is not a file" )
346346
@@ -376,7 +376,7 @@ def ingest_single_file(path: str, query: Dict[str, Any]) -> Tuple[str, str, str]
376376 return summary , tree , files_content
377377
378378
379- def ingest_directory (path : str , query : Dict [str , Any ]) -> Tuple [str , str , str ]:
379+ def ingest_directory (path : str , query : dict [str , Any ]) -> tuple [str , str , str ]:
380380 nodes = scan_directory (path = path , query = query )
381381 if not nodes :
382382 raise ValueError (f"No files found in { path } " )
@@ -392,7 +392,7 @@ def ingest_directory(path: str, query: Dict[str, Any]) -> Tuple[str, str, str]:
392392 return summary , tree , files_content
393393
394394
395- def ingest_from_query (query : Dict [str , Any ]) -> Tuple [str , str , str ]:
395+ def ingest_from_query (query : dict [str , Any ]) -> tuple [str , str , str ]:
396396 """Main entry point for analyzing a codebase directory or single file."""
397397 path = f"{ query ['local_path' ]} { query ['subpath' ]} "
398398 if not os .path .exists (path ):
0 commit comments