vcode-analysis 0.12.0__tar.gz → 0.13.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.12.0/vcode_analysis.egg-info → vcode_analysis-0.13.0}/PKG-INFO +1 -1
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/cli.py +27 -6
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/analyzer.py +5 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/config.py +70 -3
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/llm_client.py +84 -3
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/pyproject.toml +1 -1
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0/vcode_analysis.egg-info}/PKG-INFO +1 -1
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_mcp/server.py +1 -1
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_mcp/tool_handler.py +2 -2
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/LICENSE +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/MANIFEST.in +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/README.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/_tuning_context.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/architecture.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/code_review.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/context_builder.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/directory.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/documentation.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/duplication.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/knowledge_graph.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/security.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/analyzers/security_ast.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/batch_analyzer.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/batch_planner.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/cache_manager.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/feedback_hub.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/git_handler.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/ignore.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/json_utils.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/metrics_store.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompt_manager.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/architecture.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/batch_review.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/code_review.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/code_review_v2.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/commit_review.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/documentation/api.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/documentation/module.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/documentation/readme.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/duplication_refactor.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/mcp/code_review_checklist.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/mcp/mr_review_template.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/mcp/vuln_tuning_advisor.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/prompts/security_analysis.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/report_generator.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/core/token_estimator.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/2026-stage-highlights.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/PPT/345/244/247/347/272/262-VCode_Analysis_/346/231/272/350/203/275/344/273/243/347/240/201/345/210/206/346/236/220/345/267/245/345/205/267/345/210/206/344/272/253.md" +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/PPT/347/224/237/346/210/220/346/217/220/347/244/272/350/257/215-VCode_Analysis/345/210/206/344/272/253.md" +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/USER_MANUAL.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/batch-cache-optimization.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/c-parser-design.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/code-knowledge-graph.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/critical-severity.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/expert-review-response-2026-07.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/kotlin-parser-design.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/prompt-externalization.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/three-year-roadmap.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/vcode-analysis-tool.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/review-scenarios.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/security-sharing-article.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/severity-standard.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/superpowers/plans/2026-07-22-expert-review-response.md +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs//350/207/252/350/215/220/344/272/256/347/202/271/350/257/264/346/230/216.md" +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/c/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/c/ast_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/c/models.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/c/patterns.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/c/regex_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/c_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/java_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/javascript_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/kotlin/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/kotlin/ast_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/kotlin/models.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/kotlin/patterns.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/kotlin/regex_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/kotlin_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/python_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/sql_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/parsers/typescript_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/requirements.txt +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/setup.cfg +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_batch_operations.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_c_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_context_builder_sql.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_duplication.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_kotlin_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_llm_client.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_mcp_tools.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_metrics_store.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_prompt_manager.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_report_generator.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_security_rules.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/tests/test_sql_parser.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_analysis.egg-info/SOURCES.txt +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_analysis.egg-info/dependency_links.txt +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_analysis.egg-info/entry_points.txt +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_analysis.egg-info/requires.txt +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_analysis.egg-info/top_level.txt +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_mcp/__init__.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_mcp/prompt_handler.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_mcp/resource_handler.py +0 -0
- {vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_mcp/transports/__init__.py +0 -0
|
@@ -18,7 +18,7 @@ Usage:
|
|
|
18
18
|
vcode-analysis feedback <issue-id> --status <status> [--note <text>] [options]
|
|
19
19
|
vcode-analysis feedback pending [--limit <n>] [options]
|
|
20
20
|
vcode-analysis feedback import <file> [options]
|
|
21
|
-
vcode-analysis config [--show] [--init]
|
|
21
|
+
vcode-analysis config [--show] [--init] [options]
|
|
22
22
|
vcode-analysis --version
|
|
23
23
|
|
|
24
24
|
Commands:
|
|
@@ -40,6 +40,9 @@ Commands:
|
|
|
40
40
|
|
|
41
41
|
Options:
|
|
42
42
|
-c, --config <file> 配置文件路径
|
|
43
|
+
-v, --verbose 输出详细调试日志(LLM 请求/响应/失败原因等,排查问题用)
|
|
44
|
+
--log-full 配合 --verbose 打印完整请求头/请求体(含真实 API Key,默认脱敏)
|
|
45
|
+
--insecure 忽略 HTTPS 证书校验(自签名证书的 base_url 用;等价 CODE_ANALYSIS_VERIFY_SSL=0)
|
|
43
46
|
--prompts-dir <dir> 自定义提示词目录(与内置提示词叠加,同名覆盖)
|
|
44
47
|
--path <path> 仓库路径 (review-commit 使用)
|
|
45
48
|
--type <type> 文档类型 (doc 使用, 默认: module)
|
|
@@ -79,6 +82,7 @@ Options:
|
|
|
79
82
|
from __future__ import annotations
|
|
80
83
|
|
|
81
84
|
import sys
|
|
85
|
+
import os
|
|
82
86
|
import json
|
|
83
87
|
import time
|
|
84
88
|
import threading
|
|
@@ -112,6 +116,7 @@ from core import (
|
|
|
112
116
|
)
|
|
113
117
|
from core.report_generator import ReviewReportGenerator
|
|
114
118
|
from core.ignore import get_default_ignore_patterns
|
|
119
|
+
from core.config import setup_logging
|
|
115
120
|
from analyzers import (
|
|
116
121
|
CodeReviewAnalyzer, DocumentationAnalyzer,
|
|
117
122
|
ArchitectureAnalyzer, SecurityAnalyzer, DirectoryAnalyzer,
|
|
@@ -119,7 +124,7 @@ from analyzers import (
|
|
|
119
124
|
)
|
|
120
125
|
|
|
121
126
|
|
|
122
|
-
__version__ = "0.
|
|
127
|
+
__version__ = "0.13.0"
|
|
123
128
|
|
|
124
129
|
|
|
125
130
|
def _timestamp() -> str:
|
|
@@ -152,6 +157,10 @@ def _format_duration(seconds: float) -> str:
|
|
|
152
157
|
return f"{hours}h {mins}m"
|
|
153
158
|
|
|
154
159
|
|
|
160
|
+
# 详细日志开关(--verbose 开启,控制 _log(..., "DEBUG") 是否输出)
|
|
161
|
+
_VERBOSE = False
|
|
162
|
+
|
|
163
|
+
|
|
155
164
|
def _log(message: str, level: str = "INFO") -> None:
|
|
156
165
|
"""打印带时间戳和级别的日志"""
|
|
157
166
|
level_styles = {
|
|
@@ -163,6 +172,8 @@ def _log(message: str, level: str = "INFO") -> None:
|
|
|
163
172
|
"END": ("<<< ", ""),
|
|
164
173
|
"DEBUG": (" -> ", ""),
|
|
165
174
|
}
|
|
175
|
+
if level == "DEBUG" and not _VERBOSE:
|
|
176
|
+
return
|
|
166
177
|
prefix, _ = level_styles.get(level, ("", ""))
|
|
167
178
|
print(f"[{_timestamp()}] {prefix}{message}")
|
|
168
179
|
|
|
@@ -538,7 +549,7 @@ def cmd_review(args: dict) -> int:
|
|
|
538
549
|
reviewer.metrics_store = _metrics_store
|
|
539
550
|
reviewer._current_run_id = _metrics_store.record_scan_run(ScanRun(
|
|
540
551
|
repo_path=str(Path(target_path).resolve()),
|
|
541
|
-
analyzer="code_review", tool_version="0.
|
|
552
|
+
analyzer="code_review", tool_version="0.13.0",
|
|
542
553
|
))
|
|
543
554
|
_log_section("分析中(逐文件模式)")
|
|
544
555
|
_log(f"开始分析 {total} 个文件...", "START")
|
|
@@ -648,7 +659,7 @@ def cmd_review(args: dict) -> int:
|
|
|
648
659
|
_metrics_store = MetricsStore(_metrics_db)
|
|
649
660
|
_run_id = _metrics_store.record_scan_run(ScanRun(
|
|
650
661
|
repo_path=str(Path(target_path).resolve()),
|
|
651
|
-
analyzer="code_review", tool_version="0.
|
|
662
|
+
analyzer="code_review", tool_version="0.13.0",
|
|
652
663
|
))
|
|
653
664
|
for r in results:
|
|
654
665
|
if r.success and r.issues:
|
|
@@ -816,7 +827,7 @@ def cmd_review_commit(args: dict) -> int:
|
|
|
816
827
|
_metrics_store = MetricsStore(_metrics_db)
|
|
817
828
|
_run_id = _metrics_store.record_scan_run(ScanRun(
|
|
818
829
|
repo_path=str(Path(target_path).resolve()),
|
|
819
|
-
analyzer="code_review", tool_version="0.
|
|
830
|
+
analyzer="code_review", tool_version="0.13.0",
|
|
820
831
|
))
|
|
821
832
|
|
|
822
833
|
with Analyzer(config) as analyzer:
|
|
@@ -1358,7 +1369,7 @@ def cmd_security(args: dict) -> int:
|
|
|
1358
1369
|
security.metrics_store = _metrics_store
|
|
1359
1370
|
security._current_run_id = _metrics_store.record_scan_run(ScanRun(
|
|
1360
1371
|
repo_path=str(Path(target_path).resolve()),
|
|
1361
|
-
analyzer="security", tool_version="0.
|
|
1372
|
+
analyzer="security", tool_version="0.13.0",
|
|
1362
1373
|
))
|
|
1363
1374
|
results = security.scan_project(target_path, deep=deep_scan, log_callback=_log)
|
|
1364
1375
|
scan_time = time.time() - scan_start
|
|
@@ -2303,6 +2314,16 @@ def main():
|
|
|
2303
2314
|
print(f" 提示: 你是不是想用 {matched_opts[0]} ?")
|
|
2304
2315
|
print()
|
|
2305
2316
|
|
|
2317
|
+
# 详细日志开关:控制 _log(DEBUG) 与 llm/analyzer 等 logger 的 DEBUG 输出
|
|
2318
|
+
global _VERBOSE
|
|
2319
|
+
_VERBOSE = bool(args.get("--verbose"))
|
|
2320
|
+
# docopt 对未提供的布尔参数返回 False,这里转成 None 以便 setup_logging 回落到环境变量
|
|
2321
|
+
setup_logging(verbose=_VERBOSE, log_full=args.get("--log-full") or None)
|
|
2322
|
+
|
|
2323
|
+
# --insecure:忽略 HTTPS 证书校验,通过环境变量桥接(对所有命令/多模型统一生效)
|
|
2324
|
+
if args.get("--insecure"):
|
|
2325
|
+
os.environ["CODE_ANALYSIS_VERIFY_SSL"] = "0"
|
|
2326
|
+
|
|
2306
2327
|
if args.get("--version"):
|
|
2307
2328
|
print(f"code-analysis {__version__}")
|
|
2308
2329
|
return 0
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from pathlib import Path
|
|
7
|
+
import logging
|
|
7
8
|
from dataclasses import dataclass, field
|
|
8
9
|
from typing import Optional, Iterator, Callable, Any
|
|
9
10
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
@@ -187,6 +188,7 @@ class Analyzer:
|
|
|
187
188
|
**extra_context
|
|
188
189
|
) -> AnalysisResult:
|
|
189
190
|
"""分析单个文件"""
|
|
191
|
+
logger = logging.getLogger("analyzer")
|
|
190
192
|
try:
|
|
191
193
|
content = self.read_file_content(file_info)
|
|
192
194
|
|
|
@@ -197,8 +199,10 @@ class Analyzer:
|
|
|
197
199
|
content=content,
|
|
198
200
|
**extra_context,
|
|
199
201
|
)
|
|
202
|
+
logger.debug("开始 LLM 分析: %s (提示词 %d 字符)", file_info.relative_path, len(prompt))
|
|
200
203
|
|
|
201
204
|
response = self.llm.simple_chat(prompt)
|
|
205
|
+
logger.debug("LLM 分析完成: %s (输出 %d 字符)", file_info.relative_path, len(response))
|
|
202
206
|
|
|
203
207
|
return AnalysisResult(
|
|
204
208
|
file_path=file_info.relative_path,
|
|
@@ -208,6 +212,7 @@ class Analyzer:
|
|
|
208
212
|
)
|
|
209
213
|
|
|
210
214
|
except Exception as e:
|
|
215
|
+
logger.debug("LLM 分析失败: %s 异常=%s: %s", file_info.relative_path, type(e).__name__, str(e), exc_info=True)
|
|
211
216
|
return AnalysisResult(
|
|
212
217
|
file_path=file_info.relative_path,
|
|
213
218
|
analyzer="generic",
|
|
@@ -25,6 +25,54 @@ except ImportError:
|
|
|
25
25
|
|
|
26
26
|
logger = logging.getLogger("config")
|
|
27
27
|
|
|
28
|
+
# 日志完整模式开关:True 时打印完整请求头/请求体(含真实 API Key),默认仅脱敏打印
|
|
29
|
+
_LOG_FULL = False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def set_log_full(enabled: bool) -> None:
|
|
33
|
+
"""设置日志完整模式(--log-full / CODE_ANALYSIS_LOG_FULL 会调用)"""
|
|
34
|
+
global _LOG_FULL
|
|
35
|
+
_LOG_FULL = bool(enabled)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def is_log_full() -> bool:
|
|
39
|
+
"""当前是否处于日志完整模式"""
|
|
40
|
+
return _LOG_FULL
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _env_flag(name: str, default: bool = False) -> bool:
|
|
44
|
+
"""读取布尔型环境变量(1/true/yes/on 视为 True)"""
|
|
45
|
+
val = os.environ.get(name, "").strip().lower()
|
|
46
|
+
if not val:
|
|
47
|
+
return default
|
|
48
|
+
return val in ("1", "true", "yes", "on")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def setup_logging(verbose: bool = False, log_full: Optional[bool] = None) -> None:
|
|
52
|
+
"""初始化全局日志配置
|
|
53
|
+
|
|
54
|
+
项目默认不初始化 logging,导致 llm / security.deep_scan / config 等 logger
|
|
55
|
+
的 DEBUG 日志全部被吞掉,排查 LLM 调用失败时看不到原因。
|
|
56
|
+
|
|
57
|
+
- verbose=True: 输出 DEBUG 级别(请求/响应/失败详情)
|
|
58
|
+
- verbose=False: 仅输出 WARNING 及以上(如模型降级冷却警告)
|
|
59
|
+
- log_full=True: 打印完整请求头/请求体(含真实 API Key)
|
|
60
|
+
- log_full=False/None: 打印脱敏请求头(API Key 打码)+ 截断请求体
|
|
61
|
+
log_full 未显式指定时,读取环境变量 CODE_ANALYSIS_LOG_FULL=1 开启完整模式
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
verbose: 是否输出详细调试日志
|
|
65
|
+
log_full: 是否打印完整(非脱敏)请求头/请求体
|
|
66
|
+
"""
|
|
67
|
+
if log_full is None:
|
|
68
|
+
log_full = _env_flag("CODE_ANALYSIS_LOG_FULL")
|
|
69
|
+
set_log_full(log_full)
|
|
70
|
+
logging.basicConfig(
|
|
71
|
+
level=logging.DEBUG if verbose else logging.WARNING,
|
|
72
|
+
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
73
|
+
force=True,
|
|
74
|
+
)
|
|
75
|
+
|
|
28
76
|
|
|
29
77
|
@dataclass
|
|
30
78
|
class LLMConfig:
|
|
@@ -37,6 +85,7 @@ class LLMConfig:
|
|
|
37
85
|
timeout: int = 180 # 增加到3分钟
|
|
38
86
|
custom_headers: dict = field(default_factory=dict) # 自定义请求头
|
|
39
87
|
chat_path: str = "/chat/completions" # 聊天请求路径(可自定义,base_url 后的 path)
|
|
88
|
+
verify_ssl: bool = True # HTTPS 是否校验证书(自签名证书可设为 False,或 CLI 用 --insecure)
|
|
40
89
|
|
|
41
90
|
|
|
42
91
|
@dataclass
|
|
@@ -252,6 +301,7 @@ class Config:
|
|
|
252
301
|
"CODE_ANALYSIS_TEMPERATURE": ("llm", "temperature"),
|
|
253
302
|
"CODE_ANALYSIS_MAX_TOKENS": ("llm", "max_tokens"),
|
|
254
303
|
"CODE_ANALYSIS_CHAT_PATH": ("llm", "chat_path"),
|
|
304
|
+
"CODE_ANALYSIS_VERIFY_SSL": ("llm", "verify_ssl"),
|
|
255
305
|
"CODE_ANALYSIS_PROMPTS_DIR": ("_prompts_dir", "prompts_dir"),
|
|
256
306
|
}
|
|
257
307
|
|
|
@@ -263,9 +313,11 @@ class Config:
|
|
|
263
313
|
self.prompts_dir = value
|
|
264
314
|
continue
|
|
265
315
|
target = self.llm if section == "llm" else self.analysis
|
|
266
|
-
#
|
|
316
|
+
# 类型转换(注意 bool 需在 int 之前判断,True 是 int 的子类)
|
|
267
317
|
current_value = getattr(target, attr)
|
|
268
|
-
if isinstance(current_value,
|
|
318
|
+
if isinstance(current_value, bool):
|
|
319
|
+
value = value.strip().lower() in ("1", "true", "yes", "on")
|
|
320
|
+
elif isinstance(current_value, int):
|
|
269
321
|
value = int(value)
|
|
270
322
|
elif isinstance(current_value, float):
|
|
271
323
|
value = float(value)
|
|
@@ -289,11 +341,18 @@ class Config:
|
|
|
289
341
|
value = os.environ.get(env_key)
|
|
290
342
|
if value:
|
|
291
343
|
current_value = getattr(self.llm_models.models[0], attr)
|
|
292
|
-
if isinstance(current_value,
|
|
344
|
+
if isinstance(current_value, bool):
|
|
345
|
+
value = value.strip().lower() in ("1", "true", "yes", "on")
|
|
346
|
+
elif isinstance(current_value, int):
|
|
293
347
|
value = int(value)
|
|
294
348
|
elif isinstance(current_value, float):
|
|
295
349
|
value = float(value)
|
|
296
350
|
setattr(self.llm_models.models[0], attr, value)
|
|
351
|
+
# verify_ssl 是全局安全设置,环境变量对全部模型生效(而不只是主模型)
|
|
352
|
+
ssl_val = os.environ.get("CODE_ANALYSIS_VERIFY_SSL")
|
|
353
|
+
if ssl_val:
|
|
354
|
+
for m in self.llm_models.models:
|
|
355
|
+
m.verify_ssl = ssl_val.strip().lower() in ("1", "true", "yes", "on")
|
|
297
356
|
|
|
298
357
|
def apply_cli_overrides(self, **kwargs) -> None:
|
|
299
358
|
"""应用 CLI 参数覆盖"""
|
|
@@ -316,6 +375,8 @@ class Config:
|
|
|
316
375
|
logger.warning("--headers 不是合法的 JSON 对象,已忽略")
|
|
317
376
|
if kwargs.get("chat_path"):
|
|
318
377
|
self.llm.chat_path = kwargs["chat_path"]
|
|
378
|
+
if kwargs.get("insecure"):
|
|
379
|
+
self.llm.verify_ssl = False
|
|
319
380
|
if kwargs.get("target_path"):
|
|
320
381
|
self.target_path = kwargs["target_path"]
|
|
321
382
|
if kwargs.get("output_format"):
|
|
@@ -346,6 +407,10 @@ class Config:
|
|
|
346
407
|
pass
|
|
347
408
|
if kwargs.get("chat_path"):
|
|
348
409
|
self.llm_models.models[0].chat_path = kwargs["chat_path"]
|
|
410
|
+
if kwargs.get("insecure"):
|
|
411
|
+
# --insecure 是全局设置,对全部模型生效
|
|
412
|
+
for m in self.llm_models.models:
|
|
413
|
+
m.verify_ssl = False
|
|
349
414
|
|
|
350
415
|
@classmethod
|
|
351
416
|
def create(cls, **cli_kwargs) -> "Config":
|
|
@@ -382,6 +447,7 @@ class Config:
|
|
|
382
447
|
"max_tokens": self.llm.max_tokens,
|
|
383
448
|
"custom_headers": self.llm.custom_headers,
|
|
384
449
|
"chat_path": self.llm.chat_path,
|
|
450
|
+
"verify_ssl": self.llm.verify_ssl,
|
|
385
451
|
},
|
|
386
452
|
"analysis": {
|
|
387
453
|
"max_file_size": self.analysis.max_file_size,
|
|
@@ -411,6 +477,7 @@ class Config:
|
|
|
411
477
|
"max_tokens": m.max_tokens,
|
|
412
478
|
"timeout": m.timeout,
|
|
413
479
|
"custom_headers": m.custom_headers,
|
|
480
|
+
"verify_ssl": m.verify_ssl,
|
|
414
481
|
}
|
|
415
482
|
for m in self.llm_models.models
|
|
416
483
|
],
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import time
|
|
7
|
+
import json
|
|
7
8
|
import logging
|
|
8
9
|
import threading
|
|
9
10
|
from typing import Optional, Generator
|
|
@@ -16,9 +17,55 @@ except ImportError:
|
|
|
16
17
|
httpx = None
|
|
17
18
|
HTTPX_AVAILABLE = False
|
|
18
19
|
|
|
20
|
+
from .config import is_log_full
|
|
21
|
+
|
|
19
22
|
logger = logging.getLogger("llm")
|
|
20
23
|
|
|
21
24
|
|
|
25
|
+
def _mask_secret(value: str) -> str:
|
|
26
|
+
"""脱敏:密钥类字符串只保留前 4 后 4,中间打码"""
|
|
27
|
+
if not value:
|
|
28
|
+
return value
|
|
29
|
+
prefix = ""
|
|
30
|
+
if value.startswith("Bearer "):
|
|
31
|
+
prefix = "Bearer "
|
|
32
|
+
value = value[len("Bearer "):]
|
|
33
|
+
if len(value) <= 8:
|
|
34
|
+
return prefix + value[0] + "***"
|
|
35
|
+
return prefix + value[:4] + "***" + value[-4:]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _mask_headers(headers: dict) -> dict:
|
|
39
|
+
"""对请求头脱敏:Authorization/Cookie 等敏感头的值打码,其余原样"""
|
|
40
|
+
sensitive = {
|
|
41
|
+
"authorization", "api-key", "x-api-key", "cookie",
|
|
42
|
+
"proxy-authorization", "x-auth-token",
|
|
43
|
+
}
|
|
44
|
+
masked = {}
|
|
45
|
+
for k, v in (headers or {}).items():
|
|
46
|
+
key = str(k)
|
|
47
|
+
if key.lower() in sensitive:
|
|
48
|
+
masked[key] = _mask_secret(str(v))
|
|
49
|
+
else:
|
|
50
|
+
masked[key] = str(v)
|
|
51
|
+
return masked
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _format_payload_for_log(payload: dict, max_content: int = 500) -> dict:
|
|
55
|
+
"""格式化请求体用于日志:超长 message content 截断,避免刷屏"""
|
|
56
|
+
log_payload = dict(payload)
|
|
57
|
+
messages = log_payload.get("messages")
|
|
58
|
+
if isinstance(messages, list):
|
|
59
|
+
truncated = []
|
|
60
|
+
for m in messages:
|
|
61
|
+
content = m.get("content") or ""
|
|
62
|
+
if len(content) > max_content:
|
|
63
|
+
content = content[:max_content] + f"…(截断,共{len(content)}字符)"
|
|
64
|
+
truncated.append({**m, "content": content})
|
|
65
|
+
log_payload["messages"] = truncated
|
|
66
|
+
return log_payload
|
|
67
|
+
|
|
68
|
+
|
|
22
69
|
class AllModelsFailedError(Exception):
|
|
23
70
|
"""所有模型均请求失败"""
|
|
24
71
|
|
|
@@ -60,6 +107,7 @@ class LLMClient:
|
|
|
60
107
|
timeout: int = 120,
|
|
61
108
|
custom_headers: dict = None,
|
|
62
109
|
chat_path: str = "/chat/completions",
|
|
110
|
+
verify_ssl: bool = True,
|
|
63
111
|
):
|
|
64
112
|
if not HTTPX_AVAILABLE:
|
|
65
113
|
raise ImportError("请安装 httpx: pip install httpx")
|
|
@@ -72,9 +120,10 @@ class LLMClient:
|
|
|
72
120
|
self.timeout = timeout
|
|
73
121
|
self.custom_headers = dict(custom_headers or {})
|
|
74
122
|
self.chat_path = chat_path
|
|
123
|
+
self.verify_ssl = verify_ssl
|
|
75
124
|
|
|
76
|
-
# HTTP
|
|
77
|
-
self._client = httpx.Client(timeout=timeout)
|
|
125
|
+
# HTTP 客户端(verify_ssl=False 时忽略 HTTPS 证书校验,用于自签名证书场景)
|
|
126
|
+
self._client = httpx.Client(timeout=timeout, verify=verify_ssl)
|
|
78
127
|
|
|
79
128
|
def _build_url(self) -> str:
|
|
80
129
|
"""构建聊天端点 URL(支持配置 base_url 后的 path)
|
|
@@ -131,6 +180,21 @@ class LLMClient:
|
|
|
131
180
|
payload = self._build_payload(messages, stream=False, **kwargs)
|
|
132
181
|
# print(payload)
|
|
133
182
|
|
|
183
|
+
logger.debug(
|
|
184
|
+
"LLM 请求: url=%s model=%s messages=%d 输入字符=%d temperature=%s max_tokens=%s",
|
|
185
|
+
url, self.model, len(messages),
|
|
186
|
+
sum(len(m.content or "") for m in messages),
|
|
187
|
+
payload.get("temperature"), payload.get("max_tokens"),
|
|
188
|
+
)
|
|
189
|
+
if is_log_full():
|
|
190
|
+
# 完整模式:打印真实请求头(含 API Key)与完整请求体
|
|
191
|
+
logger.debug("LLM 请求头: %s", headers)
|
|
192
|
+
logger.debug("LLM 请求体: %s", payload)
|
|
193
|
+
else:
|
|
194
|
+
# 默认脱敏模式:API Key 打码,超长请求体截断
|
|
195
|
+
logger.debug("LLM 请求头(脱敏): %s", _mask_headers(headers))
|
|
196
|
+
logger.debug("LLM 请求体(截断): %s", _format_payload_for_log(payload))
|
|
197
|
+
|
|
134
198
|
start_time = time.time()
|
|
135
199
|
try:
|
|
136
200
|
response = self._client.post(url, headers=headers, json=payload)
|
|
@@ -138,6 +202,11 @@ class LLMClient:
|
|
|
138
202
|
response.raise_for_status()
|
|
139
203
|
except Exception as e:
|
|
140
204
|
latency_ms = (time.time() - start_time) * 1000
|
|
205
|
+
logger.debug(
|
|
206
|
+
"LLM 请求异常: url=%s 延迟=%.0fms 异常=%s: %s",
|
|
207
|
+
url, latency_ms, type(e).__name__, str(e),
|
|
208
|
+
exc_info=True,
|
|
209
|
+
)
|
|
141
210
|
error_msg = str(e)
|
|
142
211
|
# 提供更有意义的错误信息
|
|
143
212
|
if "504" in error_msg or "Gateway Time-out" in error_msg:
|
|
@@ -153,12 +222,16 @@ class LLMClient:
|
|
|
153
222
|
raise
|
|
154
223
|
|
|
155
224
|
latency_ms = (time.time() - start_time) * 1000
|
|
225
|
+
logger.debug(
|
|
226
|
+
"LLM 响应: url=%s status=%d 延迟=%.0fms", url, response.status_code, latency_ms
|
|
227
|
+
)
|
|
156
228
|
|
|
157
229
|
# 处理可能返回的 SSE 格式响应
|
|
158
230
|
content = response.text
|
|
159
231
|
if content.startswith("data:"):
|
|
160
232
|
# SSE 格式,解析流式响应
|
|
161
233
|
full_content = self._parse_sse_response(content)
|
|
234
|
+
logger.debug("LLM 响应内容(SSE): 输出字符=%d", len(full_content))
|
|
162
235
|
return ChatResponse(
|
|
163
236
|
content=full_content,
|
|
164
237
|
model=self.model,
|
|
@@ -168,10 +241,15 @@ class LLMClient:
|
|
|
168
241
|
|
|
169
242
|
# 标准 JSON 格式
|
|
170
243
|
data = response.json()
|
|
244
|
+
usage = data.get("usage", {})
|
|
245
|
+
logger.debug(
|
|
246
|
+
"LLM 响应内容(JSON): 输出字符=%d usage=%s",
|
|
247
|
+
len(data["choices"][0]["message"]["content"] or ""), usage,
|
|
248
|
+
)
|
|
171
249
|
return ChatResponse(
|
|
172
250
|
content=data["choices"][0]["message"]["content"],
|
|
173
251
|
model=data.get("model", self.model),
|
|
174
|
-
usage=
|
|
252
|
+
usage=usage,
|
|
175
253
|
latency_ms=latency_ms,
|
|
176
254
|
)
|
|
177
255
|
|
|
@@ -274,6 +352,7 @@ class FallbackLLMClient:
|
|
|
274
352
|
timeout=cfg.timeout,
|
|
275
353
|
custom_headers=getattr(cfg, "custom_headers", None),
|
|
276
354
|
chat_path=getattr(cfg, "chat_path", "/chat/completions"),
|
|
355
|
+
verify_ssl=getattr(cfg, "verify_ssl", True),
|
|
277
356
|
))
|
|
278
357
|
self._model_names.append(cfg.model)
|
|
279
358
|
|
|
@@ -367,6 +446,7 @@ class FallbackLLMClient:
|
|
|
367
446
|
result = getattr(client, method_name)(*args, **kwargs)
|
|
368
447
|
with self._lock:
|
|
369
448
|
self._clear_cooldown(available)
|
|
449
|
+
logger.debug("模型 [%s] 请求成功", name)
|
|
370
450
|
return result
|
|
371
451
|
except Exception as e:
|
|
372
452
|
error_class = self._classify_error(e)
|
|
@@ -384,6 +464,7 @@ class FallbackLLMClient:
|
|
|
384
464
|
self._mark_cooldown(available)
|
|
385
465
|
break
|
|
386
466
|
|
|
467
|
+
logger.debug("所有模型均失败: %d 个错误", len(errors))
|
|
387
468
|
raise AllModelsFailedError(errors)
|
|
388
469
|
|
|
389
470
|
def chat(self, messages: list[ChatMessage], **kwargs) -> ChatResponse:
|
|
@@ -8,7 +8,7 @@ from vcode_mcp.prompt_handler import PROMPTS
|
|
|
8
8
|
from vcode_mcp.resource_handler import read_metrics_summary, read_report, read_rule
|
|
9
9
|
from vcode_mcp.tool_handler import handle_tool
|
|
10
10
|
|
|
11
|
-
mcp = MCPServer("vcode-analysis", version="0.
|
|
11
|
+
mcp = MCPServer("vcode-analysis", version="0.13.0")
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
# ── Tools ────────────────────────────────────────────────────────
|
|
@@ -63,7 +63,7 @@ def _run_review(target: str, config, args: dict) -> list[dict]:
|
|
|
63
63
|
reviewer.metrics_store = ms
|
|
64
64
|
reviewer._current_run_id = ms.record_scan_run(ScanRun(
|
|
65
65
|
repo_path=str(Path(target).resolve()), analyzer="code_review",
|
|
66
|
-
tool_version="0.
|
|
66
|
+
tool_version="0.13.0",
|
|
67
67
|
))
|
|
68
68
|
|
|
69
69
|
path = Path(target)
|
|
@@ -101,7 +101,7 @@ def _run_security(target: str, config, args: dict) -> list[dict]:
|
|
|
101
101
|
scanner.metrics_store = ms
|
|
102
102
|
scanner._current_run_id = ms.record_scan_run(ScanRun(
|
|
103
103
|
repo_path=str(Path(target).resolve()), analyzer="security",
|
|
104
|
-
tool_version="0.
|
|
104
|
+
tool_version="0.13.0",
|
|
105
105
|
))
|
|
106
106
|
|
|
107
107
|
path = Path(target)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/docs/design/expert-review-response-2026-07.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vcode_analysis-0.12.0 → vcode_analysis-0.13.0}/vcode_analysis.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|