完善口径管理、主动调查与后台任务,修复通用问题

- 完善口径编辑、只读试运行、统一质量验证与执行语义指纹
- 增加可执行指标约束、有预算的主动调查和过程评测
- 提取发布检查、证据读取与起草服务,支持任务停止、重试和检查点恢复
- 增加版本传递影响分析,修复并发覆盖、敏感值遮罩、异常评分及页面状态问题
- 修复 SQLite 复合查询追溯和 microVM 可选依赖缺失处理
- 纳入当前设计文档及部署配置调整

验证:相关主回归 3822 项通过,4 项跳过、8 项预期失败;补充回归通过。
前端构建、文案检查及 git diff --check 通过。
全量检查仍有环境权限、PostgreSQL 可选依赖和既有部署配置、SQLite 文件基线差异导致的未通过项。
This commit is contained in:
ThearchyHelios
2026-11-06 17:14:45 +08:00
parent 5f0b2359ac
commit 9d8b41430e
94 changed files with 9730 additions and 957 deletions
+19 -2
View File
@@ -54,7 +54,7 @@ GOLD_GUARD = "eval_gold_guard"
#: 口径题指的卡不能当口径题(422):不存在、不是口径卡、不能复用、取数节点引用了入口字段以外的值
CALIBER_NOT_REUSABLE = "eval_caliber_not_reusable"
EXPECTATION_KINDS = ("scalar", "table", "set", "none", "ask", "text", "contribution", "verdict")
EXPECTATION_KINDS = ("scalar", "table", "set", "none", "ask", "text", "contribution", "verdict", "investigation")
#: 要期望答案来源的期望:数都由 SQL / 口径算,分析的判定由算子在期望 SQL 的结果上算
NEEDS_GOLD = ("scalar", "table", "set", "none", "contribution", "verdict")
#: 不计入准确率的(评测-D4:文字要点由裁判判,单列)
@@ -74,6 +74,7 @@ _EXPECTATION_KEYS: dict[str, tuple[str, ...]] = {
"text": ("points",),
"contribution": ("op", "mode", "params", "top_n"),
"verdict": ("op", "mode", "params"),
"investigation": ("minimum_depth", "max_queries", "status", "stop_reason"),
}
_COMMON_KEYS = ("id", "kind", "required", "label")
#: 期望答案来源的键(客户端能写的);from_run 只能由服务端建
@@ -236,7 +237,7 @@ def _expectation(raw: Any, i: int, *, gold_kind: str | None, taken: set[str]) ->
if kind in NEEDS_GOLD and gold_kind is None:
raise CaseInvalid(f"{where}要答出数(或答「没有数据」),需要期望答案的来源:写一条期望 SQL、选一个口径,"
"或从运行里认定一条查询", "gold")
if gold_kind == "caliber" and kind not in ("scalar", "ask", "text"):
if gold_kind == "caliber" and kind not in ("scalar", "ask", "text", "investigation"):
raise CaseInvalid(f"{where}({kind})不能用口径题算:口径卡给的是一个个指标,只配「一个数」的期望",
f"{path}.kind")
if kind == "scalar":
@@ -286,6 +287,22 @@ def _expectation(raw: Any, i: int, *, gold_kind: str | None, taken: set[str]) ->
if len(points) > POINTS_MAX or any(len(p.strip()) > POINT_MAX for p in points):
raise CaseInvalid(f"{where}最多 {POINTS_MAX} 条要点,每条不超过 {POINT_MAX} 个字符", f"{path}.points")
out["points"] = [p.strip() for p in points]
elif kind == "investigation":
status = raw.get("status", "complete")
if status not in ("complete", "partial"):
raise CaseInvalid("调查期望 status 只能是 complete 或 partial", f"{path}.status")
out["status"] = status
for key, low, high in (("minimum_depth", 0, 5), ("max_queries", 1, 1000)):
if key in raw:
value = raw[key]
if isinstance(value, bool) or not isinstance(value, int) or not low <= value <= high:
raise CaseInvalid(f"{key} 需要是 {low} 到 {high} 的整数", f"{path}.{key}")
out[key] = value
if raw.get("stop_reason") is not None:
reason = raw["stop_reason"]
if not isinstance(reason, str) or not reason.strip() or len(reason) > 80:
raise CaseInvalid("停止原因需要是简短的机器码", f"{path}.stop_reason")
out["stop_reason"] = reason
elif kind in ("contribution", "verdict"):
out.update(_analysis_expectation(raw, kind, where, path))
return out
+3 -2
View File
@@ -100,7 +100,7 @@ def leader_of(run: Any) -> str:
def prompt_fingerprint() -> str:
"""助手提示词的指纹:节点手册、输出协议、问数据的请求包法、重来的两种措辞、复核的规则;平台的分析方法(分析工具的
guide:id 带版本,连同全文)、写作者的分析规则(写作目录里分析结论那一段、判断词的写法、重写时补的那句)和说法表的
版本;自查判问题意图的词表(版本,改词表要升)和「分析类问题、查库的 Agent 没绑分析工具」时交回模型的那一句。
版本;自查判问题意图的词表、默认调查策略及其版本,和「分析类问题、查库的 Agent 没绑分析工具」时交回模型的那一句。
改了任何一段,和上一次比时就标「提示词变了」。"""
from app.analysis.intent import INTENT_VERSION
from app.api import copilot
@@ -108,6 +108,7 @@ def prompt_fingerprint() -> str:
from app.chat import turn
from app.core.artifact_store import canonical_json, content_hash
from app.engine import analysis_claims, evidence, review
from app.engine.investigation import INVESTIGATION_VERSION, InvestigationPolicy
from app.tools.builtin.analysis import METHOD_GUIDE
parts = [copilot.NODE_REFERENCE, copilot._STREAM_PROTOCOL,
@@ -117,7 +118,7 @@ def prompt_fingerprint() -> str:
METHOD_GUIDE.id, METHOD_GUIDE.text, evidence.ANALYSIS_PROMPT, evidence.ANALYSIS_SEE_ONLY_PROMPT,
analysis_claims.ANALYSIS_RULES_PROMPT, analysis_claims.ANALYSIS_NONE_PROMPT,
analysis_claims.ANALYSIS_REPAIR_PROMPT, analysis_claims.LEXICON_VERSION,
INTENT_VERSION, analysis_gaps_fix()]
INTENT_VERSION, analysis_gaps_fix(), INVESTIGATION_VERSION, InvestigationPolicy().model_dump()]
return content_hash(canonical_json(parts))[:16]
+28 -2
View File
@@ -186,12 +186,13 @@ class Answer:
problem: str | None = None
analyses: list[dict[str, Any]] = field(default_factory=list)
sentences: list[dict[str, Any]] = field(default_factory=list)
investigations: list[dict[str, Any]] = field(default_factory=list)
def to_dict(self) -> dict[str, Any]:
return {"run_id": self.run_id, "text": self.text, "values": self.values, "bare": self.bare,
"queries": self.queries, "cited": self.cited, "stats": self.stats, "tier": self.tier,
"report": self.report, "problem": self.problem, "analyses": self.analyses,
"sentences": self.sentences}
"sentences": self.sentences, "investigations": self.investigations}
@classmethod
def from_dict(cls, raw: Mapping[str, Any]) -> Answer:
@@ -199,7 +200,7 @@ class Answer:
bare=list(raw.get("bare") or []), queries=list(raw.get("queries") or []),
cited=list(raw.get("cited") or []), stats=dict(raw.get("stats") or {}), tier=raw.get("tier"),
report=raw.get("report"), problem=raw.get("problem"), analyses=list(raw.get("analyses") or []),
sentences=list(raw.get("sentences") or []))
sentences=list(raw.get("sentences") or []), investigations=list(raw.get("investigations") or []))
def _output_text(output: Any) -> str:
@@ -291,6 +292,11 @@ async def read_answer(run_id: str | None, *, reply: str | None = None) -> Answer
return Answer(run_id=run_id, problem="作答的运行封存核对不一致,答案不能当证据")
cache: dict[str, Any] = {}
answer = Answer(run_id=run_id)
for node_id in sealed.nodes_of("agent", nested=True):
payload = sealed.payload_of([node_id]) or {}
investigation = payload.get("investigation")
if isinstance(investigation, dict) and investigation.get("active"):
answer.investigations.append({**investigation, "node_id": node_id})
for artifact, info in sealed.queries.items():
snap = _snapshot(artifact, cache)
if snap is None:
@@ -615,6 +621,26 @@ def _expectation_scores(expectations: Sequence[Mapping[str, Any]], values: Mappi
out.append({**base, "outcome": "traced" if ok else "wrong",
**({} if ok else {"reason": "期望反问(问法含糊),助手却没有反问"})})
continue
if kind == "investigation":
findings = answer.investigations
problems = []
if answer.problem:
out.append({**base, "outcome": "ungradable", "reason": answer.problem})
continue
if not findings:
problems.append("没有封存的调查过程记录")
for finding in findings:
if finding.get("status") != exp.get("status", "complete"):
problems.append("调查完成状态不符合期望")
if int(finding.get("depth") or 0) < int(exp.get("minimum_depth") or 0):
problems.append("未达到要求的下钻深度")
if exp.get("stop_reason") and finding.get("stop_reason") != exp["stop_reason"]:
problems.append("停止原因不符合期望")
if exp.get("max_queries") is not None and sum(int(f.get("query_count") or 0) for f in findings) > exp["max_queries"]:
problems.append("查询次数超出预算")
out.append({**base, "outcome": "wrong" if problems else "traced",
"reason": ";".join(dict.fromkeys(problems)) or None, "investigations": findings})
continue
gold = values.get(exp["id"])
if gold is None:
out.append({**base, "outcome": "ungradable", "reason": "期望没有算出这一项"})