@@ -132,17 +132,36 @@ <h2 class="section-title" id="header-classes">Classes</h2>
132132 return modified_ignore_patterns
133133
134134 def get_include_paths(self):
135+ """
136+ Loads include paths from:
137+ 1. .praisoninclude (includes ONLY files/directories listed)
138+ 2. .praisoncontext (if .praisoninclude doesn't exist, this is used
139+ to include all other relevant files, excluding ignore patterns)
140+ """
135141 include_paths = []
136-
137- # 1. Load from .praisoninclude
138- include_file = os.path.join(self.directory, '.praisoninclude ')
142+ include_all = False # Flag to indicate if we need to include all files
143+
144+ include_file = os.path.join(self.directory, '.praisoncontext ')
139145 if os.path.exists(include_file):
140146 with open(include_file, 'r') as f:
141147 include_paths.extend(
142148 line.strip() for line in f
143149 if line.strip() and not line.startswith('#')
144150 )
145- return include_paths
151+
152+ # If .praisoncontext doesn't exist, fall back to .praisoninclude
153+ # for including all relevant files
154+ if not include_paths:
155+ include_file = os.path.join(self.directory, '.praisoninclude')
156+ if os.path.exists(include_file):
157+ with open(include_file, 'r') as f:
158+ include_paths.extend(
159+ line.strip() for line in f
160+ if line.strip() and not line.startswith('#')
161+ )
162+ include_all = True # Include all files along with specified paths
163+
164+ return include_paths, include_all
146165
147166 def should_ignore(self, file_path):
148167 """
@@ -165,61 +184,78 @@ <h2 class="section-title" id="header-classes">Classes</h2>
165184 any(file_path.endswith(ext) for ext in self.relevant_extensions)
166185
167186 def gather_context(self):
168- """Gather context from relevant files, respecting ignore patterns and include paths."""
187+ """
188+ Gather context from relevant files, respecting ignore patterns
189+ and include options from .praisoninclude and .praisoncontext.
190+ """
169191 context = []
170192 total_files = 0
171193 processed_files = 0
194+ self.include_paths, include_all = self.get_include_paths()
172195
173- if not self.include_paths:
174- # No include paths specified, process the entire directory
175- for root, dirs, files in os.walk(self.directory):
176- total_files += len(files)
177- dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
178- for file in files:
179- file_path = os.path.join(root, file)
180- if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
181- try:
182- with open(file_path, 'r', encoding='utf-8') as f:
183- content = f.read()
184- context.append(f"File: {file_path}\n\n{content}\n\n{'='*50}\n")
185- self.included_files.append(Path(file_path).relative_to(self.directory))
186- except Exception as e:
187- logger.error(f"Error reading {file_path}: {e}")
188- processed_files += 1
189- print(f"\rProcessed {processed_files}/{total_files} files", end="", flush=True)
190- else:
191- # Process specified include paths
196+ def add_file_content(file_path):
197+ """Helper function to add file content to context."""
198+ try:
199+ with open(file_path, 'r', encoding='utf-8') as f:
200+ content = f.read()
201+ context.append(
202+ f"File: {file_path}\n\n{content}\n\n{'=' * 50}\n"
203+ )
204+ self.included_files.append(
205+ Path(file_path).relative_to(self.directory)
206+ )
207+ except Exception as e:
208+ logger.error(f"Error reading {file_path}: {e}")
209+
210+ def process_path(path):
211+ """Helper function to process a single path (file or directory)."""
212+ nonlocal total_files, processed_files
213+ if os.path.isdir(path):
214+ for root, dirs, files in os.walk(path):
215+ total_files += len(files)
216+ dirs[:] = [
217+ d
218+ for d in dirs
219+ if not self.should_ignore(os.path.join(root, d))
220+ ]
221+ for file in files:
222+ file_path = os.path.join(root, file)
223+ if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
224+ add_file_content(file_path)
225+ processed_files += 1
226+ print(
227+ f"\rProcessed {processed_files}/{total_files} files",
228+ end="",
229+ flush=True,
230+ )
231+ elif os.path.isfile(path) and self.is_relevant_file(path):
232+ add_file_content(path)
233+ processed_files += 1
234+ print(
235+ f"\rProcessed {processed_files}/1 files",
236+ end="",
237+ flush=True,
238+ )
239+
240+ if include_all:
241+ # Include ALL relevant files from the entire directory
242+ process_path(self.directory)
243+
244+ # Include files from .praisoninclude specifically
192245 for include_path in self.include_paths:
193246 full_path = os.path.join(self.directory, include_path)
194- if os.path.isdir(full_path):
195- for root, dirs, files in os.walk(full_path):
196- total_files += len(files)
197- dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
198- for file in files:
199- file_path = os.path.join(root, file)
200- if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
201- try:
202- with open(file_path, 'r', encoding='utf-8') as f:
203- content = f.read()
204- context.append(f"File: {file_path}\n\n{content}\n\n{'='*50}\n")
205- self.included_files.append(Path(file_path).relative_to(self.directory))
206- except Exception as e:
207- logger.error(f"Error reading {file_path}: {e}")
208- processed_files += 1
209- print(f"\rProcessed {processed_files}/{total_files} files", end="", flush=True)
210- elif os.path.isfile(full_path) and self.is_relevant_file(full_path):
211- try:
212- with open(full_path, 'r', encoding='utf-8') as f:
213- content = f.read()
214- context.append(f"File: {full_path}\n\n{content}\n\n{'='*50}\n")
215- self.included_files.append(Path(full_path).relative_to(self.directory))
216- except Exception as e:
217- logger.error(f"Error reading {full_path}: {e}")
218- processed_files += 1
219- print(f"\rProcessed {processed_files}/{total_files} files", end="", flush=True)
247+ process_path(full_path)
248+ elif self.include_paths:
249+ # Include only files specified in .praisoncontext
250+ for include_path in self.include_paths:
251+ full_path = os.path.join(self.directory, include_path)
252+ process_path(full_path)
253+ else:
254+ # No include options, process the entire directory
255+ process_path(self.directory)
220256
221257 print() # New line after progress indicator
222- return ' ;\n' ;.join(context)
258+ return " ;\n" ;.join(context)
223259
224260 def count_tokens(self, text):
225261 """Count tokens using a simple whitespace-based tokenizer."""
@@ -282,7 +318,8 @@ <h3>Methods</h3>
282318< span > def < span class ="ident "> gather_context</ span > </ span > (< span > self)</ span >
283319</ code > </ dt >
284320< dd >
285- < div class ="desc "> < p > Gather context from relevant files, respecting ignore patterns and include paths.</ p > </ div >
321+ < div class ="desc "> < p > Gather context from relevant files, respecting ignore patterns
322+ and include options from .praisoninclude and .praisoncontext.</ p > </ div >
286323</ dd >
287324< dt id ="praisonai.ui.context.ContextGatherer.get_context_tree "> < code class ="name flex ">
288325< span > def < span class ="ident "> get_context_tree</ span > </ span > (< span > self)</ span >
@@ -306,7 +343,10 @@ <h3>Methods</h3>
306343< span > def < span class ="ident "> get_include_paths</ span > </ span > (< span > self)</ span >
307344</ code > </ dt >
308345< dd >
309- < div class ="desc "> </ div >
346+ < div class ="desc "> < p > Loads include paths from:
347+ 1. .praisoninclude (includes ONLY files/directories listed)
348+ 2. .praisoncontext (if .praisoninclude doesn't exist, this is used
349+ to include all other relevant files, excluding ignore patterns)</ p > </ div >
310350</ dd >
311351< dt id ="praisonai.ui.context.ContextGatherer.is_relevant_file "> < code class ="name flex ">
312352< span > def < span class ="ident "> is_relevant_file</ span > </ span > (< span > self, file_path)</ span >
0 commit comments