MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / index_directory

Function index_directory

tools/kb_scraper.py:120–166  ·  view source on GitHub ↗

Index all matching files in a directory recursively. Args: dirpath: Root directory to scan category: Category label for all files extensions: File extensions to include max_files: Safety cap (prevents runaway indexing of huge repos) Returns: Tot

(
    dirpath: str,
    category: str = "docs",
    extensions: tuple = DEFAULT_EXTENSIONS,
    max_files: int = 500,
)

Source from the content-addressed store, hash-verified

118
119
120def index_directory(
121 dirpath: str,
122 category: str = "docs",
123 extensions: tuple = DEFAULT_EXTENSIONS,
124 max_files: int = 500,
125) -> int:
126 """
127 Index all matching files in a directory recursively.
128
129 Args:
130 dirpath: Root directory to scan
131 category: Category label for all files
132 extensions: File extensions to include
133 max_files: Safety cap (prevents runaway indexing of huge repos)
134
135 Returns:
136 Total number of chunks indexed
137 """
138 root = Path(dirpath)
139 if not root.is_dir():
140 print(f"[kb_scraper] Not a directory: {dirpath}")
141 return 0
142
143 total_chunks = 0
144 files_indexed = 0
145
146 for path in sorted(root.rglob("*")):
147 if files_indexed >= max_files:
148 print(f"[kb_scraper] Reached max_files={max_files}, stopping.")
149 break
150 if not path.is_file():
151 continue
152 if path.suffix.lower() not in extensions:
153 continue
154 # Skip hidden dirs and common noise
155 parts = path.parts
156 if any(p.startswith(".") or p in ("__pycache__", "node_modules", ".git") for p in parts):
157 continue
158
159 chunks = index_file(str(path), category)
160 if chunks:
161 total_chunks += len(chunks)
162 files_indexed += 1
163 print(f" [kb_scraper] {path.name}: {len(chunks)} chunks")
164
165 print(f"[kb_scraper] Total: {total_chunks} chunks from {files_indexed} files in {dirpath}")
166 return total_chunks
167
168
169def list_indexed() -> list:

Callers

nothing calls this directly

Calls 3

index_fileFunction · 0.85
is_dirMethod · 0.80
is_fileMethod · 0.80

Tested by

no test coverage detected