homegraph 1.2.0 → 1.4.1
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.
- package/dist/bin/homegraph.js +3 -0
- package/dist/bin/homegraph.js.map +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +85 -0
- package/dist/context/index.js.map +1 -1
- package/dist/db/index.d.ts +64 -5
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +178 -14
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +19 -1
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/queries.d.ts +117 -2
- package/dist/db/queries.d.ts.map +1 -1
- package/dist/db/queries.js +299 -6
- package/dist/db/queries.js.map +1 -1
- package/dist/db/schema.sql +32 -1
- package/dist/db/wal-valve.d.ts +106 -0
- package/dist/db/wal-valve.d.ts.map +1 -0
- package/dist/db/wal-valve.js +208 -0
- package/dist/db/wal-valve.js.map +1 -0
- package/dist/directory.d.ts +9 -5
- package/dist/directory.d.ts.map +1 -1
- package/dist/directory.js +210 -19
- package/dist/directory.js.map +1 -1
- package/dist/extraction/cfml-extractor.d.ts +107 -0
- package/dist/extraction/cfml-extractor.d.ts.map +1 -0
- package/dist/extraction/cfml-extractor.js +494 -0
- package/dist/extraction/cfml-extractor.js.map +1 -0
- package/dist/extraction/grammars.d.ts +25 -1
- package/dist/extraction/grammars.d.ts.map +1 -1
- package/dist/extraction/grammars.js +177 -24
- package/dist/extraction/grammars.js.map +1 -1
- package/dist/extraction/index.d.ts +43 -4
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +308 -5
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/languages/c-cpp.d.ts +42 -0
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/dist/extraction/languages/c-cpp.js +369 -4
- package/dist/extraction/languages/c-cpp.js.map +1 -1
- package/dist/extraction/languages/cfquery.d.ts +12 -0
- package/dist/extraction/languages/cfquery.d.ts.map +1 -0
- package/dist/extraction/languages/cfquery.js +28 -0
- package/dist/extraction/languages/cfquery.js.map +1 -0
- package/dist/extraction/languages/cfscript.d.ts +3 -0
- package/dist/extraction/languages/cfscript.d.ts.map +1 -0
- package/dist/extraction/languages/cfscript.js +73 -0
- package/dist/extraction/languages/cfscript.js.map +1 -0
- package/dist/extraction/languages/cobol.d.ts +33 -0
- package/dist/extraction/languages/cobol.d.ts.map +1 -0
- package/dist/extraction/languages/cobol.js +499 -0
- package/dist/extraction/languages/cobol.js.map +1 -0
- package/dist/extraction/languages/erlang.d.ts +3 -0
- package/dist/extraction/languages/erlang.d.ts.map +1 -0
- package/dist/extraction/languages/erlang.js +350 -0
- package/dist/extraction/languages/erlang.js.map +1 -0
- package/dist/extraction/languages/index.d.ts.map +1 -1
- package/dist/extraction/languages/index.js +16 -0
- package/dist/extraction/languages/index.js.map +1 -1
- package/dist/extraction/languages/nix.d.ts +3 -0
- package/dist/extraction/languages/nix.d.ts.map +1 -0
- package/dist/extraction/languages/nix.js +294 -0
- package/dist/extraction/languages/nix.js.map +1 -0
- package/dist/extraction/languages/solidity.d.ts +3 -0
- package/dist/extraction/languages/solidity.d.ts.map +1 -0
- package/dist/extraction/languages/solidity.js +293 -0
- package/dist/extraction/languages/solidity.js.map +1 -0
- package/dist/extraction/languages/terraform.d.ts +3 -0
- package/dist/extraction/languages/terraform.d.ts.map +1 -0
- package/dist/extraction/languages/terraform.js +641 -0
- package/dist/extraction/languages/terraform.js.map +1 -0
- package/dist/extraction/languages/vbnet.d.ts +11 -0
- package/dist/extraction/languages/vbnet.d.ts.map +1 -0
- package/dist/extraction/languages/vbnet.js +141 -0
- package/dist/extraction/languages/vbnet.js.map +1 -0
- package/dist/extraction/mybatis-extractor.d.ts +30 -10
- package/dist/extraction/mybatis-extractor.d.ts.map +1 -1
- package/dist/extraction/mybatis-extractor.js +140 -38
- package/dist/extraction/mybatis-extractor.js.map +1 -1
- package/dist/extraction/parse-pool.d.ts +27 -1
- package/dist/extraction/parse-pool.d.ts.map +1 -1
- package/dist/extraction/parse-pool.js +75 -7
- package/dist/extraction/parse-pool.js.map +1 -1
- package/dist/extraction/parse-worker.js +9 -2
- package/dist/extraction/parse-worker.js.map +1 -1
- package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
- package/dist/extraction/tree-sitter-helpers.js +1 -0
- package/dist/extraction/tree-sitter-helpers.js.map +1 -1
- package/dist/extraction/tree-sitter-types.d.ts +3 -1
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.d.ts +38 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.js +754 -10
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/extraction/wasm/tree-sitter-arkts.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-terraform.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
- package/dist/graph/traversal.d.ts.map +1 -1
- package/dist/graph/traversal.js +1 -1
- package/dist/graph/traversal.js.map +1 -1
- package/dist/index.d.ts +60 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +348 -5
- package/dist/index.js.map +1 -1
- package/dist/installer/index.d.ts +42 -0
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +97 -2
- package/dist/installer/index.js.map +1 -1
- package/dist/mcp/daemon.d.ts +25 -3
- package/dist/mcp/daemon.d.ts.map +1 -1
- package/dist/mcp/daemon.js +62 -8
- package/dist/mcp/daemon.js.map +1 -1
- package/dist/mcp/dynamic-boundaries.d.ts.map +1 -1
- package/dist/mcp/dynamic-boundaries.js +2 -1
- package/dist/mcp/dynamic-boundaries.js.map +1 -1
- package/dist/mcp/early-ppid.d.ts +26 -0
- package/dist/mcp/early-ppid.d.ts.map +1 -0
- package/dist/mcp/early-ppid.js +29 -0
- package/dist/mcp/early-ppid.js.map +1 -0
- package/dist/mcp/engine.d.ts +4 -5
- package/dist/mcp/engine.d.ts.map +1 -1
- package/dist/mcp/engine.js +27 -1
- package/dist/mcp/engine.js.map +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +41 -6
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/liveness-watchdog.d.ts +18 -1
- package/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/dist/mcp/liveness-watchdog.js +73 -13
- package/dist/mcp/liveness-watchdog.js.map +1 -1
- package/dist/mcp/memory-budget.d.ts +30 -0
- package/dist/mcp/memory-budget.d.ts.map +1 -0
- package/dist/mcp/memory-budget.js +123 -0
- package/dist/mcp/memory-budget.js.map +1 -0
- package/dist/mcp/proxy.d.ts.map +1 -1
- package/dist/mcp/proxy.js +88 -4
- package/dist/mcp/proxy.js.map +1 -1
- package/dist/mcp/query-cache.d.ts +35 -4
- package/dist/mcp/query-cache.d.ts.map +1 -1
- package/dist/mcp/query-cache.js +89 -19
- package/dist/mcp/query-cache.js.map +1 -1
- package/dist/mcp/query-pool.d.ts +46 -12
- package/dist/mcp/query-pool.d.ts.map +1 -1
- package/dist/mcp/query-pool.js +100 -23
- package/dist/mcp/query-pool.js.map +1 -1
- package/dist/mcp/server-instructions.d.ts +4 -27
- package/dist/mcp/server-instructions.d.ts.map +1 -1
- package/dist/mcp/server-instructions.js +39 -84
- package/dist/mcp/server-instructions.js.map +1 -1
- package/dist/mcp/session.d.ts +14 -0
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +28 -1
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/startup-handshake.d.ts +44 -0
- package/dist/mcp/startup-handshake.d.ts.map +1 -0
- package/dist/mcp/startup-handshake.js +73 -0
- package/dist/mcp/startup-handshake.js.map +1 -0
- package/dist/mcp/tools.d.ts +104 -4
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +2390 -191
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/transport.d.ts.map +1 -1
- package/dist/mcp/transport.js +18 -0
- package/dist/mcp/transport.js.map +1 -1
- package/dist/project-config.d.ts +38 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +101 -2
- package/dist/project-config.js.map +1 -1
- package/dist/resolution/c-fnptr-synthesizer.d.ts +2 -1
- package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/dist/resolution/c-fnptr-synthesizer.js +178 -146
- package/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/dist/resolution/callback-synthesizer.d.ts +9 -1
- package/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/dist/resolution/callback-synthesizer.js +1164 -176
- package/dist/resolution/callback-synthesizer.js.map +1 -1
- package/dist/resolution/frameworks/cics.d.ts +20 -0
- package/dist/resolution/frameworks/cics.d.ts.map +1 -0
- package/dist/resolution/frameworks/cics.js +90 -0
- package/dist/resolution/frameworks/cics.js.map +1 -0
- package/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/dist/resolution/frameworks/index.js +3 -0
- package/dist/resolution/frameworks/index.js.map +1 -1
- package/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/dist/resolution/frameworks/java.js +14 -6
- package/dist/resolution/frameworks/java.js.map +1 -1
- package/dist/resolution/frameworks/terraform.d.ts +38 -0
- package/dist/resolution/frameworks/terraform.d.ts.map +1 -0
- package/dist/resolution/frameworks/terraform.js +277 -0
- package/dist/resolution/frameworks/terraform.js.map +1 -0
- package/dist/resolution/goframe-synthesizer.d.ts +2 -1
- package/dist/resolution/goframe-synthesizer.d.ts.map +1 -1
- package/dist/resolution/goframe-synthesizer.js +8 -3
- package/dist/resolution/goframe-synthesizer.js.map +1 -1
- package/dist/resolution/import-resolver.d.ts +7 -0
- package/dist/resolution/import-resolver.d.ts.map +1 -1
- package/dist/resolution/import-resolver.js +129 -4
- package/dist/resolution/import-resolver.js.map +1 -1
- package/dist/resolution/index.d.ts +60 -7
- package/dist/resolution/index.d.ts.map +1 -1
- package/dist/resolution/index.js +430 -80
- package/dist/resolution/index.js.map +1 -1
- package/dist/resolution/name-matcher.d.ts +0 -3
- package/dist/resolution/name-matcher.d.ts.map +1 -1
- package/dist/resolution/name-matcher.js +354 -33
- package/dist/resolution/name-matcher.js.map +1 -1
- package/dist/resolution/strip-comments.d.ts +1 -1
- package/dist/resolution/strip-comments.d.ts.map +1 -1
- package/dist/resolution/strip-comments.js +49 -0
- package/dist/resolution/strip-comments.js.map +1 -1
- package/dist/resolution/types.d.ts +29 -0
- package/dist/resolution/types.d.ts.map +1 -1
- package/dist/resolution/workspace-packages.d.ts +10 -0
- package/dist/resolution/workspace-packages.d.ts.map +1 -1
- package/dist/resolution/workspace-packages.js +142 -4
- package/dist/resolution/workspace-packages.js.map +1 -1
- package/dist/search/identifier-segments.d.ts +60 -0
- package/dist/search/identifier-segments.d.ts.map +1 -0
- package/dist/search/identifier-segments.js +176 -0
- package/dist/search/identifier-segments.js.map +1 -0
- package/dist/search/query-utils.d.ts +201 -0
- package/dist/search/query-utils.d.ts.map +1 -1
- package/dist/search/query-utils.js +919 -2
- package/dist/search/query-utils.js.map +1 -1
- package/dist/sync/git-hooks.d.ts.map +1 -1
- package/dist/sync/git-hooks.js +2 -0
- package/dist/sync/git-hooks.js.map +1 -1
- package/dist/sync/watcher.d.ts +10 -5
- package/dist/sync/watcher.d.ts.map +1 -1
- package/dist/sync/watcher.js +51 -14
- package/dist/sync/watcher.js.map +1 -1
- package/dist/sync/worktree.d.ts.map +1 -1
- package/dist/sync/worktree.js +5 -0
- package/dist/sync/worktree.js.map +1 -1
- package/dist/types.d.ts +19 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -1
- package/dist/upgrade/index.d.ts +32 -0
- package/dist/upgrade/index.d.ts.map +1 -1
- package/dist/upgrade/index.js +162 -14
- package/dist/upgrade/index.js.map +1 -1
- package/dist/upgrade/remove-binary.d.ts +87 -0
- package/dist/upgrade/remove-binary.d.ts.map +1 -0
- package/dist/upgrade/remove-binary.js +289 -0
- package/dist/upgrade/remove-binary.js.map +1 -0
- package/dist/upgrade/update-check.d.ts +92 -0
- package/dist/upgrade/update-check.d.ts.map +1 -0
- package/dist/upgrade/update-check.js +258 -0
- package/dist/upgrade/update-check.js.map +1 -0
- package/package.json +2 -2
- package/scripts/agent-eval/run-all.sh +6 -0
- package/scripts/build-bundle.sh +5 -0
- package/scripts/npm-shim.js +8 -1
- package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/deveco_arm.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/__pycache__/setup.cpython-310.pyc +0 -0
- package/scripts/exp_boundary_eval/data/agents.json +0 -109
- package/scripts/exp_boundary_eval/data/experiments.json +0 -140
- package/scripts/qa_eval/README.md +0 -407
- package/scripts/qa_eval/_test_deveco_probe.py +0 -41
- package/scripts/qa_eval/agent_runner.py +0 -526
- package/scripts/qa_eval/data/.gitignore +0 -4
- package/scripts/qa_eval/data/test-set.jsonl +0 -2
- package/scripts/qa_eval/eval_metrics.py +0 -274
- package/scripts/qa_eval/external_agent.py +0 -976
- package/scripts/qa_eval/llm_config.py +0 -92
- package/scripts/qa_eval/memory_monitor.py +0 -132
- package/scripts/qa_eval/my_answer_accuracy.py +0 -187
- package/scripts/qa_eval/requirements.txt +0 -2
- package/scripts/qa_eval/run_pipeline.py +0 -804
- package/scripts/qa_eval/stats_efficiency.py +0 -279
- package/scripts/qa_eval/stats_scores.py +0 -207
|
@@ -1,804 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
QA Eval A/B 一条龙:Agent 跑题 → Judge 打分 → 完整对比报告。
|
|
4
|
-
|
|
5
|
-
Usage:
|
|
6
|
-
export DASHSCOPE_API_KEY=sk-...
|
|
7
|
-
# 或智谱: export ZHIPU_API_KEY='id.secret'
|
|
8
|
-
python scripts/qa_eval/run_pipeline.py ab -r /path/to/your/repo
|
|
9
|
-
python scripts/qa_eval/run_pipeline.py ab -r /path/to/your/repo --provider zhipu
|
|
10
|
-
|
|
11
|
-
# 只重打报告、不重跑 Agent/Judge(无需 --repo):
|
|
12
|
-
python scripts/qa_eval/run_pipeline.py ab --no-agent --no-judge
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import argparse
|
|
18
|
-
import io
|
|
19
|
-
import json
|
|
20
|
-
import os
|
|
21
|
-
import re
|
|
22
|
-
import shutil
|
|
23
|
-
import statistics
|
|
24
|
-
import subprocess
|
|
25
|
-
import sys
|
|
26
|
-
from collections import defaultdict
|
|
27
|
-
from contextlib import redirect_stdout
|
|
28
|
-
from pathlib import Path
|
|
29
|
-
|
|
30
|
-
_SCRIPT_DIR = Path(__file__).resolve().parent
|
|
31
|
-
DATA_DIR = _SCRIPT_DIR / "data"
|
|
32
|
-
LOG_DIR = _SCRIPT_DIR / "log"
|
|
33
|
-
DEFAULT_REPORT = DATA_DIR / "report-builtin.txt"
|
|
34
|
-
DEFAULT_DATASET = DATA_DIR / "test-set.jsonl"
|
|
35
|
-
DEFAULT_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
36
|
-
DEFAULT_MODEL = "qwen3-235b-a22b-instruct-2507"
|
|
37
|
-
|
|
38
|
-
if str(_SCRIPT_DIR) not in sys.path:
|
|
39
|
-
sys.path.insert(0, str(_SCRIPT_DIR))
|
|
40
|
-
|
|
41
|
-
from agent_runner import run_agent_dataset # noqa: E402
|
|
42
|
-
from external_agent import HOST_CLAUDE, HOST_DEVECO, SUPPORTED_HOSTS, run_external_dataset, verify_claude_login # noqa: E402
|
|
43
|
-
from llm_config import PROVIDER_DASHSCOPE, PROVIDER_ZHIPU, provider_help, resolve_llm_config # noqa: E402
|
|
44
|
-
from my_answer_accuracy import extract_json_blocks_answerbyCOT, remove_tool_calls # noqa: E402
|
|
45
|
-
from stats_efficiency import parse_agent_log, summarize_jsonl_usage, summarize_tasks # noqa: E402
|
|
46
|
-
from stats_scores import compute_stats_from_rows, print_statistics # noqa: E402
|
|
47
|
-
|
|
48
|
-
AGENT_HOST_BUILTIN = "builtin"
|
|
49
|
-
ALL_AGENT_HOSTS = (AGENT_HOST_BUILTIN, HOST_CLAUDE, HOST_DEVECO)
|
|
50
|
-
|
|
51
|
-
# 各宿主产出文件后缀 → report-builtin.txt / report-claude.txt / report-deveco.txt
|
|
52
|
-
HOST_FILE_SUFFIX: dict[str, str] = {
|
|
53
|
-
AGENT_HOST_BUILTIN: "builtin",
|
|
54
|
-
HOST_CLAUDE: "claude",
|
|
55
|
-
HOST_DEVECO: "deveco",
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def require_repo_arg(repo: str | None, *, no_agent: bool) -> Path | None:
|
|
60
|
-
"""Return resolved repo path; required unless --no-agent (report-only)."""
|
|
61
|
-
if no_agent:
|
|
62
|
-
return Path(repo).expanduser().resolve() if repo else None
|
|
63
|
-
if not repo:
|
|
64
|
-
print("错误: 请指定被测仓库路径 --repo / -r(跑 Agent 时必填)")
|
|
65
|
-
return None
|
|
66
|
-
path = Path(repo).expanduser().resolve()
|
|
67
|
-
if not path.is_dir():
|
|
68
|
-
print(f"错误: 仓库不存在: {path}")
|
|
69
|
-
return None
|
|
70
|
-
return path
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def host_tag(agent_host: str) -> str:
|
|
74
|
-
suffix = HOST_FILE_SUFFIX.get(agent_host, agent_host.replace("-code", ""))
|
|
75
|
-
return f"-{suffix}"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def clear_log_dir(log_dir: Path) -> tuple[int, list[str]]:
|
|
79
|
-
"""Remove files/subdirs under qa_eval log/ before a fresh run.
|
|
80
|
-
|
|
81
|
-
Skips paths locked by another process (common on Windows when a file is open
|
|
82
|
-
in the editor) instead of aborting the pipeline.
|
|
83
|
-
"""
|
|
84
|
-
log_dir.mkdir(parents=True, exist_ok=True)
|
|
85
|
-
removed = 0
|
|
86
|
-
skipped: list[str] = []
|
|
87
|
-
for child in sorted(log_dir.iterdir(), key=lambda p: (p.is_dir(), p.name.lower())):
|
|
88
|
-
try:
|
|
89
|
-
if child.is_file():
|
|
90
|
-
child.unlink()
|
|
91
|
-
elif child.is_dir():
|
|
92
|
-
shutil.rmtree(child)
|
|
93
|
-
else:
|
|
94
|
-
continue
|
|
95
|
-
removed += 1
|
|
96
|
-
except OSError as e:
|
|
97
|
-
skipped.append(f"{child.name} ({e})")
|
|
98
|
-
return removed, skipped
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def paths_for_host(agent_host: str, *, log_dir: Path = LOG_DIR, data_dir: Path = DATA_DIR) -> dict[str, Path]:
|
|
102
|
-
tag = host_tag(agent_host)
|
|
103
|
-
log_dir.mkdir(parents=True, exist_ok=True)
|
|
104
|
-
return {
|
|
105
|
-
"with_jsonl": log_dir / f"result-with{tag}.jsonl",
|
|
106
|
-
"without_jsonl": log_dir / f"result-without{tag}.jsonl",
|
|
107
|
-
"with_scored": log_dir / f"result-with{tag}-scored.jsonl",
|
|
108
|
-
"without_scored": log_dir / f"result-without{tag}-scored.jsonl",
|
|
109
|
-
"with_log": log_dir / f"agent-with{tag}.log",
|
|
110
|
-
"without_log": log_dir / f"agent-without{tag}.log",
|
|
111
|
-
"report": data_dir / f"report{tag}.txt",
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def load_jsonl(path: Path) -> list[dict]:
|
|
116
|
-
rows: list[dict] = []
|
|
117
|
-
with path.open("r", encoding="utf-8") as f:
|
|
118
|
-
for line in f:
|
|
119
|
-
line = line.strip()
|
|
120
|
-
if line:
|
|
121
|
-
rows.append(json.loads(line))
|
|
122
|
-
return rows
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def index_by_id(rows: list[dict]) -> dict[str, dict]:
|
|
126
|
-
return {str(r.get("id", i)): r for i, r in enumerate(rows)}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def fmt_num(value: float | None, *, digits: int = 2) -> str:
|
|
130
|
-
if value is None:
|
|
131
|
-
return "N/A"
|
|
132
|
-
return f"{value:.{digits}f}"
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def fmt_delta(a: float | None, b: float | None, *, digits: int = 2) -> str:
|
|
136
|
-
if a is None or b is None:
|
|
137
|
-
return "N/A"
|
|
138
|
-
sign = "+" if a - b >= 0 else ""
|
|
139
|
-
return f"{sign}{a - b:.{digits}f}"
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def clip(text: str, n: int = 56) -> str:
|
|
143
|
-
text = " ".join(text.split())
|
|
144
|
-
return text if len(text) <= n else text[: n - 1] + "…"
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
def clean_answer(raw: str) -> str:
|
|
148
|
-
return remove_tool_calls(extract_json_blocks_answerbyCOT(str(raw or "")))
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def tool_chain_summary(raw: str, *, used_homegraph: bool | None = None) -> str:
|
|
152
|
-
tools = re.findall(r"---\n([^\n]+)\n", str(raw or ""))
|
|
153
|
-
chain = " → ".join(tools) if tools else "-"
|
|
154
|
-
if used_homegraph is True:
|
|
155
|
-
return f"{chain} [homegraph]"
|
|
156
|
-
if used_homegraph is False:
|
|
157
|
-
return f"{chain} [无homegraph]"
|
|
158
|
-
return chain
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def print_trajectory_section(rows_with: list[dict], rows_without: list[dict]) -> None:
|
|
162
|
-
rows = [( "with", r) for r in rows_with] + [("without", r) for r in rows_without]
|
|
163
|
-
if not any(r.get("deveco_session_id") or r.get("agent_trace_file") for _, r in rows):
|
|
164
|
-
return
|
|
165
|
-
print("\n" + "=" * 120)
|
|
166
|
-
print("【Agent 轨迹 / DevEco Session】")
|
|
167
|
-
print("跑完后查看完整轨迹:")
|
|
168
|
-
print(" 1) JSON 文件:scripts/qa_eval/log/traces/<with|without>-deveco/<ID>-ses_*.json")
|
|
169
|
-
print(" 2) CLI:deveco export <session_id> 或 deveco session list 找标题 qa-eval-*")
|
|
170
|
-
print("-" * 120)
|
|
171
|
-
print(f"{'ID':<6}{'臂':<8}{'HG':<4}{'状态':<8}{'工具链':<28}{'session_id':<28}{'轨迹文件'}")
|
|
172
|
-
print("-" * 120)
|
|
173
|
-
for arm, r in rows:
|
|
174
|
-
rid = str(r.get("id", ""))
|
|
175
|
-
status = str(r.get("agent_status", ""))[:7]
|
|
176
|
-
hg = "Y" if r.get("agent_used_homegraph") else ("N" if arm == "with" else "-")
|
|
177
|
-
chain = clip(
|
|
178
|
-
tool_chain_summary(
|
|
179
|
-
str(r.get("output_answer", "")),
|
|
180
|
-
used_homegraph=r.get("agent_used_homegraph") if arm == "with" else None,
|
|
181
|
-
),
|
|
182
|
-
26,
|
|
183
|
-
)
|
|
184
|
-
sid = str(r.get("deveco_session_id") or "-")
|
|
185
|
-
trace = str(r.get("agent_trace_file") or "-")
|
|
186
|
-
print(f"{rid:<6}{arm:<8}{hg:<4}{status:<8}{chain:<28}{sid:<28}{trace}")
|
|
187
|
-
print("=" * 120)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
def row_tokens(row: dict) -> int | None:
|
|
191
|
-
usage = row.get("agent_usage") or {}
|
|
192
|
-
total = usage.get("total_tokens")
|
|
193
|
-
return int(total) if isinstance(total, (int, float)) else None
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
def resolve_api_key() -> str | None:
|
|
197
|
-
try:
|
|
198
|
-
return resolve_llm_config(provider=os.environ.get("QA_EVAL_PROVIDER")).api_key
|
|
199
|
-
except RuntimeError:
|
|
200
|
-
return None
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
def run_judge(agent_jsonl: Path, scored_jsonl: Path, *, workers: int, llm) -> int:
|
|
204
|
-
if not agent_jsonl.is_file():
|
|
205
|
-
print(f"错误: Agent 产出不存在,无法 Judge: {agent_jsonl}")
|
|
206
|
-
return 1
|
|
207
|
-
n = sum(1 for line in agent_jsonl.open(encoding="utf-8") if line.strip())
|
|
208
|
-
print(f"\n>>> Judge ({llm.provider}):{agent_jsonl.name},共 {n} 条", flush=True)
|
|
209
|
-
cmd = [
|
|
210
|
-
sys.executable,
|
|
211
|
-
str(_SCRIPT_DIR / "eval_metrics.py"),
|
|
212
|
-
"-i",
|
|
213
|
-
str(agent_jsonl),
|
|
214
|
-
"-o",
|
|
215
|
-
str(scored_jsonl),
|
|
216
|
-
"-w",
|
|
217
|
-
str(workers),
|
|
218
|
-
"-m",
|
|
219
|
-
llm.model,
|
|
220
|
-
"--base-url",
|
|
221
|
-
llm.base_url,
|
|
222
|
-
"--provider",
|
|
223
|
-
llm.provider,
|
|
224
|
-
]
|
|
225
|
-
print(f"\n>>> {' '.join(cmd)}\n")
|
|
226
|
-
return subprocess.call(cmd)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def run_judge_if_needed(agent_jsonl: Path, scored_jsonl: Path, *, workers: int, llm) -> int:
|
|
230
|
-
return run_judge(agent_jsonl, scored_jsonl, workers=workers, llm=llm)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def print_category_table(rows_with: list[dict], rows_without: list[dict]) -> None:
|
|
234
|
-
by_cat: dict[str, list[tuple[float, float]]] = defaultdict(list)
|
|
235
|
-
wo = index_by_id(rows_without)
|
|
236
|
-
for r in rows_with:
|
|
237
|
-
rid = str(r.get("id"))
|
|
238
|
-
if rid not in wo:
|
|
239
|
-
continue
|
|
240
|
-
if r.get("evaluation_status") != "success" or wo[rid].get("evaluation_status") != "success":
|
|
241
|
-
continue
|
|
242
|
-
cat = str(r.get("category_l1") or "未分类")
|
|
243
|
-
by_cat[cat].append((float(r["answer_accuracy_score"]), float(wo[rid]["answer_accuracy_score"])))
|
|
244
|
-
|
|
245
|
-
print("\n" + "=" * 88)
|
|
246
|
-
print("按类别准确率")
|
|
247
|
-
print("=" * 88)
|
|
248
|
-
print(f"{'类别':<12}{'题数':>6}{'with均分':>12}{'without均分':>14}{'Δ':>10}")
|
|
249
|
-
print("-" * 88)
|
|
250
|
-
for cat in sorted(by_cat):
|
|
251
|
-
pairs = by_cat[cat]
|
|
252
|
-
w_mean = statistics.mean(p[0] for p in pairs)
|
|
253
|
-
wo_mean = statistics.mean(p[1] for p in pairs)
|
|
254
|
-
print(f"{cat:<12}{len(pairs):>6}{w_mean:>12.4f}{wo_mean:>14.4f}{w_mean - wo_mean:>+10.4f}")
|
|
255
|
-
print("=" * 88)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
def print_per_item_table(rows_with: list[dict], rows_without: list[dict]) -> None:
|
|
259
|
-
wo = index_by_id(rows_without)
|
|
260
|
-
wins = ties = losses = 0
|
|
261
|
-
|
|
262
|
-
print("\n" + "=" * 120)
|
|
263
|
-
print("逐题对比(query → with / without 得分与答案摘要)")
|
|
264
|
-
print("=" * 120)
|
|
265
|
-
print(
|
|
266
|
-
f"{'ID':<5}{'类':<6}{'with':>6}{'wo':>6}{'Δ':>7} {'问题':<28} {'with答案':<32} {'without答案'}"
|
|
267
|
-
)
|
|
268
|
-
print("-" * 120)
|
|
269
|
-
|
|
270
|
-
for r in rows_with:
|
|
271
|
-
rid = str(r.get("id", ""))
|
|
272
|
-
w = wo.get(rid, {})
|
|
273
|
-
sw = float(r["answer_accuracy_score"]) if r.get("evaluation_status") == "success" else None
|
|
274
|
-
swo = float(w["answer_accuracy_score"]) if w.get("evaluation_status") == "success" else None
|
|
275
|
-
if sw is not None and swo is not None:
|
|
276
|
-
if sw > swo:
|
|
277
|
-
wins += 1
|
|
278
|
-
elif sw < swo:
|
|
279
|
-
losses += 1
|
|
280
|
-
else:
|
|
281
|
-
ties += 1
|
|
282
|
-
cat = str(r.get("category_l1") or "")[:4]
|
|
283
|
-
q = clip(str(r.get("query", "")), 26)
|
|
284
|
-
aw = clip(clean_answer(str(r.get("output_answer", ""))), 30)
|
|
285
|
-
awo = clip(clean_answer(str(w.get("output_answer", ""))), 30)
|
|
286
|
-
print(
|
|
287
|
-
f"{rid:<5}{cat:<6}"
|
|
288
|
-
f"{fmt_num(sw, digits=2):>6}"
|
|
289
|
-
f"{fmt_num(swo, digits=2):>6}"
|
|
290
|
-
f"{fmt_delta(sw, swo, digits=2):>7} "
|
|
291
|
-
f"{q:<28} {aw:<32} {awo}"
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
print("-" * 120)
|
|
295
|
-
print(f"with 更高: {wins} | 持平: {ties} | without 更高: {losses}")
|
|
296
|
-
print("=" * 120)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
def print_efficiency_section(
|
|
300
|
-
label: str, log_path: Path | None, rows: list[dict], *, print_report: bool = True
|
|
301
|
-
) -> dict:
|
|
302
|
-
if print_report:
|
|
303
|
-
print(f"\n{'=' * 88}")
|
|
304
|
-
print(f"{label} — 效率明细")
|
|
305
|
-
print("=" * 88)
|
|
306
|
-
|
|
307
|
-
if log_path and log_path.is_file():
|
|
308
|
-
tasks = parse_agent_log(log_path)
|
|
309
|
-
if tasks:
|
|
310
|
-
summary = summarize_tasks(tasks, print_report=print_report)
|
|
311
|
-
summary["source"] = f"日志 {log_path}"
|
|
312
|
-
return summary
|
|
313
|
-
|
|
314
|
-
if print_report:
|
|
315
|
-
print(f"日志: {log_path} (不存在或未解析到 Evaluate 段)")
|
|
316
|
-
print("\n从 JSONL agent_usage 逐题 Token:")
|
|
317
|
-
print(f"{'ID':<6}{'Token':>10}{'agent_backend':>20}")
|
|
318
|
-
print("-" * 40)
|
|
319
|
-
tokens: list[int] = []
|
|
320
|
-
for r in rows:
|
|
321
|
-
tok = row_tokens(r)
|
|
322
|
-
if tok is not None:
|
|
323
|
-
tokens.append(tok)
|
|
324
|
-
if print_report:
|
|
325
|
-
print(
|
|
326
|
-
f"{str(r.get('id', '')):<6}"
|
|
327
|
-
f"{tok if tok is not None else 'N/A':>10}"
|
|
328
|
-
f"{str(r.get('agent_backend', '')):>20}"
|
|
329
|
-
)
|
|
330
|
-
summary = summarize_jsonl_usage(rows)
|
|
331
|
-
summary["source"] = "JSONL agent_usage"
|
|
332
|
-
if print_report:
|
|
333
|
-
print("-" * 40)
|
|
334
|
-
print(f"平均 Token: {summary['avg_tokens']:.0f}" if summary.get("avg_tokens") else "平均 Token: N/A")
|
|
335
|
-
print(f"合计 Token: {summary.get('total_tokens', 0)}")
|
|
336
|
-
print("=" * 88)
|
|
337
|
-
return summary
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
def print_full_ab_report(
|
|
341
|
-
*,
|
|
342
|
-
with_scored: Path,
|
|
343
|
-
without_scored: Path,
|
|
344
|
-
with_log: Path | None,
|
|
345
|
-
without_log: Path | None,
|
|
346
|
-
rows_with: list[dict],
|
|
347
|
-
rows_without: list[dict],
|
|
348
|
-
) -> None:
|
|
349
|
-
stats_with = compute_stats_from_rows(rows_with)
|
|
350
|
-
stats_without = compute_stats_from_rows(rows_without)
|
|
351
|
-
|
|
352
|
-
print("\n")
|
|
353
|
-
print("#" * 88)
|
|
354
|
-
print("#" + " " * 30 + "A/B 完整评测报告" + " " * 30 + "#")
|
|
355
|
-
print("#" * 88)
|
|
356
|
-
|
|
357
|
-
print("\n【输入文件】")
|
|
358
|
-
print(f" with scored : {with_scored}")
|
|
359
|
-
print(f" without scored: {without_scored}")
|
|
360
|
-
print(f" with log : {with_log} {'(存在)' if with_log and with_log.is_file() else '(无)'}")
|
|
361
|
-
print(f" without log : {without_log} {'(存在)' if without_log and without_log.is_file() else '(无)'}")
|
|
362
|
-
|
|
363
|
-
eff_with = print_efficiency_section("WITH homegraph", with_log, rows_with)
|
|
364
|
-
eff_without = print_efficiency_section("WITHOUT homegraph", without_log, rows_without)
|
|
365
|
-
|
|
366
|
-
print_statistics(stats_with, with_scored, title="【WITH homegraph】准确率统计")
|
|
367
|
-
print_statistics(stats_without, without_scored, title="【WITHOUT homegraph】准确率统计")
|
|
368
|
-
|
|
369
|
-
print_category_table(rows_with, rows_without)
|
|
370
|
-
print_per_item_table(rows_with, rows_without)
|
|
371
|
-
print_trajectory_section(rows_with, rows_without)
|
|
372
|
-
|
|
373
|
-
w = 22
|
|
374
|
-
print("\n" + "=" * 88)
|
|
375
|
-
print("【A/B 汇总表】")
|
|
376
|
-
print("=" * 88)
|
|
377
|
-
print(f"{'指标':<24}{'with':>{w}}{'without':>{w}}{'Δ (with−without)':>{w}}")
|
|
378
|
-
print("-" * 88)
|
|
379
|
-
|
|
380
|
-
def sm(s: dict | None) -> float | None:
|
|
381
|
-
return float(s["mean"]) if s and s.get("valid_scores") else None
|
|
382
|
-
|
|
383
|
-
def sd(s: dict | None) -> float | None:
|
|
384
|
-
return float(s["median"]) if s and s.get("valid_scores") else None
|
|
385
|
-
|
|
386
|
-
print(
|
|
387
|
-
f"{'准确率 均值':<24}"
|
|
388
|
-
f"{fmt_num(sm(stats_with), digits=4):>{w}}"
|
|
389
|
-
f"{fmt_num(sm(stats_without), digits=4):>{w}}"
|
|
390
|
-
f"{fmt_delta(sm(stats_with), sm(stats_without), digits=4):>{w}}"
|
|
391
|
-
)
|
|
392
|
-
print(
|
|
393
|
-
f"{'准确率 中位数':<24}"
|
|
394
|
-
f"{fmt_num(sd(stats_with), digits=4):>{w}}"
|
|
395
|
-
f"{fmt_num(sd(stats_without), digits=4):>{w}}"
|
|
396
|
-
f"{fmt_delta(sd(stats_with), sd(stats_without), digits=4):>{w}}"
|
|
397
|
-
)
|
|
398
|
-
jw = f"{stats_with['success_samples']}/{stats_with['total_samples']}"
|
|
399
|
-
jo = f"{stats_without['success_samples']}/{stats_without['total_samples']}"
|
|
400
|
-
print(
|
|
401
|
-
f"{'Judge 成功/总数':<24}"
|
|
402
|
-
f"{jw:>{w}}"
|
|
403
|
-
f"{jo:>{w}}"
|
|
404
|
-
f"{'—':>{w}}"
|
|
405
|
-
)
|
|
406
|
-
print("-" * 88)
|
|
407
|
-
print(
|
|
408
|
-
f"{'平均轮次':<24}"
|
|
409
|
-
f"{fmt_num(eff_with.get('avg_turns')):>{w}}"
|
|
410
|
-
f"{fmt_num(eff_without.get('avg_turns')):>{w}}"
|
|
411
|
-
f"{fmt_delta(eff_with.get('avg_turns'), eff_without.get('avg_turns')):>{w}}"
|
|
412
|
-
)
|
|
413
|
-
print(
|
|
414
|
-
f"{'平均耗时 (秒)':<24}"
|
|
415
|
-
f"{fmt_num(eff_with.get('avg_duration_s')):>{w}}"
|
|
416
|
-
f"{fmt_num(eff_without.get('avg_duration_s')):>{w}}"
|
|
417
|
-
f"{fmt_delta(eff_with.get('avg_duration_s'), eff_without.get('avg_duration_s')):>{w}}"
|
|
418
|
-
)
|
|
419
|
-
tw = eff_with.get("avg_tokens")
|
|
420
|
-
two = eff_without.get("avg_tokens")
|
|
421
|
-
print(
|
|
422
|
-
f"{'平均 Token (k)':<24}"
|
|
423
|
-
f"{fmt_num(tw / 1000 if tw else None, digits=2):>{w}}"
|
|
424
|
-
f"{fmt_num(two / 1000 if two else None, digits=2):>{w}}"
|
|
425
|
-
f"{fmt_delta(tw / 1000 if tw else None, two / 1000 if two else None, digits=2):>{w}}"
|
|
426
|
-
)
|
|
427
|
-
print(
|
|
428
|
-
f"{'平均首响应 (秒)':<24}"
|
|
429
|
-
f"{fmt_num(eff_with.get('avg_first_token_s')):>{w}}"
|
|
430
|
-
f"{fmt_num(eff_without.get('avg_first_token_s')):>{w}}"
|
|
431
|
-
f"{fmt_delta(eff_with.get('avg_first_token_s'), eff_without.get('avg_first_token_s')):>{w}}"
|
|
432
|
-
)
|
|
433
|
-
print(
|
|
434
|
-
f"{'平均峰值内存 (MB)':<24}"
|
|
435
|
-
f"{fmt_num(eff_with.get('avg_peak_rss_mb')):>{w}}"
|
|
436
|
-
f"{fmt_num(eff_without.get('avg_peak_rss_mb')):>{w}}"
|
|
437
|
-
f"{fmt_delta(eff_with.get('avg_peak_rss_mb'), eff_without.get('avg_peak_rss_mb')):>{w}}"
|
|
438
|
-
)
|
|
439
|
-
print(
|
|
440
|
-
f"{'最大峰值内存 (MB)':<24}"
|
|
441
|
-
f"{fmt_num(eff_with.get('max_peak_rss_mb')):>{w}}"
|
|
442
|
-
f"{fmt_num(eff_without.get('max_peak_rss_mb')):>{w}}"
|
|
443
|
-
f"{fmt_delta(eff_with.get('max_peak_rss_mb'), eff_without.get('max_peak_rss_mb')):>{w}}"
|
|
444
|
-
)
|
|
445
|
-
print("-" * 88)
|
|
446
|
-
print("效率数据来源:")
|
|
447
|
-
print(f" with : {eff_with.get('source', '?')}")
|
|
448
|
-
print(f" without : {eff_without.get('source', '?')}")
|
|
449
|
-
print("=" * 88)
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
def run_agent_stage(
|
|
453
|
-
*,
|
|
454
|
-
agent_host: str,
|
|
455
|
-
repo: Path,
|
|
456
|
-
dataset: list[dict],
|
|
457
|
-
with_jsonl: Path,
|
|
458
|
-
without_jsonl: Path,
|
|
459
|
-
with_log: Path | None,
|
|
460
|
-
without_log: Path | None,
|
|
461
|
-
llm,
|
|
462
|
-
hg_bin: str | None,
|
|
463
|
-
max_turns: int,
|
|
464
|
-
deveco_model: str | None = None,
|
|
465
|
-
deveco_attach: str | None = None,
|
|
466
|
-
) -> None:
|
|
467
|
-
if agent_host == HOST_CLAUDE:
|
|
468
|
-
verify_claude_login()
|
|
469
|
-
for arm, out, log in (
|
|
470
|
-
("with", with_jsonl, with_log),
|
|
471
|
-
("without", without_jsonl, without_log),
|
|
472
|
-
):
|
|
473
|
-
label = "WITH homegraph" if arm == "with" else "WITHOUT (grep/read only)"
|
|
474
|
-
print(f"\n>>> Agent [{agent_host}] [{label}] → {out}")
|
|
475
|
-
if agent_host == AGENT_HOST_BUILTIN:
|
|
476
|
-
run_agent_dataset(
|
|
477
|
-
repo,
|
|
478
|
-
dataset,
|
|
479
|
-
arm=arm,
|
|
480
|
-
output=out,
|
|
481
|
-
log_file=log,
|
|
482
|
-
api_key=llm.api_key,
|
|
483
|
-
base_url=llm.base_url,
|
|
484
|
-
model=llm.model,
|
|
485
|
-
hg_bin=hg_bin,
|
|
486
|
-
max_turns=max_turns,
|
|
487
|
-
extra_body=llm.extra_body,
|
|
488
|
-
)
|
|
489
|
-
else:
|
|
490
|
-
run_external_dataset(
|
|
491
|
-
agent_host,
|
|
492
|
-
repo,
|
|
493
|
-
dataset,
|
|
494
|
-
arm=arm,
|
|
495
|
-
output=out,
|
|
496
|
-
log_file=log,
|
|
497
|
-
hg_bin=hg_bin or "",
|
|
498
|
-
model=deveco_model if agent_host == HOST_DEVECO else None,
|
|
499
|
-
deveco_attach=deveco_attach if agent_host == HOST_DEVECO else None,
|
|
500
|
-
)
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
def cmd_ab(args: argparse.Namespace) -> int:
|
|
504
|
-
if args.agent_host == "all":
|
|
505
|
-
return cmd_hosts(args)
|
|
506
|
-
|
|
507
|
-
agent_host = args.agent_host
|
|
508
|
-
paths = paths_for_host(agent_host)
|
|
509
|
-
if args.with_scored:
|
|
510
|
-
with_scored = Path(args.with_scored)
|
|
511
|
-
else:
|
|
512
|
-
with_scored = paths["with_scored"]
|
|
513
|
-
if args.without_scored:
|
|
514
|
-
without_scored = Path(args.without_scored)
|
|
515
|
-
else:
|
|
516
|
-
without_scored = paths["without_scored"]
|
|
517
|
-
if args.with_jsonl:
|
|
518
|
-
with_jsonl = Path(args.with_jsonl)
|
|
519
|
-
else:
|
|
520
|
-
with_jsonl = paths["with_jsonl"]
|
|
521
|
-
if args.without_jsonl:
|
|
522
|
-
without_jsonl = Path(args.without_jsonl)
|
|
523
|
-
else:
|
|
524
|
-
without_jsonl = paths["without_jsonl"]
|
|
525
|
-
with_log = Path(args.with_log) if args.with_log else paths["with_log"]
|
|
526
|
-
without_log = Path(args.without_log) if args.without_log else paths["without_log"]
|
|
527
|
-
repo = require_repo_arg(getattr(args, "repo", None), no_agent=args.no_agent)
|
|
528
|
-
if repo is None and not args.no_agent:
|
|
529
|
-
return 1
|
|
530
|
-
dataset_path = Path(args.dataset).expanduser().resolve()
|
|
531
|
-
|
|
532
|
-
try:
|
|
533
|
-
llm = resolve_llm_config(
|
|
534
|
-
provider=getattr(args, "provider", None),
|
|
535
|
-
model=getattr(args, "model", None),
|
|
536
|
-
base_url=getattr(args, "base_url", None),
|
|
537
|
-
)
|
|
538
|
-
except RuntimeError as e:
|
|
539
|
-
print(f"错误: {e}")
|
|
540
|
-
return 1
|
|
541
|
-
|
|
542
|
-
if not args.no_agent:
|
|
543
|
-
if not dataset_path.is_file():
|
|
544
|
-
print(f"错误: 测试集不存在: {dataset_path}")
|
|
545
|
-
return 1
|
|
546
|
-
|
|
547
|
-
dataset = load_jsonl(dataset_path)
|
|
548
|
-
if not getattr(args, "keep_log", False):
|
|
549
|
-
removed, skipped = clear_log_dir(LOG_DIR)
|
|
550
|
-
print(f"已清空 log 目录: {LOG_DIR} ({removed} 项)", flush=True)
|
|
551
|
-
if skipped:
|
|
552
|
-
print("⚠ 以下项被占用,未删除(关闭占用进程后可手动删):", flush=True)
|
|
553
|
-
for item in skipped:
|
|
554
|
-
print(f" - {item}", flush=True)
|
|
555
|
-
print("=" * 60)
|
|
556
|
-
print(f"Stage 1 — Agent 跑题 ({len(dataset)} 条) host={agent_host}")
|
|
557
|
-
print(f" LLM : {llm.provider}")
|
|
558
|
-
print(f" 仓库 : {repo}")
|
|
559
|
-
print(f" 测试集 : {dataset_path}")
|
|
560
|
-
print(f" 报告 : {paths['report']}")
|
|
561
|
-
print("=" * 60)
|
|
562
|
-
|
|
563
|
-
assert repo is not None
|
|
564
|
-
run_agent_stage(
|
|
565
|
-
agent_host=agent_host,
|
|
566
|
-
repo=repo,
|
|
567
|
-
dataset=dataset,
|
|
568
|
-
with_jsonl=with_jsonl,
|
|
569
|
-
without_jsonl=without_jsonl,
|
|
570
|
-
with_log=with_log,
|
|
571
|
-
without_log=without_log,
|
|
572
|
-
llm=llm,
|
|
573
|
-
hg_bin=args.homegraph_bin,
|
|
574
|
-
max_turns=args.max_turns,
|
|
575
|
-
deveco_model=getattr(args, "deveco_model", None),
|
|
576
|
-
deveco_attach=getattr(args, "deveco_attach", None),
|
|
577
|
-
)
|
|
578
|
-
|
|
579
|
-
if not args.no_judge:
|
|
580
|
-
print("\n" + "=" * 60)
|
|
581
|
-
print(f"Stage 2 — Judge 打分 ({llm.provider})")
|
|
582
|
-
print("=" * 60)
|
|
583
|
-
if run_judge(with_jsonl, with_scored, workers=args.workers, llm=llm) != 0:
|
|
584
|
-
return 1
|
|
585
|
-
if run_judge(without_jsonl, without_scored, workers=args.workers, llm=llm) != 0:
|
|
586
|
-
return 1
|
|
587
|
-
|
|
588
|
-
if not with_scored.is_file() or not without_scored.is_file():
|
|
589
|
-
print("错误: 缺少 scored 结果。请去掉 --no-agent --no-judge 完整跑一遍,或提供 scored 文件。")
|
|
590
|
-
return 1
|
|
591
|
-
|
|
592
|
-
rows_with = load_jsonl(with_scored)
|
|
593
|
-
rows_without = load_jsonl(without_scored)
|
|
594
|
-
|
|
595
|
-
print("\n" + "=" * 60)
|
|
596
|
-
print("Stage 3–4 — 效率统计 + A/B 对比报告")
|
|
597
|
-
print("=" * 60)
|
|
598
|
-
|
|
599
|
-
eff_with = print_efficiency_section("WITH homegraph", with_log, rows_with)
|
|
600
|
-
eff_without = print_efficiency_section("WITHOUT homegraph", without_log, rows_without)
|
|
601
|
-
|
|
602
|
-
report_path = Path(args.report).expanduser().resolve() if args.report else paths["report"]
|
|
603
|
-
report_path.parent.mkdir(parents=True, exist_ok=True)
|
|
604
|
-
|
|
605
|
-
buf = io.StringIO()
|
|
606
|
-
with redirect_stdout(buf):
|
|
607
|
-
print_full_ab_report(
|
|
608
|
-
with_scored=with_scored,
|
|
609
|
-
without_scored=without_scored,
|
|
610
|
-
with_log=with_log,
|
|
611
|
-
without_log=without_log,
|
|
612
|
-
rows_with=rows_with,
|
|
613
|
-
rows_without=rows_without,
|
|
614
|
-
)
|
|
615
|
-
|
|
616
|
-
report_path.write_text(buf.getvalue(), encoding="utf-8")
|
|
617
|
-
print(f"\nA/B 完整报告已写入: {report_path}")
|
|
618
|
-
return 0
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
def cmd_score(args: argparse.Namespace) -> int:
|
|
622
|
-
input_jsonl = Path(args.input)
|
|
623
|
-
scored = Path(args.scored) if args.scored else input_jsonl.with_name(input_jsonl.stem + "-scored.jsonl")
|
|
624
|
-
cmd = [
|
|
625
|
-
sys.executable,
|
|
626
|
-
str(_SCRIPT_DIR / "eval_metrics.py"),
|
|
627
|
-
"-i",
|
|
628
|
-
str(input_jsonl),
|
|
629
|
-
"-o",
|
|
630
|
-
str(scored),
|
|
631
|
-
"-w",
|
|
632
|
-
str(args.workers),
|
|
633
|
-
]
|
|
634
|
-
if getattr(args, "provider", None):
|
|
635
|
-
cmd.extend(["--provider", args.provider])
|
|
636
|
-
if args.model:
|
|
637
|
-
cmd.extend(["-m", args.model])
|
|
638
|
-
rc = subprocess.call(cmd)
|
|
639
|
-
if rc != 0:
|
|
640
|
-
return rc
|
|
641
|
-
rows = load_jsonl(scored)
|
|
642
|
-
print_statistics(compute_stats_from_rows(rows), scored)
|
|
643
|
-
if args.log:
|
|
644
|
-
print_efficiency_section("单路", Path(args.log), rows)
|
|
645
|
-
return 0
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
def cmd_hosts(args: argparse.Namespace) -> int:
|
|
649
|
-
"""Run full A/B for each Agent host (builtin, claude-code, deveco-code)."""
|
|
650
|
-
repo = require_repo_arg(getattr(args, "repo", None), no_agent=args.no_agent)
|
|
651
|
-
if repo is None and not args.no_agent:
|
|
652
|
-
return 1
|
|
653
|
-
|
|
654
|
-
hosts_raw = getattr(args, "agent_hosts", None) or ",".join(ALL_AGENT_HOSTS)
|
|
655
|
-
hosts = [h.strip() for h in hosts_raw.split(",") if h.strip()]
|
|
656
|
-
unknown = [h for h in hosts if h not in ALL_AGENT_HOSTS]
|
|
657
|
-
if unknown:
|
|
658
|
-
print(f"错误: 未知 agent host: {unknown},可选: {', '.join(ALL_AGENT_HOSTS)}")
|
|
659
|
-
return 1
|
|
660
|
-
|
|
661
|
-
rc = 0
|
|
662
|
-
for host in hosts:
|
|
663
|
-
print("\n" + "#" * 88)
|
|
664
|
-
print(f"# Agent host: {host}")
|
|
665
|
-
print("#" * 88)
|
|
666
|
-
host_args = argparse.Namespace(
|
|
667
|
-
repo=args.repo,
|
|
668
|
-
dataset=args.dataset,
|
|
669
|
-
with_scored=None,
|
|
670
|
-
without_scored=None,
|
|
671
|
-
with_jsonl=None,
|
|
672
|
-
without_jsonl=None,
|
|
673
|
-
with_log=None,
|
|
674
|
-
without_log=None,
|
|
675
|
-
workers=args.workers,
|
|
676
|
-
provider=getattr(args, "provider", None),
|
|
677
|
-
model=args.model,
|
|
678
|
-
base_url=args.base_url,
|
|
679
|
-
homegraph_bin=args.homegraph_bin,
|
|
680
|
-
max_turns=args.max_turns,
|
|
681
|
-
no_agent=args.no_agent,
|
|
682
|
-
no_judge=args.no_judge,
|
|
683
|
-
keep_log=getattr(args, "keep_log", False),
|
|
684
|
-
report=None,
|
|
685
|
-
agent_host=host,
|
|
686
|
-
deveco_model=getattr(args, "deveco_model", None),
|
|
687
|
-
deveco_attach=getattr(args, "deveco_attach", None),
|
|
688
|
-
)
|
|
689
|
-
if cmd_ab(host_args) != 0:
|
|
690
|
-
rc = 1
|
|
691
|
-
if rc == 0:
|
|
692
|
-
print("\n" + "=" * 60)
|
|
693
|
-
print("全部宿主跑完,报告文件:")
|
|
694
|
-
for host in hosts:
|
|
695
|
-
p = paths_for_host(host)["report"]
|
|
696
|
-
print(f" {host}: {p}")
|
|
697
|
-
print("=" * 60)
|
|
698
|
-
return rc
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
def main() -> int:
|
|
702
|
-
parser = argparse.ArgumentParser(description="QA Eval A/B — 完整打印全部对比结果")
|
|
703
|
-
sub = parser.add_subparsers(dest="command", required=True)
|
|
704
|
-
|
|
705
|
-
p_ab = sub.add_parser("ab", help="一条龙:Agent → Judge → 完整报告(默认会更新全部数据)")
|
|
706
|
-
p_ab.add_argument(
|
|
707
|
-
"--repo",
|
|
708
|
-
"-r",
|
|
709
|
-
default=None,
|
|
710
|
-
help="被测仓库绝对路径(跑 Agent 时必填;仅 --no-agent 重打报告时可省略)",
|
|
711
|
-
)
|
|
712
|
-
p_ab.add_argument("--dataset", "-d", default=str(DEFAULT_DATASET))
|
|
713
|
-
p_ab.add_argument(
|
|
714
|
-
"--agent-host",
|
|
715
|
-
default=AGENT_HOST_BUILTIN,
|
|
716
|
-
choices=[*ALL_AGENT_HOSTS, "all"],
|
|
717
|
-
help="Agent 宿主: builtin(Python+Qwen) | claude-code | deveco-code | all",
|
|
718
|
-
)
|
|
719
|
-
p_ab.add_argument("--with-scored", default=None)
|
|
720
|
-
p_ab.add_argument("--without-scored", default=None)
|
|
721
|
-
p_ab.add_argument("--with-jsonl", default=None)
|
|
722
|
-
p_ab.add_argument("--without-jsonl", default=None)
|
|
723
|
-
p_ab.add_argument("--with-log", default=None)
|
|
724
|
-
p_ab.add_argument("--without-log", default=None)
|
|
725
|
-
p_ab.add_argument("--workers", "-w", type=int, default=1)
|
|
726
|
-
p_ab.add_argument(
|
|
727
|
-
"--provider",
|
|
728
|
-
choices=[PROVIDER_DASHSCOPE, PROVIDER_ZHIPU],
|
|
729
|
-
default=None,
|
|
730
|
-
help=provider_help(),
|
|
731
|
-
)
|
|
732
|
-
p_ab.add_argument("--model", "-m", default=None, help="LLM 模型(默认随 provider)")
|
|
733
|
-
p_ab.add_argument("--base-url", default=None, help="OpenAI 兼容 API 端点(默认随 provider)")
|
|
734
|
-
p_ab.add_argument("--homegraph-bin", default=None)
|
|
735
|
-
p_ab.add_argument("--max-turns", type=int, default=8, help="Agent 最多工具轮次")
|
|
736
|
-
p_ab.add_argument(
|
|
737
|
-
"--deveco-model",
|
|
738
|
-
default=None,
|
|
739
|
-
help="DevEco Agent 模型(provider/model,如 zhipuai/glm-4.5-flash);默认用 DevEco 自身配置,不用 --model",
|
|
740
|
-
)
|
|
741
|
-
p_ab.add_argument(
|
|
742
|
-
"--deveco-attach",
|
|
743
|
-
default=os.environ.get("QA_EVAL_DEVECO_ATTACH"),
|
|
744
|
-
help="已运行的 deveco serve 地址(如 http://127.0.0.1:4096),复用进程避免每题冷启动",
|
|
745
|
-
)
|
|
746
|
-
p_ab.add_argument("--no-agent", action="store_true", help="不跑 Agent,沿用已有 JSONL")
|
|
747
|
-
p_ab.add_argument("--no-judge", action="store_true", help="不跑 Judge,沿用已有 scored")
|
|
748
|
-
p_ab.add_argument(
|
|
749
|
-
"--keep-log",
|
|
750
|
-
action="store_true",
|
|
751
|
-
help="保留 scripts/qa_eval/log 下旧文件(默认每次跑 Agent 前清空)",
|
|
752
|
-
)
|
|
753
|
-
p_ab.add_argument(
|
|
754
|
-
"--report",
|
|
755
|
-
default=None,
|
|
756
|
-
help="A/B 完整报告输出路径(默认 data/report-{host}.txt,如 report-deveco.txt)",
|
|
757
|
-
)
|
|
758
|
-
p_ab.set_defaults(func=cmd_ab)
|
|
759
|
-
|
|
760
|
-
p_hosts = sub.add_parser("hosts", help="依次跑 builtin + claude-code + deveco-code 的 A/B")
|
|
761
|
-
p_hosts.add_argument(
|
|
762
|
-
"--repo",
|
|
763
|
-
"-r",
|
|
764
|
-
default=None,
|
|
765
|
-
help="被测仓库绝对路径(跑 Agent 时必填;仅 --no-agent 重打报告时可省略)",
|
|
766
|
-
)
|
|
767
|
-
p_hosts.add_argument("--dataset", "-d", default=str(DEFAULT_DATASET))
|
|
768
|
-
p_hosts.add_argument("--workers", "-w", type=int, default=1)
|
|
769
|
-
p_hosts.add_argument("--provider", choices=[PROVIDER_DASHSCOPE, PROVIDER_ZHIPU], default=None)
|
|
770
|
-
p_hosts.add_argument("--model", "-m", default=None)
|
|
771
|
-
p_hosts.add_argument("--base-url", default=None)
|
|
772
|
-
p_hosts.add_argument("--homegraph-bin", default=None)
|
|
773
|
-
p_hosts.add_argument("--max-turns", type=int, default=8)
|
|
774
|
-
p_hosts.add_argument("--deveco-model", default=None)
|
|
775
|
-
p_hosts.add_argument(
|
|
776
|
-
"--deveco-attach",
|
|
777
|
-
default=os.environ.get("QA_EVAL_DEVECO_ATTACH"),
|
|
778
|
-
help="deveco serve 地址,见 ab --deveco-attach",
|
|
779
|
-
)
|
|
780
|
-
p_hosts.add_argument("--no-agent", action="store_true")
|
|
781
|
-
p_hosts.add_argument("--no-judge", action="store_true")
|
|
782
|
-
p_hosts.add_argument("--keep-log", action="store_true")
|
|
783
|
-
p_hosts.add_argument(
|
|
784
|
-
"--agent-hosts",
|
|
785
|
-
default=",".join(ALL_AGENT_HOSTS),
|
|
786
|
-
help="逗号分隔: builtin,claude-code,deveco-code",
|
|
787
|
-
)
|
|
788
|
-
p_hosts.set_defaults(func=cmd_hosts)
|
|
789
|
-
|
|
790
|
-
p_score = sub.add_parser("score", help="单路:Agent JSONL → Judge → 统计")
|
|
791
|
-
p_score.add_argument("--input", "-i", required=True)
|
|
792
|
-
p_score.add_argument("--scored", "-o", default=None)
|
|
793
|
-
p_score.add_argument("--log", "-l", default=None)
|
|
794
|
-
p_score.add_argument("--workers", "-w", type=int, default=1)
|
|
795
|
-
p_score.add_argument("--provider", choices=[PROVIDER_DASHSCOPE, PROVIDER_ZHIPU], default=None)
|
|
796
|
-
p_score.add_argument("--model", "-m", default=None)
|
|
797
|
-
p_score.set_defaults(func=cmd_score)
|
|
798
|
-
|
|
799
|
-
args = parser.parse_args()
|
|
800
|
-
return args.func(args)
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if __name__ == "__main__":
|
|
804
|
-
raise SystemExit(main())
|