Skip to content

Commit ba3cea3

Browse files
committed
refactor(pipeline): split core/pipeline.py into cohesive package
Behavior-preserving package split of the 867-line pipeline.py: - _llm_config.py: _get_llm_config_from_context - base.py: AnalysisStep ABC - steps.py: the five concrete AnalysisStep implementations - executor.py: AnalysisPipeline orchestrator - tags.py: sanitize_tag __init__.py re-exports the full public surface. All 17 defs/classes verified byte-identical via AST. 97 passed / 2 skipped, ruff clean.
1 parent 103dcb5 commit ba3cea3

6 files changed

Lines changed: 498 additions & 440 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""分析流水线模块
2+
提供分析步骤的定义和流水线执行功能。
3+
"""
4+
5+
from ._llm_config import _get_llm_config_from_context
6+
from .base import AnalysisStep
7+
from .executor import AnalysisPipeline
8+
from .steps import (
9+
CodeQLGenerationStep,
10+
CVEAnalysisStep,
11+
PathAnalysisStep,
12+
SinkAnalysisStep,
13+
SourceAnalysisStep,
14+
)
15+
from .tags import sanitize_tag
16+
17+
__all__ = [
18+
"AnalysisStep",
19+
"AnalysisPipeline",
20+
"CVEAnalysisStep",
21+
"SinkAnalysisStep",
22+
"SourceAnalysisStep",
23+
"PathAnalysisStep",
24+
"CodeQLGenerationStep",
25+
"sanitize_tag",
26+
"_get_llm_config_from_context",
27+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""流水线的 LLM 配置解析。"""
2+
3+
from typing import Any
4+
5+
from ..context import AnalysisContext
6+
7+
8+
def _get_llm_config_from_context(context: AnalysisContext, role) -> Any:
9+
"""从上下文中获取LLM配置,支持配置中的模型、API Key和Base URL"""
10+
config = getattr(context, '_config', None)
11+
if not config:
12+
from pure_auto_codeql.configuration import LLMRole, get_resilient_llm_config
13+
return get_resilient_llm_config(role)
14+
15+
from pure_auto_codeql.configuration import LLMRole, get_llm_config
16+
# 从配置中获取参数
17+
provider = config.llm_provider
18+
model_name = config.think_model if role == LLMRole.THINK else config.chat_model
19+
api_key = config.api_key
20+
base_url = config.base_url
21+
22+
return get_llm_config(
23+
role,
24+
provider_name=provider,
25+
model_name=model_name,
26+
api_key=api_key,
27+
base_url=base_url
28+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""分析步骤抽象基类。"""
2+
3+
from abc import ABC, abstractmethod
4+
from typing import Any
5+
6+
from ..context import AnalysisContext
7+
8+
9+
class AnalysisStep(ABC):
10+
"""分析步骤抽象基类。"""
11+
12+
def __init__(self, name: str, agent_name: str = None):
13+
self.name = name
14+
self.agent_name = agent_name or name
15+
16+
@abstractmethod
17+
async def execute(self, context: AnalysisContext) -> Any:
18+
"""执行分析步骤。"""
19+
pass

0 commit comments

Comments
 (0)