|
7 | 7 |
|
8 | 8 | import asyncio |
9 | 9 | import logging |
10 | | -import signal |
11 | 10 | import sys |
12 | 11 | from pathlib import Path |
13 | | -from typing import Dict, List, Optional, Set |
14 | | -import json |
| 12 | +from typing import Any, Dict, List, Optional, Set |
15 | 13 | import time |
16 | 14 |
|
17 | 15 | from ..database.database import DatabaseManager |
18 | 16 | from ..database.models import Project |
19 | 17 | from .config import VectorConfig, load_vector_config |
20 | 18 | from .monitoring.file_watcher import create_file_watcher, FileWatcher |
21 | | -from .monitoring.utils import _write_debug_log |
| 19 | + |
22 | 20 | from .monitoring.change_detector import FileChange, ChangeType |
23 | 21 | from .chunking.ast_chunker import ASTChunker |
| 22 | +from .types import ( |
| 23 | + ScanProjectTask, |
| 24 | + VectorDaemonTaskType, |
| 25 | + ProcessFileChangeTask, |
| 26 | +) |
24 | 27 |
|
25 | 28 | logger = logging.getLogger(__name__) |
26 | 29 |
|
@@ -75,8 +78,8 @@ def callback(change: FileChange) -> None: |
75 | 78 | """Non-blocking callback that queues file change processing.""" |
76 | 79 | try: |
77 | 80 | # Create file change processing task |
78 | | - task_item = { |
79 | | - "type": "process_file_change", |
| 81 | + task_item: ProcessFileChangeTask = { |
| 82 | + "type": VectorDaemonTaskType.PROCESS_FILE_CHANGE, |
80 | 83 | "project_name": project_name, |
81 | 84 | "change": change, |
82 | 85 | "timestamp": time.time(), |
@@ -223,8 +226,8 @@ async def _monitor_projects(self) -> None: |
223 | 226 |
|
224 | 227 | async def _queue_project_scan(self, project_name: str, folder_path: str) -> None: |
225 | 228 | """Queue a project for scanning and indexing.""" |
226 | | - task = { |
227 | | - "type": "scan_project", |
| 229 | + task: ScanProjectTask = { |
| 230 | + "type": VectorDaemonTaskType.SCAN_PROJECT, |
228 | 231 | "project_name": project_name, |
229 | 232 | "folder_path": folder_path, |
230 | 233 | "timestamp": time.time(), |
@@ -268,20 +271,19 @@ async def _process_task(self, task: dict, worker_id: str) -> None: |
268 | 271 | """Process a queued task.""" |
269 | 272 | task_type = task.get("type") |
270 | 273 |
|
271 | | - if task_type == "scan_project": |
| 274 | + if task_type == VectorDaemonTaskType.SCAN_PROJECT: |
272 | 275 | await self._process_project_scan(task, worker_id) |
273 | | - elif task_type == "process_file_change": |
| 276 | + elif task_type == VectorDaemonTaskType.PROCESS_FILE_CHANGE: |
274 | 277 | await self._process_file_change_task(task, worker_id) |
275 | 278 | else: |
276 | 279 | logger.warning(f"Unknown task type: {task_type}") |
277 | 280 |
|
278 | | - async def _process_file_change_task(self, task: dict, worker_id: str) -> None: |
| 281 | + async def _process_file_change_task( |
| 282 | + self, task: ProcessFileChangeTask, worker_id: str |
| 283 | + ) -> None: |
279 | 284 | """Process a file change task.""" |
280 | 285 | project_name: str = task["project_name"] |
281 | 286 | change: FileChange = task["change"] |
282 | | - _write_debug_log( |
283 | | - f"Worker {worker_id}: Processing file change for {change.path}" |
284 | | - ) |
285 | 287 | logger.info( |
286 | 288 | f"Worker {worker_id}: File change detected for project {project_name}: {change.path} ({change.change_type.value})", |
287 | 289 | extra={ |
@@ -347,22 +349,26 @@ async def _process_file_change_task(self, task: dict, worker_id: str) -> None: |
347 | 349 | }, |
348 | 350 | ) |
349 | 351 |
|
350 | | - # Write detailed debug information |
351 | | - _write_debug_log( |
352 | | - f"Worker {worker_id}: File {change.path} chunking details:\n" |
353 | | - f" Total chunks: {chunk_count}\n" |
354 | | - f" Chunk types: {chunk_types}\n" |
355 | | - f" Redacted chunks: {redacted_count}\n" |
356 | | - f" Sample chunks:\n" |
357 | | - + "\n".join( |
358 | | - [ |
359 | | - f" [{i}] {chunk.chunk_type.value} - {chunk.name or 'unnamed'} " |
360 | | - f"(lines {chunk.start_line}-{chunk.end_line}, " |
361 | | - f"{len(chunk.content)} chars, redacted: {chunk.redacted})" |
362 | | - for i, chunk in enumerate(chunks[:3]) # Show first 3 chunks |
363 | | - ] |
364 | | - ) |
| 352 | + # Log detailed debug information |
| 353 | + sample_chunks = [ |
| 354 | + f" [{i}] {chunk.chunk_type.value} - {chunk.name or 'unnamed'} " |
| 355 | + f"(lines {chunk.start_line}-{chunk.end_line}, " |
| 356 | + f"{len(chunk.content)} chars, redacted: {chunk.redacted})" |
| 357 | + for i, chunk in enumerate(chunks[:3]) # Show first 3 chunks |
| 358 | + ] |
| 359 | + logger.debug( |
| 360 | + f"Worker {worker_id}: File {change.path} chunking details: " |
| 361 | + f"Total chunks: {chunk_count}, " |
| 362 | + f"Chunk types: {chunk_types}, " |
| 363 | + f"Redacted chunks: {redacted_count}, " |
| 364 | + f"Sample chunks: {', '.join(sample_chunks)}" |
| 365 | + ) |
| 366 | + |
| 367 | + # Generate and store embeddings for chunks |
| 368 | + embeddings = await self._generate_embeddings( |
| 369 | + chunks, project_name, change.path |
365 | 370 | ) |
| 371 | + await self._store_embeddings(embeddings, project_name, change.path) |
366 | 372 |
|
367 | 373 | # Only increment stats for successfully chunked files |
368 | 374 | self.stats["files_processed"] += 1 |
@@ -421,29 +427,25 @@ async def _process_project_scan(self, task: dict, worker_id: str) -> None: |
421 | 427 | ignore_patterns=self.config.ignore_patterns, |
422 | 428 | debounce_interval=self.config.watch_debounce_ms / 1000.0, |
423 | 429 | ) |
424 | | - _write_debug_log( |
425 | | - f"VectorDaemon: Created watcher for {project_name}" |
426 | | - ) |
| 430 | + logger.debug(f"VectorDaemon: Created watcher for {project_name}") |
427 | 431 | # Initialize the watcher |
428 | 432 | await watcher.initialize() |
429 | | - _write_debug_log( |
| 433 | + logger.debug( |
430 | 434 | f"VectorDaemon: Initialized watcher for {project_name}" |
431 | 435 | ) |
432 | 436 | # Add change callback |
433 | 437 | watcher.add_change_callback(self._on_file_change(project_name)) |
434 | | - _write_debug_log( |
| 438 | + logger.debug( |
435 | 439 | f"VectorDaemon: Added change callback for {project_name}" |
436 | 440 | ) |
437 | 441 |
|
438 | 442 | # Start watching |
439 | 443 | watcher.start_watching() |
440 | | - _write_debug_log( |
441 | | - f"VectorDaemon: Started watching for {project_name}" |
442 | | - ) |
| 444 | + logger.debug(f"VectorDaemon: Started watching for {project_name}") |
443 | 445 |
|
444 | 446 | # Store watcher for later cleanup |
445 | 447 | self.file_watchers[project_name] = watcher |
446 | | - _write_debug_log(f"VectorDaemon: Stored watcher for {project_name}") |
| 448 | + logger.debug(f"VectorDaemon: Stored watcher for {project_name}") |
447 | 449 |
|
448 | 450 | logger.info( |
449 | 451 | f"File watcher started for project {project_name}", |
@@ -554,6 +556,20 @@ def get_status(self) -> dict: |
554 | 556 | "file_watcher_stats": watcher_stats, |
555 | 557 | } |
556 | 558 |
|
| 559 | + async def _generate_embeddings( |
| 560 | + self, chunks: list, project_name: str, file_path |
| 561 | + ) -> list[list[float]]: |
| 562 | + """Generate embeddings for file chunks.""" |
| 563 | + # TODO: implement |
| 564 | + return [] |
| 565 | + |
| 566 | + async def _store_embeddings( |
| 567 | + self, embeddings: list[list[float]], project_name: str, file_path |
| 568 | + ) -> None: |
| 569 | + """Store embeddings in vector database.""" |
| 570 | + # TODO: implement |
| 571 | + pass |
| 572 | + |
557 | 573 |
|
558 | 574 | async def start_vector_daemon( |
559 | 575 | config_path: Optional[Path] = None, |
|
0 commit comments