homegraph 1.1.2 → 1.2.0
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/LICENSE +21 -21
- package/README.md +268 -243
- package/dist/arkts/ohos-api-index.d.ts +15 -0
- package/dist/arkts/ohos-api-index.d.ts.map +1 -0
- package/dist/arkts/ohos-api-index.js +190 -0
- package/dist/arkts/ohos-api-index.js.map +1 -0
- package/dist/arkts/ohos-sdk-input.d.ts +36 -0
- package/dist/arkts/ohos-sdk-input.d.ts.map +1 -0
- package/dist/arkts/ohos-sdk-input.js +214 -0
- package/dist/arkts/ohos-sdk-input.js.map +1 -0
- package/dist/bin/command-supervision.d.ts +12 -0
- package/dist/bin/command-supervision.d.ts.map +1 -0
- package/dist/bin/command-supervision.js +86 -0
- package/dist/bin/command-supervision.js.map +1 -0
- package/dist/bin/homegraph.d.ts +1 -1
- package/dist/bin/homegraph.js +971 -71
- package/dist/bin/homegraph.js.map +1 -1
- package/dist/db/index.d.ts +20 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +39 -0
- 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 +58 -19
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/queries.d.ts +14 -0
- package/dist/db/queries.d.ts.map +1 -1
- package/dist/db/queries.js +314 -143
- package/dist/db/queries.js.map +1 -1
- package/dist/db/schema.sql +172 -152
- package/dist/directory.d.ts +32 -0
- package/dist/directory.d.ts.map +1 -1
- package/dist/directory.js +88 -5
- package/dist/directory.js.map +1 -1
- package/dist/extraction/arkts-batch-worker.d.ts +2 -0
- package/dist/extraction/arkts-batch-worker.d.ts.map +1 -0
- package/dist/extraction/arkts-batch-worker.js +28 -0
- package/dist/extraction/arkts-batch-worker.js.map +1 -0
- package/dist/extraction/context.d.ts +11 -0
- package/dist/extraction/context.d.ts.map +1 -1
- package/dist/extraction/context.js +20 -0
- package/dist/extraction/context.js.map +1 -1
- package/dist/extraction/index.d.ts +16 -2
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +619 -380
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/languages/arkts-state-decorators.d.ts +13 -0
- package/dist/extraction/languages/arkts-state-decorators.d.ts.map +1 -0
- package/dist/extraction/languages/arkts-state-decorators.js +26 -0
- package/dist/extraction/languages/arkts-state-decorators.js.map +1 -0
- package/dist/extraction/languages/arkts-viewtree.d.ts +4 -2
- package/dist/extraction/languages/arkts-viewtree.d.ts.map +1 -1
- package/dist/extraction/languages/arkts-viewtree.js +21 -6
- package/dist/extraction/languages/arkts-viewtree.js.map +1 -1
- package/dist/extraction/languages/arkts.d.ts +98 -2
- package/dist/extraction/languages/arkts.d.ts.map +1 -1
- package/dist/extraction/languages/arkts.js +1290 -61
- package/dist/extraction/languages/arkts.js.map +1 -1
- package/dist/extraction/languages/c-cpp.d.ts +56 -0
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/dist/extraction/languages/c-cpp.js +198 -1
- package/dist/extraction/languages/c-cpp.js.map +1 -1
- package/dist/extraction/languages/ohos-api-consumer.d.ts +34 -0
- package/dist/extraction/languages/ohos-api-consumer.d.ts.map +1 -0
- package/dist/extraction/languages/ohos-api-consumer.js +283 -0
- package/dist/extraction/languages/ohos-api-consumer.js.map +1 -0
- package/dist/extraction/parse-pool.d.ts +126 -0
- package/dist/extraction/parse-pool.d.ts.map +1 -0
- package/dist/extraction/parse-pool.js +319 -0
- package/dist/extraction/parse-pool.js.map +1 -0
- package/dist/extraction/tree-sitter-types.d.ts +17 -0
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.d.ts +21 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.js +198 -27
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
- package/dist/graph/traversal.d.ts.map +1 -1
- package/dist/graph/traversal.js +76 -17
- package/dist/graph/traversal.js.map +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -4
- package/dist/index.js.map +1 -1
- package/dist/installer/instructions-template.js +9 -9
- package/dist/installer/targets/shared.d.ts +5 -6
- package/dist/installer/targets/shared.d.ts.map +1 -1
- package/dist/installer/targets/shared.js +5 -6
- package/dist/installer/targets/shared.js.map +1 -1
- package/dist/mcp/daemon-paths.d.ts +30 -3
- package/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/dist/mcp/daemon-paths.js +50 -10
- package/dist/mcp/daemon-paths.js.map +1 -1
- package/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/dist/mcp/daemon-registry.js +7 -3
- package/dist/mcp/daemon-registry.js.map +1 -1
- package/dist/mcp/daemon.d.ts +48 -0
- package/dist/mcp/daemon.d.ts.map +1 -1
- package/dist/mcp/daemon.js +196 -32
- package/dist/mcp/daemon.js.map +1 -1
- package/dist/mcp/engine.d.ts +17 -0
- package/dist/mcp/engine.d.ts.map +1 -1
- package/dist/mcp/engine.js +73 -1
- package/dist/mcp/engine.js.map +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +25 -43
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/liveness-watchdog.js +16 -16
- package/dist/mcp/ppid-watchdog.d.ts +18 -0
- package/dist/mcp/ppid-watchdog.d.ts.map +1 -1
- package/dist/mcp/ppid-watchdog.js +37 -0
- package/dist/mcp/ppid-watchdog.js.map +1 -1
- package/dist/mcp/query-cache.d.ts +25 -0
- package/dist/mcp/query-cache.d.ts.map +1 -0
- package/dist/mcp/query-cache.js +191 -0
- package/dist/mcp/query-cache.js.map +1 -0
- package/dist/mcp/query-pool.d.ts +94 -0
- package/dist/mcp/query-pool.d.ts.map +1 -0
- package/dist/mcp/query-pool.js +297 -0
- package/dist/mcp/query-pool.js.map +1 -0
- package/dist/mcp/query-worker.d.ts +24 -0
- package/dist/mcp/query-worker.d.ts.map +1 -0
- package/dist/mcp/query-worker.js +87 -0
- package/dist/mcp/query-worker.js.map +1 -0
- package/dist/mcp/server-instructions.d.ts +5 -7
- package/dist/mcp/server-instructions.d.ts.map +1 -1
- package/dist/mcp/server-instructions.js +72 -74
- package/dist/mcp/server-instructions.js.map +1 -1
- package/dist/mcp/tools.d.ts +94 -4
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +877 -71
- package/dist/mcp/tools.js.map +1 -1
- package/dist/project-config.d.ts +20 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +42 -2
- package/dist/project-config.js.map +1 -1
- package/dist/reasoning/login.js +1 -1
- package/dist/reasoning/login.js.map +1 -1
- package/dist/reasoning/reasoner.js +32 -32
- package/dist/resolution/c-fnptr-synthesizer.d.ts +0 -28
- package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/dist/resolution/c-fnptr-synthesizer.js +765 -79
- package/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/dist/resolution/callback-synthesizer.d.ts +1 -1
- package/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/dist/resolution/callback-synthesizer.js +72 -11
- package/dist/resolution/callback-synthesizer.js.map +1 -1
- package/dist/resolution/cooperative-yield.d.ts +32 -0
- package/dist/resolution/cooperative-yield.d.ts.map +1 -0
- package/dist/resolution/cooperative-yield.js +42 -0
- package/dist/resolution/cooperative-yield.js.map +1 -0
- package/dist/resolution/index.d.ts +11 -2
- package/dist/resolution/index.d.ts.map +1 -1
- package/dist/resolution/index.js +72 -4
- package/dist/resolution/index.js.map +1 -1
- package/dist/resolution/name-matcher.d.ts +22 -0
- package/dist/resolution/name-matcher.d.ts.map +1 -1
- package/dist/resolution/name-matcher.js +317 -20
- package/dist/resolution/name-matcher.js.map +1 -1
- package/dist/spec/config.d.ts +39 -0
- package/dist/spec/config.d.ts.map +1 -0
- package/dist/spec/config.js +304 -0
- package/dist/spec/config.js.map +1 -0
- package/dist/spec/db/commit-node.d.ts +23 -0
- package/dist/spec/db/commit-node.d.ts.map +1 -0
- package/dist/spec/db/commit-node.js +62 -0
- package/dist/spec/db/commit-node.js.map +1 -0
- package/dist/spec/db/fragment-node.d.ts +24 -0
- package/dist/spec/db/fragment-node.d.ts.map +1 -0
- package/dist/spec/db/fragment-node.js +128 -0
- package/dist/spec/db/fragment-node.js.map +1 -0
- package/dist/spec/db/fts.d.ts +74 -0
- package/dist/spec/db/fts.d.ts.map +1 -0
- package/dist/spec/db/fts.js +324 -0
- package/dist/spec/db/fts.js.map +1 -0
- package/dist/spec/db/index.d.ts +13 -0
- package/dist/spec/db/index.d.ts.map +1 -0
- package/dist/spec/db/index.js +50 -0
- package/dist/spec/db/index.js.map +1 -0
- package/dist/spec/db/relations.d.ts +55 -0
- package/dist/spec/db/relations.d.ts.map +1 -0
- package/dist/spec/db/relations.js +158 -0
- package/dist/spec/db/relations.js.map +1 -0
- package/dist/spec/db/schema.d.ts +33 -0
- package/dist/spec/db/schema.d.ts.map +1 -0
- package/dist/spec/db/schema.js +119 -0
- package/dist/spec/db/schema.js.map +1 -0
- package/dist/spec/db/schema.sql +117 -0
- package/dist/spec/db/spec-node.d.ts +41 -0
- package/dist/spec/db/spec-node.d.ts.map +1 -0
- package/dist/spec/db/spec-node.js +114 -0
- package/dist/spec/db/spec-node.js.map +1 -0
- package/dist/spec/evolve/impact-locator.d.ts +13 -0
- package/dist/spec/evolve/impact-locator.d.ts.map +1 -0
- package/dist/spec/evolve/impact-locator.js +25 -0
- package/dist/spec/evolve/impact-locator.js.map +1 -0
- package/dist/spec/evolve/llm-client.d.ts +50 -0
- package/dist/spec/evolve/llm-client.d.ts.map +1 -0
- package/dist/spec/evolve/llm-client.js +176 -0
- package/dist/spec/evolve/llm-client.js.map +1 -0
- package/dist/spec/evolve/logic-checker.d.ts +12 -0
- package/dist/spec/evolve/logic-checker.d.ts.map +1 -0
- package/dist/spec/evolve/logic-checker.js +24 -0
- package/dist/spec/evolve/logic-checker.js.map +1 -0
- package/dist/spec/evolve/pipeline.d.ts +42 -0
- package/dist/spec/evolve/pipeline.d.ts.map +1 -0
- package/dist/spec/evolve/pipeline.js +567 -0
- package/dist/spec/evolve/pipeline.js.map +1 -0
- package/dist/spec/evolve/spec-rewriter.d.ts +42 -0
- package/dist/spec/evolve/spec-rewriter.d.ts.map +1 -0
- package/dist/spec/evolve/spec-rewriter.js +230 -0
- package/dist/spec/evolve/spec-rewriter.js.map +1 -0
- package/dist/spec/graph/queries.d.ts +155 -0
- package/dist/spec/graph/queries.d.ts.map +1 -0
- package/dist/spec/graph/queries.js +440 -0
- package/dist/spec/graph/queries.js.map +1 -0
- package/dist/spec/llm/client.d.ts +29 -0
- package/dist/spec/llm/client.d.ts.map +1 -0
- package/dist/spec/llm/client.js +123 -0
- package/dist/spec/llm/client.js.map +1 -0
- package/dist/spec/llm/index.d.ts +3 -0
- package/dist/spec/llm/index.d.ts.map +1 -0
- package/dist/spec/llm/index.js +11 -0
- package/dist/spec/llm/index.js.map +1 -0
- package/dist/spec/llm/prompts.d.ts +13 -0
- package/dist/spec/llm/prompts.d.ts.map +1 -0
- package/dist/spec/llm/prompts.js +75 -0
- package/dist/spec/llm/prompts.js.map +1 -0
- package/dist/spec/mining/diff-parser.d.ts +33 -0
- package/dist/spec/mining/diff-parser.d.ts.map +1 -0
- package/dist/spec/mining/diff-parser.js +166 -0
- package/dist/spec/mining/diff-parser.js.map +1 -0
- package/dist/spec/mining/git-scanner.d.ts +103 -0
- package/dist/spec/mining/git-scanner.d.ts.map +1 -0
- package/dist/spec/mining/git-scanner.js +307 -0
- package/dist/spec/mining/git-scanner.js.map +1 -0
- package/dist/spec/mining/pipeline.d.ts +53 -0
- package/dist/spec/mining/pipeline.d.ts.map +1 -0
- package/dist/spec/mining/pipeline.js +178 -0
- package/dist/spec/mining/pipeline.js.map +1 -0
- package/dist/spec/mining/scope-resolver.d.ts +45 -0
- package/dist/spec/mining/scope-resolver.d.ts.map +1 -0
- package/dist/spec/mining/scope-resolver.js +103 -0
- package/dist/spec/mining/scope-resolver.js.map +1 -0
- package/dist/spec/mining/spec-extractor.d.ts +69 -0
- package/dist/spec/mining/spec-extractor.d.ts.map +1 -0
- package/dist/spec/mining/spec-extractor.js +369 -0
- package/dist/spec/mining/spec-extractor.js.map +1 -0
- package/dist/spec/types.d.ts +149 -0
- package/dist/spec/types.d.ts.map +1 -0
- package/dist/spec/types.js +15 -0
- package/dist/spec/types.js.map +1 -0
- package/dist/spec/utils.d.ts +167 -0
- package/dist/spec/utils.d.ts.map +1 -0
- package/dist/spec/utils.js +463 -0
- package/dist/spec/utils.js.map +1 -0
- package/dist/sync/worktree.d.ts +9 -0
- package/dist/sync/worktree.d.ts.map +1 -1
- package/dist/sync/worktree.js +40 -0
- package/dist/sync/worktree.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/shimmer-progress.d.ts +2 -0
- package/dist/ui/shimmer-progress.d.ts.map +1 -1
- package/dist/ui/shimmer-progress.js +19 -2
- package/dist/ui/shimmer-progress.js.map +1 -1
- package/dist/upgrade/index.js +1 -1
- package/dist/upgrade/index.js.map +1 -1
- package/package.json +58 -57
- package/scripts/add-lang/bench.sh +60 -60
- package/scripts/add-lang/check-grammar.mjs +75 -75
- package/scripts/add-lang/dump-ast.mjs +103 -103
- package/scripts/add-lang/verify-extraction.mjs +70 -70
- package/scripts/agent-eval/ab-adoption.sh +91 -91
- package/scripts/agent-eval/ab-hook.sh +86 -86
- package/scripts/agent-eval/ab-impl.sh +78 -78
- package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -102
- package/scripts/agent-eval/ab-sufficiency.sh +78 -78
- package/scripts/agent-eval/arms-F.sh +21 -21
- package/scripts/agent-eval/arms-matrix.sh +37 -37
- package/scripts/agent-eval/audit.sh +68 -68
- package/scripts/agent-eval/bench-readme.sh +28 -28
- package/scripts/agent-eval/bench-why-repo.sh +22 -22
- package/scripts/agent-eval/block-read-hook.sh +19 -19
- package/scripts/agent-eval/hook-settings.json +15 -15
- package/scripts/agent-eval/itrun.sh +120 -120
- package/scripts/agent-eval/offload-eval-3arm.sh +72 -72
- package/scripts/agent-eval/offload-eval-cost.mjs +133 -133
- package/scripts/agent-eval/offload-eval-effort.mjs +108 -108
- package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -25
- package/scripts/agent-eval/offload-eval-frontload.sh +47 -47
- package/scripts/agent-eval/offload-eval-ground-truth.json +18 -18
- package/scripts/agent-eval/offload-eval-hook.mjs +84 -84
- package/scripts/agent-eval/offload-eval-judge.mjs +103 -103
- package/scripts/agent-eval/offload-eval-matrix.sh +20 -20
- package/scripts/agent-eval/offload-eval-metrics.mjs +94 -94
- package/scripts/agent-eval/offload-eval-refs1.sh +50 -50
- package/scripts/agent-eval/offload-eval-setup.sh +24 -24
- package/scripts/agent-eval/offload-eval-styles.sh +71 -71
- package/scripts/agent-eval/offload-eval-summarize.mjs +68 -68
- package/scripts/agent-eval/offload-eval.md +76 -76
- package/scripts/agent-eval/parse-arms.mjs +116 -116
- package/scripts/agent-eval/parse-bench-readme.mjs +84 -84
- package/scripts/agent-eval/parse-run.mjs +45 -45
- package/scripts/agent-eval/parse-session.mjs +93 -93
- package/scripts/agent-eval/probe-context.mjs +21 -21
- package/scripts/agent-eval/probe-explore.mjs +40 -40
- package/scripts/agent-eval/probe-node.mjs +20 -20
- package/scripts/agent-eval/probe-sweep.mjs +119 -119
- package/scripts/agent-eval/probe-trace.mjs +20 -20
- package/scripts/agent-eval/redirect-read-hook.sh +38 -38
- package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
- package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
- package/scripts/agent-eval/run-agent.sh +34 -34
- package/scripts/agent-eval/run-all.sh +69 -69
- package/scripts/agent-eval/run-arms.sh +56 -56
- package/scripts/agent-eval/seq-matrix.mjs +137 -137
- package/scripts/build-bundle.sh +118 -118
- package/scripts/exp_boundary_eval/README.md +247 -0
- 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/_test_mcp_chain.py +78 -0
- package/scripts/exp_boundary_eval/_test_stdin.py +8 -0
- package/scripts/exp_boundary_eval/_utils.py +1116 -0
- package/scripts/exp_boundary_eval/analyze.py +1313 -0
- package/scripts/exp_boundary_eval/data/agents.json +109 -0
- package/scripts/exp_boundary_eval/data/experiments.json +140 -0
- package/scripts/exp_boundary_eval/deveco_arm.py +519 -0
- package/scripts/exp_boundary_eval/run_all.py +378 -0
- package/scripts/exp_boundary_eval/run_one.py +165 -0
- package/scripts/exp_boundary_eval/run_session.py +158 -0
- package/scripts/exp_boundary_eval/setup.py +120 -0
- package/scripts/exp_boundary_eval/win_mcp_launcher.py +73 -0
- package/scripts/exp_boundary_eval/win_mcp_stdio_wrap.js +36 -0
- package/scripts/exp_boundary_eval/win_node_launcher.py +24 -0
- package/scripts/extract-release-notes.mjs +130 -130
- package/scripts/local-install.sh +41 -41
- package/scripts/npm-sdk.js +75 -75
- package/scripts/npm-shim.js +268 -246
- package/scripts/ohos-sdk-publish.mjs +133 -0
- package/scripts/pack-npm.sh +119 -119
- package/scripts/prepare-release.mjs +270 -270
- package/scripts/qa_eval/README.md +407 -404
- package/scripts/qa_eval/_test_deveco_probe.py +41 -41
- package/scripts/qa_eval/agent_runner.py +526 -526
- package/scripts/qa_eval/data/.gitignore +4 -4
- package/scripts/qa_eval/data/test-set.jsonl +2 -22
- package/scripts/qa_eval/eval_metrics.py +274 -233
- package/scripts/qa_eval/external_agent.py +976 -671
- package/scripts/qa_eval/llm_config.py +92 -92
- package/scripts/qa_eval/memory_monitor.py +132 -132
- package/scripts/qa_eval/my_answer_accuracy.py +187 -187
- package/scripts/qa_eval/requirements.txt +2 -2
- package/scripts/qa_eval/run_pipeline.py +804 -711
- package/scripts/qa_eval/stats_efficiency.py +279 -279
- package/scripts/qa_eval/stats_scores.py +207 -207
|
@@ -1,711 +1,804 @@
|
|
|
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
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
from
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
from
|
|
42
|
-
from
|
|
43
|
-
from
|
|
44
|
-
from
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if r.get("
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
print("-"
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
print(
|
|
295
|
-
print(f" without
|
|
296
|
-
print(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
)
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
)
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
print(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
)
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
else
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
)
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
if
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
)
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
"
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
print(
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
"-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
)
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
"
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
)
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
)
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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())
|