dknowc-dsh 1.4.0 → 2.1.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/README.md +18 -19
- package/package.json +3 -3
- package/skills/dknowc-official-doc-writer/README.md +24 -18
- package/skills/dknowc-official-doc-writer/SKILL.md +118 -144
- package/skills/dknowc-official-doc-writer/attribution.json +5 -0
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +5 -0
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +60 -13
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +34 -0
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +2 -9
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +38 -18
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +100 -33
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +6 -6
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +77 -55
- package/skills/dknowc-official-doc-writer/reference/task_router.md +6 -6
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +41 -14
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +61 -0
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +293 -0
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +263 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +235 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +333 -0
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +14 -5
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +245 -0
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +106 -18
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +13 -7
- package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +272 -0
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +257 -143
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +72 -8
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +14 -4
- package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +6 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +283 -59
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +264 -97
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +26 -57
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +13 -0
- package/skills/dknowc-ppt-assistant/README.md +14 -10
- package/skills/dknowc-ppt-assistant/SKILL.md +34 -16
- package/skills/dknowc-ppt-assistant/attribution.json +5 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +10 -6
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +56 -15
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +123 -115
- package/skills/dknowc-ppt-assistant/references/search_intro.md +1 -1
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +1 -1
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +41 -14
- package/skills/dknowc-ppt-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +6 -4
- package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +188 -0
- package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +356 -94
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +260 -233
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +35 -5
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +21 -16
- package/skills/dknowc-trusted-search/README.md +28 -24
- package/skills/dknowc-trusted-search/SKILL.md +217 -141
- package/skills/dknowc-trusted-search/attribution.json +5 -0
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +51 -12
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +129 -521
- package/skills/dknowc-trusted-search/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-trusted-search/scripts/api_key.py +41 -14
- package/skills/dknowc-trusted-search/scripts/attribution.py +61 -0
- package/skills/dknowc-trusted-search/scripts/chart_embed.py +350 -0
- package/skills/dknowc-trusted-search/scripts/deep_query.py +27 -6
- package/skills/dknowc-trusted-search/scripts/initialize.py +20 -29
- package/skills/dknowc-trusted-search/scripts/mcp_convert.py +198 -0
- package/skills/dknowc-trusted-search/scripts/merge_search_results.py +335 -0
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +339 -65
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +386 -210
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +30 -30
- package/src/index.js +2 -7
- package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +0 -279
- package/skills/dknowc-trusted-consulting/README.md +0 -63
- package/skills/dknowc-trusted-consulting/SKILL.md +0 -241
- package/skills/dknowc-trusted-consulting/reference/consult_intro.md +0 -47
- package/skills/dknowc-trusted-consulting/reference/onboarding_scripts.md +0 -132
- package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +0 -31
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +0 -867
- package/skills/dknowc-trusted-consulting/scripts/adapt_mcp_result.py +0 -283
- package/skills/dknowc-trusted-consulting/scripts/api_key.py +0 -41
- package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +0 -508
- package/skills/dknowc-trusted-consulting/scripts/initialize.py +0 -123
- package/skills/dknowc-trusted-consulting/scripts/mcp_direct.py +0 -166
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +0 -281
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +0 -2534
- package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +0 -261
- package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +0 -894
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""可信溯源核验报告渲染器:把搜索结果 JSON + 最终答案渲染为单文件可核验 HTML。
|
|
3
3
|
|
|
4
|
-
深知可信搜索 SkillHub
|
|
4
|
+
深知可信搜索 SkillHub 版(渲染层与深知系列核验报告同构,数据口径保持自有与真实)。
|
|
5
5
|
输入直读 trusted_search.py / deep_query.py 的 --json-only 输出(可信搜索 content.data
|
|
6
6
|
或深度搜索 deep-query/v3 格式),正文用 --answer-file 传入最终答案(关键结论带 [n] 角标),
|
|
7
7
|
成稿自检用 --self-check-file 传入五项结果。
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
报告定位:不止展示"材料从哪来"(溯源),更要传达"我们查过了,可以交付"(核验)。
|
|
10
10
|
架构(参考深知晓交互原型):
|
|
11
11
|
- 顶栏:身份章 + 标题 + 工具组(只看正文 / 复制全文 / 打印归档)+ 阅读进度条
|
|
12
|
-
- Hero:大标题 + 真实统计(N 次检索 · M
|
|
12
|
+
- Hero:大标题 + 真实统计(N 次检索 · M 篇来源文章 · K 处引用)+ 双视图切换
|
|
13
13
|
- 过程回顾条:检索 → 入库 → 逐条比对 → 核验完成(静态回放,数字全部真实计算;
|
|
14
14
|
无思考流数据就不展示"思考"步骤——硬造即违背核验诚实性)
|
|
15
|
-
- 核验报告视图(默认):核验报告单 +
|
|
16
|
-
-
|
|
15
|
+
- 核验报告视图(默认):核验报告单 + 正文分节卡;角标点击跳知识专库定位
|
|
16
|
+
- 知识专库视图(全屏):大搜索 + 热词(标题/正文高频词真实计算)+ 检索分组 tabs + 材料卡
|
|
17
17
|
三个核验层次:报告级(核验报告单)/材料级(来源卡核验链标记)/引用级(角标一一绑定)。
|
|
18
|
-
|
|
19
|
-
生成前预处理(内置):policyFiles
|
|
20
|
-
|
|
18
|
+
诚实原则:脚本真实计算的结果才打勾;无法自动判定的项不虚构展示("现行效力"人工复核提示行已移除,2026-09-19 起)。
|
|
19
|
+
生成前预处理(内置):policyFiles 发文字号本地匹配、存档快照兜底(screenShotPath /A/ 容错 + 格式校验;
|
|
20
|
+
原文链接原样进报告、不做活性探测——2026-10-08 起,--skip-link-check 保留为兼容 no-op),
|
|
21
21
|
--no-snapshot 关闭);缺原文链接不拖垮核验结论,按提醒呈现。
|
|
22
22
|
布局为单文件静态 HTML;打印归档模式单栏全展开并附材料附录。
|
|
23
23
|
所有输入输出经路径安全层限制在 skill 工作区 official-docs/ 内。
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
from __future__ import annotations
|
|
27
27
|
|
|
28
28
|
import argparse
|
|
29
|
-
import concurrent.futures
|
|
30
29
|
import html
|
|
31
30
|
import json
|
|
32
31
|
import re
|
|
33
32
|
import sys
|
|
34
33
|
import unicodedata
|
|
35
|
-
import urllib.error
|
|
36
|
-
import urllib.request
|
|
37
34
|
from datetime import datetime
|
|
38
35
|
from pathlib import Path
|
|
39
36
|
from typing import Any, Dict, List, Optional, Tuple
|
|
40
37
|
|
|
38
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
39
|
+
import chart_embed # noqa: E402 图表渲染共享模块(1.4.0,与可视化报告共用)
|
|
40
|
+
|
|
41
41
|
|
|
42
42
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
43
43
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
@@ -62,8 +62,17 @@ def _is_within(path: Path, parent: Path) -> bool:
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
def _safe_input_path(value: str, allowed_suffixes: set) -> Path:
|
|
65
|
-
"""输入文件必须位于 skill 工作区内且后缀合法,阻断路径遍历。
|
|
65
|
+
"""输入文件必须位于 skill 工作区内且后缀合法,阻断路径遍历。
|
|
66
|
+
|
|
67
|
+
兼容只写文件名的调用(1.4.0):形如 `xxx.json` 的相对路径先在 SKILL_ROOT 下找,
|
|
68
|
+
找不到再到 official-docs/search-results/ 找——避免 Agent 因"文件不在预期位置"
|
|
69
|
+
转而全盘 find/grep 触发宿主安全策略。
|
|
70
|
+
"""
|
|
66
71
|
raw = Path(value).expanduser()
|
|
72
|
+
if not raw.is_absolute() and raw.parent == Path("."):
|
|
73
|
+
candidate = SKILL_ROOT / raw
|
|
74
|
+
if not candidate.exists() and (SEARCH_RESULTS_DIR / raw.name).exists():
|
|
75
|
+
raw = SEARCH_RESULTS_DIR / raw.name
|
|
67
76
|
resolved = raw.resolve() if raw.is_absolute() else raw.resolve()
|
|
68
77
|
if resolved.suffix.lower() not in allowed_suffixes:
|
|
69
78
|
raise ValueError(f"输入文件后缀必须是 {sorted(allowed_suffixes)} 之一: {value}")
|
|
@@ -148,51 +157,15 @@ def strip_citation_markers(text: str) -> str:
|
|
|
148
157
|
|
|
149
158
|
|
|
150
159
|
# ============================================================
|
|
151
|
-
# 生成前预处理(文号匹配 /
|
|
160
|
+
# 生成前预处理(文号匹配 / 快照兜底;链接活性检测已于 2026-10-08 移除)
|
|
152
161
|
# ============================================================
|
|
153
162
|
|
|
154
163
|
# 快照兜底开关:默认启用。接口 screenShotPath 曾存在路径缺 /A/ 层级的拼接 bug
|
|
155
164
|
# (后端修复中);verify_snapshots 在展示前完成"/A/ 修订 + 格式校验 + 不合法弃用"。
|
|
156
165
|
SNAPSHOT_ENABLED = True
|
|
157
166
|
|
|
158
|
-
# 软 404 关键词:政府站常以 HTTP 200 返回"页面不存在"错误页,状态码识别不了,
|
|
159
|
-
# 需读页面标题嗅探。关键词取自实测样例,且仅匹配 <title>(政策正文不会出现在标题里),
|
|
160
|
-
# 误杀风险极低。
|
|
161
|
-
SOFT_404_KEYWORDS = ("页面不存在", "页面未找到", "您访问的页面", "已删除", "已下线", "无法找到", "not found", "404")
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def check_link_alive(url: str, timeout: int = 8) -> bool:
|
|
165
|
-
"""检测原文链接是否仍然可达。失效判据(客观信号,与请求方无关):
|
|
166
|
-
① HTTP 404/410;② 软 404——HTTP 200 但页面标题为典型失效页。
|
|
167
|
-
连接失败、超时、403、5xx 等一律视为"无法确认"按有效处理——政府站
|
|
168
|
-
常对脚本请求反爬,凭这些判死会误杀可用链接。
|
|
169
|
-
"""
|
|
170
|
-
for method in ("HEAD", "GET"):
|
|
171
|
-
try:
|
|
172
|
-
req = urllib.request.Request(
|
|
173
|
-
url, method=method,
|
|
174
|
-
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"},
|
|
175
|
-
)
|
|
176
|
-
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
177
|
-
if resp.status in (404, 410):
|
|
178
|
-
return False
|
|
179
|
-
if method == "GET":
|
|
180
|
-
chunk = resp.read(4096).decode("utf-8", errors="replace")
|
|
181
|
-
title = re.search(r"<title>(.*?)</title>", chunk, re.I | re.S)
|
|
182
|
-
text = title.group(1) if title else chunk[:200]
|
|
183
|
-
lowered = text.lower()
|
|
184
|
-
return not any(k in text or k in lowered for k in SOFT_404_KEYWORDS)
|
|
185
|
-
except urllib.error.HTTPError as e:
|
|
186
|
-
if method == "GET":
|
|
187
|
-
return e.code not in (404, 410)
|
|
188
|
-
except Exception:
|
|
189
|
-
if method == "GET":
|
|
190
|
-
return True
|
|
191
|
-
return True
|
|
192
|
-
|
|
193
|
-
|
|
194
167
|
def normalize_snapshot_url(url: str) -> str:
|
|
195
|
-
"""快照路径容错:接口部分返回值缺 /A/
|
|
168
|
+
"""快照路径容错:接口部分返回值缺 /A/ 层级(实测 60 条中 5 条,补全后即可访问),
|
|
196
169
|
统一规范化为 https://attach.dknowc.cn/snapshot/A/<2位>/<2位>/<哈希>.jpg。"""
|
|
197
170
|
u = (url or "").strip()
|
|
198
171
|
if u.startswith("https://attach.dknowc.cn/snapshot/") and "/snapshot/A/" not in u:
|
|
@@ -200,21 +173,6 @@ def normalize_snapshot_url(url: str) -> str:
|
|
|
200
173
|
return u
|
|
201
174
|
|
|
202
175
|
|
|
203
|
-
def mark_dead_links(articles: List[Dict[str, Any]]) -> int:
|
|
204
|
-
"""并发检测全部材料的原文链接,404/410/软404 的标记 链接失效=True。返回失效数。"""
|
|
205
|
-
targets = [(i, a["源网址"]) for i, a in enumerate(articles) if (a.get("源网址") or "").strip()]
|
|
206
|
-
if not targets:
|
|
207
|
-
return 0
|
|
208
|
-
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
|
|
209
|
-
alive = dict(zip((i for i, _ in targets), pool.map(check_link_alive, (u for _, u in targets))))
|
|
210
|
-
dead = 0
|
|
211
|
-
for i, _ in targets:
|
|
212
|
-
if not alive.get(i, True):
|
|
213
|
-
articles[i]["链接失效"] = True
|
|
214
|
-
dead += 1
|
|
215
|
-
return dead
|
|
216
|
-
|
|
217
|
-
|
|
218
176
|
def verify_snapshots(articles: List[Dict[str, Any]]) -> int:
|
|
219
177
|
"""快照展示前的路径校验(纯本地检查,不发网络请求):
|
|
220
178
|
组装阶段已由 normalize_snapshot_url 补全 /A/ 层级;此处校验修订后的路径
|
|
@@ -249,6 +207,9 @@ def attach_doc_numbers(articles: List[Dict[str, Any]], payload: Dict[str, Any])
|
|
|
249
207
|
|
|
250
208
|
文号与检索文章分开展示在同一响应里,本地标题匹配即可拿到,无需接口改动;
|
|
251
209
|
新闻/解读类不在 policyFiles 中(本就无文号),匹配不上则不显示。
|
|
210
|
+
检索库对同一政策文件常有多个抓取变体(新闻稿版/发文版,文号挂在发文版条目上),
|
|
211
|
+
标题精确匹配不上时**不做模糊猜测**(宁缺勿错)——变体识别与回填由 SKILL.md
|
|
212
|
+
选材规则执行:Agent 引用政策文件时优先带文号的发文版条目。
|
|
252
213
|
"""
|
|
253
214
|
doc_numbers: Dict[str, str] = {}
|
|
254
215
|
for holder in (payload.get("content") if isinstance(payload.get("content"), dict) else {},
|
|
@@ -276,10 +237,12 @@ def attach_doc_numbers(articles: List[Dict[str, Any]], payload: Dict[str, Any])
|
|
|
276
237
|
|
|
277
238
|
def preprocess_articles(articles: List[Dict[str, Any]], payload: Dict[str, Any],
|
|
278
239
|
skip_link_check: bool = False, snapshot_enabled: bool = True) -> None:
|
|
279
|
-
"""extract_sources
|
|
240
|
+
"""extract_sources 前的统一预处理:文号匹配、快照兜底。
|
|
280
241
|
|
|
281
|
-
直接改写文章 dict(注入 文号 / 快照链接
|
|
282
|
-
|
|
242
|
+
直接改写文章 dict(注入 文号 / 快照链接 字段),供 source_from_article 读取;
|
|
243
|
+
均为幂等操作,多轮渲染不叠加。
|
|
244
|
+
原文链接活性检测已整体移除(2026-10-08 起)——接口返回的链接原样进报告;
|
|
245
|
+
skip_link_check 参数保留为兼容 no-op。
|
|
283
246
|
"""
|
|
284
247
|
attach_doc_numbers(articles, payload)
|
|
285
248
|
if snapshot_enabled:
|
|
@@ -290,8 +253,6 @@ def preprocess_articles(articles: List[Dict[str, Any]], payload: Dict[str, Any],
|
|
|
290
253
|
else:
|
|
291
254
|
for a in articles:
|
|
292
255
|
a["快照链接"] = ""
|
|
293
|
-
if not skip_link_check:
|
|
294
|
-
mark_dead_links(articles)
|
|
295
256
|
|
|
296
257
|
|
|
297
258
|
# ============================================================
|
|
@@ -307,7 +268,7 @@ KIND_CATALOG = {
|
|
|
307
268
|
}
|
|
308
269
|
|
|
309
270
|
|
|
310
|
-
def normalize_kind(raw: str) -> Tuple[str, str]:
|
|
271
|
+
def normalize_kind(raw: str) -> Tuple[str, str, str]:
|
|
311
272
|
"""把来源类型文本归一化为(类型键, 中文标签, css 类名)。"""
|
|
312
273
|
text = str(raw or "")
|
|
313
274
|
if "政策" in text or "法规" in text or "依据" in text or "policy" in text.lower():
|
|
@@ -436,7 +397,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
436
397
|
item.get("name"),
|
|
437
398
|
vo.get("showTitle"),
|
|
438
399
|
vo.get("title"),
|
|
439
|
-
"
|
|
400
|
+
"未命名来源文章",
|
|
440
401
|
),
|
|
441
402
|
"agency": first_str(
|
|
442
403
|
item.get("unit") if not isinstance(item.get("unit"), list) else "、".join(str(x) for x in item.get("unit")[:3]),
|
|
@@ -450,7 +411,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
450
411
|
),
|
|
451
412
|
"date": first_str(item.get("发布日期"), item.get("date"), item.get("发布时间"), item.get("createDate"), vo.get("dateTime"), vo.get("createDate")),
|
|
452
413
|
"url": first_str(item.get("sourceUrl"), item.get("source_url"), item.get("源网址"), item.get("原文链接"), item.get("url"), item.get("原文"), vo.get("sourceUrl"), vo.get("url")),
|
|
453
|
-
"policy_url": first_str(item.get("policyUrl"), item.get("policy_url"),
|
|
414
|
+
"policy_url": first_str(item.get("policyUrl"), item.get("policy_url"), vo.get("policyUrl")),
|
|
454
415
|
"excerpt": segment.get("text") or paragraph_text(item),
|
|
455
416
|
"section": first_str(item.get("正文对应"), item.get("section"), item.get("支撑")),
|
|
456
417
|
"kind": first_str(item.get("类型"), item.get("type"), item.get("素材类型"), vo.get("typeName"), "材料"),
|
|
@@ -480,17 +441,16 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
480
441
|
source["used"] = item.get("已引用", item.get("used", True))
|
|
481
442
|
if not isinstance(source["used"], bool):
|
|
482
443
|
source["used"] = True
|
|
483
|
-
#
|
|
484
|
-
#
|
|
444
|
+
# 快照是接口自带的存档副本,统一作为附加回看入口展示(2026-10-08 起不再做
|
|
445
|
+
# 链接活性探测,原文链接原样进报告;快照仅做本地格式校验,不发网络请求)。
|
|
485
446
|
source["snapshot"] = first_str(item.get("快照链接"), item.get("snapshot"), item.get("screenShotPath"))
|
|
486
|
-
source["link_dead"] = item.get("链接失效") is True or item.get("link_dead") is True
|
|
487
447
|
# 发布日期可信度(实测:「高」=模型治理入库、标题模型精抽;「较高」=门户抓取、标题规则提取)
|
|
488
448
|
source["conf"] = first_str(item.get("发布日期可信度"), item.get("可信度"), item.get("confidence"))
|
|
489
449
|
key, label, css = normalize_kind(source["kind"])
|
|
490
450
|
source["type_key"] = key
|
|
491
451
|
source["type_label"] = label
|
|
492
452
|
source["type_css"] = css
|
|
493
|
-
live_url = bool(source["url"] and source["url"] != "接口未返回")
|
|
453
|
+
live_url = bool(source["url"] and source["url"] != "接口未返回")
|
|
494
454
|
source["has_link"] = live_url or bool(source["policy_url"]) or bool(source["snapshot"])
|
|
495
455
|
# 核验状态只看摘录可比对;原文链接死活与快照有无是回看通道问题,不影响核验结论
|
|
496
456
|
source["verified"] = bool(source["excerpt"])
|
|
@@ -509,7 +469,7 @@ def extract_articles_from_search(payload: Dict[str, Any]) -> List[Dict[str, Any]
|
|
|
509
469
|
def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
510
470
|
"""深度搜索 deep-query/v3 非流式格式:{"data": {"searches": [{"result": [...]}], "common_articles": [...]}}。
|
|
511
471
|
|
|
512
|
-
按源网址去重摊平;为每篇材料注入"搜索条件"
|
|
472
|
+
按源网址去重摊平;为每篇材料注入"搜索条件"(子查询的地域·查询词),供知识专库检索分组筛选。
|
|
513
473
|
"""
|
|
514
474
|
data = payload.get("data")
|
|
515
475
|
if not isinstance(data, dict):
|
|
@@ -553,18 +513,6 @@ def extract_reference_materials(payload: Dict[str, Any]) -> List[Dict[str, Any]]
|
|
|
553
513
|
return []
|
|
554
514
|
|
|
555
515
|
|
|
556
|
-
def extract_knowledge_base(payload: Dict[str, Any]) -> str:
|
|
557
|
-
"""知识专库链接(可信搜索响应 content.knowledgeBase):缺原文链接材料的回看通道。"""
|
|
558
|
-
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
559
|
-
data = content.get("data") if isinstance(content.get("data"), dict) else {}
|
|
560
|
-
return first_str(
|
|
561
|
-
content.get("knowledgeBase"),
|
|
562
|
-
payload.get("knowledgeBase"),
|
|
563
|
-
data.get("knowledgeBase"),
|
|
564
|
-
payload.get("knowledgeBaseUrl"),
|
|
565
|
-
)
|
|
566
|
-
|
|
567
|
-
|
|
568
516
|
def extract_sources(payload: Dict[str, Any],
|
|
569
517
|
skip_link_check: bool = False, snapshot_enabled: bool = True) -> List[Dict[str, str]]:
|
|
570
518
|
raw_sources: List[Dict[str, Any]] = []
|
|
@@ -578,24 +526,29 @@ def extract_sources(payload: Dict[str, Any],
|
|
|
578
526
|
if not item.get("搜索条件"):
|
|
579
527
|
item["搜索条件"] = "本次检索"
|
|
580
528
|
|
|
581
|
-
# 生成前预处理:文号匹配(policyFiles
|
|
529
|
+
# 生成前预处理:文号匹配(policyFiles)、快照兜底(不做链接活性探测)
|
|
582
530
|
preprocess_articles(raw_sources, payload, skip_link_check=skip_link_check, snapshot_enabled=snapshot_enabled)
|
|
583
531
|
|
|
584
|
-
# 知识专库回看:原文链接缺失/失效的材料挂知识专库链接作为回看通道(不影响核验判定)
|
|
585
|
-
kb_url = extract_knowledge_base(payload)
|
|
586
|
-
if kb_url:
|
|
587
|
-
for item in raw_sources:
|
|
588
|
-
if not (item.get("源网址") or "").strip() or item.get("链接失效") is True:
|
|
589
|
-
if not first_str(item.get("知识专库原文"), item.get("policyUrl"), item.get("policy_url")):
|
|
590
|
-
item["知识专库原文"] = kb_url
|
|
591
|
-
|
|
592
532
|
sources: List[Dict[str, str]] = []
|
|
593
533
|
seen = set()
|
|
594
534
|
for item in raw_sources:
|
|
595
535
|
# 一篇材料一张卡:段落合并为摘录(paragraph_text 拼接全部段落),不按段落拆卡——
|
|
596
536
|
# 溯源 JSON 的 materials 与正文角标按"材料"粒度一一对应,拆段会使编号错位。
|
|
597
537
|
source = source_from_article(item, len(sources) + 1)
|
|
598
|
-
|
|
538
|
+
# 去重键(2026-10-08 修复):归一化「标题+URL」。旧键含 id(递增序号每条不同)
|
|
539
|
+
# 等于从不去重——同一篇文章跨提取器/多段片段全部出卡(实测曾出现同名卡片 ×17)。单边缺失退用其一,均缺失退摘录前缀。
|
|
540
|
+
t_key = re.sub(r"\s+", "", source["title"] or "")
|
|
541
|
+
u_key = (source["url"] or "").strip().rstrip("/")
|
|
542
|
+
if u_key == "接口未返回":
|
|
543
|
+
u_key = ""
|
|
544
|
+
if t_key and u_key:
|
|
545
|
+
key = ("tu", t_key, u_key)
|
|
546
|
+
elif t_key:
|
|
547
|
+
key = ("t", t_key)
|
|
548
|
+
elif u_key:
|
|
549
|
+
key = ("u", u_key)
|
|
550
|
+
else:
|
|
551
|
+
key = ("e", (source["excerpt"] or "")[:80])
|
|
599
552
|
if key in seen:
|
|
600
553
|
continue
|
|
601
554
|
seen.add(key)
|
|
@@ -616,18 +569,18 @@ def extract_answer(payload: Dict[str, Any]) -> str:
|
|
|
616
569
|
return normalize_citations(answer)
|
|
617
570
|
articles = extract_articles_from_search(payload)
|
|
618
571
|
if articles:
|
|
619
|
-
rows = ["
|
|
572
|
+
rows = ["可信搜索召回了以下重点来源文章:"]
|
|
620
573
|
for idx, item in enumerate(articles[:8], start=1):
|
|
621
|
-
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '
|
|
574
|
+
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '未命名来源文章')}")
|
|
622
575
|
return "\n".join(rows)
|
|
623
576
|
deep_articles = extract_articles_from_deep(payload)
|
|
624
577
|
if deep_articles:
|
|
625
|
-
rows = ["
|
|
578
|
+
rows = ["深度搜索召回了以下重点来源文章:"]
|
|
626
579
|
for idx, item in enumerate(deep_articles[:8], start=1):
|
|
627
580
|
vo = item.get("vo") if isinstance(item.get("vo"), dict) else {}
|
|
628
|
-
rows.append(f"[{idx}] {first_str(item.get('文章标题'), vo.get('showTitle'), vo.get('title'), item.get('title'), '
|
|
581
|
+
rows.append(f"[{idx}] {first_str(item.get('文章标题'), vo.get('showTitle'), vo.get('title'), item.get('title'), '未命名来源文章')}")
|
|
629
582
|
return "\n".join(rows)
|
|
630
|
-
return "
|
|
583
|
+
return "接口返回中未识别到正文内容;请查看知识专库或原始 JSON。"
|
|
631
584
|
|
|
632
585
|
|
|
633
586
|
def extract_question(payload: Dict[str, Any]) -> str:
|
|
@@ -680,8 +633,9 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
680
633
|
"""把自检项的值解析为(状态, 核验说明)。
|
|
681
634
|
|
|
682
635
|
兼容多种写法:`pass` / `true` / `通过` / `通过:说明文字` / `✓` 等;
|
|
683
|
-
|
|
684
|
-
|
|
636
|
+
值后面的说明文字保留下来供核验单展示。无法识别的状态按未记录(none)处理:
|
|
637
|
+
描述性文本不等于"未通过"——红项只给显式声明的未通过,避免书写格式问题
|
|
638
|
+
被放大成核验未通过(2026-09-20 WorkBuddy 实测:Agent 把备注写成自检值导致 5/7 红项)。
|
|
685
639
|
"""
|
|
686
640
|
text = str(raw or "").strip()
|
|
687
641
|
lowered = text.lower()
|
|
@@ -691,7 +645,7 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
691
645
|
for prefix in ("已通过", "通过", "合格", "pass", "ok", "true", "是", "✓", "yes"):
|
|
692
646
|
if lowered.startswith(prefix):
|
|
693
647
|
return "pass", text[len(prefix):].lstrip("::,,、 ").strip()
|
|
694
|
-
return "
|
|
648
|
+
return "none", text
|
|
695
649
|
|
|
696
650
|
|
|
697
651
|
def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
@@ -699,8 +653,13 @@ def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
|
699
653
|
return None
|
|
700
654
|
items: Dict[str, Tuple[str, str]] = {}
|
|
701
655
|
for key, value in raw.items():
|
|
656
|
+
# 只认五项标准自检键(英文/中文);白名单外的多余键(如 Agent 自行追加的
|
|
657
|
+
# "备注""待核验/下一步补充"等描述性键)不构成"交付前检查"定义的核验项,
|
|
658
|
+
# 直接忽略不计入——核验单只统计定义过的检查项(2026-09-20 实测修正)。
|
|
659
|
+
label = SELF_CHECK_LABELS.get(key) or SELF_CHECK_LABELS.get(str(key))
|
|
660
|
+
if not label:
|
|
661
|
+
continue
|
|
702
662
|
status, note = classify_check_value(value)
|
|
703
|
-
label = SELF_CHECK_LABELS.get(key, SELF_CHECK_LABELS.get(str(key), str(key)))
|
|
704
663
|
items[label] = (status, note)
|
|
705
664
|
return items or None
|
|
706
665
|
|
|
@@ -730,7 +689,9 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
730
689
|
no_citation = bool(sources) and not cited
|
|
731
690
|
|
|
732
691
|
# ③ 时效检查:材料日期范围与历史材料计数
|
|
733
|
-
|
|
692
|
+
# ③ 时效只统计**正文依据**(2026-09-29 起):sources 含未引用召回材料,
|
|
693
|
+
# 此前误用全集,未引用材料里的异常日期(如接口标注的未来年份)会写进交付物口径。
|
|
694
|
+
dated = [parse_year_month(s.get("date")) for s in cited_sources]
|
|
734
695
|
dated = [d for d in dated if d]
|
|
735
696
|
freshness = None
|
|
736
697
|
old_count = 0
|
|
@@ -741,9 +702,9 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
741
702
|
"old_count": sum(1 for y, _ in dated if y <= generated_at.year - 3),
|
|
742
703
|
}
|
|
743
704
|
|
|
744
|
-
# ④
|
|
705
|
+
# ④ 类型覆盖:**正文依据**的素材四分类分布(口径同③,2026-09-29 修复)
|
|
745
706
|
coverage = {key: 0 for key in KIND_CATALOG}
|
|
746
|
-
for s in
|
|
707
|
+
for s in cited_sources:
|
|
747
708
|
coverage[s.get("type_key", "material")] = coverage.get(s.get("type_key", "material"), 0) + 1
|
|
748
709
|
|
|
749
710
|
# ⑤ 成稿自检:由溯源 JSON 的 self_check 传入,未传入如实显示未记录
|
|
@@ -754,32 +715,45 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
754
715
|
self_check = None
|
|
755
716
|
if self_items:
|
|
756
717
|
passed = sum(1 for status, _ in self_items.values() if status == "pass")
|
|
757
|
-
|
|
758
|
-
|
|
718
|
+
failed = sum(1 for status, _ in self_items.values() if status == "fail")
|
|
719
|
+
# 状态只由显式 fail 决定:none(值无法识别,如描述性文本)不拖垮结论,
|
|
720
|
+
# 显示为"通过,N 项未记录"——红项只给真正声明未通过的项。
|
|
721
|
+
self_check = {"items": self_items, "passed": passed, "total": len(self_items), "failed": failed,
|
|
722
|
+
"status": "fail" if failed else "pass"}
|
|
759
723
|
else:
|
|
760
|
-
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS), "status": "missing"}
|
|
724
|
+
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS), "failed": 0, "status": "missing"}
|
|
761
725
|
|
|
762
726
|
# 政策效力:无法自动判定现行效力,列出建议人工复核
|
|
763
727
|
policy_count = coverage.get("policy", 0)
|
|
764
728
|
|
|
765
729
|
trace_ok = cited_sources and not missing_excerpts
|
|
766
730
|
binding_ok = (not unbound) and not no_citation
|
|
767
|
-
|
|
731
|
+
# 自检显式"未通过"纳为报告级否决项:不能自检失败还顶部打绿章。
|
|
732
|
+
self_check_ok = self_check["status"] != "fail"
|
|
733
|
+
overall_passed = bool(trace_ok and binding_ok and self_check_ok)
|
|
768
734
|
|
|
769
735
|
reasons = []
|
|
770
736
|
if not sources:
|
|
771
|
-
reasons.append("
|
|
737
|
+
reasons.append("没有找到来源文章")
|
|
772
738
|
if no_citation:
|
|
773
|
-
reasons.append("
|
|
739
|
+
reasons.append("正文里没有来源角标,对不上来源文章")
|
|
774
740
|
if unbound:
|
|
775
|
-
reasons.append(f"有 {len(unbound)}
|
|
741
|
+
reasons.append(f"有 {len(unbound)} 处角标找不到对应来源文章")
|
|
776
742
|
if self_check["status"] == "fail":
|
|
777
743
|
reasons.append("交付前检查有没过的项")
|
|
744
|
+
if missing_links:
|
|
745
|
+
reasons.append(f"有 {len(missing_links)} 条正文依据没有原文链接或存档快照,无法回看")
|
|
746
|
+
|
|
747
|
+
if overall_passed and missing_links:
|
|
748
|
+
# 摘录可比对、结论成立,但确有材料无回看通道时,顶部表述要与事实一致
|
|
749
|
+
overall_label = f"核验完成,其中 {len(missing_links)} 条依据无原文或存档快照可回看"
|
|
750
|
+
else:
|
|
751
|
+
overall_label = "核验完成,正文依据逐条对过原文" if overall_passed else "核验未完全通过"
|
|
778
752
|
|
|
779
753
|
return {
|
|
780
754
|
"overall": {
|
|
781
755
|
"passed": overall_passed,
|
|
782
|
-
"label":
|
|
756
|
+
"label": overall_label,
|
|
783
757
|
"reasons": reasons,
|
|
784
758
|
},
|
|
785
759
|
"traceability": {"total": len(cited_sources), "passed": trace_passed,
|
|
@@ -842,7 +816,7 @@ HOT_STOP = {
|
|
|
842
816
|
|
|
843
817
|
|
|
844
818
|
def extract_hot_terms(answer: str, sources: List[Dict[str, str]], top: int = 8) -> List[str]:
|
|
845
|
-
"""
|
|
819
|
+
"""知识专库热词:材料标题(加权)+ 检索条件 + 正文的高频 2-4 字词,真实统计。
|
|
846
820
|
|
|
847
821
|
泛词过滤:出现在超过 60% 材料标题中的词(如库内全部材料共有的主题词)
|
|
848
822
|
无法筛出子集,没有筛选价值,剔除。
|
|
@@ -961,7 +935,7 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
|
|
|
961
935
|
if not jb:
|
|
962
936
|
return ""
|
|
963
937
|
if jb.get("url"):
|
|
964
|
-
btn_txt = "
|
|
938
|
+
btn_txt = "查看全文" if jb.get("url") else "查看存档全文"
|
|
965
939
|
link = (f'<a class="jb-src" href="{esc(jb["url"])}" target="_blank" rel="noopener noreferrer">'
|
|
966
940
|
f'{ARROW_SVG}<span>{btn_txt}</span></a>')
|
|
967
941
|
else:
|
|
@@ -1129,32 +1103,28 @@ def build_chip_data(sources: List[Dict[str, str]]) -> Dict[str, Dict[str, str]]:
|
|
|
1129
1103
|
continue
|
|
1130
1104
|
meta_bits = [v for v in [source.get("agency"), source.get("date")] if v and v != "未知来源"]
|
|
1131
1105
|
url = source.get("url") if (source.get("url") and source["url"] != "接口未返回") else (source.get("policy_url") or "")
|
|
1132
|
-
if source.get("link_dead"):
|
|
1133
|
-
url = source.get("snapshot") or ""
|
|
1134
1106
|
site_bits = ([source["doc_number"]] if source.get("doc_number") else []) + meta_bits
|
|
1135
1107
|
chip_map[cid] = {
|
|
1136
|
-
"title": short(source.get("title") or "
|
|
1108
|
+
"title": short(source.get("title") or "未命名来源文章", 30),
|
|
1137
1109
|
"site": " · ".join(site_bits) or "来源站点",
|
|
1138
1110
|
"url": url,
|
|
1139
1111
|
"snapshot": source.get("snapshot") or "",
|
|
1140
|
-
"dead": bool(source.get("link_dead")),
|
|
1141
1112
|
"excerpt": (source.get("excerpt") or "").strip(),
|
|
1142
1113
|
"segments": source.get("segments") or [],
|
|
1143
1114
|
}
|
|
1144
1115
|
return chip_map
|
|
1145
1116
|
|
|
1146
1117
|
|
|
1147
|
-
def render_source_links(url: str, policy_url: str = "", snapshot: str = ""
|
|
1148
|
-
"""
|
|
1149
|
-
|
|
1118
|
+
def render_source_links(url: str, policy_url: str = "", snapshot: str = "") -> str:
|
|
1119
|
+
"""链接区:原文可回看 / 无源网址但有快照。接口返回的链接原样展示(不做活性探测,
|
|
1120
|
+
2026-10-08 起);快照是接口对原文的存档副本,文案如实标注。"""
|
|
1150
1121
|
links = []
|
|
1151
|
-
if url and url != "接口未返回"
|
|
1122
|
+
if url and url != "接口未返回":
|
|
1152
1123
|
links.append(f'<a href="{esc(url)}" target="_blank" rel="noopener">查看全文 ↗</a>')
|
|
1153
1124
|
if snapshot:
|
|
1154
1125
|
# 有哪个显示哪个:快照统一展示"查看存档全文",不做原文失效的状态解释
|
|
1155
1126
|
links.append(f'<a class="snap" href="{esc(snapshot)}" target="_blank" rel="noopener">查看存档全文 ↗</a>')
|
|
1156
|
-
|
|
1157
|
-
links.append(f'<a href="{esc(policy_url)}" target="_blank" rel="noopener">知识专库原文 ↗</a>')
|
|
1127
|
+
# 回看通道只有原网址与快照(2026-09-29 起:外链知识专库属老能力,已移除)
|
|
1158
1128
|
if not links:
|
|
1159
1129
|
return ""
|
|
1160
1130
|
return '<div class="sc-links">' + "".join(f"<span>{link}</span>" for link in links) + "</div>"
|
|
@@ -1171,25 +1141,34 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1171
1141
|
reasons_html = '<div class="v-reasons">' + ";".join(esc(r) for r in ov["reasons"]) + "</div>"
|
|
1172
1142
|
|
|
1173
1143
|
tr = v["traceability"]
|
|
1144
|
+
n_no_link = len(tr.get("missing_links") or [])
|
|
1174
1145
|
if not tr["total"]:
|
|
1175
1146
|
tr_html = ('<div class="vi"><span class="s fail">✗ 依据溯源 0/0</span>'
|
|
1176
|
-
'<span class="d"
|
|
1177
|
-
elif tr["passed"] == tr["total"]:
|
|
1147
|
+
'<span class="d">未识别到来源文章</span></div>')
|
|
1148
|
+
elif tr["passed"] == tr["total"] and not n_no_link:
|
|
1178
1149
|
tr_html = (f'<div class="vi"><span class="s ok">✓ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
1179
1150
|
f'<span class="d">每条素材摘录可比对,原文或存档快照可回看</span></div>')
|
|
1151
|
+
elif tr["passed"] == tr["total"]:
|
|
1152
|
+
# 摘录齐全但有材料没有回看通道:不得照写"原文或存档快照可回看"
|
|
1153
|
+
# (此前 missing_links 算出却从未参与结论,属虚假背书)
|
|
1154
|
+
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
1155
|
+
f'<span class="d">摘录可比对,其中 {n_no_link} 条没有原文链接或存档快照、无法回看</span></div>')
|
|
1180
1156
|
else:
|
|
1157
|
+
detail = f'待补摘录 {len(tr.get("missing_excerpts") or [])} 条'
|
|
1158
|
+
if n_no_link:
|
|
1159
|
+
detail += f';{n_no_link} 条无原文链接或快照'
|
|
1181
1160
|
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
1182
|
-
f'<span class="d"
|
|
1161
|
+
f'<span class="d">{detail}</span></div>')
|
|
1183
1162
|
|
|
1184
1163
|
bd = v["binding"]
|
|
1185
1164
|
if bd.get("no_citation"):
|
|
1186
1165
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 0/0</span>'
|
|
1187
|
-
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]}
|
|
1166
|
+
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]} 篇来源文章对不上正文</span></div>')
|
|
1188
1167
|
elif not bd["total"]:
|
|
1189
1168
|
bd_html = '<div class="vi"><span class="s none">— 引用对应 0/0</span><span class="d">正文里没有来源角标</span></div>'
|
|
1190
1169
|
elif not bd["unbound"]:
|
|
1191
1170
|
bd_html = (f'<div class="vi"><span class="s ok">✓ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
1192
|
-
f'<span class="d">正文每处 [n]
|
|
1171
|
+
f'<span class="d">正文每处 [n] 都能找到对应来源文章</span></div>')
|
|
1193
1172
|
else:
|
|
1194
1173
|
unbound_text = "、".join(f"[{esc(x)}]" for x in bd["unbound"][:8])
|
|
1195
1174
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
@@ -1198,28 +1177,33 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1198
1177
|
fr = v["freshness"]
|
|
1199
1178
|
if fr:
|
|
1200
1179
|
rng = f"{fr['min'][0]}-{fr['min'][1]:02d}~{fr['max'][0]}-{fr['max'][1]:02d}"
|
|
1201
|
-
|
|
1202
|
-
|
|
1180
|
+
# 2026-09-29 起:去掉"N 条年头较久,按参考口径使用"——对长期有效的
|
|
1181
|
+
# 政策法规偏严,且"按参考口径使用"读者无从理解;old_count 仍照常计算留待后续。
|
|
1182
|
+
fr_html = f'<div class="vi"><span class="s ok">✓ 材料新旧 已核</span><span class="d">材料日期 {esc(rng)}</span></div>'
|
|
1203
1183
|
else:
|
|
1204
1184
|
fr_html = '<div class="vi"><span class="s none">— 材料新旧 未记录</span><span class="d">材料没标发布日期</span></div>'
|
|
1205
1185
|
|
|
1186
|
+
# 材料构成:材料类型四分类(政策依据型/数据支撑型/…)非本检索接口返回字段
|
|
1187
|
+
# → 没有类型数据时**整行不显示**,不再渲染"材料没标类型"这种永远为空的占位行(2026-09-28 修复)。
|
|
1206
1188
|
cov = v["coverage"]
|
|
1207
1189
|
parts = [f"{KIND_CATALOG[k][0]} {cov[k]}" for k in ("policy", "data", "case", "reference") if cov.get(k)]
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
f'<span class="d">{esc(" · ".join(parts)) if parts else "材料没标类型"}</span></div>')
|
|
1190
|
+
cov_html = (f'<div class="vi"><span class="s ok">✓ 材料构成</span>'
|
|
1191
|
+
f'<span class="d">{esc(" · ".join(parts))}</span></div>') if parts else ""
|
|
1211
1192
|
|
|
1212
1193
|
sc = v["self_check"]
|
|
1213
1194
|
if sc["status"] == "pass":
|
|
1214
1195
|
notes = ";".join(note for _, note in sc["items"].values() if note)
|
|
1215
1196
|
title_attr = f' title="{esc(notes)}"' if notes else ""
|
|
1216
1197
|
item_names = "、".join(sc["items"].keys()) if sc["items"] else "、".join(label for _, label in SELF_CHECK_ITEMS)
|
|
1217
|
-
|
|
1198
|
+
unrecorded = sc["total"] - sc["passed"] - sc.get("failed", 0)
|
|
1199
|
+
sc_head = f'✓ 交付前检查 {sc["passed"]}/{sc["total"]}' if not unrecorded else \
|
|
1200
|
+
f'✓ 交付前检查 通过({unrecorded} 项未记录)'
|
|
1201
|
+
sc_html = (f'<div class="vi"><span class="s ok"{title_attr}>{sc_head}</span>'
|
|
1218
1202
|
f'<span class="d">{esc(item_names)}{esc(" · 悬停查看说明" if notes else "")}</span></div>')
|
|
1219
1203
|
elif sc["status"] == "fail":
|
|
1220
1204
|
failed_parts = []
|
|
1221
1205
|
for label, (status, note) in sc["items"].items():
|
|
1222
|
-
if status
|
|
1206
|
+
if status == "fail":
|
|
1223
1207
|
suffix = f"({note[:40]}…)" if len(note) > 40 else (f"({note})" if note else "")
|
|
1224
1208
|
failed_parts.append(label + suffix)
|
|
1225
1209
|
sc_html = (f'<div class="vi"><span class="s fail">✗ 交付前检查 {sc["passed"]}/{sc["total"]}</span>'
|
|
@@ -1227,10 +1211,9 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1227
1211
|
else:
|
|
1228
1212
|
sc_html = '<div class="vi"><span class="s none">— 交付前检查 未记录</span><span class="d">本次溯源 JSON 没写入检查结果</span></div>'
|
|
1229
1213
|
|
|
1214
|
+
# "现行效力"人工复核提示行已移除(2026-09-19 起):
|
|
1215
|
+
# 政策是否现行有效无法自动判定,此提示对用户无操作价值;policy_count 仅保留在计算层不再展示。
|
|
1230
1216
|
manual = ""
|
|
1231
|
-
if v["policy_count"]:
|
|
1232
|
-
manual = (f'<div class="vi"><span class="s man">◐ 现行效力</span>'
|
|
1233
|
-
f'<span class="d">{v["policy_count"]} 份政策文件建议按官方发布确认是否现行有效</span></div>')
|
|
1234
1217
|
|
|
1235
1218
|
return f"""
|
|
1236
1219
|
<div class="verify {state}">
|
|
@@ -1239,7 +1222,7 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1239
1222
|
<div class="v-grid">
|
|
1240
1223
|
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}{manual}
|
|
1241
1224
|
</div>
|
|
1242
|
-
<div class="v-note"
|
|
1225
|
+
<div class="v-note">核验方式:先用深知可信搜索找权威来源,再把正文每处依据和原文逐条比对(都能点开原文回看),最后做了交付前五项检查。{manual_checks_html}</div>
|
|
1243
1226
|
</div>"""
|
|
1244
1227
|
|
|
1245
1228
|
|
|
@@ -1273,14 +1256,51 @@ def render_src_card(jb: Dict[str, str], cid: str, dup: bool = False) -> str:
|
|
|
1273
1256
|
)
|
|
1274
1257
|
|
|
1275
1258
|
|
|
1276
|
-
|
|
1259
|
+
_CN_DIGITS = {"〇": "0", "零": "0", "一": "1", "二": "2", "三": "3", "四": "4", "五": "5",
|
|
1260
|
+
"六": "6", "七": "7", "八": "8", "九": "9", "十": "10"}
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
def _norm_heading(text: Any) -> str:
|
|
1264
|
+
return re.sub(r"[\s、,,。.::;;()()\[\]【】]+", "", str(text or ""))
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
def _cn_to_digit(text: str) -> str:
|
|
1268
|
+
return _CN_DIGITS.get(text.strip(), text.strip())
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
def resolve_chart_anchor(sections: List[Dict[str, Any]], anchor: Any) -> int:
|
|
1272
|
+
"""把图表的 section 锚点解析为章节序号(1-based);解析不到返回 0。
|
|
1273
|
+
|
|
1274
|
+
锚点容错:可写章节号(`二` / `2` / `二、`)、章节标题(`一次性奖励金额对比`)、
|
|
1275
|
+
或带序号的完整标题(`二、一次性奖励金额对比`)——统一去空白与顿号后按
|
|
1276
|
+
「序号相等」或「标题互相包含」匹配。
|
|
1277
|
+
"""
|
|
1278
|
+
raw = _norm_heading(anchor)
|
|
1279
|
+
if not raw:
|
|
1280
|
+
return 0
|
|
1281
|
+
want_num = _cn_to_digit(raw[0]) if raw and _cn_to_digit(raw[0]).isdigit() else ""
|
|
1282
|
+
for idx, sec in enumerate(sections, 1):
|
|
1283
|
+
number, title_text = split_heading_number(sec["title"] or "")
|
|
1284
|
+
if want_num and number and _cn_to_digit(_norm_heading(number)) == want_num and len(raw) == 1:
|
|
1285
|
+
return idx
|
|
1286
|
+
title_norm = _norm_heading(title_text)
|
|
1287
|
+
if title_norm and (title_norm in raw or raw in title_norm):
|
|
1288
|
+
return idx
|
|
1289
|
+
return 0
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
def render_section_cards(sections: List[Dict[str, Any]], sources: List[Dict[str, str]],
|
|
1293
|
+
charts_by_section: Optional[Dict[int, str]] = None) -> str:
|
|
1277
1294
|
"""正文渲染(原型复刻):chapter(h2)+ lead/para 段落 + 段后 src-card 溯源卡。
|
|
1278
1295
|
|
|
1279
1296
|
溯源卡按段内角标顺序输出;同一材料在同段只出一张,跨段重复出现标记 dup-card(灰化)。
|
|
1297
|
+
charts_by_section:{章节序号: 图表 HTML}——图表**跟着它展示的数据所在的章节走**
|
|
1298
|
+
(1.4.0:不再固定堆在报告末尾),插在该章节正文之后。
|
|
1280
1299
|
"""
|
|
1281
1300
|
parts: List[str] = []
|
|
1282
1301
|
first_para = True
|
|
1283
1302
|
source_ids = {s["id"] for s in sources}
|
|
1303
|
+
charts_by_section = charts_by_section or {}
|
|
1284
1304
|
for sec_idx, sec in enumerate(sections, 1):
|
|
1285
1305
|
number, title_text = split_heading_number(sec["title"] or "")
|
|
1286
1306
|
chapter_title = f"{number}、{title_text}" if (number and title_text) else (title_text or "")
|
|
@@ -1313,6 +1333,8 @@ def render_section_cards(sections: List[Dict[str, Any]], sources: List[Dict[str,
|
|
|
1313
1333
|
else:
|
|
1314
1334
|
parts.append(f'<p class="{cls}">{b["html"]}</p>')
|
|
1315
1335
|
if chapter_title:
|
|
1336
|
+
if sec_idx in charts_by_section:
|
|
1337
|
+
parts.append(charts_by_section[sec_idx])
|
|
1316
1338
|
parts.append("</section>")
|
|
1317
1339
|
return "\n".join(parts)
|
|
1318
1340
|
|
|
@@ -1346,9 +1368,11 @@ def strip_leading_chain(text: str, chain: List[str]) -> str:
|
|
|
1346
1368
|
|
|
1347
1369
|
|
|
1348
1370
|
def render_crumb(chain: List[str]) -> str:
|
|
1349
|
-
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1371
|
+
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1372
|
+
段落本身无章节层级(链上只有文章名)时不显示——材料卡标题已是文章名,
|
|
1373
|
+
单独一行重复文章名对定位无增量(2026-09-19 反馈)。"""
|
|
1350
1374
|
parts = [esc(level) for level in chain if level]
|
|
1351
|
-
if
|
|
1375
|
+
if len(parts) < 2:
|
|
1352
1376
|
return ""
|
|
1353
1377
|
return '<span class="crumb">' + ' <i>›</i> '.join(parts) + "</span>"
|
|
1354
1378
|
|
|
@@ -1375,16 +1399,21 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1375
1399
|
else '<span class="sc-vk warn">待补链接</span>')
|
|
1376
1400
|
note_html = ""
|
|
1377
1401
|
elif source.get("verified"):
|
|
1378
|
-
note = source.get("verify_note") or "
|
|
1402
|
+
note = source.get("verify_note") or "摘录可比对,原文或存档快照可回看"
|
|
1379
1403
|
vk = f'<span class="sc-vk ok" title="{esc(note)}">✓ 已核验</span>'
|
|
1380
1404
|
note_html = f'<div class="sc-vnote">{esc(short(note, 90))}</div>' if source.get("verify_note") else ""
|
|
1381
1405
|
else:
|
|
1382
1406
|
reason = "待补原文链接" if not source.get("has_link") else "待补摘录"
|
|
1383
1407
|
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
1384
1408
|
note_html = ""
|
|
1385
|
-
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", "")
|
|
1386
|
-
# 关键性行:有文号(接口 policyFiles 匹配)时"文号 · 数据源 · 日期",否则"数据源 · 日期"
|
|
1387
|
-
|
|
1409
|
+
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", ""))
|
|
1410
|
+
# 关键性行:有文号(接口 policyFiles 匹配)时"文号 · 数据源 · 日期",否则"数据源 · 日期"。
|
|
1411
|
+
# 文号必须是标准格式——政府公文"〔年份〕序号"(杭政函〔2022〕81号)、公告/令类"第X号"
|
|
1412
|
+
# (财政部税务总局公告2023年第19号、主席令第三十五号、国务院令第765号,含汉字数字);
|
|
1413
|
+
# 描述性文字("XX印发"类自造描述)不显示,当无文号处理。
|
|
1414
|
+
_dn = source.get("doc_number") or ""
|
|
1415
|
+
_dn = _dn if re.search(r"〔\d{4}〕\s*\d+\s*号|第\s*(?:\d+|[〇零一二三四五六七八九十百千]+)\s*号", _dn) else ""
|
|
1416
|
+
meta_parts = [v for v in [_dn, source.get("agency"), source.get("date"), source.get("area")]
|
|
1388
1417
|
if v and v != "未知来源"]
|
|
1389
1418
|
meta = " | ".join(meta_parts)
|
|
1390
1419
|
# 高可信徽标:仅"发布日期可信度=高"(模型治理入库、标题模型精抽)的材料;"较高"(门户抓取)不标。
|
|
@@ -1438,12 +1467,12 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
|
|
|
1438
1467
|
<ol class="p-steps">
|
|
1439
1468
|
<li class="p-step expandable" id="p-step-search" role="button" tabindex="0" title="展开各路检索明细">
|
|
1440
1469
|
<span class="p-no">1</span>
|
|
1441
|
-
<div class="p-txt"><b>深知检索 {stats['n_searches']}
|
|
1470
|
+
<div class="p-txt"><b>深知检索 {stats['n_searches']} 路</b><i>{step1_sub}</i></div>
|
|
1442
1471
|
</li>
|
|
1443
1472
|
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1444
1473
|
<li class="p-step">
|
|
1445
1474
|
<span class="p-no">2</span>
|
|
1446
|
-
<div class="p-txt"><b
|
|
1475
|
+
<div class="p-txt"><b>来源文章入库 {stats['n_materials']} 篇</b><i>正文采用 {stats['used_count']} · 召回未采用 {stats['unused_count']}</i></div>
|
|
1447
1476
|
</li>
|
|
1448
1477
|
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1449
1478
|
<li class="p-step">
|
|
@@ -1461,10 +1490,10 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
|
|
|
1461
1490
|
|
|
1462
1491
|
|
|
1463
1492
|
def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) -> str:
|
|
1464
|
-
"""
|
|
1493
|
+
"""知识专库全屏视图:大搜索 + 热词 + 检索分组 tabs + 材料卡列表。"""
|
|
1465
1494
|
if not sources:
|
|
1466
|
-
return ('<section class="view" id="view-library" aria-label="
|
|
1467
|
-
'<div class="lib-empty"
|
|
1495
|
+
return ('<section class="view" id="view-library" aria-label="知识专库">'
|
|
1496
|
+
'<div class="lib-empty">接口返回中未识别到可展示的来源文章。</div></section>')
|
|
1468
1497
|
used_sources = [s for s in sources if s.get("used", True)]
|
|
1469
1498
|
unused_sources = [s for s in sources if not s.get("used", True)]
|
|
1470
1499
|
|
|
@@ -1497,33 +1526,42 @@ def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) ->
|
|
|
1497
1526
|
cited_verified = sum(1 for s in used_sources if s.get("verified"))
|
|
1498
1527
|
badge = "全部已核验" if used_sources and cited_verified == len(used_sources) else f"{cited_verified}/{len(used_sources)} 已核验"
|
|
1499
1528
|
return f"""
|
|
1500
|
-
<section class="view" id="view-library" aria-label="
|
|
1529
|
+
<section class="view" id="view-library" aria-label="知识专库">
|
|
1501
1530
|
<div class="lib-head">
|
|
1502
|
-
<div class="lib-title"><b
|
|
1531
|
+
<div class="lib-title"><b>知识专库</b>
|
|
1503
1532
|
<span>共 {len(sources)} 条 · 已引用 {len(used_sources)} · {esc(badge)}</span>
|
|
1504
1533
|
</div>
|
|
1505
1534
|
<div class="lib-searchWrap">
|
|
1506
1535
|
<span class="lib-searchIcon" aria-hidden="true">⌕</span>
|
|
1507
|
-
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="
|
|
1536
|
+
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="搜索来源文章">
|
|
1508
1537
|
</div>
|
|
1509
1538
|
{hot_html}
|
|
1510
1539
|
<div class="lib-tabs" role="tablist" aria-label="按检索分组筛选">{"".join(tabs)}</div>
|
|
1511
1540
|
</div>
|
|
1512
1541
|
<div class="lib-list" id="lib-list">{cards_html}</div>
|
|
1513
|
-
<div class="lib-empty hide" id="lib-empty"
|
|
1514
|
-
<div class="lib-foot"
|
|
1542
|
+
<div class="lib-empty hide" id="lib-empty">没有符合当前筛选的来源文章。</div>
|
|
1543
|
+
<div class="lib-foot">来源:深知可信搜索 · 每条摘录均取自原文原段</div>
|
|
1515
1544
|
</section>"""
|
|
1516
1545
|
|
|
1517
1546
|
|
|
1518
|
-
def render_toc(sections: List[Dict[str, Any]]) -> str:
|
|
1519
|
-
"""章节目录(滚动 spy):长报告(≥6
|
|
1520
|
-
|
|
1521
|
-
|
|
1547
|
+
def render_toc(sections: List[Dict[str, Any]], extra: str = "") -> str:
|
|
1548
|
+
"""章节目录(滚动 spy):长报告(≥6 个**有标题**的章节)显示,桌面端左侧浮动。
|
|
1549
|
+
|
|
1550
|
+
无标题节(正文开头的导语段)跳过——此前兜底成「第 N 节」占位项,且该锚点
|
|
1551
|
+
#sec-i 在 render_section_cards 里根本不生成(死链接),点它没反应。
|
|
1552
|
+
extra 为附加条目 HTML(图表独立呈现时);门槛按有标题章节数计。
|
|
1553
|
+
"""
|
|
1522
1554
|
items = []
|
|
1523
1555
|
for i, sec in enumerate(sections, 1):
|
|
1524
|
-
|
|
1525
|
-
|
|
1556
|
+
title = (sec.get("title") or "").strip()
|
|
1557
|
+
if not title:
|
|
1558
|
+
continue # 导语内容照常在正文展示,只是不占目录条目
|
|
1559
|
+
number, title_text = split_heading_number(title)
|
|
1560
|
+
label = f"{number} {title_text}" if (number and title_text) else title_text
|
|
1526
1561
|
items.append(f'<a href="#sec-{i}">{esc(short(label, 16))}</a>')
|
|
1562
|
+
if len(items) < 6 and not extra:
|
|
1563
|
+
return ""
|
|
1564
|
+
items.append(extra)
|
|
1527
1565
|
return f'<nav class="toc" aria-label="章节目录">{"".join(items)}</nav>'
|
|
1528
1566
|
|
|
1529
1567
|
|
|
@@ -1532,12 +1570,25 @@ def render_print_appendix(sources: List[Dict[str, str]]) -> str:
|
|
|
1532
1570
|
if not sources:
|
|
1533
1571
|
return ""
|
|
1534
1572
|
cards = "".join(render_source_card(s, for_print=True) for s in sources)
|
|
1535
|
-
return (f'<section class="print-appendix" aria-label="
|
|
1536
|
-
f'<h3
|
|
1573
|
+
return (f'<section class="print-appendix" aria-label="来源文章附录(打印归档)">'
|
|
1574
|
+
f'<h3>来源文章(全 {len(sources)} 篇)</h3>{cards}</section>')
|
|
1537
1575
|
|
|
1538
1576
|
|
|
1539
1577
|
def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dknowc_search_trace", suffix_ext: str = ".html") -> str:
|
|
1540
1578
|
raw = question.strip() or fallback
|
|
1579
|
+
# 清理对话指令性措辞(1.4.0):文件名用主题本身,不保留"帮我梳理一下…做个系统"这类口吻
|
|
1580
|
+
# (实测:WB 交付物文件名直接带用户原话的"帮我梳理一下…做个系统",冗长且不像正式交付名)
|
|
1581
|
+
for _ in range(3): # 反复剥离直到无变化(如"请帮我…一下吧")
|
|
1582
|
+
before = raw
|
|
1583
|
+
raw = re.sub(r"^(请|麻烦|帮我|帮忙|给我|我想|想问下|请问|你能|帮我看看|帮我看下)+", "", raw)
|
|
1584
|
+
# 只剥离明确不是主题词的整理类动词("分析/对比"等可能是主题的一部分,如"分析化学",不剥离)
|
|
1585
|
+
raw = re.sub(r"^(梳理|整理|汇总|总结|归纳|罗列)(一下)?", "", raw)
|
|
1586
|
+
raw = re.sub(r"(一下|吧|谢谢|多谢|可以吗|好吗|行吗|呢)+$", "", raw)
|
|
1587
|
+
raw = re.sub(r"(做个?系统(对比|比较|梳理)?|系统对比|系统梳理|对比一下|整理一下|汇总一下|总结一下)$", "", raw)
|
|
1588
|
+
raw = raw.strip(" ,,。.、!!??~~")
|
|
1589
|
+
if raw == before:
|
|
1590
|
+
break
|
|
1591
|
+
raw = raw or question.strip() or fallback
|
|
1541
1592
|
normalized = re.sub(r"\s+", "_", raw)
|
|
1542
1593
|
normalized = re.sub(r"[\\/:*?\"<>|#%&{}$!@`+=;',。、?!:;“”‘’()()【】《》\[\]]+", "", normalized)
|
|
1543
1594
|
normalized = normalized.strip("._-")
|
|
@@ -1573,6 +1624,19 @@ body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe
|
|
|
1573
1624
|
color:var(--ink);background:#f4f5f7;line-height:1.75;font-size:14.5px}
|
|
1574
1625
|
a{color:var(--brand)}
|
|
1575
1626
|
|
|
1627
|
+
/* ===== 数据可视化(1.4.0 一体化:图表并入核验报告,不再另出独立报告) ===== */
|
|
1628
|
+
/* 主形态:图表跟着它展示的数据所在章节走(.chart-inline 插在该章节正文之后) */
|
|
1629
|
+
.chart-inline{margin:18px 0 4px;padding-top:14px;border-top:1px dashed var(--line)}
|
|
1630
|
+
.chart-h3{margin:0 0 4px;font-size:14px;font-weight:600;color:var(--ink)}
|
|
1631
|
+
/* 退化形态:锚点缺失/匹配不上时,作为独立章节排在核验报告单之后、正文之前 */
|
|
1632
|
+
.chart-section{background:#fff;border-radius:14px;box-shadow:var(--shadow-1);padding:22px 26px 18px;margin:0 0 16px}
|
|
1633
|
+
.chart-h2{margin:0 0 6px;font-size:16px;line-height:1.4}
|
|
1634
|
+
.chart-note{margin:0 0 14px;color:var(--muted);font-size:12px}
|
|
1635
|
+
.chart-section .card,.chart-inline .card{box-shadow:none;padding:0;border:0;background:transparent}
|
|
1636
|
+
.chart-section .viz-panel h3,.chart-inline .viz-panel h3{margin:0 0 6px;font-size:13.5px;font-weight:600;color:var(--ink)}
|
|
1637
|
+
.viz-duo{display:grid;grid-template-columns:1fr 1fr;gap:8px 18px;align-items:start}
|
|
1638
|
+
@media(max-width:900px){.viz-duo{grid-template-columns:1fr}}
|
|
1639
|
+
|
|
1576
1640
|
/* ===== 顶栏 ===== */
|
|
1577
1641
|
.topbar{position:sticky;top:0;z-index:50;display:flex;justify-content:space-between;align-items:center;gap:10px;
|
|
1578
1642
|
padding:9px 22px;background:rgba(255,255,255,.92);backdrop-filter:blur(10px);
|
|
@@ -1612,6 +1676,10 @@ a{color:var(--brand)}
|
|
|
1612
1676
|
box-shadow:0 2px 8px rgba(101,18,173,.22)}
|
|
1613
1677
|
.hero h1{margin:0 0 10px;font-size:24px;line-height:1.5;max-width:860px;margin-left:auto;margin-right:auto;color:var(--ink)}
|
|
1614
1678
|
.hero .meta{color:var(--muted);font-size:13px;letter-spacing:.5px}
|
|
1679
|
+
.hero-q{max-width:860px;margin:0 auto 12px;padding:10px 16px;background:#fff;border:1px dashed #c9b8ec;
|
|
1680
|
+
border-radius:10px;color:#4a3f63;font-size:14px;line-height:1.75;text-align:left}
|
|
1681
|
+
.hero-q .q-label{display:inline-block;margin-right:10px;padding:0 10px;background:var(--grad);color:#fff;
|
|
1682
|
+
border-radius:6px;font-size:12px;font-weight:700;letter-spacing:2px;vertical-align:1px}
|
|
1615
1683
|
.hero-switch{margin-top:16px;display:flex;justify-content:center}
|
|
1616
1684
|
.hero-switch .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
|
|
1617
1685
|
.hero-switch .view-switch button{color:#70678a;padding:6px 22px;font-size:13px}
|
|
@@ -1753,7 +1821,7 @@ a.jb-quote{text-decoration:none}
|
|
|
1753
1821
|
.sc-links a{display:inline-flex;align-items:center;min-height:24px;padding:3px 9px;border-radius:6px;
|
|
1754
1822
|
background:var(--brand-soft);color:var(--brand);font-weight:700;text-decoration:none;font-size:12px}
|
|
1755
1823
|
|
|
1756
|
-
/* =====
|
|
1824
|
+
/* ===== 知识专库视图 ===== */
|
|
1757
1825
|
#view-library{padding:26px 0 30px}
|
|
1758
1826
|
.lib-head{max-width:860px;margin:0 auto 16px;text-align:center}
|
|
1759
1827
|
.lib-title{margin-bottom:14px}
|
|
@@ -1823,7 +1891,6 @@ a.jb-quote{text-decoration:none}
|
|
|
1823
1891
|
.scard .sc-links{margin-top:4px}
|
|
1824
1892
|
.no-link{font-size:11.5px;color:var(--muted)}
|
|
1825
1893
|
.sc-links a.snap{background:#faf5ff;border-color:#d9c9f4;color:#5b21b6}
|
|
1826
|
-
.dead-link{font-size:11.5px;color:var(--warn)}
|
|
1827
1894
|
|
|
1828
1895
|
/* ===== 章节目录(spy,长报告) ===== */
|
|
1829
1896
|
.toc{position:fixed;left:calc((100vw - 1080px)/2 - 168px);top:120px;width:140px;max-height:60vh;overflow:auto;
|
|
@@ -1831,6 +1898,9 @@ a.jb-quote{text-decoration:none}
|
|
|
1831
1898
|
.toc a{color:var(--muted);text-decoration:none;padding:4px 10px;border-left:2px solid var(--line);
|
|
1832
1899
|
line-height:1.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1833
1900
|
.toc a.on{color:var(--brand);border-left-color:var(--brand);font-weight:700}
|
|
1901
|
+
/* 知识专库视图下隐藏章节目录(2026-09-29 起):.toc 渲染在 .app 之外,
|
|
1902
|
+
视图切换只由 .app[data-view] 驱动,此前无任何规则处理 .toc,专库视图下目录仍挂在左侧 */
|
|
1903
|
+
.app[data-view="library"] ~ .toc,.app[data-view="library"] .toc{display:none}
|
|
1834
1904
|
@media (max-width:1460px){.toc{display:none}}
|
|
1835
1905
|
|
|
1836
1906
|
.foot{text-align:center;color:var(--muted);font-size:11.5px;padding:16px 0 4px;line-height:1.8}
|
|
@@ -1997,7 +2067,7 @@ PAGE_JS = """
|
|
|
1997
2067
|
var on = document.body.classList.toggle("reading");
|
|
1998
2068
|
readBtn.setAttribute("aria-pressed", on ? "true" : "false");
|
|
1999
2069
|
readBtn.textContent = on ? "显示核验" : "只看正文";
|
|
2000
|
-
/*
|
|
2070
|
+
/* 只看正文只作用于核验报告视图:正在知识专库时切回报告,专库不受影响 */
|
|
2001
2071
|
if (on && app && app.getAttribute("data-view") !== "report") setView("report");
|
|
2002
2072
|
});
|
|
2003
2073
|
}
|
|
@@ -2152,7 +2222,7 @@ PAGE_JS = """
|
|
|
2152
2222
|
name.addEventListener("click", function () { toggleJb(name.closest(".jb")); });
|
|
2153
2223
|
});
|
|
2154
2224
|
|
|
2155
|
-
/* 引文条目点击 →
|
|
2225
|
+
/* 引文条目点击 → 知识专库定位对应卡:库内导航看完整材料;
|
|
2156
2226
|
外部原文跳转只保留 jb-head 的"查看全文"按钮,动线分离 */
|
|
2157
2227
|
function jumpToLibrary(id) {
|
|
2158
2228
|
var card = byId[id];
|
|
@@ -2198,7 +2268,7 @@ PAGE_JS = """
|
|
|
2198
2268
|
});
|
|
2199
2269
|
});
|
|
2200
2270
|
|
|
2201
|
-
/* ===== 7.
|
|
2271
|
+
/* ===== 7. 知识专库:tabs + 搜索 + 热词 ===== */
|
|
2202
2272
|
var cond = "";
|
|
2203
2273
|
var kw = "";
|
|
2204
2274
|
function applyFilter() {
|
|
@@ -2255,7 +2325,13 @@ PAGE_JS = """
|
|
|
2255
2325
|
a.addEventListener("click", function (e) {
|
|
2256
2326
|
e.preventDefault();
|
|
2257
2327
|
var target = document.querySelector(a.getAttribute("href"));
|
|
2258
|
-
if (target)
|
|
2328
|
+
if (!target) return;
|
|
2329
|
+
/* 手动定位而非 scrollIntoView({block:"start"}):后者把标题顶到视口 y=0,
|
|
2330
|
+
会被 sticky 顶栏盖住。偏移量与目录吸顶位置同一基准(顶栏高 + 20px)。 */
|
|
2331
|
+
var bar = document.querySelector(".topbar");
|
|
2332
|
+
var offset = (bar ? bar.offsetHeight : 0) + 20;
|
|
2333
|
+
var y = target.getBoundingClientRect().top + window.scrollY - offset;
|
|
2334
|
+
window.scrollTo({ top: Math.max(0, y), behavior: "smooth" });
|
|
2259
2335
|
});
|
|
2260
2336
|
});
|
|
2261
2337
|
function spy() {
|
|
@@ -2265,6 +2341,22 @@ PAGE_JS = """
|
|
|
2265
2341
|
links.forEach(function (a, i) { a.classList.toggle("on", i === current); });
|
|
2266
2342
|
}
|
|
2267
2343
|
window.addEventListener("scroll", spy, { passive: true });
|
|
2344
|
+
|
|
2345
|
+
/* 目录纵向定位(2026-09-29 起):此前 CSS 写死 top:120px,目录顶部与页头
|
|
2346
|
+
齐平、离正文很远。改为——直接跟随正文首节,只保留"不低于顶栏下方"的下限;首屏看不到
|
|
2347
|
+
目录属正常,向下滚动后自然吸附在顶栏下方。目录过长由 CSS max-height:60vh+overflow:auto
|
|
2348
|
+
内部滚动兜底。 */
|
|
2349
|
+
var topbar = document.querySelector(".topbar");
|
|
2350
|
+
function placeToc() {
|
|
2351
|
+
var first = secs[0];
|
|
2352
|
+
if (!first) return;
|
|
2353
|
+
var stick = (topbar ? topbar.offsetHeight : 0) + 20;
|
|
2354
|
+
var want = Math.round(first.getBoundingClientRect().top);
|
|
2355
|
+
toc.style.top = Math.max(stick, want) + "px";
|
|
2356
|
+
}
|
|
2357
|
+
window.addEventListener("scroll", placeToc, { passive: true });
|
|
2358
|
+
window.addEventListener("resize", placeToc);
|
|
2359
|
+
placeToc();
|
|
2268
2360
|
spy();
|
|
2269
2361
|
}
|
|
2270
2362
|
})();
|
|
@@ -2273,7 +2365,8 @@ PAGE_JS = """
|
|
|
2273
2365
|
|
|
2274
2366
|
def render_html(payload: Dict[str, Any], title: str, answer_override: str = "", question_override: str = "",
|
|
2275
2367
|
generated_at: Optional[datetime] = None,
|
|
2276
|
-
skip_link_check: bool = False, snapshot_enabled: bool = True
|
|
2368
|
+
skip_link_check: bool = False, snapshot_enabled: bool = True,
|
|
2369
|
+
charts_data: Optional[Dict[str, Any]] = None) -> str:
|
|
2277
2370
|
payload = unwrap(payload)
|
|
2278
2371
|
answer = normalize_citations(answer_override) if answer_override.strip() else extract_answer(payload)
|
|
2279
2372
|
sources = align_sources_to_answer(answer, extract_sources(payload, skip_link_check=skip_link_check, snapshot_enabled=snapshot_enabled))
|
|
@@ -2291,7 +2384,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2291
2384
|
citation_warning = (
|
|
2292
2385
|
'<div class="warn-box"><b>生成检查未通过:正文没有来源角标。</b>'
|
|
2293
2386
|
'本报告无法建立"结论-素材"核验对应,仅作素材清单参考。'
|
|
2294
|
-
'请修正最终答案(--answer-file):在关键结论后标注 [1]、[2]
|
|
2387
|
+
'请修正最终答案(--answer-file):在关键结论后标注 [1]、[2] 等角标并逐条对应来源文章,'
|
|
2295
2388
|
'然后重新运行本脚本生成核验报告。</div>'
|
|
2296
2389
|
)
|
|
2297
2390
|
chip_map = build_chip_data(sources)
|
|
@@ -2303,6 +2396,12 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2303
2396
|
jb_tables[key] = html
|
|
2304
2397
|
doc_title, sections = group_sections(blocks)
|
|
2305
2398
|
display_title = doc_title or title
|
|
2399
|
+
# 原问题行(2026-10-08 起):只显示 --question 显式传入的原始问题,
|
|
2400
|
+
# 不用文档标题冒充(标题是答案的成稿名,不是用户原话)。未传则整行不渲染。
|
|
2401
|
+
hero_question = (
|
|
2402
|
+
f'<div class="hero-q"><span class="q-label">原问题</span>{esc(question_override.strip())}</div>'
|
|
2403
|
+
if question_override.strip() else ""
|
|
2404
|
+
)
|
|
2306
2405
|
|
|
2307
2406
|
jb_tables_json = json.dumps(jb_tables, ensure_ascii=False).replace("</", "<\\/")
|
|
2308
2407
|
jb_tables_script = (f'<script type="application/json" id="jb-tables">{jb_tables_json}</script>\n'
|
|
@@ -2310,14 +2409,56 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2310
2409
|
|
|
2311
2410
|
meta_bits = []
|
|
2312
2411
|
if process_stats["n_searches"]:
|
|
2313
|
-
meta_bits.append(f"深知检索 {process_stats['n_searches']}
|
|
2412
|
+
meta_bits.append(f"深知检索 {process_stats['n_searches']} 路")
|
|
2314
2413
|
if sources:
|
|
2315
|
-
meta_bits.append(f"
|
|
2414
|
+
meta_bits.append(f"来源文章 {len(sources)} 篇")
|
|
2316
2415
|
if process_stats["n_cite_marks"]:
|
|
2317
2416
|
meta_bits.append(f"正文引用 {process_stats['n_cite_marks']} 处")
|
|
2318
2417
|
meta_bits.append(f"生成于 {generated}")
|
|
2319
2418
|
meta_line = " · ".join(meta_bits)
|
|
2320
2419
|
|
|
2420
|
+
# 图表并入核验报告(1.4.0 一体化):有图表数据且包内 ECharts 可用时,
|
|
2421
|
+
# 图表并入核验报告(1.4.0 一体化)——交付物始终是**一个** HTML,不再另出独立图表报告。
|
|
2422
|
+
# 位置按 metadata.section 锚点插进对应章节(图表跟着它展示的数据走);锚点缺失或不匹配
|
|
2423
|
+
# 才退化为核验报告单之后的独立"数据可视化"章节。资源缺失或数据不可用则整块不渲染
|
|
2424
|
+
# (不出现空白图,也不阻断报告生成)。
|
|
2425
|
+
charts_html = ""
|
|
2426
|
+
charts_script = ""
|
|
2427
|
+
chart_toc = ""
|
|
2428
|
+
charts_by_section: Dict[int, str] = {}
|
|
2429
|
+
if charts_data:
|
|
2430
|
+
echarts_src = chart_embed.load_echarts_source()
|
|
2431
|
+
if not echarts_src:
|
|
2432
|
+
print(f"提示:未找到 {chart_embed.ECHARTS_RESOURCE},本次不生成图表章节(报告其余部分不受影响)。",
|
|
2433
|
+
file=sys.stderr)
|
|
2434
|
+
charts = chart_embed.build_charts(charts_data) if echarts_src else []
|
|
2435
|
+
if echarts_src and not charts:
|
|
2436
|
+
print("提示:图表数据不足以成图(需 ≥2 个数据点/系列),本次不生成图表章节。", file=sys.stderr)
|
|
2437
|
+
if charts:
|
|
2438
|
+
chart_meta = charts_data.get("metadata") or {}
|
|
2439
|
+
chart_title = str(chart_meta.get("title") or "").strip() or "数据可视化"
|
|
2440
|
+
note = '<p class="chart-note">图表由已核验材料数据生成,点击图例或数据项可跳转对应来源原文。</p>'
|
|
2441
|
+
blocks = chart_embed.render_blocks(charts)
|
|
2442
|
+
# 图表跟着它展示的数据所在的章节走(1.4.0):metadata.section 指定章节号/标题,
|
|
2443
|
+
# 命中就插进该章节正文之后;未指定或匹配不上,才退化为独立的"数据可视化"章节
|
|
2444
|
+
# (放在核验报告单之后、正文之前,作为总体摘要,不再堆到报告最末尾)。
|
|
2445
|
+
anchor_idx = resolve_chart_anchor(sections, chart_meta.get("section"))
|
|
2446
|
+
if anchor_idx:
|
|
2447
|
+
charts_by_section[anchor_idx] = (
|
|
2448
|
+
f'<div class="chart-inline" aria-label="数据可视化">'
|
|
2449
|
+
f'<h3 class="chart-h3">{esc(chart_title)}</h3>{note}{blocks}</div>'
|
|
2450
|
+
)
|
|
2451
|
+
else:
|
|
2452
|
+
charts_html = (
|
|
2453
|
+
f'<section class="chart-section" id="chart-block" aria-label="数据可视化">'
|
|
2454
|
+
f'<h2 class="chart-h2">{esc(chart_title)}</h2>{note}{blocks}</section>'
|
|
2455
|
+
)
|
|
2456
|
+
chart_toc = f'<a href="#chart-block">{esc(short(chart_title, 16))}</a>'
|
|
2457
|
+
if chart_meta.get("section"):
|
|
2458
|
+
print(f"提示:图表锚点「{chart_meta.get('section')}」在正文里找不到对应章节,"
|
|
2459
|
+
f"已改为独立章节呈现。", file=sys.stderr)
|
|
2460
|
+
charts_script = chart_embed.render_script(charts, echarts_src)
|
|
2461
|
+
|
|
2321
2462
|
return f"""<!doctype html>
|
|
2322
2463
|
<html lang="zh-CN">
|
|
2323
2464
|
<head>
|
|
@@ -2336,7 +2477,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2336
2477
|
<div class="tb-right">
|
|
2337
2478
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2338
2479
|
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2339
|
-
<button data-view="library" type="button"
|
|
2480
|
+
<button data-view="library" type="button">知识专库</button>
|
|
2340
2481
|
</div>
|
|
2341
2482
|
<div class="tb-tools">
|
|
2342
2483
|
<button id="btn-reading" type="button" aria-pressed="false" title="隐藏核验元素,纯阅读正文">只看正文</button>
|
|
@@ -2345,7 +2486,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2345
2486
|
<button id="btn-print" type="button" aria-haspopup="true" title="浏览器打印/另存为 PDF">打印归档 ▾</button>
|
|
2346
2487
|
<span class="print-drop" id="print-drop" hidden>
|
|
2347
2488
|
<button id="print-body" type="button">只打印正文</button>
|
|
2348
|
-
<button id="print-full" type="button"
|
|
2489
|
+
<button id="print-full" type="button">完整归档(含来源文章)</button>
|
|
2349
2490
|
</span>
|
|
2350
2491
|
</span>
|
|
2351
2492
|
</div>
|
|
@@ -2356,11 +2497,12 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2356
2497
|
<div class="hero">
|
|
2357
2498
|
<div class="r-badge">溯源核验报告</div>
|
|
2358
2499
|
<h1>{esc(display_title)}</h1>
|
|
2500
|
+
{hero_question}
|
|
2359
2501
|
<div class="meta">{esc(meta_line)} | 素材来源:深知可信搜索</div>
|
|
2360
2502
|
<div class="hero-switch">
|
|
2361
2503
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2362
2504
|
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2363
|
-
<button data-view="library" type="button"
|
|
2505
|
+
<button data-view="library" type="button">知识专库({len(sources)})</button>
|
|
2364
2506
|
</div>
|
|
2365
2507
|
</div>
|
|
2366
2508
|
</div>
|
|
@@ -2371,27 +2513,29 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2371
2513
|
<main class="view" id="view-report" aria-label="核验报告正文">
|
|
2372
2514
|
{citation_warning}
|
|
2373
2515
|
{render_verify_panel(verification)}
|
|
2516
|
+
{charts_html}
|
|
2374
2517
|
<div class="doc-paper">
|
|
2375
|
-
{render_section_cards(sections, sources)}
|
|
2518
|
+
{render_section_cards(sections, sources, charts_by_section)}
|
|
2376
2519
|
</div>
|
|
2377
|
-
<div class="foot">深知可信搜索 · 溯源核验报告 | 内容由 AI
|
|
2520
|
+
<div class="foot">深知可信搜索 · 溯源核验报告 | 内容由 AI 生成,仅供参考</div>
|
|
2378
2521
|
</main>
|
|
2379
2522
|
|
|
2380
2523
|
{render_library_view(sources, hot_terms)}
|
|
2381
2524
|
{render_print_appendix(sources)}
|
|
2382
2525
|
</div>
|
|
2383
2526
|
|
|
2384
|
-
{render_toc(sections)}
|
|
2527
|
+
{render_toc(sections, chart_toc)}
|
|
2385
2528
|
|
|
2386
2529
|
<div class="ev-panel" id="ev-pop" hidden></div>
|
|
2387
2530
|
{jb_tables_script}<div class="sheet-mask" aria-hidden="true"></div>
|
|
2388
|
-
<div class="sheet" role="dialog" aria-label="
|
|
2531
|
+
<div class="sheet" role="dialog" aria-label="来源文章">
|
|
2389
2532
|
<div class="sheet-grab"></div>
|
|
2390
2533
|
<div class="sheet-head"><b>依据对照</b><button class="sheet-close" type="button">收起</button></div>
|
|
2391
2534
|
<div class="sheet-body"></div>
|
|
2392
2535
|
</div>
|
|
2393
2536
|
|
|
2394
2537
|
<script>{PAGE_JS}</script>
|
|
2538
|
+
{charts_script}
|
|
2395
2539
|
</body>
|
|
2396
2540
|
</html>"""
|
|
2397
2541
|
|
|
@@ -2436,21 +2580,50 @@ def renumber_citations(answer: str, sources: List[Dict[str, str]]) -> Tuple[str,
|
|
|
2436
2580
|
|
|
2437
2581
|
|
|
2438
2582
|
def align_sources_to_answer(answer: str, sources: List[Dict[str, str]]) -> List[Dict[str, str]]:
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2583
|
+
"""不再按位置给材料重编号。
|
|
2584
|
+
|
|
2585
|
+
修复历史实现缺陷:原实现会在"正文角标与素材 id 完全不相交"时按顺序把素材改号
|
|
2586
|
+
迎合角标——正文写 [7] 而只有 1 篇来源文章时,会被洗成"✓ 引用对应 1/1",与
|
|
2587
|
+
"未绑定角标绝不按位置猜测"的核验诚实性原则相反。现如实返回原素材,由核验单报未绑定。
|
|
2588
|
+
角标 1..N 的连续重排由 renumber_citations 独立完成(按首现顺序,1.1.5 用户要求)。
|
|
2589
|
+
"""
|
|
2590
|
+
return sources
|
|
2591
|
+
|
|
2592
|
+
|
|
2593
|
+
def resolve_charts_data(value: str) -> Optional[Dict[str, Any]]:
|
|
2594
|
+
"""解析 --charts-json:支持直接内联 JSON,也支持 official-docs/search-results/ 内的文件名。
|
|
2595
|
+
|
|
2596
|
+
非法/为空一律返回 None(图表章节不渲染),绝不因此阻断核验报告生成——
|
|
2597
|
+
报告的核验正文是主交付,图表是附加视图。
|
|
2598
|
+
"""
|
|
2599
|
+
raw = (value or "").strip()
|
|
2600
|
+
if not raw:
|
|
2601
|
+
return None
|
|
2602
|
+
try:
|
|
2603
|
+
if raw.startswith("{"):
|
|
2604
|
+
data = json.loads(raw)
|
|
2605
|
+
else:
|
|
2606
|
+
data = json.loads(_safe_input_path(raw, {".json"}).read_text(encoding="utf-8"))
|
|
2607
|
+
except (ValueError, OSError, json.JSONDecodeError) as exc:
|
|
2608
|
+
print(f"提示:图表数据无法读取({exc}),本次不生成图表章节。", file=sys.stderr)
|
|
2609
|
+
return None
|
|
2610
|
+
return data if isinstance(data, dict) else None
|
|
2611
|
+
|
|
2612
|
+
|
|
2613
|
+
def _next_version_path(path: Path) -> Path:
|
|
2614
|
+
"""输出文件已存在时不覆盖(1.4.0 起):自动改为 原名_v2 / _v3 … 另存。
|
|
2615
|
+
|
|
2616
|
+
追加图表/修改答案后重跑渲染时,旧版本保留、新版本号递增——不覆盖已交付内容,
|
|
2617
|
+
也不会再靠宿主目录里的 "名字 (2)" 兜底。命名与 deliver_outputs.py 的重名规则一致。
|
|
2618
|
+
"""
|
|
2619
|
+
if not path.exists():
|
|
2620
|
+
return path
|
|
2621
|
+
for index in range(2, 100):
|
|
2622
|
+
candidate = path.with_name(f"{path.stem}_v{index}{path.suffix}")
|
|
2623
|
+
if not candidate.exists():
|
|
2624
|
+
print(f"提示:{path.name} 已存在,本次输出改为 {candidate.name}(不覆盖旧版,1.4.0 起)。")
|
|
2625
|
+
return candidate
|
|
2626
|
+
raise SystemExit(f"错误:{path.name} 的版本号 _v2~_v99 均已占用,请清理 {path.parent} 后重试。")
|
|
2454
2627
|
|
|
2455
2628
|
|
|
2456
2629
|
def main() -> None:
|
|
@@ -2462,8 +2635,9 @@ def main() -> None:
|
|
|
2462
2635
|
parser.add_argument("--clean-md-output", help="输出干净 Markdown 路径;内容来自同一份最终答案,并移除 [1]、【1】等溯源角标。")
|
|
2463
2636
|
parser.add_argument("--question", default="", help="用户原始问题,用于自动生成文件名。")
|
|
2464
2637
|
parser.add_argument("--self-check-file", help="答案自检结果 JSON(五项:fact_basis/binding/consistency/freshness/no_gap,值写 通过/未通过:原因);未传时核验单如实显示'未记录'。")
|
|
2465
|
-
parser.add_argument("--skip-link-check", action="store_true", help="
|
|
2638
|
+
parser.add_argument("--skip-link-check", action="store_true", help="(兼容 no-op)链接活性检测已于 2026-10-08 移除,接口返回的链接原样进报告")
|
|
2466
2639
|
parser.add_argument("--no-snapshot", action="store_true", help="关闭存档快照兜底展示(默认启用:原文失效时以 /A/ 修订后的存档快照回看)")
|
|
2640
|
+
parser.add_argument("--charts-json", help="图表数据:official-docs/search-results/ 内的 JSON 文件名,或直接内联 JSON。传入后图表并入本报告(一体化,不另出独立 HTML)。")
|
|
2467
2641
|
args = parser.parse_args()
|
|
2468
2642
|
|
|
2469
2643
|
input_path = _safe_input_path(args.input_json, {".json"})
|
|
@@ -2489,8 +2663,8 @@ def main() -> None:
|
|
|
2489
2663
|
if preview_sources and not preview_cited:
|
|
2490
2664
|
print(
|
|
2491
2665
|
"错误:生成检查未通过——已召回 "
|
|
2492
|
-
f"{len(preview_sources)}
|
|
2493
|
-
"请修正最终答案(--answer-file
|
|
2666
|
+
f"{len(preview_sources)} 篇来源文章,但答案中没有 [1]、[2] 等来源角标,无法建立\"结论-来源文章\"核验对应。\n"
|
|
2667
|
+
"请修正最终答案(--answer-file):在关键结论后标注角标并逐条对应来源文章,然后重新运行本脚本。",
|
|
2494
2668
|
file=sys.stderr,
|
|
2495
2669
|
)
|
|
2496
2670
|
raise SystemExit(1)
|
|
@@ -2499,9 +2673,9 @@ def main() -> None:
|
|
|
2499
2673
|
if unbound_preview:
|
|
2500
2674
|
shown = "、".join(f"[{c}]" for c in unbound_preview[:8])
|
|
2501
2675
|
print(
|
|
2502
|
-
f"错误:生成检查未通过——答案角标 {shown}
|
|
2676
|
+
f"错误:生成检查未通过——答案角标 {shown} 未绑定到任何来源文章"
|
|
2503
2677
|
f"(共召回 {len(preview_sources)} 条,可绑定编号 {min(preview_ids) if preview_ids else '-'}~{max(preview_ids) if preview_ids else '-'})。\n"
|
|
2504
|
-
"
|
|
2678
|
+
"请修正最终答案:角标必须逐条对应实际引用的来源文章,然后重新运行本脚本。",
|
|
2505
2679
|
file=sys.stderr,
|
|
2506
2680
|
)
|
|
2507
2681
|
raise SystemExit(1)
|
|
@@ -2513,17 +2687,19 @@ def main() -> None:
|
|
|
2513
2687
|
else:
|
|
2514
2688
|
output = _safe_output_path(safe_output_filename(question, generated_at), {".html", ".htm"}, ".html")
|
|
2515
2689
|
|
|
2690
|
+
output = _next_version_path(output)
|
|
2516
2691
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
2517
2692
|
output.write_text(
|
|
2518
2693
|
render_html(payload, args.title, answer_override=answer_override, question_override=args.question,
|
|
2519
2694
|
generated_at=generated_at, skip_link_check=args.skip_link_check,
|
|
2520
|
-
snapshot_enabled=snapshot_enabled),
|
|
2695
|
+
snapshot_enabled=snapshot_enabled, charts_data=resolve_charts_data(args.charts_json)),
|
|
2521
2696
|
encoding="utf-8")
|
|
2522
2697
|
print(f"已生成:{output}")
|
|
2523
2698
|
if args.clean_md_output:
|
|
2524
2699
|
clean_output = _safe_output_path(args.clean_md_output, {".md"}, ".md")
|
|
2525
2700
|
else:
|
|
2526
2701
|
clean_output = _safe_output_path(output.with_suffix(".clean.md").name, {".md"}, ".md")
|
|
2702
|
+
clean_output = _next_version_path(clean_output)
|
|
2527
2703
|
clean_output.parent.mkdir(parents=True, exist_ok=True)
|
|
2528
2704
|
clean_answer = strip_citation_markers(final_answer)
|
|
2529
2705
|
clean_output.write_text(clean_answer, encoding="utf-8")
|