-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add multiple processing modes for diffgraph generation #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
avikalpg
wants to merge
1
commit into
main
Choose a base branch
from
feature/multiple-processing-modes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
| DiffGraph - A CLI tool for visualizing code changes with AI | ||
| """ | ||
|
|
||
| __version__ = "0.1.0" | ||
| __version__ = "1.1.0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """ | ||
| Processing modes module for different diffgraph generation strategies. | ||
|
|
||
| This module provides a registry of available processing modes and factory | ||
| functions to create processor instances. | ||
| """ | ||
|
|
||
| from typing import Dict, Type, Optional | ||
| from .base import BaseProcessor, DiffAnalysis | ||
|
|
||
| # Registry of available processing modes | ||
| _PROCESSOR_REGISTRY: Dict[str, Type[BaseProcessor]] = {} | ||
|
|
||
|
|
||
| def register_processor(mode_name: str): | ||
| """ | ||
| Decorator to register a processor class. | ||
|
|
||
| Args: | ||
| mode_name: The name identifier for this processing mode | ||
|
|
||
| Example: | ||
| @register_processor("openai-agents-dependency-graph") | ||
| class OpenAIAgentsProcessor(BaseProcessor): | ||
| ... | ||
| """ | ||
| def decorator(cls: Type[BaseProcessor]): | ||
| _PROCESSOR_REGISTRY[mode_name] = cls | ||
| return cls | ||
| return decorator | ||
|
|
||
|
|
||
| def get_processor(mode_name: str, **kwargs) -> BaseProcessor: | ||
| """ | ||
| Factory function to create a processor instance. | ||
|
|
||
| Args: | ||
| mode_name: The name of the processing mode | ||
| **kwargs: Configuration parameters for the processor | ||
|
|
||
| Returns: | ||
| An instance of the requested processor | ||
|
|
||
| Raises: | ||
| ValueError: If the mode_name is not registered | ||
| """ | ||
| if mode_name not in _PROCESSOR_REGISTRY: | ||
| available_modes = ", ".join(_PROCESSOR_REGISTRY.keys()) | ||
| raise ValueError( | ||
| f"Unknown processing mode: '{mode_name}'. " | ||
| f"Available modes: {available_modes}" | ||
| ) | ||
|
|
||
| processor_class = _PROCESSOR_REGISTRY[mode_name] | ||
| return processor_class(**kwargs) | ||
|
|
||
|
|
||
| def list_available_modes() -> Dict[str, str]: | ||
| """ | ||
| Get a dictionary of available processing modes and their descriptions. | ||
|
|
||
| Returns: | ||
| Dictionary mapping mode names to descriptions | ||
| """ | ||
| modes = {} | ||
| for mode_name, processor_class in _PROCESSOR_REGISTRY.items(): | ||
| # Get description by creating a minimal instance | ||
| try: | ||
| # Try to create instance without required parameters to get description | ||
| # Most processors should allow getting description without full initialization | ||
| temp_instance = processor_class.__new__(processor_class) | ||
| if hasattr(temp_instance, 'description'): | ||
| desc = temp_instance.description | ||
| if isinstance(desc, property): | ||
| # For property descriptors, we need to access via class | ||
| description = processor_class.description.fget(temp_instance) | ||
| else: | ||
| description = desc | ||
| else: | ||
| description = "No description available" | ||
| except Exception as e: | ||
| # Fallback: try to get from docstring or use default | ||
| description = processor_class.__doc__.split('\n')[0] if processor_class.__doc__ else "No description available" | ||
| modes[mode_name] = description | ||
| return modes | ||
|
|
||
|
|
||
| # Import processors to trigger registration | ||
| # This will be populated as we add more processors | ||
| from . import openai_agents_dependency # noqa: F401, E402 | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "BaseProcessor", | ||
| "DiffAnalysis", | ||
| "register_processor", | ||
| "get_processor", | ||
| "list_available_modes", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """ | ||
| Base processor interface for different diffgraph generation modes. | ||
|
|
||
| This module defines the abstract base class that all processing modes must implement. | ||
| """ | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import List, Dict, Optional, Callable | ||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class DiffAnalysis(BaseModel): | ||
| """Model representing the analysis of code changes.""" | ||
| summary: str | ||
| mermaid_diagram: str | ||
|
|
||
|
|
||
| class BaseProcessor(ABC): | ||
| """ | ||
| Abstract base class for diffgraph processors. | ||
|
|
||
| Each processing mode (e.g., OpenAI Agents, Tree-sitter, etc.) should inherit | ||
| from this class and implement the analyze_changes method. | ||
| """ | ||
|
|
||
| def __init__(self, **kwargs): | ||
| """ | ||
| Initialize the processor with configuration options. | ||
|
|
||
| Args: | ||
| **kwargs: Configuration parameters specific to the processor | ||
| """ | ||
| self.config = kwargs | ||
|
|
||
| @abstractmethod | ||
| def analyze_changes( | ||
| self, | ||
| files_with_content: List[Dict[str, str]], | ||
| progress_callback: Optional[Callable] = None | ||
| ) -> DiffAnalysis: | ||
| """ | ||
| Analyze code changes and generate a diffgraph. | ||
|
|
||
| Args: | ||
| files_with_content: List of dictionaries containing: | ||
| - path: File path | ||
| - status: Change status (modified, untracked, etc.) | ||
| - content: File content or diff | ||
| progress_callback: Optional callback function to report progress. | ||
| Should accept (current_file, total_files, status) | ||
|
|
||
| Returns: | ||
| DiffAnalysis object containing summary and mermaid diagram | ||
| """ | ||
| pass | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def name(self) -> str: | ||
| """Return the name/identifier of this processing mode.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def description(self) -> str: | ||
| """Return a human-readable description of this processing mode.""" | ||
| pass | ||
|
|
||
| @classmethod | ||
| def get_required_config(cls) -> List[str]: | ||
| """ | ||
| Return list of required configuration parameters for this processor. | ||
|
|
||
| Returns: | ||
| List of configuration parameter names | ||
| """ | ||
| return [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Replace unused exception variable.
The caught exception is never used. Replace
ewith_to indicate it's intentionally ignored.Apply this diff:
🧰 Tools
🪛 Ruff (0.14.2)
81-81: Do not catch blind exception:
Exception(BLE001)
81-81: Local variable
eis assigned to but never usedRemove assignment to unused variable
e(F841)
🤖 Prompt for AI Agents