vcode-analysis 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.
- vcode_analysis-0.1.0/LICENSE +21 -0
- vcode_analysis-0.1.0/MANIFEST.in +14 -0
- vcode_analysis-0.1.0/PKG-INFO +246 -0
- vcode_analysis-0.1.0/README.md +206 -0
- vcode_analysis-0.1.0/analyzers/__init__.py +24 -0
- vcode_analysis-0.1.0/analyzers/architecture.py +510 -0
- vcode_analysis-0.1.0/analyzers/code_review.py +150 -0
- vcode_analysis-0.1.0/analyzers/directory.py +867 -0
- vcode_analysis-0.1.0/analyzers/documentation.py +209 -0
- vcode_analysis-0.1.0/analyzers/security.py +671 -0
- vcode_analysis-0.1.0/core/__init__.py +17 -0
- vcode_analysis-0.1.0/core/analyzer.py +207 -0
- vcode_analysis-0.1.0/core/config.py +166 -0
- vcode_analysis-0.1.0/core/git_handler.py +718 -0
- vcode_analysis-0.1.0/core/llm_client.py +186 -0
- vcode_analysis-0.1.0/docs/USER_MANUAL.md +1020 -0
- vcode_analysis-0.1.0/docs/design/c-parser-design.md +188 -0
- vcode_analysis-0.1.0/docs/design/code-analysis-tool.md +143 -0
- vcode_analysis-0.1.0/docs/design/kotlin-parser-design.md +266 -0
- vcode_analysis-0.1.0/parsers/__init__.py +209 -0
- vcode_analysis-0.1.0/parsers/c/__init__.py +57 -0
- vcode_analysis-0.1.0/parsers/c/ast_parser.py +424 -0
- vcode_analysis-0.1.0/parsers/c/models.py +211 -0
- vcode_analysis-0.1.0/parsers/c/patterns.py +143 -0
- vcode_analysis-0.1.0/parsers/c/regex_parser.py +594 -0
- vcode_analysis-0.1.0/parsers/c_parser.py +275 -0
- vcode_analysis-0.1.0/parsers/java_parser.py +430 -0
- vcode_analysis-0.1.0/parsers/javascript_parser.py +587 -0
- vcode_analysis-0.1.0/parsers/kotlin/__init__.py +61 -0
- vcode_analysis-0.1.0/parsers/kotlin/ast_parser.py +591 -0
- vcode_analysis-0.1.0/parsers/kotlin/models.py +274 -0
- vcode_analysis-0.1.0/parsers/kotlin/patterns.py +146 -0
- vcode_analysis-0.1.0/parsers/kotlin/regex_parser.py +906 -0
- vcode_analysis-0.1.0/parsers/kotlin_parser.py +279 -0
- vcode_analysis-0.1.0/parsers/python_parser.py +429 -0
- vcode_analysis-0.1.0/parsers/typescript_parser.py +381 -0
- vcode_analysis-0.1.0/pyproject.toml +68 -0
- vcode_analysis-0.1.0/requirements.txt +13 -0
- vcode_analysis-0.1.0/setup.cfg +4 -0
- vcode_analysis-0.1.0/tests/test_batch_operations.py +193 -0
- vcode_analysis-0.1.0/tests/test_c_parser.py +367 -0
- vcode_analysis-0.1.0/tests/test_kotlin_parser.py +327 -0
- vcode_analysis-0.1.0/tests/test_security_rules.py +305 -0
- vcode_analysis-0.1.0/vcode_analysis.egg-info/PKG-INFO +246 -0
- vcode_analysis-0.1.0/vcode_analysis.egg-info/SOURCES.txt +47 -0
- vcode_analysis-0.1.0/vcode_analysis.egg-info/dependency_links.txt +1 -0
- vcode_analysis-0.1.0/vcode_analysis.egg-info/entry_points.txt +2 -0
- vcode_analysis-0.1.0/vcode_analysis.egg-info/requires.txt +15 -0
- vcode_analysis-0.1.0/vcode_analysis.egg-info/top_level.txt +3 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Wellchang
|
|
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,14 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
include requirements.txt
|
|
5
|
+
|
|
6
|
+
recursive-include docs *.md
|
|
7
|
+
recursive-include analyzers *.py
|
|
8
|
+
recursive-include core *.py
|
|
9
|
+
recursive-include parsers *.py
|
|
10
|
+
|
|
11
|
+
global-exclude __pycache__
|
|
12
|
+
global-exclude *.py[cod]
|
|
13
|
+
global-exclude *.so
|
|
14
|
+
global-exclude .DS_Store
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vcode-analysis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 基于大模型的智能代码分析工具,支持代码审查、文档生成、架构分析和安全扫描
|
|
5
|
+
Author-email: Wellchang <2483808264@qq.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitcode.com/wellchang/code-analysis
|
|
8
|
+
Project-URL: Repository, https://gitcode.com/wellchang/code-analysis
|
|
9
|
+
Project-URL: Documentation, https://gitcode.com/wellchang/code-analysis/blob/master/docs/USER_MANUAL.md
|
|
10
|
+
Project-URL: Bug Tracker, https://gitcode.com/wellchang/code-analysis/issues
|
|
11
|
+
Keywords: vcode-analysis,llm,code-review,documentation
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: httpx>=0.25.0
|
|
28
|
+
Requires-Dist: docopt>=0.6.2
|
|
29
|
+
Requires-Dist: pyyaml>=6.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
34
|
+
Provides-Extra: rich
|
|
35
|
+
Requires-Dist: rich>=13.0.0; extra == "rich"
|
|
36
|
+
Provides-Extra: parsers
|
|
37
|
+
Requires-Dist: javalang>=0.13.0; extra == "parsers"
|
|
38
|
+
Requires-Dist: pycparser>=2.21; extra == "parsers"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# Code Analysis - 智能代码分析工具
|
|
42
|
+
|
|
43
|
+
[](https://www.python.org/downloads/)
|
|
44
|
+
[](https://opensource.org/licenses/MIT)
|
|
45
|
+
|
|
46
|
+
基于私有化部署大模型的智能代码分析工具,支持代码审查、文档生成、架构分析和安全扫描。
|
|
47
|
+
|
|
48
|
+
## ✨ 核心特性
|
|
49
|
+
|
|
50
|
+
| 特性 | 描述 |
|
|
51
|
+
|------|------|
|
|
52
|
+
| 🔍 **代码审查** | 自动分析代码质量,识别问题和安全漏洞 |
|
|
53
|
+
| 📝 **文档生成** | 自动生成模块文档、API 文档 |
|
|
54
|
+
| 🏗️ **架构分析** | 分析项目结构、依赖关系、代码度量 |
|
|
55
|
+
| 🔒 **安全扫描** | 检测常见安全漏洞和风险代码 |
|
|
56
|
+
| 📦 **批量操作** | 批量克隆、批量 Git 操作、多仓库管理 |
|
|
57
|
+
| 📂 **目录分析** | 扫描项目结构、识别技术栈 |
|
|
58
|
+
| 🌐 **多语言支持** | Python, Java, Kotlin, C, JavaScript, TypeScript 等 |
|
|
59
|
+
| 🤖 **私有化部署** | 兼容 OpenAI API 格式,支持任何私有化 LLM |
|
|
60
|
+
|
|
61
|
+
## 🚀 快速开始
|
|
62
|
+
|
|
63
|
+
### 安装
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# 克隆项目
|
|
67
|
+
git clone https://gitcode.com/wellchang/code-analysis.git
|
|
68
|
+
cd code-analysis
|
|
69
|
+
|
|
70
|
+
# 安装依赖
|
|
71
|
+
pip install httpx docopt pyyaml
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 配置
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 初始化配置文件
|
|
78
|
+
python cli.py config --init
|
|
79
|
+
|
|
80
|
+
# 编辑配置文件
|
|
81
|
+
# ~/.code-analysis/config.yaml
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 使用
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 代码审查
|
|
88
|
+
python cli.py review ./src
|
|
89
|
+
|
|
90
|
+
# 架构分析
|
|
91
|
+
python cli.py arch ./src
|
|
92
|
+
|
|
93
|
+
# 安全扫描
|
|
94
|
+
python cli.py security ./src --deep
|
|
95
|
+
|
|
96
|
+
# 目录扫描
|
|
97
|
+
python cli.py scan-dir ./project
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 📖 命令概览
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
Commands:
|
|
104
|
+
review 代码审查
|
|
105
|
+
review-commit 审查指定提交
|
|
106
|
+
doc 生成文档
|
|
107
|
+
arch 架构分析
|
|
108
|
+
security 安全漏洞扫描
|
|
109
|
+
clone 克隆仓库并分析
|
|
110
|
+
batch-clone 批量克隆仓库
|
|
111
|
+
batch-pull 批量拉取更新
|
|
112
|
+
git-status 查看多仓库状态
|
|
113
|
+
scan-dir 扫描目录结构
|
|
114
|
+
config 配置管理
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 🌍 支持的语言
|
|
118
|
+
|
|
119
|
+
| 语言 | 文件扩展名 | 解析模式 |
|
|
120
|
+
|------|------------|----------|
|
|
121
|
+
| Python | `.py` | AST |
|
|
122
|
+
| Java | `.java` | AST |
|
|
123
|
+
| Kotlin | `.kt`, `.kts` | 双模式 |
|
|
124
|
+
| C | `.c`, `.h` | 双模式 |
|
|
125
|
+
| JavaScript | `.js`, `.jsx` | 正则 |
|
|
126
|
+
| TypeScript | `.ts`, `.tsx` | 正则 |
|
|
127
|
+
|
|
128
|
+
## 📚 文档
|
|
129
|
+
|
|
130
|
+
- [完整使用手册](docs/USER_MANUAL.md)
|
|
131
|
+
- [Kotlin 解析器设计](docs/design/kotlin-parser-design.md)
|
|
132
|
+
- [C 解析器设计](docs/design/c-parser-design.md)
|
|
133
|
+
|
|
134
|
+
## 🔧 项目结构
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
code-analysis/
|
|
138
|
+
├── cli.py # CLI 入口
|
|
139
|
+
├── core/
|
|
140
|
+
│ ├── analyzer.py # 分析引擎核心
|
|
141
|
+
│ ├── llm_client.py # LLM 客户端
|
|
142
|
+
│ ├── git_handler.py # Git 操作 + 批量操作
|
|
143
|
+
│ └── config.py # 配置管理
|
|
144
|
+
├── analyzers/
|
|
145
|
+
│ ├── code_review.py # 代码审查
|
|
146
|
+
│ ├── documentation.py # 文档生成
|
|
147
|
+
│ ├── architecture.py # 架构分析
|
|
148
|
+
│ ├── security.py # 安全扫描
|
|
149
|
+
│ └── directory.py # 目录分析
|
|
150
|
+
└── parsers/
|
|
151
|
+
├── python_parser.py # Python AST 解析器
|
|
152
|
+
├── java_parser.py # Java AST 解析器
|
|
153
|
+
├── kotlin_parser.py # Kotlin 解析器(双模式)
|
|
154
|
+
├── c_parser.py # C 语言解析器(双模式)
|
|
155
|
+
└── ...
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 💡 使用示例
|
|
159
|
+
|
|
160
|
+
### 代码审查
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# 审查整个项目
|
|
164
|
+
python cli.py review ./src --output report.md
|
|
165
|
+
|
|
166
|
+
# 审查最新提交
|
|
167
|
+
python cli.py review-commit HEAD
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 安全扫描
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# 深度安全扫描
|
|
174
|
+
python cli.py security ./src --deep --output security.md
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 批量操作
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# 批量克隆(从文件读取 URL 列表)
|
|
181
|
+
python cli.py batch-clone repos.txt ./projects --parallel
|
|
182
|
+
|
|
183
|
+
# 查看多仓库状态
|
|
184
|
+
python cli.py git-status ~/projects
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## ⚙️ 配置示例
|
|
188
|
+
|
|
189
|
+
```yaml
|
|
190
|
+
# ~/.code-analysis/config.yaml
|
|
191
|
+
llm:
|
|
192
|
+
base_url: http://localhost:8000/v1
|
|
193
|
+
api_key: sk-your-api-key
|
|
194
|
+
model: qwen3.5-35b-a3b
|
|
195
|
+
temperature: 0.7
|
|
196
|
+
max_tokens: 4096
|
|
197
|
+
|
|
198
|
+
analysis:
|
|
199
|
+
max_file_size: 102400
|
|
200
|
+
ignore_patterns:
|
|
201
|
+
- node_modules
|
|
202
|
+
- .git
|
|
203
|
+
- __pycache__
|
|
204
|
+
- venv
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 🤝 扩展开发
|
|
208
|
+
|
|
209
|
+
### 添加新的分析器
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from core import Analyzer
|
|
213
|
+
|
|
214
|
+
class CustomAnalyzer:
|
|
215
|
+
def __init__(self, analyzer: Analyzer):
|
|
216
|
+
self.analyzer = analyzer
|
|
217
|
+
|
|
218
|
+
def analyze(self, file_path: str) -> dict:
|
|
219
|
+
content = self.analyzer.read_file(file_path)
|
|
220
|
+
prompt = f"分析以下代码:\n{content}"
|
|
221
|
+
result = self.analyzer.llm_client.chat(prompt)
|
|
222
|
+
return {"result": result}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 使用解析器 API
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from parsers import KotlinASTParser, CASTParser
|
|
229
|
+
|
|
230
|
+
# Kotlin 解析
|
|
231
|
+
parser = KotlinASTParser()
|
|
232
|
+
result = parser.parse_file('Example.kt', mode='auto')
|
|
233
|
+
|
|
234
|
+
# C 解析
|
|
235
|
+
parser = CASTParser()
|
|
236
|
+
result = parser.parse_file('main.c', mode='fast')
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## 📄 许可证
|
|
240
|
+
|
|
241
|
+
[MIT License](LICENSE)
|
|
242
|
+
|
|
243
|
+
## 🔗 链接
|
|
244
|
+
|
|
245
|
+
- [项目主页](https://gitcode.com/wellchang/code-analysis)
|
|
246
|
+
- [问题反馈](https://gitcode.com/wellchang/code-analysis/issues)
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Code Analysis - 智能代码分析工具
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/downloads/)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
基于私有化部署大模型的智能代码分析工具,支持代码审查、文档生成、架构分析和安全扫描。
|
|
7
|
+
|
|
8
|
+
## ✨ 核心特性
|
|
9
|
+
|
|
10
|
+
| 特性 | 描述 |
|
|
11
|
+
|------|------|
|
|
12
|
+
| 🔍 **代码审查** | 自动分析代码质量,识别问题和安全漏洞 |
|
|
13
|
+
| 📝 **文档生成** | 自动生成模块文档、API 文档 |
|
|
14
|
+
| 🏗️ **架构分析** | 分析项目结构、依赖关系、代码度量 |
|
|
15
|
+
| 🔒 **安全扫描** | 检测常见安全漏洞和风险代码 |
|
|
16
|
+
| 📦 **批量操作** | 批量克隆、批量 Git 操作、多仓库管理 |
|
|
17
|
+
| 📂 **目录分析** | 扫描项目结构、识别技术栈 |
|
|
18
|
+
| 🌐 **多语言支持** | Python, Java, Kotlin, C, JavaScript, TypeScript 等 |
|
|
19
|
+
| 🤖 **私有化部署** | 兼容 OpenAI API 格式,支持任何私有化 LLM |
|
|
20
|
+
|
|
21
|
+
## 🚀 快速开始
|
|
22
|
+
|
|
23
|
+
### 安装
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 克隆项目
|
|
27
|
+
git clone https://gitcode.com/wellchang/code-analysis.git
|
|
28
|
+
cd code-analysis
|
|
29
|
+
|
|
30
|
+
# 安装依赖
|
|
31
|
+
pip install httpx docopt pyyaml
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 配置
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 初始化配置文件
|
|
38
|
+
python cli.py config --init
|
|
39
|
+
|
|
40
|
+
# 编辑配置文件
|
|
41
|
+
# ~/.code-analysis/config.yaml
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 使用
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 代码审查
|
|
48
|
+
python cli.py review ./src
|
|
49
|
+
|
|
50
|
+
# 架构分析
|
|
51
|
+
python cli.py arch ./src
|
|
52
|
+
|
|
53
|
+
# 安全扫描
|
|
54
|
+
python cli.py security ./src --deep
|
|
55
|
+
|
|
56
|
+
# 目录扫描
|
|
57
|
+
python cli.py scan-dir ./project
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 📖 命令概览
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
Commands:
|
|
64
|
+
review 代码审查
|
|
65
|
+
review-commit 审查指定提交
|
|
66
|
+
doc 生成文档
|
|
67
|
+
arch 架构分析
|
|
68
|
+
security 安全漏洞扫描
|
|
69
|
+
clone 克隆仓库并分析
|
|
70
|
+
batch-clone 批量克隆仓库
|
|
71
|
+
batch-pull 批量拉取更新
|
|
72
|
+
git-status 查看多仓库状态
|
|
73
|
+
scan-dir 扫描目录结构
|
|
74
|
+
config 配置管理
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 🌍 支持的语言
|
|
78
|
+
|
|
79
|
+
| 语言 | 文件扩展名 | 解析模式 |
|
|
80
|
+
|------|------------|----------|
|
|
81
|
+
| Python | `.py` | AST |
|
|
82
|
+
| Java | `.java` | AST |
|
|
83
|
+
| Kotlin | `.kt`, `.kts` | 双模式 |
|
|
84
|
+
| C | `.c`, `.h` | 双模式 |
|
|
85
|
+
| JavaScript | `.js`, `.jsx` | 正则 |
|
|
86
|
+
| TypeScript | `.ts`, `.tsx` | 正则 |
|
|
87
|
+
|
|
88
|
+
## 📚 文档
|
|
89
|
+
|
|
90
|
+
- [完整使用手册](docs/USER_MANUAL.md)
|
|
91
|
+
- [Kotlin 解析器设计](docs/design/kotlin-parser-design.md)
|
|
92
|
+
- [C 解析器设计](docs/design/c-parser-design.md)
|
|
93
|
+
|
|
94
|
+
## 🔧 项目结构
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
code-analysis/
|
|
98
|
+
├── cli.py # CLI 入口
|
|
99
|
+
├── core/
|
|
100
|
+
│ ├── analyzer.py # 分析引擎核心
|
|
101
|
+
│ ├── llm_client.py # LLM 客户端
|
|
102
|
+
│ ├── git_handler.py # Git 操作 + 批量操作
|
|
103
|
+
│ └── config.py # 配置管理
|
|
104
|
+
├── analyzers/
|
|
105
|
+
│ ├── code_review.py # 代码审查
|
|
106
|
+
│ ├── documentation.py # 文档生成
|
|
107
|
+
│ ├── architecture.py # 架构分析
|
|
108
|
+
│ ├── security.py # 安全扫描
|
|
109
|
+
│ └── directory.py # 目录分析
|
|
110
|
+
└── parsers/
|
|
111
|
+
├── python_parser.py # Python AST 解析器
|
|
112
|
+
├── java_parser.py # Java AST 解析器
|
|
113
|
+
├── kotlin_parser.py # Kotlin 解析器(双模式)
|
|
114
|
+
├── c_parser.py # C 语言解析器(双模式)
|
|
115
|
+
└── ...
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 💡 使用示例
|
|
119
|
+
|
|
120
|
+
### 代码审查
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# 审查整个项目
|
|
124
|
+
python cli.py review ./src --output report.md
|
|
125
|
+
|
|
126
|
+
# 审查最新提交
|
|
127
|
+
python cli.py review-commit HEAD
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 安全扫描
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# 深度安全扫描
|
|
134
|
+
python cli.py security ./src --deep --output security.md
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 批量操作
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# 批量克隆(从文件读取 URL 列表)
|
|
141
|
+
python cli.py batch-clone repos.txt ./projects --parallel
|
|
142
|
+
|
|
143
|
+
# 查看多仓库状态
|
|
144
|
+
python cli.py git-status ~/projects
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## ⚙️ 配置示例
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
# ~/.code-analysis/config.yaml
|
|
151
|
+
llm:
|
|
152
|
+
base_url: http://localhost:8000/v1
|
|
153
|
+
api_key: sk-your-api-key
|
|
154
|
+
model: qwen3.5-35b-a3b
|
|
155
|
+
temperature: 0.7
|
|
156
|
+
max_tokens: 4096
|
|
157
|
+
|
|
158
|
+
analysis:
|
|
159
|
+
max_file_size: 102400
|
|
160
|
+
ignore_patterns:
|
|
161
|
+
- node_modules
|
|
162
|
+
- .git
|
|
163
|
+
- __pycache__
|
|
164
|
+
- venv
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 🤝 扩展开发
|
|
168
|
+
|
|
169
|
+
### 添加新的分析器
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from core import Analyzer
|
|
173
|
+
|
|
174
|
+
class CustomAnalyzer:
|
|
175
|
+
def __init__(self, analyzer: Analyzer):
|
|
176
|
+
self.analyzer = analyzer
|
|
177
|
+
|
|
178
|
+
def analyze(self, file_path: str) -> dict:
|
|
179
|
+
content = self.analyzer.read_file(file_path)
|
|
180
|
+
prompt = f"分析以下代码:\n{content}"
|
|
181
|
+
result = self.analyzer.llm_client.chat(prompt)
|
|
182
|
+
return {"result": result}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 使用解析器 API
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from parsers import KotlinASTParser, CASTParser
|
|
189
|
+
|
|
190
|
+
# Kotlin 解析
|
|
191
|
+
parser = KotlinASTParser()
|
|
192
|
+
result = parser.parse_file('Example.kt', mode='auto')
|
|
193
|
+
|
|
194
|
+
# C 解析
|
|
195
|
+
parser = CASTParser()
|
|
196
|
+
result = parser.parse_file('main.c', mode='fast')
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## 📄 许可证
|
|
200
|
+
|
|
201
|
+
[MIT License](LICENSE)
|
|
202
|
+
|
|
203
|
+
## 🔗 链接
|
|
204
|
+
|
|
205
|
+
- [项目主页](https://gitcode.com/wellchang/code-analysis)
|
|
206
|
+
- [问题反馈](https://gitcode.com/wellchang/code-analysis/issues)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""分析器模块"""
|
|
2
|
+
|
|
3
|
+
from .code_review import CodeReviewAnalyzer, CodeReviewResult
|
|
4
|
+
from .documentation import DocumentationAnalyzer, DocumentationResult
|
|
5
|
+
from .architecture import ArchitectureAnalyzer, ArchitectureResult, ModuleInfo, DependencyInfo
|
|
6
|
+
from .security import SecurityAnalyzer, SecurityResult, SecurityIssue
|
|
7
|
+
from .directory import DirectoryAnalyzer, DirectoryAnalysisResult, ProjectInfo
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"CodeReviewAnalyzer",
|
|
11
|
+
"CodeReviewResult",
|
|
12
|
+
"DocumentationAnalyzer",
|
|
13
|
+
"DocumentationResult",
|
|
14
|
+
"ArchitectureAnalyzer",
|
|
15
|
+
"ArchitectureResult",
|
|
16
|
+
"ModuleInfo",
|
|
17
|
+
"DependencyInfo",
|
|
18
|
+
"SecurityAnalyzer",
|
|
19
|
+
"SecurityResult",
|
|
20
|
+
"SecurityIssue",
|
|
21
|
+
"DirectoryAnalyzer",
|
|
22
|
+
"DirectoryAnalysisResult",
|
|
23
|
+
"ProjectInfo",
|
|
24
|
+
]
|