Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions codebase_rag/deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any

from rich.console import Console

from .services import QueryProtocol


@dataclass
class RAGDeps:
project_root: Path
ingestor: QueryProtocol
cypher_generator: Any
code_retriever: Any
file_reader: Any
file_writer: Any
file_editor: Any
shell_commander: Any
directory_lister: Any
document_analyzer: Any
Comment on lines +14 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The RAGDeps dataclass uses Any for most of its fields. This undermines the goal of "Explicit, type-safe dependency injection" mentioned in the PR description. To improve type safety and developer experience, you should use specific class types for these dependencies.

To avoid circular imports that this might cause, you can use a typing.TYPE_CHECKING block and string forward references.

First, add these imports at the top of the file:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .services.llm import CypherGenerator
    from .tools.code_retrieval import CodeRetriever
    from .tools.directory_lister import DirectoryLister
    from .tools.document_analyzer import DocumentAnalyzer
    from .tools.file_editor import FileEditor
    from .tools.file_reader import FileReader
    from .tools.file_writer import FileWriter
    from .tools.shell_command import ShellCommander

Then, update the dataclass fields:

Suggested change
cypher_generator: Any
code_retriever: Any
file_reader: Any
file_writer: Any
file_editor: Any
shell_commander: Any
directory_lister: Any
document_analyzer: Any
cypher_generator: "CypherGenerator"
code_retriever: "CodeRetriever"
file_reader: "FileReader"
file_writer: "FileWriter"
file_editor: "FileEditor"
shell_commander: "ShellCommander"
directory_lister: "DirectoryLister"
document_analyzer: "DocumentAnalyzer"

console: Console
2 changes: 2 additions & 0 deletions codebase_rag/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class LLMGenerationError(Exception):
pass
Loading