naive-knowledge-base 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- naive_knowledge_base-0.1.0/LICENSE +21 -0
- naive_knowledge_base-0.1.0/MANIFEST.in +9 -0
- naive_knowledge_base-0.1.0/PKG-INFO +215 -0
- naive_knowledge_base-0.1.0/README.md +184 -0
- naive_knowledge_base-0.1.0/agents/__init__.py +7 -0
- naive_knowledge_base-0.1.0/agents/common/__init__.py +28 -0
- naive_knowledge_base-0.1.0/agents/common/base.py +187 -0
- naive_knowledge_base-0.1.0/agents/common/exceptions.py +62 -0
- naive_knowledge_base-0.1.0/agents/common/logging.py +60 -0
- naive_knowledge_base-0.1.0/agents/common/schema_converter.py +112 -0
- naive_knowledge_base-0.1.0/agents/common/tools.py +195 -0
- naive_knowledge_base-0.1.0/agents/common/utils.py +161 -0
- naive_knowledge_base-0.1.0/agents/dependency_graph/__init__.py +7 -0
- naive_knowledge_base-0.1.0/agents/dependency_graph/agent.py +205 -0
- naive_knowledge_base-0.1.0/agents/dependency_graph/model.py +38 -0
- naive_knowledge_base-0.1.0/api_models/__init__.py +3 -0
- naive_knowledge_base-0.1.0/api_models/flow_api_model.py +390 -0
- naive_knowledge_base-0.1.0/cli.py +203 -0
- naive_knowledge_base-0.1.0/main.py +68 -0
- naive_knowledge_base-0.1.0/naive_knowledge_base.egg-info/PKG-INFO +215 -0
- naive_knowledge_base-0.1.0/naive_knowledge_base.egg-info/SOURCES.txt +30 -0
- naive_knowledge_base-0.1.0/naive_knowledge_base.egg-info/dependency_links.txt +1 -0
- naive_knowledge_base-0.1.0/naive_knowledge_base.egg-info/entry_points.txt +2 -0
- naive_knowledge_base-0.1.0/naive_knowledge_base.egg-info/not-zip-safe +1 -0
- naive_knowledge_base-0.1.0/naive_knowledge_base.egg-info/top_level.txt +5 -0
- naive_knowledge_base-0.1.0/pyproject.toml +57 -0
- naive_knowledge_base-0.1.0/requirements.txt +106 -0
- naive_knowledge_base-0.1.0/setup.cfg +4 -0
- naive_knowledge_base-0.1.0/setup.py +81 -0
- naive_knowledge_base-0.1.0/tools/__init__.py +11 -0
- naive_knowledge_base-0.1.0/tools/io.py +59 -0
- naive_knowledge_base-0.1.0/tools/tree.py +42 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include requirements.txt
|
|
4
|
+
include pyproject.toml
|
|
5
|
+
recursive-include naive_knowledge_base *.py
|
|
6
|
+
recursive-include naive_knowledge_base py.typed
|
|
7
|
+
recursive-exclude * __pycache__
|
|
8
|
+
recursive-exclude * *.py[co]
|
|
9
|
+
recursive-exclude * .DS_Store
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: naive-knowledge-base
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A dependency graph analyzer using smolagents
|
|
5
|
+
Home-page: https://github.com/yourusername/naive-knowledge-base
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: Your Name <your.email@example.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/yourusername/naive-knowledge-base
|
|
10
|
+
Project-URL: Documentation, https://github.com/yourusername/naive-knowledge-base#readme
|
|
11
|
+
Project-URL: Repository, https://github.com/yourusername/naive-knowledge-base
|
|
12
|
+
Project-URL: Issues, https://github.com/yourusername/naive-knowledge-base/issues
|
|
13
|
+
Keywords: dependency-graph,code-analysis,smolagents,ai-agents
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
|
|
32
|
+
# Naive Knowledge Base
|
|
33
|
+
|
|
34
|
+
A dependency graph analyzer using smolagents for building and analyzing code dependencies.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- 🔍 **Dependency Graph Generation**: Automatically generate dependency graphs from source code
|
|
39
|
+
- 🤖 **AI-Powered Analysis**: Uses smolagents for intelligent code analysis
|
|
40
|
+
- 📊 **Multiple Language Support**: Support for Java and other languages
|
|
41
|
+
- 🌳 **Directory Tree Visualization**: Generate visual representations of project structure
|
|
42
|
+
- 📝 **File Operations**: Read, write, and manage files programmatically
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
### From Source
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/yourusername/naive-knowledge-base.git
|
|
50
|
+
cd naive-knowledge-base
|
|
51
|
+
pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### From PyPI (when published)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install naive-knowledge-base
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Requirements
|
|
61
|
+
|
|
62
|
+
- Python 3.8+
|
|
63
|
+
- OpenAI API key (or compatible API)
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
Create a `.env` file in your project directory with the following:
|
|
68
|
+
|
|
69
|
+
```env
|
|
70
|
+
OPENAI_API_KEY=your_api_key_here
|
|
71
|
+
# Or configure your API endpoint
|
|
72
|
+
API_BASE_URL=your_api_base_url
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
### Command Line Interface
|
|
78
|
+
|
|
79
|
+
After installation, you can use the `naive-kb` command:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Basic usage
|
|
83
|
+
naive-kb /path/to/source/directory
|
|
84
|
+
|
|
85
|
+
# Specify file extensions
|
|
86
|
+
naive-kb /path/to/source/directory java
|
|
87
|
+
|
|
88
|
+
# Specify directories to ignore
|
|
89
|
+
naive-kb /path/to/source/directory java "target,.git,test,node_modules"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Python API
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from naive_knowledge_base import run_analysis
|
|
96
|
+
|
|
97
|
+
# Run dependency graph analysis
|
|
98
|
+
result = run_analysis(
|
|
99
|
+
source_directory="/path/to/source",
|
|
100
|
+
file_extensions="java",
|
|
101
|
+
ignore_dirs="target,.git,test"
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Advanced Usage
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from smolagents import CodeAgent, ToolCallingAgent
|
|
109
|
+
from naive_knowledge_base.api_models import FlowApiModel
|
|
110
|
+
from naive_knowledge_base.tools import (
|
|
111
|
+
save_content_to_file,
|
|
112
|
+
read_file_content,
|
|
113
|
+
delete_folder_or_file,
|
|
114
|
+
generate_folder_tree
|
|
115
|
+
)
|
|
116
|
+
from naive_knowledge_base.agents.dependency_graph import generate_dependency_graph
|
|
117
|
+
|
|
118
|
+
# Create custom agents
|
|
119
|
+
model = FlowApiModel(model_id="gpt-4.1", temperature=0.5)
|
|
120
|
+
|
|
121
|
+
dependency_agent = ToolCallingAgent(
|
|
122
|
+
tools=[generate_dependency_graph],
|
|
123
|
+
model=model,
|
|
124
|
+
max_steps=7,
|
|
125
|
+
name="dependency_graph_agent"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
manager_agent = CodeAgent(
|
|
129
|
+
managed_agents=[dependency_agent],
|
|
130
|
+
model=model,
|
|
131
|
+
tools=[read_file_content, save_content_to_file],
|
|
132
|
+
max_steps=30,
|
|
133
|
+
name="tech_lead_agent"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Run analysis
|
|
137
|
+
result = manager_agent.run("Analyze dependencies in /path/to/source")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Package Structure
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
naive_knowledge_base/
|
|
144
|
+
├── agents/
|
|
145
|
+
│ ├── common/ # Common agent utilities
|
|
146
|
+
│ │ ├── base.py
|
|
147
|
+
│ │ ├── exceptions.py
|
|
148
|
+
│ │ ├── logging.py
|
|
149
|
+
│ │ └── utils.py
|
|
150
|
+
│ └── dependency_graph/ # Dependency graph analysis
|
|
151
|
+
│ ├── agent.py
|
|
152
|
+
│ └── model.py
|
|
153
|
+
├── api_models/ # API model integrations
|
|
154
|
+
│ └── flow_api_model.py
|
|
155
|
+
└── tools/ # Agent tools
|
|
156
|
+
├── io.py # File I/O operations
|
|
157
|
+
└── tree.py # Directory tree generation
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
### Setup Development Environment
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# Clone the repository
|
|
166
|
+
git clone https://github.com/yourusername/naive-knowledge-base.git
|
|
167
|
+
cd naive-knowledge-base
|
|
168
|
+
|
|
169
|
+
# Create virtual environment
|
|
170
|
+
python -m venv venv
|
|
171
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
172
|
+
|
|
173
|
+
# Install in editable mode with dev dependencies
|
|
174
|
+
pip install -e ".[dev]"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Running Tests
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pytest tests/
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Code Formatting
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Format code
|
|
187
|
+
black .
|
|
188
|
+
isort .
|
|
189
|
+
|
|
190
|
+
# Check code quality
|
|
191
|
+
pylint naive_knowledge_base/
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Contributing
|
|
195
|
+
|
|
196
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
197
|
+
|
|
198
|
+
1. Fork the repository
|
|
199
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
200
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
201
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
202
|
+
5. Open a Pull Request
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
207
|
+
|
|
208
|
+
## Acknowledgments
|
|
209
|
+
|
|
210
|
+
- Built with [smolagents](https://github.com/huggingface/smolagents)
|
|
211
|
+
- Uses OpenAI API for AI-powered analysis
|
|
212
|
+
|
|
213
|
+
## Support
|
|
214
|
+
|
|
215
|
+
For issues and questions, please file an issue on the [GitHub repository](https://github.com/yourusername/naive-knowledge-base/issues).
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Naive Knowledge Base
|
|
2
|
+
|
|
3
|
+
A dependency graph analyzer using smolagents for building and analyzing code dependencies.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔍 **Dependency Graph Generation**: Automatically generate dependency graphs from source code
|
|
8
|
+
- 🤖 **AI-Powered Analysis**: Uses smolagents for intelligent code analysis
|
|
9
|
+
- 📊 **Multiple Language Support**: Support for Java and other languages
|
|
10
|
+
- 🌳 **Directory Tree Visualization**: Generate visual representations of project structure
|
|
11
|
+
- 📝 **File Operations**: Read, write, and manage files programmatically
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### From Source
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/yourusername/naive-knowledge-base.git
|
|
19
|
+
cd naive-knowledge-base
|
|
20
|
+
pip install -e .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### From PyPI (when published)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install naive-knowledge-base
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- Python 3.8+
|
|
32
|
+
- OpenAI API key (or compatible API)
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
Create a `.env` file in your project directory with the following:
|
|
37
|
+
|
|
38
|
+
```env
|
|
39
|
+
OPENAI_API_KEY=your_api_key_here
|
|
40
|
+
# Or configure your API endpoint
|
|
41
|
+
API_BASE_URL=your_api_base_url
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Command Line Interface
|
|
47
|
+
|
|
48
|
+
After installation, you can use the `naive-kb` command:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Basic usage
|
|
52
|
+
naive-kb /path/to/source/directory
|
|
53
|
+
|
|
54
|
+
# Specify file extensions
|
|
55
|
+
naive-kb /path/to/source/directory java
|
|
56
|
+
|
|
57
|
+
# Specify directories to ignore
|
|
58
|
+
naive-kb /path/to/source/directory java "target,.git,test,node_modules"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Python API
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from naive_knowledge_base import run_analysis
|
|
65
|
+
|
|
66
|
+
# Run dependency graph analysis
|
|
67
|
+
result = run_analysis(
|
|
68
|
+
source_directory="/path/to/source",
|
|
69
|
+
file_extensions="java",
|
|
70
|
+
ignore_dirs="target,.git,test"
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Advanced Usage
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from smolagents import CodeAgent, ToolCallingAgent
|
|
78
|
+
from naive_knowledge_base.api_models import FlowApiModel
|
|
79
|
+
from naive_knowledge_base.tools import (
|
|
80
|
+
save_content_to_file,
|
|
81
|
+
read_file_content,
|
|
82
|
+
delete_folder_or_file,
|
|
83
|
+
generate_folder_tree
|
|
84
|
+
)
|
|
85
|
+
from naive_knowledge_base.agents.dependency_graph import generate_dependency_graph
|
|
86
|
+
|
|
87
|
+
# Create custom agents
|
|
88
|
+
model = FlowApiModel(model_id="gpt-4.1", temperature=0.5)
|
|
89
|
+
|
|
90
|
+
dependency_agent = ToolCallingAgent(
|
|
91
|
+
tools=[generate_dependency_graph],
|
|
92
|
+
model=model,
|
|
93
|
+
max_steps=7,
|
|
94
|
+
name="dependency_graph_agent"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
manager_agent = CodeAgent(
|
|
98
|
+
managed_agents=[dependency_agent],
|
|
99
|
+
model=model,
|
|
100
|
+
tools=[read_file_content, save_content_to_file],
|
|
101
|
+
max_steps=30,
|
|
102
|
+
name="tech_lead_agent"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Run analysis
|
|
106
|
+
result = manager_agent.run("Analyze dependencies in /path/to/source")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Package Structure
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
naive_knowledge_base/
|
|
113
|
+
├── agents/
|
|
114
|
+
│ ├── common/ # Common agent utilities
|
|
115
|
+
│ │ ├── base.py
|
|
116
|
+
│ │ ├── exceptions.py
|
|
117
|
+
│ │ ├── logging.py
|
|
118
|
+
│ │ └── utils.py
|
|
119
|
+
│ └── dependency_graph/ # Dependency graph analysis
|
|
120
|
+
│ ├── agent.py
|
|
121
|
+
│ └── model.py
|
|
122
|
+
├── api_models/ # API model integrations
|
|
123
|
+
│ └── flow_api_model.py
|
|
124
|
+
└── tools/ # Agent tools
|
|
125
|
+
├── io.py # File I/O operations
|
|
126
|
+
└── tree.py # Directory tree generation
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
### Setup Development Environment
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Clone the repository
|
|
135
|
+
git clone https://github.com/yourusername/naive-knowledge-base.git
|
|
136
|
+
cd naive-knowledge-base
|
|
137
|
+
|
|
138
|
+
# Create virtual environment
|
|
139
|
+
python -m venv venv
|
|
140
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
141
|
+
|
|
142
|
+
# Install in editable mode with dev dependencies
|
|
143
|
+
pip install -e ".[dev]"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Running Tests
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pytest tests/
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Code Formatting
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Format code
|
|
156
|
+
black .
|
|
157
|
+
isort .
|
|
158
|
+
|
|
159
|
+
# Check code quality
|
|
160
|
+
pylint naive_knowledge_base/
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Contributing
|
|
164
|
+
|
|
165
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
166
|
+
|
|
167
|
+
1. Fork the repository
|
|
168
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
169
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
170
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
171
|
+
5. Open a Pull Request
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
176
|
+
|
|
177
|
+
## Acknowledgments
|
|
178
|
+
|
|
179
|
+
- Built with [smolagents](https://github.com/huggingface/smolagents)
|
|
180
|
+
- Uses OpenAI API for AI-powered analysis
|
|
181
|
+
|
|
182
|
+
## Support
|
|
183
|
+
|
|
184
|
+
For issues and questions, please file an issue on the [GitHub repository](https://github.com/yourusername/naive-knowledge-base/issues).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from exceptions import (
|
|
2
|
+
CodeRefactorError,
|
|
3
|
+
ConfigurationError,
|
|
4
|
+
DependencyGraphError,
|
|
5
|
+
SonarQubeError,
|
|
6
|
+
RefactoringError,
|
|
7
|
+
FileOperationError,
|
|
8
|
+
MissingDependencyError,
|
|
9
|
+
wrap_exceptions
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from .logging import configure_logging, get_logger
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
# Exceptions
|
|
16
|
+
"CodeRefactorError",
|
|
17
|
+
"ConfigurationError",
|
|
18
|
+
"DependencyGraphError",
|
|
19
|
+
"SonarQubeError",
|
|
20
|
+
"RefactoringError",
|
|
21
|
+
"FileOperationError",
|
|
22
|
+
"MissingDependencyError",
|
|
23
|
+
"wrap_exceptions",
|
|
24
|
+
|
|
25
|
+
# Logging
|
|
26
|
+
"configure_logging",
|
|
27
|
+
"get_logger",
|
|
28
|
+
]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import List, Dict, Any, Optional, Union
|
|
3
|
+
from smolagents import Tool, CodeAgent, ToolCallingAgent
|
|
4
|
+
|
|
5
|
+
from .logging import get_logger
|
|
6
|
+
|
|
7
|
+
logger = get_logger(__name__)
|
|
8
|
+
|
|
9
|
+
class BaseAgent(ABC):
|
|
10
|
+
"""
|
|
11
|
+
Abstract base class for all agents in the refactor system.
|
|
12
|
+
|
|
13
|
+
This class defines the common interface that all agents must implement.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def run(self, input_data: Any) -> Any:
|
|
18
|
+
"""
|
|
19
|
+
Run the agent with the provided input data.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
input_data: Input data for the agent
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
Agent output
|
|
26
|
+
"""
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def name(self) -> str:
|
|
32
|
+
"""Get the agent name."""
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def description(self) -> str:
|
|
38
|
+
"""Get the agent description."""
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
class AnalysisAgent(BaseAgent):
|
|
42
|
+
"""
|
|
43
|
+
Base class for agents that analyze code.
|
|
44
|
+
|
|
45
|
+
These agents are responsible for analyzing code and providing information about it.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
@abstractmethod
|
|
49
|
+
def analyze(self, file_path: str, **kwargs) -> Dict[str, Any]:
|
|
50
|
+
"""
|
|
51
|
+
Analyze the code in the given file.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
file_path: Path to the file to analyze
|
|
55
|
+
**kwargs: Additional arguments for the analysis
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Analysis results
|
|
59
|
+
"""
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
class RefactoringAgent(BaseAgent):
|
|
63
|
+
"""
|
|
64
|
+
Base class for agents that refactor code.
|
|
65
|
+
|
|
66
|
+
These agents are responsible for refactoring code based on analysis results.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def generate_plan(self, file_path: str, analysis_results: Dict[str, Any]) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Generate a refactoring plan for the given file based on analysis results.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
file_path: Path to the file to refactor
|
|
76
|
+
analysis_results: Results from analysis agents
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Refactoring plan
|
|
80
|
+
"""
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def execute_plan(self, file_path: str, plan: str) -> bool:
|
|
85
|
+
"""
|
|
86
|
+
Execute a refactoring plan on the given file.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
file_path: Path to the file to refactor
|
|
90
|
+
plan: Refactoring plan
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
True if successful, False otherwise
|
|
94
|
+
"""
|
|
95
|
+
pass
|
|
96
|
+
|
|
97
|
+
class SmolagentsAdapter(BaseAgent):
|
|
98
|
+
"""
|
|
99
|
+
Adapter class for smolagents agents.
|
|
100
|
+
|
|
101
|
+
This class adapts smolagents agents to our BaseAgent interface.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
def __init__(self, agent: Union[CodeAgent, ToolCallingAgent]):
|
|
105
|
+
"""
|
|
106
|
+
Initialize the adapter.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
agent: The smolagents agent to adapt
|
|
110
|
+
"""
|
|
111
|
+
self._agent = agent
|
|
112
|
+
|
|
113
|
+
def run(self, input_data: Any) -> Any:
|
|
114
|
+
"""
|
|
115
|
+
Run the smolagents agent.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
input_data: Input data for the agent
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
Agent output
|
|
122
|
+
"""
|
|
123
|
+
return self._agent.run(input_data)
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def name(self) -> str:
|
|
127
|
+
"""Get the agent name."""
|
|
128
|
+
return self._agent.name
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def description(self) -> str:
|
|
132
|
+
"""Get the agent description."""
|
|
133
|
+
return self._agent.description
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def agent(self) -> Union[CodeAgent, ToolCallingAgent]:
|
|
137
|
+
"""Get the underlying smolagents agent."""
|
|
138
|
+
return self._agent
|
|
139
|
+
|
|
140
|
+
class AgentFactory:
|
|
141
|
+
"""
|
|
142
|
+
Factory class for creating agents.
|
|
143
|
+
|
|
144
|
+
This class provides methods for creating different types of agents.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def create_analysis_agent(agent_type: str, **kwargs) -> AnalysisAgent:
|
|
149
|
+
"""
|
|
150
|
+
Create an analysis agent of the specified type.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
agent_type: Type of analysis agent to create
|
|
154
|
+
**kwargs: Additional arguments for the agent
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
An instance of the requested analysis agent
|
|
158
|
+
|
|
159
|
+
Raises:
|
|
160
|
+
ValueError: If the agent type is not supported
|
|
161
|
+
"""
|
|
162
|
+
# Import here to avoid circular imports
|
|
163
|
+
from agents.sonar import create_sonar_agent
|
|
164
|
+
from agents.dependency_graph import create_dependency_graph_agent
|
|
165
|
+
|
|
166
|
+
if agent_type == "sonar":
|
|
167
|
+
return create_sonar_agent(**kwargs)
|
|
168
|
+
elif agent_type == "dependency_graph":
|
|
169
|
+
return create_dependency_graph_agent(**kwargs)
|
|
170
|
+
else:
|
|
171
|
+
raise ValueError(f"Unsupported analysis agent type: {agent_type}")
|
|
172
|
+
|
|
173
|
+
@staticmethod
|
|
174
|
+
def create_refactoring_agent(**kwargs) -> RefactoringAgent:
|
|
175
|
+
"""
|
|
176
|
+
Create a refactoring agent.
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
**kwargs: Additional arguments for the agent
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
An instance of the refactoring agent
|
|
183
|
+
"""
|
|
184
|
+
# Import here to avoid circular imports
|
|
185
|
+
from agents.coder import create_coder_agent
|
|
186
|
+
|
|
187
|
+
return create_coder_agent(**kwargs)
|