vcode-analysis 0.8.0__tar.gz → 0.10.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.
Files changed (104) hide show
  1. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/MANIFEST.in +1 -0
  2. {vcode_analysis-0.8.0/vcode_analysis.egg-info → vcode_analysis-0.10.0}/PKG-INFO +1 -1
  3. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/cli.py +84 -29
  4. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/config.py +33 -9
  5. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/prompt_manager.py +79 -11
  6. vcode_analysis-0.10.0/core/prompts/__init__.py +1 -0
  7. vcode_analysis-0.10.0/core/prompts/architecture.md +27 -0
  8. vcode_analysis-0.10.0/core/prompts/batch_review.md +22 -0
  9. vcode_analysis-0.10.0/core/prompts/code_review.md +31 -0
  10. vcode_analysis-0.10.0/core/prompts/code_review_v2.md +37 -0
  11. vcode_analysis-0.10.0/core/prompts/commit_review.md +49 -0
  12. vcode_analysis-0.10.0/core/prompts/documentation/api.md +28 -0
  13. vcode_analysis-0.10.0/core/prompts/documentation/module.md +33 -0
  14. vcode_analysis-0.10.0/core/prompts/documentation/readme.md +42 -0
  15. vcode_analysis-0.10.0/core/prompts/mcp/code_review_checklist.md +16 -0
  16. vcode_analysis-0.10.0/core/prompts/mcp/mr_review_template.md +15 -0
  17. vcode_analysis-0.10.0/core/prompts/mcp/vuln_tuning_advisor.md +14 -0
  18. vcode_analysis-0.10.0/core/prompts/security_analysis.md +61 -0
  19. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/pyproject.toml +5 -1
  20. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0/vcode_analysis.egg-info}/PKG-INFO +1 -1
  21. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_analysis.egg-info/SOURCES.txt +13 -0
  22. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_mcp/server.py +1 -1
  23. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_mcp/tool_handler.py +2 -2
  24. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/LICENSE +0 -0
  25. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/README.md +0 -0
  26. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/__init__.py +0 -0
  27. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/_tuning_context.py +0 -0
  28. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/architecture.py +0 -0
  29. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/code_review.py +0 -0
  30. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/context_builder.py +0 -0
  31. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/directory.py +0 -0
  32. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/documentation.py +0 -0
  33. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/knowledge_graph.py +0 -0
  34. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/security.py +0 -0
  35. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/analyzers/security_ast.py +0 -0
  36. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/__init__.py +0 -0
  37. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/analyzer.py +0 -0
  38. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/batch_analyzer.py +0 -0
  39. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/batch_planner.py +0 -0
  40. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/cache_manager.py +0 -0
  41. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/feedback_hub.py +0 -0
  42. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/git_handler.py +0 -0
  43. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/ignore.py +0 -0
  44. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/json_utils.py +0 -0
  45. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/llm_client.py +0 -0
  46. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/metrics_store.py +0 -0
  47. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/report_generator.py +0 -0
  48. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/core/token_estimator.py +0 -0
  49. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/2026-stage-highlights.md +0 -0
  50. {vcode_analysis-0.8.0 → vcode_analysis-0.10.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
  51. {vcode_analysis-0.8.0 → vcode_analysis-0.10.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
  52. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/USER_MANUAL.md +0 -0
  53. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/batch-cache-optimization.md +0 -0
  54. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/c-parser-design.md +0 -0
  55. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/code-knowledge-graph.md +0 -0
  56. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/critical-severity.md +0 -0
  57. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/expert-review-response-2026-07.md +0 -0
  58. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/kotlin-parser-design.md +0 -0
  59. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/prompt-externalization.md +0 -0
  60. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/three-year-roadmap.md +0 -0
  61. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/design/vcode-analysis-tool.md +0 -0
  62. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/review-scenarios.md +0 -0
  63. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/security-sharing-article.md +0 -0
  64. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/severity-standard.md +0 -0
  65. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs/superpowers/plans/2026-07-22-expert-review-response.md +0 -0
  66. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/docs//350/207/252/350/215/220/344/272/256/347/202/271/350/257/264/346/230/216.md" +0 -0
  67. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/__init__.py +0 -0
  68. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/c/__init__.py +0 -0
  69. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/c/ast_parser.py +0 -0
  70. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/c/models.py +0 -0
  71. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/c/patterns.py +0 -0
  72. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/c/regex_parser.py +0 -0
  73. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/c_parser.py +0 -0
  74. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/java_parser.py +0 -0
  75. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/javascript_parser.py +0 -0
  76. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/kotlin/__init__.py +0 -0
  77. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/kotlin/ast_parser.py +0 -0
  78. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/kotlin/models.py +0 -0
  79. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/kotlin/patterns.py +0 -0
  80. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/kotlin/regex_parser.py +0 -0
  81. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/kotlin_parser.py +0 -0
  82. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/python_parser.py +0 -0
  83. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/sql_parser.py +0 -0
  84. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/parsers/typescript_parser.py +0 -0
  85. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/requirements.txt +0 -0
  86. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/setup.cfg +0 -0
  87. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_batch_operations.py +0 -0
  88. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_c_parser.py +0 -0
  89. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_context_builder_sql.py +0 -0
  90. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_kotlin_parser.py +0 -0
  91. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_mcp_tools.py +0 -0
  92. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_metrics_store.py +0 -0
  93. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_prompt_manager.py +0 -0
  94. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_report_generator.py +0 -0
  95. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_security_rules.py +0 -0
  96. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/tests/test_sql_parser.py +0 -0
  97. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_analysis.egg-info/dependency_links.txt +0 -0
  98. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_analysis.egg-info/entry_points.txt +0 -0
  99. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_analysis.egg-info/requires.txt +0 -0
  100. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_analysis.egg-info/top_level.txt +0 -0
  101. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_mcp/__init__.py +0 -0
  102. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_mcp/prompt_handler.py +0 -0
  103. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_mcp/resource_handler.py +0 -0
  104. {vcode_analysis-0.8.0 → vcode_analysis-0.10.0}/vcode_mcp/transports/__init__.py +0 -0
@@ -7,6 +7,7 @@ recursive-include docs *.md
7
7
  recursive-include analyzers *.py
8
8
  recursive-include core *.py
9
9
  recursive-include parsers *.py
10
+ recursive-include core/prompts *.md
10
11
 
11
12
  global-exclude __pycache__
12
13
  global-exclude *.py[cod]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vcode-analysis
3
- Version: 0.8.0
3
+ Version: 0.10.0
4
4
  Summary: 基于大模型的智能代码分析工具,支持代码审查、文档生成、架构分析和安全扫描
5
5
  Author-email: Wellchang <2483808264@qq.com>
6
6
  License: MIT
@@ -38,6 +38,7 @@ Commands:
38
38
 
39
39
  Options:
40
40
  -c, --config <file> 配置文件路径
41
+ --prompts-dir <dir> 自定义提示词目录(与内置提示词叠加,同名覆盖)
41
42
  --path <path> 仓库路径 (review-commit 使用)
42
43
  --type <type> 文档类型 (doc 使用, 默认: module)
43
44
  --base-url <url> LLM API 地址
@@ -69,6 +70,8 @@ Options:
69
70
  --limit <n> 限制数量 (feedback pending 使用)
70
71
  """
71
72
 
73
+ from __future__ import annotations
74
+
72
75
  import sys
73
76
  import json
74
77
  import time
@@ -110,7 +113,7 @@ from analyzers import (
110
113
  )
111
114
 
112
115
 
113
- __version__ = "0.8.0"
116
+ __version__ = "0.10.0"
114
117
 
115
118
 
116
119
  def _timestamp() -> str:
@@ -246,6 +249,17 @@ def get_default_output_path(target_path: str, prefix: str) -> Path:
246
249
  return result_dir / filename
247
250
 
248
251
 
252
+ def _save_output_to_file(args: dict, content: str, prefix: str) -> str:
253
+ """将输出内容保存到文件(未指定 --output 时生成默认路径并返回)。
254
+
255
+ 用于 metrics/feedback/clone 等命令:既保存到 result/ 目录,也保留终端输出。
256
+ """
257
+ output_path = args.get("--output") or str(get_default_output_path(".", prefix))
258
+ Path(output_path).write_text(content, encoding="utf-8")
259
+ _log(f"结果已保存到: {output_path}")
260
+ return output_path
261
+
262
+
249
263
  def format_review_result(result, output_format: str = "markdown") -> str:
250
264
  """格式化审查结果"""
251
265
  if output_format == "json":
@@ -430,6 +444,7 @@ def cmd_review(args: dict) -> int:
430
444
 
431
445
  config = Config.create(
432
446
  config_file=args.get("--config"),
447
+ prompts_dir=args.get("--prompts-dir"),
433
448
  base_url=args.get("--base-url"),
434
449
  api_key=args.get("--api-key"),
435
450
  model=args.get("--model"),
@@ -515,7 +530,7 @@ def cmd_review(args: dict) -> int:
515
530
  reviewer.metrics_store = _metrics_store
516
531
  reviewer._current_run_id = _metrics_store.record_scan_run(ScanRun(
517
532
  repo_path=str(Path(target_path).resolve()),
518
- analyzer="code_review", tool_version="0.8.0",
533
+ analyzer="code_review", tool_version="0.10.0",
519
534
  ))
520
535
  _log_section("分析中(逐文件模式)")
521
536
  _log(f"开始分析 {total} 个文件...", "START")
@@ -625,7 +640,7 @@ def cmd_review(args: dict) -> int:
625
640
  _metrics_store = MetricsStore(_metrics_db)
626
641
  _run_id = _metrics_store.record_scan_run(ScanRun(
627
642
  repo_path=str(Path(target_path).resolve()),
628
- analyzer="code_review", tool_version="0.8.0",
643
+ analyzer="code_review", tool_version="0.10.0",
629
644
  ))
630
645
  for r in results:
631
646
  if r.success and r.issues:
@@ -761,6 +776,7 @@ def cmd_review_commit(args: dict) -> int:
761
776
 
762
777
  config = Config.create(
763
778
  config_file=args.get("--config"),
779
+ prompts_dir=args.get("--prompts-dir"),
764
780
  base_url=args.get("--base-url"),
765
781
  api_key=args.get("--api-key"),
766
782
  model=args.get("--model"),
@@ -787,7 +803,7 @@ def cmd_review_commit(args: dict) -> int:
787
803
  _metrics_store = MetricsStore(_metrics_db)
788
804
  _run_id = _metrics_store.record_scan_run(ScanRun(
789
805
  repo_path=str(Path(target_path).resolve()),
790
- analyzer="code_review", tool_version="0.8.0",
806
+ analyzer="code_review", tool_version="0.10.0",
791
807
  ))
792
808
 
793
809
  with Analyzer(config) as analyzer:
@@ -857,6 +873,7 @@ def cmd_doc(args: dict) -> int:
857
873
 
858
874
  config = Config.create(
859
875
  config_file=args.get("--config"),
876
+ prompts_dir=args.get("--prompts-dir"),
860
877
  base_url=args.get("--base-url"),
861
878
  api_key=args.get("--api-key"),
862
879
  model=args.get("--model"),
@@ -945,7 +962,10 @@ def cmd_metrics(args: dict) -> int:
945
962
  from datetime import date
946
963
  from core.metrics_store import MetricsStore
947
964
 
948
- config = Config.create(config_file=args.get("--config"))
965
+ config = Config.create(
966
+ config_file=args.get("--config"),
967
+ prompts_dir=args.get("--prompts-dir"),
968
+ )
949
969
  db_path = config.metrics.db_path or str(
950
970
  Path.home() / ".code-analysis" / "metrics.db"
951
971
  )
@@ -997,12 +1017,14 @@ def cmd_metrics(args: dict) -> int:
997
1017
  lines.append(f"| {item['key']} | {item['count']} |")
998
1018
  content = "\n".join(lines)
999
1019
 
1000
- if output_path:
1001
- with open(output_path, "w", encoding="utf-8") as f:
1002
- f.write(content)
1003
- _log(f"[OK] 指标报告已保存到 {output_path}")
1004
- else:
1005
- print(content)
1020
+ # 默认保存到文件(未指定 --output 时生成默认路径)
1021
+ if not output_path:
1022
+ output_path = str(get_default_output_path(".", "metrics"))
1023
+
1024
+ with open(output_path, "w", encoding="utf-8") as f:
1025
+ f.write(content)
1026
+ _log(f"[OK] 指标报告已保存到 {output_path}")
1027
+ print(content) # 同时保留终端输出
1006
1028
 
1007
1029
  return 0
1008
1030
 
@@ -1011,12 +1033,18 @@ def cmd_feedback(args: dict) -> int:
1011
1033
  """反馈管理命令"""
1012
1034
  from core.metrics_store import MetricsStore
1013
1035
 
1014
- config = Config.create(config_file=args.get("--config"))
1036
+ config = Config.create(
1037
+ config_file=args.get("--config"),
1038
+ prompts_dir=args.get("--prompts-dir"),
1039
+ )
1015
1040
  db_path = config.metrics.db_path or str(
1016
1041
  Path.home() / ".code-analysis" / "metrics.db"
1017
1042
  )
1018
1043
  store = MetricsStore(Path(db_path))
1019
1044
 
1045
+ # 收集输出文本,统一在末尾保存到默认文件
1046
+ output_lines: list[str] = []
1047
+
1020
1048
  if args.get("pending"):
1021
1049
  limit = int(args.get("--limit") or 50)
1022
1050
  conn = store._get_conn()
@@ -1027,12 +1055,17 @@ def cmd_feedback(args: dict) -> int:
1027
1055
  ).fetchall()
1028
1056
  conn.close()
1029
1057
  if not rows:
1030
- print("无待复核 issue")
1058
+ output_lines.append("无待复核 issue")
1031
1059
  else:
1032
- print(f"{'ID':<12} {'规则':<25} {'严重度':<10} {'文件':<30} {'行号':<6}")
1033
- print("-" * 90)
1060
+ output_lines.append(f"{'ID':<12} {'规则':<25} {'严重度':<10} {'文件':<30} {'行号':<6}")
1061
+ output_lines.append("-" * 90)
1034
1062
  for r in rows:
1035
- print(f"{r[0][:10]:<12} {r[1] or '':<25} {r[2] or '':<10} {r[3]:<30} {r[4]:<6}")
1063
+ output_lines.append(
1064
+ f"{r[0][:10]:<12} {r[1] or '':<25} {r[2] or '':<10} {r[3]:<30} {r[4]:<6}"
1065
+ )
1066
+ output = "\n".join(output_lines)
1067
+ print(output)
1068
+ _save_output_to_file(args, output, "feedback")
1036
1069
  return 0
1037
1070
 
1038
1071
  if args.get("import"):
@@ -1046,7 +1079,9 @@ def cmd_feedback(args: dict) -> int:
1046
1079
  item.get("reviewer", "import"), item.get("note", ""),
1047
1080
  )
1048
1081
  count += 1
1049
- print(f"[OK] 已导入 {count} 条反馈")
1082
+ output = f"[OK] 已导入 {count} 条反馈"
1083
+ print(output)
1084
+ _save_output_to_file(args, output, "feedback")
1050
1085
  return 0
1051
1086
 
1052
1087
  # 单条标记
@@ -1057,7 +1092,9 @@ def cmd_feedback(args: dict) -> int:
1057
1092
  print("用法: vcode-analysis feedback <issue-id> --status <status> [--note <text>]")
1058
1093
  return 1
1059
1094
  store.update_issue_status(issue_id, status, "cli", note)
1060
- print(f"[OK] issue {issue_id[:10]} 状态已更新为 {status}")
1095
+ output = f"[OK] issue {issue_id[:10]} 状态已更新为 {status}"
1096
+ print(output)
1097
+ _save_output_to_file(args, output, "feedback")
1061
1098
  return 0
1062
1099
 
1063
1100
 
@@ -1118,6 +1155,7 @@ def cmd_arch(args: dict) -> int:
1118
1155
 
1119
1156
  config = Config.create(
1120
1157
  config_file=args.get("--config"),
1158
+ prompts_dir=args.get("--prompts-dir"),
1121
1159
  base_url=args.get("--base-url"),
1122
1160
  api_key=args.get("--api-key"),
1123
1161
  model=args.get("--model"),
@@ -1236,6 +1274,7 @@ def cmd_security(args: dict) -> int:
1236
1274
 
1237
1275
  config = Config.create(
1238
1276
  config_file=args.get("--config"),
1277
+ prompts_dir=args.get("--prompts-dir"),
1239
1278
  base_url=args.get("--base-url"),
1240
1279
  api_key=args.get("--api-key"),
1241
1280
  model=args.get("--model"),
@@ -1265,7 +1304,7 @@ def cmd_security(args: dict) -> int:
1265
1304
  security.metrics_store = _metrics_store
1266
1305
  security._current_run_id = _metrics_store.record_scan_run(ScanRun(
1267
1306
  repo_path=str(Path(target_path).resolve()),
1268
- analyzer="security", tool_version="0.8.0",
1307
+ analyzer="security", tool_version="0.10.0",
1269
1308
  ))
1270
1309
  results = security.scan_project(target_path, deep=deep_scan, log_callback=_log)
1271
1310
  scan_time = time.time() - scan_start
@@ -1407,6 +1446,10 @@ def cmd_clone(args: dict) -> int:
1407
1446
  analyze = args.get("--analyze", False)
1408
1447
  output_file = args.get("--output")
1409
1448
 
1449
+ # 默认输出路径(未指定 --output 时生成)
1450
+ if not output_file:
1451
+ output_file = str(get_default_output_path(".", "clone"))
1452
+
1410
1453
  _log(f"克隆仓库: {repo_url}", "START")
1411
1454
 
1412
1455
  # 克隆仓库
@@ -1433,6 +1476,8 @@ def cmd_clone(args: dict) -> int:
1433
1476
  ("总耗时", _format_duration(total_time)),
1434
1477
  ],
1435
1478
  )
1479
+ # 默认保存克隆报告
1480
+ _save_output_to_file(args, f"# 克隆报告\n\n- 仓库: {repo_url}\n- 路径: {repo_path}\n- 耗时: {_format_duration(clone_time)}\n", "clone")
1436
1481
  return 0
1437
1482
 
1438
1483
  # 执行分析
@@ -1440,6 +1485,7 @@ def cmd_clone(args: dict) -> int:
1440
1485
 
1441
1486
  config = Config.create(
1442
1487
  config_file=args.get("--config"),
1488
+ prompts_dir=args.get("--prompts-dir"),
1443
1489
  base_url=args.get("--base-url"),
1444
1490
  api_key=args.get("--api-key"),
1445
1491
  model=args.get("--model"),
@@ -1487,6 +1533,10 @@ def cmd_batch_clone(args: dict) -> int:
1487
1533
  analyze = args.get("--analyze", False)
1488
1534
  output_file = args.get("--output")
1489
1535
 
1536
+ # 默认输出路径(未指定 --output 时生成)
1537
+ if not output_file:
1538
+ output_file = str(get_default_output_path(target_dir, "batch_clone"))
1539
+
1490
1540
  # 读取 URL 列表
1491
1541
  urls = []
1492
1542
  try:
@@ -1518,7 +1568,7 @@ def cmd_batch_clone(args: dict) -> int:
1518
1568
  target_dir=target_dir,
1519
1569
  parallel=parallel,
1520
1570
  max_workers=4,
1521
- progress_callback=progress_callback if not output_file else None,
1571
+ progress_callback=progress_callback if not args.get("--output") else None,
1522
1572
  )
1523
1573
  clone_time = time.time() - clone_start
1524
1574
 
@@ -1549,9 +1599,10 @@ def cmd_batch_clone(args: dict) -> int:
1549
1599
 
1550
1600
  report = "\n".join(lines)
1551
1601
 
1552
- if output_file:
1553
- Path(output_file).write_text(report, encoding="utf-8")
1554
- _log(f"报告已保存到: {output_file}")
1602
+ # 保存报告(默认已生成 output_file)
1603
+ Path(output_file).write_text(report, encoding="utf-8")
1604
+ _log(f"报告已保存到: {output_file}")
1605
+ print(report)
1555
1606
 
1556
1607
  # 如果需要分析
1557
1608
  analyze_time = 0
@@ -1581,6 +1632,10 @@ def cmd_batch_pull(args: dict) -> int:
1581
1632
  repos_str = args.get("--repos")
1582
1633
  output_file = args.get("--output")
1583
1634
 
1635
+ # 默认输出路径(未指定 --output 时生成)
1636
+ if not output_file:
1637
+ output_file = str(get_default_output_path(dir_path, "batch_pull"))
1638
+
1584
1639
  # 解析指定仓库
1585
1640
  repos = None
1586
1641
  if repos_str:
@@ -1613,12 +1668,11 @@ def cmd_batch_pull(args: dict) -> int:
1613
1668
  # 生成报告
1614
1669
  report = handler.generate_status_report(repo_infos)
1615
1670
 
1616
- if output_file:
1617
- Path(output_file).write_text(report, encoding="utf-8")
1618
- _log(f"报告已保存到: {output_file}")
1619
- else:
1620
- print("\n" + "=" * 50)
1621
- print(report)
1671
+ # 保存报告(默认已生成 output_file)
1672
+ Path(output_file).write_text(report, encoding="utf-8")
1673
+ _log(f"报告已保存到: {output_file}")
1674
+ print("\n" + "=" * 50)
1675
+ print(report)
1622
1676
 
1623
1677
  total_time = time.time() - start_time
1624
1678
  _log_section("批量拉取完成")
@@ -1720,6 +1774,7 @@ def cmd_kg(args: dict) -> int:
1720
1774
 
1721
1775
  config = Config.create(
1722
1776
  config_file=args.get("--config"),
1777
+ prompts_dir=args.get("--prompts-dir"),
1723
1778
  base_url=args.get("--base-url"),
1724
1779
  api_key=args.get("--api-key"),
1725
1780
  model=args.get("--model"),
@@ -112,6 +112,9 @@ class Config:
112
112
  target_path: Optional[str] = None
113
113
  output_format: str = "markdown" # markdown, json
114
114
 
115
+ # 自定义提示词目录(可选,与内置 prompts 叠加;同名提示词覆盖内置)
116
+ prompts_dir: Optional[str] = None
117
+
115
118
  _config_path: Optional[str] = field(default=None, repr=False)
116
119
 
117
120
  @classmethod
@@ -216,6 +219,10 @@ class Config:
216
219
  if hasattr(self.mcp, key):
217
220
  setattr(self.mcp, key, value)
218
221
 
222
+ # 加载提示词目录(顶层配置项)
223
+ if "prompts_dir" in data and data["prompts_dir"]:
224
+ self.prompts_dir = str(data["prompts_dir"])
225
+
219
226
  def load_from_env(self) -> None:
220
227
  """从环境变量加载"""
221
228
  env_mappings = {
@@ -225,19 +232,24 @@ class Config:
225
232
  "CODE_ANALYSIS_MODEL": ("llm", "model"),
226
233
  "CODE_ANALYSIS_TEMPERATURE": ("llm", "temperature"),
227
234
  "CODE_ANALYSIS_MAX_TOKENS": ("llm", "max_tokens"),
235
+ "CODE_ANALYSIS_PROMPTS_DIR": ("_prompts_dir", "prompts_dir"),
228
236
  }
229
237
 
230
238
  for env_key, (section, attr) in env_mappings.items():
231
239
  value = os.environ.get(env_key)
232
- if value:
233
- target = self.llm if section == "llm" else self.analysis
234
- # 类型转换
235
- current_value = getattr(target, attr)
236
- if isinstance(current_value, int):
237
- value = int(value)
238
- elif isinstance(current_value, float):
239
- value = float(value)
240
- setattr(target, attr, value)
240
+ if not value:
241
+ continue
242
+ if section == "_prompts_dir":
243
+ self.prompts_dir = value
244
+ continue
245
+ target = self.llm if section == "llm" else self.analysis
246
+ # 类型转换
247
+ current_value = getattr(target, attr)
248
+ if isinstance(current_value, int):
249
+ value = int(value)
250
+ elif isinstance(current_value, float):
251
+ value = float(value)
252
+ setattr(target, attr, value)
241
253
 
242
254
  # 多模型配置时,环境变量也覆盖主模型
243
255
  if self.llm_models.models:
@@ -269,6 +281,8 @@ class Config:
269
281
  self.output_format = kwargs["output_format"]
270
282
  if kwargs.get("max_workers"):
271
283
  self.analysis.max_workers = kwargs["max_workers"]
284
+ if kwargs.get("prompts_dir"):
285
+ self.prompts_dir = kwargs["prompts_dir"]
272
286
 
273
287
  # 多模型配置时,CLI 参数也覆盖主模型
274
288
  if self.llm_models.models:
@@ -297,6 +311,15 @@ class Config:
297
311
  # 3. 最后应用 CLI 参数(最高优先级)
298
312
  config.apply_cli_overrides(**cli_kwargs)
299
313
 
314
+ # 4. 将自定义提示词目录注入 PromptManager(与内置 prompts 叠加)
315
+ from .prompt_manager import set_default_prompts_dir
316
+ from pathlib import Path as _Path
317
+
318
+ if config.prompts_dir:
319
+ set_default_prompts_dir(_Path(config.prompts_dir).expanduser())
320
+ else:
321
+ set_default_prompts_dir(None)
322
+
300
323
  return config
301
324
 
302
325
  def to_dict(self) -> dict:
@@ -315,6 +338,7 @@ class Config:
315
338
  },
316
339
  "target_path": self.target_path,
317
340
  "output_format": self.output_format,
341
+ "prompts_dir": self.prompts_dir,
318
342
  }
319
343
  if self.llm_models.models:
320
344
  result["llm_models"] = {
@@ -10,6 +10,7 @@ prompts/*.md 文件(YAML front matter + Markdown 正文),启动时加载
10
10
  from __future__ import annotations
11
11
 
12
12
  import re
13
+ import sys
13
14
  from dataclasses import dataclass, field
14
15
  from pathlib import Path
15
16
  from typing import Optional
@@ -38,24 +39,71 @@ class PromptManager:
38
39
  _VAR_PATTERN = re.compile(r"\{\{\s*(\w+)\s*\}\}")
39
40
 
40
41
  def __init__(self, prompts_dir: Optional[Path] = None):
41
- self.prompts_dir = prompts_dir or Path(__file__).parent.parent / "prompts"
42
+ """初始化提示词管理器。
43
+
44
+ prompts_dir 优先级(从高到低):
45
+ 1. 显式传入的 prompts_dir(CLI / 配置 / 环境变量)
46
+ 2. 包内内置 prompts(已随 whl 打包,importlib.resources 读取)
47
+ 3. 源码仓库内 prompts/(开发模式,__file__ 回溯定位)
48
+
49
+ 当传入 prompts_dir 时,它作为**用户自定义目录**与内置 prompts **叠加**——
50
+ 用户目录中的同名提示词会覆盖内置提示词,未覆盖的仍使用内置默认。
51
+ 若不传 prompts_dir,则仅使用内置(或开发目录)提示词。
52
+ """
53
+ self.prompts_dir = prompts_dir # 用户自定义目录(可选)
54
+ self._builtin_dir = self._resolve_builtin_dir()
42
55
  self._cache: dict[str, PromptTemplate] = {}
43
56
  self.load()
44
57
 
45
58
  # ------------------------------------------------------------------ 加载
46
59
 
60
+ def _resolve_builtin_dir(self) -> Optional[Path]:
61
+ """定位内置 prompts 目录。
62
+
63
+ 优先用 importlib.resources 读取已安装的 ``core.prompts`` 子包
64
+ (随 whl 打包,作为 core 包数据),失败则回退到开发模式布局
65
+ core/prompts(__file__ 同级子目录)。
66
+ """
67
+ # 已安装 / 开发模式:prompts 作为 core 的子包
68
+ try:
69
+ from importlib import resources
70
+
71
+ try:
72
+ files = resources.files("core.prompts")
73
+ with resources.as_file(files) as f:
74
+ if f.exists():
75
+ return f
76
+ except (ModuleNotFoundError, TypeError, ValueError):
77
+ pass
78
+ except Exception:
79
+ pass
80
+
81
+ # 回退:开发模式或源码仓库布局
82
+ repo_path = Path(__file__).resolve().parent / "prompts"
83
+ if repo_path.exists():
84
+ return repo_path
85
+ return None
86
+
47
87
  def load(self) -> None:
48
- """扫描 prompts/**/*.md,解析 front matter,缓存到 _cache。
88
+ """扫描内置与自定义 prompts/**/*.md,解析 front matter,缓存到 _cache。
89
+
90
+ 先加载内置 prompts,再加载用户自定义目录——自定义目录中的同名
91
+ 提示词会**覆盖**内置提示词,实现"默认内置 + 单独覆盖"的诉求。
49
92
 
50
93
  子目录结构决定 category:
51
94
  prompts/*.md -> category 取 front matter 或 "analyzer"
52
95
  prompts/mcp/*.md -> category = "mcp"
53
96
  prompts/documentation/*.md -> category = "documentation"
54
97
  """
55
- if not self.prompts_dir.exists():
56
- return
98
+ if self._builtin_dir and self._builtin_dir.exists():
99
+ self._scan_dir(self._builtin_dir)
57
100
 
58
- for md_path in sorted(self.prompts_dir.rglob("*.md")):
101
+ if self.prompts_dir and self.prompts_dir.exists():
102
+ self._scan_dir(self.prompts_dir)
103
+
104
+ def _scan_dir(self, prompts_dir: Path) -> None:
105
+ """扫描单个 prompts 目录并写入缓存(自定义目录后扫,可覆盖)。"""
106
+ for md_path in sorted(prompts_dir.rglob("*.md")):
59
107
  try:
60
108
  text = md_path.read_text(encoding="utf-8")
61
109
  except OSError:
@@ -66,7 +114,7 @@ class PromptManager:
66
114
  continue
67
115
 
68
116
  # 子目录决定 category 默认值
69
- rel = md_path.relative_to(self.prompts_dir)
117
+ rel = md_path.relative_to(prompts_dir)
70
118
  if len(rel.parts) > 1:
71
119
  fm.setdefault("category", rel.parts[0])
72
120
  else:
@@ -201,17 +249,37 @@ class PromptManager:
201
249
  # ------------------------------------------------------------------ 单例
202
250
 
203
251
  _prompt_manager: Optional[PromptManager] = None
252
+ _default_prompts_dir: Optional[Path] = None
253
+
204
254
 
255
+ def set_default_prompts_dir(prompts_dir: Optional[Path]) -> None:
256
+ """设置应用级默认自定义提示词目录(由 CLI / 配置 / 环境变量在启动时调用)。
205
257
 
206
- def get_prompt_manager() -> PromptManager:
207
- """获取模块级单例(首次调用时加载 prompts/ 目录)"""
258
+ 之后任意无参 get_prompt_manager() 都会使用此目录(与内置 prompts 叠加)。
259
+ 若新目录与当前默认不同,会重置单例,使后续调用重新加载。
260
+ """
261
+ global _default_prompts_dir, _prompt_manager
262
+ if prompts_dir != _default_prompts_dir:
263
+ _default_prompts_dir = prompts_dir
264
+ _prompt_manager = None # 触达重建
265
+
266
+
267
+ def get_prompt_manager(prompts_dir: Optional[Path] = None) -> PromptManager:
268
+ """获取模块级单例。
269
+
270
+ 优先级:显式 prompts_dir 参数 > 应用级默认目录(set_default_prompts_dir)
271
+ > 仅内置(打包)提示词。传入任意目录都会导致单例**重建**,以便配置变更生效。
272
+ """
208
273
  global _prompt_manager
209
- if _prompt_manager is None:
210
- _prompt_manager = PromptManager()
274
+ if prompts_dir is None:
275
+ prompts_dir = _default_prompts_dir
276
+ if _prompt_manager is None or prompts_dir != _prompt_manager.prompts_dir:
277
+ _prompt_manager = PromptManager(prompts_dir=prompts_dir)
211
278
  return _prompt_manager
212
279
 
213
280
 
214
281
  def reset_prompt_manager() -> None:
215
282
  """重置单例(仅供测试使用)"""
216
- global _prompt_manager
283
+ global _prompt_manager, _default_prompts_dir
217
284
  _prompt_manager = None
285
+ _default_prompts_dir = None
@@ -0,0 +1 @@
1
+ """内置提示词包(随 whl 打包,由 core.prompt_manager 加载)"""
@@ -0,0 +1,27 @@
1
+ ---
2
+ id: architecture
3
+ version: 1.0
4
+ variables: [total_files, total_lines, languages, modules_count, circular_deps, modules_summary]
5
+ category: analyzer
6
+ ---
7
+
8
+ 分析以下项目的架构信息并提供改进建议:
9
+
10
+ 项目统计:
11
+ - 文件数: {{total_files}}
12
+ - 代码行数: {{total_lines}}
13
+ - 语言分布: {{languages}}
14
+ - 模块数: {{modules_count}}
15
+ - 循环依赖: {{circular_deps}}
16
+
17
+ 模块列表:
18
+ {{modules_summary}}
19
+
20
+ 请分析项目的架构质量,包括:
21
+ 1. 模块化程度评价
22
+ 2. 依赖关系分析
23
+ 3. 潜在的架构问题
24
+ 4. 改进建议
25
+
26
+ 以 JSON 格式输出:
27
+ {"summary": "架构评价", "suggestions": ["建议1", "建议2"]}
@@ -0,0 +1,22 @@
1
+ ---
2
+ id: batch_review
3
+ version: 1.0
4
+ variables: [language, count, file_sections]
5
+ category: analyzer
6
+ ---
7
+
8
+ 审查以下 {{language}} 文件({{count}} 个):
9
+
10
+ {{file_sections}}
11
+
12
+ 输出格式(仅输出 JSON,不要思考过程):
13
+ {"files":[{"path":"文件路径","score":8,"issues":[{"t":"类型","s":"high/medium/low","l":行号,"d":"描述"}],"suggestions":["建议"],"summary":"总结"}]}
14
+
15
+ 注意:
16
+ - score: 1-10 的整数,表示代码质量评分
17
+ - issues: 问题列表,最多 5 条(t=类型, s=严重程度, l=行号, d=描述)
18
+ - suggestions: 改进建议,最多 3 条
19
+ - summary: 简短总结,控制在 50 字以内
20
+ - path 必须与上面的文件路径一致
21
+
22
+ 只输出 JSON 对象,不要输出思考过程或其他内容。
@@ -0,0 +1,31 @@
1
+ ---
2
+ id: code_review
3
+ version: 1.3
4
+ variables: [language, file_path, content]
5
+ category: analyzer
6
+ ---
7
+
8
+ 请审查以下 {{language}} 代码:
9
+
10
+ 文件: {{file_path}}
11
+
12
+ ```{{language}}
13
+ {{content}}
14
+ ```
15
+
16
+ 请进行代码审查,必须严格按照以下 JSON 格式输出,不要输出任何其他内容:
17
+
18
+ {"score": 评分1-10, "issues": [{"type": "问题类型", "severity": "high/medium/low", "line": 行号, "description": "问题描述"}], "suggestions": ["改进建议"], "summary": "代码评价总结"}
19
+
20
+ severity 判定标准(严格按此执行):
21
+ - high: 可能导致运行时错误、数据丢失、安全漏洞(如 SQL注入、XSS、硬编码密钥、空指针、资源泄漏)
22
+ - medium: 代码质量问题,可能影响可维护性或性能(如循环依赖、重复代码、缺少异常处理、魔法数字)
23
+ - low: 轻微代码风格问题(如命名不规范、缺少注释、过长函数、未使用的导入)
24
+
25
+ ## SQL / DDL 审查要点(当语言为 SQL 时)
26
+
27
+ 若当前文件是 SQL/DDL,请重点检查:
28
+ 1. **外键类型一致性**:外键列的数据类型必须与引用表对应列类型一致(建议长度/精度也一致);类型不兼容为 high。
29
+ 2. **引用完整性**:外键引用的目标表、目标列必须存在;引用不存在的表/列为 high。
30
+ 3. **破坏性变更防护**:`DROP COLUMN`、缩短长度、改窄类型等可能丢数据,需谨慎(high)。
31
+ 4. **重复定义**:同一张表在多处定义且列不一致时提示收敛(low)。
@@ -0,0 +1,37 @@
1
+ ---
2
+ id: code_review_v2
3
+ version: 1.1
4
+ variables: [language, file_path, context_section, content]
5
+ category: analyzer
6
+ ---
7
+
8
+ 请审查以下 {{language}} 代码:
9
+
10
+ 文件: {{file_path}}
11
+
12
+ {{context_section}}
13
+
14
+ ## 当前文件代码
15
+ ```{{language}}
16
+ {{content}}
17
+ ```
18
+
19
+ 请进行代码审查,必须严格按照以下 JSON 格式输出,不要输出任何其他内容:
20
+
21
+ {"score": 评分1-10, "issues": [{"type": "问题类型", "severity": "high/medium/low", "line": 行号, "description": "问题描述", "context": "相关上下文说明(可选)"}], "suggestions": ["改进建议"], "summary": "代码评价总结", "cross_file_issues": ["跨文件问题(可选)"]}
22
+
23
+ severity 判定标准(严格按此执行):
24
+ - high: 可能导致运行时错误、数据丢失、安全漏洞(如 SQL注入、XSS、硬编码密钥、空指针、资源泄漏)
25
+ - medium: 代码质量问题,可能影响可维护性或性能(如循环依赖、重复代码、缺少异常处理、魔法数字)
26
+ - low: 轻微代码风格问题(如命名不规范、缺少注释、过长函数、未使用的导入)
27
+
28
+ ## SQL / 数据库 Schema 完整性检查(重点)
29
+
30
+ 若上下文中的「数据库 Schema 上下文」提供了本次提交涉及的表定义,请**重点核对当前文件中的数据库访问代码与 Schema 是否一致**:
31
+
32
+ 1. **代码字段引用一致性**:代码中访问的列(如 `table.column`、INSERT/SELECT 字段列表、ORM 实体字段)必须与 Schema 中声明的列一致。引用了不存在的列(可能被重命名/删除而代码未同步)标记为 medium 问题。
33
+ 2. **外键类型一致性**:若代码涉及外键关联的列,确认两端类型匹配;类型完全不兼容标记 high。
34
+ 3. **DDL 与代码同步**:若代码中内嵌了 `CREATE TABLE` / `ALTER TABLE` / `ADD COLUMN` / `DROP COLUMN` 等 DDL 字符串但本次提交没有对应迁移脚本,标记为 medium(建议收敛到迁移脚本)。
35
+ 4. **破坏性变更防护**:对已有表的 `DROP COLUMN`、缩短长度、改窄类型等破坏性操作需谨慎,确认无数据丢失风险。
36
+
37
+ 将发现的跨文件/跨文件 schema 不一致问题写入 `cross_file_issues`,并在 `issues` 中给出对应项(severity 按上述标准)。