Skip to content

Commit 8b0191e

Browse files
committed
refactor: clarify configuration import boundary
1 parent dce76e4 commit 8b0191e

20 files changed

Lines changed: 117 additions & 66 deletions

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ uv lock --check
300300
uv run python -m compileall -q Analyze.py api core services utils pure_auto_codeql tools
301301
```
302302

303+
## 配置导入约定
304+
305+
运行时代码推荐从 `pure_auto_codeql.configuration` 导入 LLM 配置:
306+
307+
```python
308+
from pure_auto_codeql.configuration import get_llm_config, LLMRole
309+
```
310+
311+
历史脚本中的 `from config import ...``python config.py ...` 仍保持兼容。
312+
303313
## 安全说明
304314

305315
- 不要提交真实密钥。`config/keys*.toml` 已被忽略,仓库只保留 `config/keys.example.toml` 模板。

config.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
"""
2-
PureAutoCodeQL LLM 配置系统入口
3-
4-
为了保持向后兼容,这个文件作为 config 模块的入口
5-
所有导入 config.py 的代码都会自动使用新的模块化系统
1+
"""Legacy script shim for the configuration CLI.
62
7-
新系统特性:
8-
- 模块化架构(config/ 文件夹)
9-
- keys.toml 统一配置
10-
- 零代码修改快速部署
3+
Runtime application code should import configuration helpers from
4+
`pure_auto_codeql.configuration`. The `config/` package remains available for
5+
legacy `from config import ...` imports, and this root-level file is kept so
6+
`python config.py ...` continues to launch the configuration CLI.
117
"""
128

13-
# 导入所有配置内容,保持向后兼容
149
from config import * # noqa: F401, F403
1510

16-
# 命令行工具入口
1711
if __name__ == "__main__":
1812
from config.cli import main
13+
1914
main()

config/MAIN_PROGRAM_INTEGRATION.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
## 验证范围
77

8-
本报告验证了项目主程序及关键模块是否正确使用了重构后的 `config/` 模块。
8+
本报告验证了项目主程序及关键模块是否正确使用了 canonical 配置入口
9+
`pure_auto_codeql.configuration`,并确认旧版 `config/` 模块兼容层仍可用。
910

1011
## 验证结果
1112

1213
### ✅ 主程序 (Analyze.py)
1314

1415
**导入内容:**
1516
```python
16-
from config import (
17+
from pure_auto_codeql.configuration import (
1718
list_available_providers,
1819
get_llm_config_by_provider,
1920
LLMRole,
@@ -23,15 +24,16 @@ from config import (
2324
```
2425

2526
**状态:** ✅ 完全兼容
26-
- 所有导入的函数和类都已在新的 `config/__init__.py` 中正确导出
27+
- 所有导入的函数和类都已通过 `pure_auto_codeql.configuration` 统一导出
28+
- 旧版 `from config import ...` 入口仍可用于历史脚本
2729
- `list_siliconflow_models()` 在命令行参数 `--list-models` 中被调用
2830
- `get_llm_config()` 用于获取 think 和 chat 模型配置
2931

3032
### ✅ LLM 服务 (services/llm_service.py)
3133

3234
**导入内容:**
3335
```python
34-
from config import (
36+
from pure_auto_codeql.configuration import (
3537
get_chat_config,
3638
LLMConfig,
3739
get_resilient_llm_config,
@@ -47,7 +49,7 @@ from config import (
4749

4850
**导入内容:**
4951
```python
50-
from config import get_chat_config
52+
from pure_auto_codeql.configuration import get_chat_config
5153
```
5254

5355
**状态:** ✅ 完全兼容
@@ -57,7 +59,7 @@ from config import get_chat_config
5759

5860
**导入内容:**
5961
```python
60-
from config import get_chat_config
62+
from pure_auto_codeql.configuration import get_chat_config
6163
```
6264

6365
**状态:** ✅ 完全兼容
@@ -148,10 +150,10 @@ config/
148150

149151
## 结论
150152

151-
**主程序完全正确地使用了新的 config 模块**
153+
**主程序完全正确地使用了 canonical 配置入口**
152154

153155
所有关键功能均已验证:
154-
1. 主程序 `Analyze.py` 可以正常导入和调用所有需要的config函数
156+
1. 主程序 `Analyze.py` 可以正常导入和调用所有需要的配置函数
155157
2. 服务层 `services/llm_service.py` 正确使用配置系统
156158
3. 示例和测试代码都能正常工作
157159
4. 向后兼容性完全保持
@@ -165,7 +167,6 @@ config/
165167
3. 运行主程序:`python Analyze.py --case CVE-XXXX-XXXX`
166168

167169
### 对于开发者
168-
1. 导入核心函数:`from config import get_llm_config, LLMRole`
170+
1. 导入核心函数:`from pure_auto_codeql.configuration import get_llm_config, LLMRole`
169171
2. 使用配置:`config = get_llm_config(LLMRole.CHAT)`
170-
3. 所有旧版API仍然可用,无需修改现有代码
171-
172+
3. 所有旧版 API 仍然可用,历史代码无需立即修改

config/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ python Analyze.py --md-file vuln.md --src-path /path/to/src --provider my_api
185185

186186
### 在代码中使用
187187

188+
运行时代码推荐使用 `pure_auto_codeql.configuration` 作为统一导入入口;旧的
189+
`from config import ...` 仍保持兼容。
190+
188191
```python
189-
from config import get_llm_config, LLMRole
192+
from pure_auto_codeql.configuration import get_llm_config, LLMRole
190193

191194
# 获取默认配置
192195
chat_config = get_llm_config(LLMRole.CHAT)
@@ -219,7 +222,7 @@ print(f"Base URL: {config.base_url}")
219222
### 便捷函数
220223

221224
```python
222-
from config import get_chat_config, get_think_config
225+
from pure_auto_codeql.configuration import get_chat_config, get_think_config
223226

224227
# 直接获取对话模型配置
225228
chat_config = get_chat_config()
@@ -525,7 +528,10 @@ exists = ProviderRegistry.has("my_api")
525528
### 显示函数
526529

527530
```python
528-
from config import display_providers_status, display_provider_detail
531+
from pure_auto_codeql.configuration import (
532+
display_provider_detail,
533+
display_providers_status,
534+
)
529535

530536
# 显示所有提供商状态
531537
display_providers_status(validate_keys=False)
@@ -537,7 +543,7 @@ display_provider_detail("my_api")
537543
### 向后兼容函数
538544

539545
```python
540-
from config import (
546+
from pure_auto_codeql.configuration import (
541547
list_available_providers,
542548
get_llm_config_by_provider,
543549
list_siliconflow_models

core/pipeline.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def _get_llm_config_from_context(context: AnalysisContext, role) -> Any:
2121
"""从上下文中获取LLM配置,支持配置中的模型、API Key和Base URL"""
2222
config = getattr(context, '_config', None)
2323
if not config:
24-
from config import get_resilient_llm_config, LLMRole
24+
from pure_auto_codeql.configuration import get_resilient_llm_config, LLMRole
2525
return get_resilient_llm_config(role)
2626

27-
from config import get_llm_config, LLMRole
27+
from pure_auto_codeql.configuration import get_llm_config, LLMRole
2828
# 从配置中获取参数
2929
provider = config.llm_provider
3030
model_name = config.think_model if role == LLMRole.THINK else config.chat_model
@@ -73,7 +73,7 @@ def __init__(self):
7373

7474
async def execute(self, context: AnalysisContext) -> Any:
7575
"""执行CVE分析。"""
76-
from config import LLMRole
76+
from pure_auto_codeql.configuration import LLMRole
7777
llm_config = _get_llm_config_from_context(context, LLMRole.CHAT)
7878
analyzer = MultiAgentAnalyzer(llm_config)
7979
await analyzer.initialize(
@@ -116,7 +116,7 @@ def __init__(self):
116116

117117
async def execute(self, context: AnalysisContext) -> Any:
118118
"""执行Sink路径分析。"""
119-
from config import LLMRole
119+
from pure_auto_codeql.configuration import LLMRole
120120
llm_config = _get_llm_config_from_context(context, LLMRole.CHAT)
121121
analyzer = MultiAgentAnalyzer(llm_config)
122122
await analyzer.initialize(
@@ -197,7 +197,7 @@ def __init__(self):
197197

198198
async def execute(self, context: AnalysisContext) -> Any:
199199
"""执行Source分析。"""
200-
from config import LLMRole
200+
from pure_auto_codeql.configuration import LLMRole
201201
llm_config = _get_llm_config_from_context(context, LLMRole.CHAT)
202202
analyzer = MultiAgentAnalyzer(llm_config)
203203
await analyzer.initialize(
@@ -281,7 +281,7 @@ def __init__(self):
281281

282282
async def execute(self, context: AnalysisContext) -> Any:
283283
"""执行Path分析。"""
284-
from config import LLMRole
284+
from pure_auto_codeql.configuration import LLMRole
285285

286286
# 检查是否有 Source 分析结果
287287
if not context.has_result("source_analysis"):
@@ -405,7 +405,7 @@ async def execute(self, context: AnalysisContext) -> Any:
405405
logger.warning("Path 分析结果 JSON 解析失败")
406406

407407
# 使用推理模型
408-
from config import LLMRole
408+
from pure_auto_codeql.configuration import LLMRole
409409
think_config = _get_llm_config_from_context(context, LLMRole.THINK)
410410
codeql_analyzer = MultiAgentAnalyzer(think_config)
411411
await codeql_analyzer.initialize(
@@ -758,7 +758,7 @@ async def _run_path_selection(
758758
return None
759759

760760
try:
761-
from config import LLMRole
761+
from pure_auto_codeql.configuration import LLMRole
762762

763763
llm_config = _get_llm_config_from_context(context, LLMRole.CHAT)
764764
service = PathSelectionService(llm_config, language=context.language)

docs/config_migration_guide.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@ chat_config = get_chat_config()
4040
#### 新增的 API
4141

4242
```python
43+
from pure_auto_codeql.configuration import (
44+
LLMRole,
45+
ProviderRegistry,
46+
display_providers_status,
47+
get_llm_config,
48+
)
49+
4350
# 🆕 新增:指定服务商
4451
config = get_llm_config(LLMRole.THINK, provider_name="siliconflow")
4552

4653
# 🆕 新增:自动切换
4754
config = get_llm_config(LLMRole.THINK, auto_fallback=True)
4855

4956
# 🆕 新增:注册中心
50-
from config import ProviderRegistry
5157
providers = ProviderRegistry.list_all()
5258

5359
# 🆕 新增:美观展示
54-
from config import display_providers_status
5560
display_providers_status()
5661
```
5762

@@ -85,7 +90,7 @@ think_config = get_llm_config(LLMRole.THINK)
8590

8691
```python
8792
# 使用新的展示功能
88-
from config import display_providers_status
93+
from pure_auto_codeql.configuration import display_providers_status
8994

9095
# 查看当前配置状态
9196
display_providers_status()
@@ -115,7 +120,7 @@ chat_config = get_llm_config(LLMRole.CHAT)
115120

116121
**新代码(推荐):**
117122
```python
118-
from config import get_llm_config, LLMRole
123+
from pure_auto_codeql.configuration import get_llm_config, LLMRole
119124

120125
# 基本使用保持不变
121126
think_config = get_llm_config(LLMRole.THINK)
@@ -188,6 +193,13 @@ config = LLMConfig(
188193

189194
**新代码(更灵活):**
190195
```python
196+
from pure_auto_codeql.configuration import (
197+
LLMRole,
198+
ProviderConfig,
199+
ProviderRegistry,
200+
get_llm_config,
201+
)
202+
191203
# 方式 1: 使用 get_llm_config(推荐)
192204
config = get_llm_config(
193205
LLMRole.THINK,
@@ -197,8 +209,6 @@ config = get_llm_config(
197209
)
198210

199211
# 方式 2: 注册自定义服务商(更好的复用)
200-
from config import ProviderRegistry, ProviderConfig
201-
202212
ProviderRegistry.register(ProviderConfig(
203213
name="my_custom",
204214
display_name="My Custom Provider",
@@ -261,7 +271,10 @@ providers = list_available_providers() # 返回 dict 列表
261271

262272
```python
263273
# 新方式:使用 ProviderRegistry
264-
from config import ProviderRegistry
274+
from pure_auto_codeql.configuration import (
275+
ProviderRegistry,
276+
display_providers_status,
277+
)
265278

266279
# 获取所有服务商
267280
providers = ProviderRegistry.list_all() # 返回 ProviderConfig 对象列表
@@ -270,7 +283,6 @@ providers = ProviderRegistry.list_all() # 返回 ProviderConfig 对象列表
270283
available = ProviderRegistry.list_available()
271284

272285
# 美观展示
273-
from config import display_providers_status
274286
display_providers_status()
275287
```
276288

@@ -299,7 +311,11 @@ python config.py test siliconflow
299311

300312
```python
301313
# test_config_migration.py
302-
from config import get_llm_config, LLMRole, display_providers_status
314+
from pure_auto_codeql.configuration import (
315+
LLMRole,
316+
display_providers_status,
317+
get_llm_config,
318+
)
303319

304320
def test_basic():
305321
"""测试基本用法"""
@@ -378,4 +394,3 @@ A: 如果您只使用了 `get_llm_config()`、`get_think_config()`、`get_chat_c
378394
- ✅ 逐步迁移,无压力
379395

380396
欢迎使用新的配置系统!🎉
381-

0 commit comments

Comments
 (0)