dknowc-dsh 2.0.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/package.json +1 -1
- package/skills/dknowc-official-doc-writer/README.md +8 -4
- package/skills/dknowc-official-doc-writer/SKILL.md +15 -10
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +42 -5
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +5 -5
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +1 -1
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +5 -4
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +7 -2
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +6 -8
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +5 -5
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +7 -7
- package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +173 -21
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +48 -25
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +18 -58
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -1
- package/skills/dknowc-ppt-assistant/README.md +2 -2
- package/skills/dknowc-ppt-assistant/SKILL.md +8 -8
- package/skills/dknowc-ppt-assistant/references/material_usage.md +2 -2
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +44 -15
- package/skills/dknowc-ppt-assistant/scripts/attribution.py +4 -3
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +202 -30
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +120 -113
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +2 -2
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +11 -4
- package/skills/dknowc-trusted-search/README.md +4 -4
- package/skills/dknowc-trusted-search/SKILL.md +33 -29
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +35 -6
- package/skills/dknowc-trusted-search/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-trusted-search/scripts/attribution.py +5 -5
- package/skills/dknowc-trusted-search/scripts/chart_embed.py +1 -1
- package/skills/dknowc-trusted-search/scripts/deep_query.py +2 -2
- package/skills/dknowc-trusted-search/scripts/initialize.py +3 -4
- package/skills/dknowc-trusted-search/scripts/mcp_convert.py +11 -2
- package/skills/dknowc-trusted-search/scripts/merge_search_results.py +67 -4
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +206 -38
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +64 -99
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +3 -3
|
@@ -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 传入五项结果。
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
- 核验报告视图(默认):核验报告单 + 正文分节卡;角标点击跳知识专库定位
|
|
16
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,14 +26,11 @@
|
|
|
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
|
|
@@ -160,51 +157,15 @@ def strip_citation_markers(text: str) -> str:
|
|
|
160
157
|
|
|
161
158
|
|
|
162
159
|
# ============================================================
|
|
163
|
-
# 生成前预处理(文号匹配 /
|
|
160
|
+
# 生成前预处理(文号匹配 / 快照兜底;链接活性检测已于 2026-10-08 移除)
|
|
164
161
|
# ============================================================
|
|
165
162
|
|
|
166
163
|
# 快照兜底开关:默认启用。接口 screenShotPath 曾存在路径缺 /A/ 层级的拼接 bug
|
|
167
164
|
# (后端修复中);verify_snapshots 在展示前完成"/A/ 修订 + 格式校验 + 不合法弃用"。
|
|
168
165
|
SNAPSHOT_ENABLED = True
|
|
169
166
|
|
|
170
|
-
# 软 404 关键词:政府站常以 HTTP 200 返回"页面不存在"错误页,状态码识别不了,
|
|
171
|
-
# 需读页面标题嗅探。关键词取自实测样例,且仅匹配 <title>(政策正文不会出现在标题里),
|
|
172
|
-
# 误杀风险极低。
|
|
173
|
-
SOFT_404_KEYWORDS = ("页面不存在", "页面未找到", "您访问的页面", "已删除", "已下线", "无法找到", "not found", "404")
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def check_link_alive(url: str, timeout: int = 8) -> bool:
|
|
177
|
-
"""检测原文链接是否仍然可达。失效判据(客观信号,与请求方无关):
|
|
178
|
-
① HTTP 404/410;② 软 404——HTTP 200 但页面标题为典型失效页。
|
|
179
|
-
连接失败、超时、403、5xx 等一律视为"无法确认"按有效处理——政府站
|
|
180
|
-
常对脚本请求反爬,凭这些判死会误杀可用链接。
|
|
181
|
-
"""
|
|
182
|
-
for method in ("HEAD", "GET"):
|
|
183
|
-
try:
|
|
184
|
-
req = urllib.request.Request(
|
|
185
|
-
url, method=method,
|
|
186
|
-
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"},
|
|
187
|
-
)
|
|
188
|
-
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
189
|
-
if resp.status in (404, 410):
|
|
190
|
-
return False
|
|
191
|
-
if method == "GET":
|
|
192
|
-
chunk = resp.read(4096).decode("utf-8", errors="replace")
|
|
193
|
-
title = re.search(r"<title>(.*?)</title>", chunk, re.I | re.S)
|
|
194
|
-
text = title.group(1) if title else chunk[:200]
|
|
195
|
-
lowered = text.lower()
|
|
196
|
-
return not any(k in text or k in lowered for k in SOFT_404_KEYWORDS)
|
|
197
|
-
except urllib.error.HTTPError as e:
|
|
198
|
-
if method == "GET":
|
|
199
|
-
return e.code not in (404, 410)
|
|
200
|
-
except Exception:
|
|
201
|
-
if method == "GET":
|
|
202
|
-
return True
|
|
203
|
-
return True
|
|
204
|
-
|
|
205
|
-
|
|
206
167
|
def normalize_snapshot_url(url: str) -> str:
|
|
207
|
-
"""快照路径容错:接口部分返回值缺 /A/
|
|
168
|
+
"""快照路径容错:接口部分返回值缺 /A/ 层级(实测 60 条中 5 条,补全后即可访问),
|
|
208
169
|
统一规范化为 https://attach.dknowc.cn/snapshot/A/<2位>/<2位>/<哈希>.jpg。"""
|
|
209
170
|
u = (url or "").strip()
|
|
210
171
|
if u.startswith("https://attach.dknowc.cn/snapshot/") and "/snapshot/A/" not in u:
|
|
@@ -212,21 +173,6 @@ def normalize_snapshot_url(url: str) -> str:
|
|
|
212
173
|
return u
|
|
213
174
|
|
|
214
175
|
|
|
215
|
-
def mark_dead_links(articles: List[Dict[str, Any]]) -> int:
|
|
216
|
-
"""并发检测全部材料的原文链接,404/410/软404 的标记 链接失效=True。返回失效数。"""
|
|
217
|
-
targets = [(i, a["源网址"]) for i, a in enumerate(articles) if (a.get("源网址") or "").strip()]
|
|
218
|
-
if not targets:
|
|
219
|
-
return 0
|
|
220
|
-
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
|
|
221
|
-
alive = dict(zip((i for i, _ in targets), pool.map(check_link_alive, (u for _, u in targets))))
|
|
222
|
-
dead = 0
|
|
223
|
-
for i, _ in targets:
|
|
224
|
-
if not alive.get(i, True):
|
|
225
|
-
articles[i]["链接失效"] = True
|
|
226
|
-
dead += 1
|
|
227
|
-
return dead
|
|
228
|
-
|
|
229
|
-
|
|
230
176
|
def verify_snapshots(articles: List[Dict[str, Any]]) -> int:
|
|
231
177
|
"""快照展示前的路径校验(纯本地检查,不发网络请求):
|
|
232
178
|
组装阶段已由 normalize_snapshot_url 补全 /A/ 层级;此处校验修订后的路径
|
|
@@ -263,7 +209,7 @@ def attach_doc_numbers(articles: List[Dict[str, Any]], payload: Dict[str, Any])
|
|
|
263
209
|
新闻/解读类不在 policyFiles 中(本就无文号),匹配不上则不显示。
|
|
264
210
|
检索库对同一政策文件常有多个抓取变体(新闻稿版/发文版,文号挂在发文版条目上),
|
|
265
211
|
标题精确匹配不上时**不做模糊猜测**(宁缺勿错)——变体识别与回填由 SKILL.md
|
|
266
|
-
选材规则执行:Agent
|
|
212
|
+
选材规则执行:Agent 引用政策文件时优先带文号的发文版条目。
|
|
267
213
|
"""
|
|
268
214
|
doc_numbers: Dict[str, str] = {}
|
|
269
215
|
for holder in (payload.get("content") if isinstance(payload.get("content"), dict) else {},
|
|
@@ -291,10 +237,12 @@ def attach_doc_numbers(articles: List[Dict[str, Any]], payload: Dict[str, Any])
|
|
|
291
237
|
|
|
292
238
|
def preprocess_articles(articles: List[Dict[str, Any]], payload: Dict[str, Any],
|
|
293
239
|
skip_link_check: bool = False, snapshot_enabled: bool = True) -> None:
|
|
294
|
-
"""extract_sources
|
|
240
|
+
"""extract_sources 前的统一预处理:文号匹配、快照兜底。
|
|
295
241
|
|
|
296
|
-
直接改写文章 dict(注入 文号 / 快照链接
|
|
297
|
-
|
|
242
|
+
直接改写文章 dict(注入 文号 / 快照链接 字段),供 source_from_article 读取;
|
|
243
|
+
均为幂等操作,多轮渲染不叠加。
|
|
244
|
+
原文链接活性检测已整体移除(2026-10-08 起)——接口返回的链接原样进报告;
|
|
245
|
+
skip_link_check 参数保留为兼容 no-op。
|
|
298
246
|
"""
|
|
299
247
|
attach_doc_numbers(articles, payload)
|
|
300
248
|
if snapshot_enabled:
|
|
@@ -305,8 +253,6 @@ def preprocess_articles(articles: List[Dict[str, Any]], payload: Dict[str, Any],
|
|
|
305
253
|
else:
|
|
306
254
|
for a in articles:
|
|
307
255
|
a["快照链接"] = ""
|
|
308
|
-
if not skip_link_check:
|
|
309
|
-
mark_dead_links(articles)
|
|
310
256
|
|
|
311
257
|
|
|
312
258
|
# ============================================================
|
|
@@ -495,17 +441,16 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
495
441
|
source["used"] = item.get("已引用", item.get("used", True))
|
|
496
442
|
if not isinstance(source["used"], bool):
|
|
497
443
|
source["used"] = True
|
|
498
|
-
#
|
|
499
|
-
#
|
|
444
|
+
# 快照是接口自带的存档副本,统一作为附加回看入口展示(2026-10-08 起不再做
|
|
445
|
+
# 链接活性探测,原文链接原样进报告;快照仅做本地格式校验,不发网络请求)。
|
|
500
446
|
source["snapshot"] = first_str(item.get("快照链接"), item.get("snapshot"), item.get("screenShotPath"))
|
|
501
|
-
source["link_dead"] = item.get("链接失效") is True or item.get("link_dead") is True
|
|
502
447
|
# 发布日期可信度(实测:「高」=模型治理入库、标题模型精抽;「较高」=门户抓取、标题规则提取)
|
|
503
448
|
source["conf"] = first_str(item.get("发布日期可信度"), item.get("可信度"), item.get("confidence"))
|
|
504
449
|
key, label, css = normalize_kind(source["kind"])
|
|
505
450
|
source["type_key"] = key
|
|
506
451
|
source["type_label"] = label
|
|
507
452
|
source["type_css"] = css
|
|
508
|
-
live_url = bool(source["url"] and source["url"] != "接口未返回")
|
|
453
|
+
live_url = bool(source["url"] and source["url"] != "接口未返回")
|
|
509
454
|
source["has_link"] = live_url or bool(source["policy_url"]) or bool(source["snapshot"])
|
|
510
455
|
# 核验状态只看摘录可比对;原文链接死活与快照有无是回看通道问题,不影响核验结论
|
|
511
456
|
source["verified"] = bool(source["excerpt"])
|
|
@@ -581,7 +526,7 @@ def extract_sources(payload: Dict[str, Any],
|
|
|
581
526
|
if not item.get("搜索条件"):
|
|
582
527
|
item["搜索条件"] = "本次检索"
|
|
583
528
|
|
|
584
|
-
# 生成前预处理:文号匹配(policyFiles
|
|
529
|
+
# 生成前预处理:文号匹配(policyFiles)、快照兜底(不做链接活性探测)
|
|
585
530
|
preprocess_articles(raw_sources, payload, skip_link_check=skip_link_check, snapshot_enabled=snapshot_enabled)
|
|
586
531
|
|
|
587
532
|
sources: List[Dict[str, str]] = []
|
|
@@ -590,7 +535,20 @@ def extract_sources(payload: Dict[str, Any],
|
|
|
590
535
|
# 一篇材料一张卡:段落合并为摘录(paragraph_text 拼接全部段落),不按段落拆卡——
|
|
591
536
|
# 溯源 JSON 的 materials 与正文角标按"材料"粒度一一对应,拆段会使编号错位。
|
|
592
537
|
source = source_from_article(item, len(sources) + 1)
|
|
593
|
-
|
|
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])
|
|
594
552
|
if key in seen:
|
|
595
553
|
continue
|
|
596
554
|
seen.add(key)
|
|
@@ -731,7 +689,7 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
731
689
|
no_citation = bool(sources) and not cited
|
|
732
690
|
|
|
733
691
|
# ③ 时效检查:材料日期范围与历史材料计数
|
|
734
|
-
# ③ 时效只统计**正文依据**(2026-09-29
|
|
692
|
+
# ③ 时效只统计**正文依据**(2026-09-29 起):sources 含未引用召回材料,
|
|
735
693
|
# 此前误用全集,未引用材料里的异常日期(如接口标注的未来年份)会写进交付物口径。
|
|
736
694
|
dated = [parse_year_month(s.get("date")) for s in cited_sources]
|
|
737
695
|
dated = [d for d in dated if d]
|
|
@@ -770,7 +728,7 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
770
728
|
|
|
771
729
|
trace_ok = cited_sources and not missing_excerpts
|
|
772
730
|
binding_ok = (not unbound) and not no_citation
|
|
773
|
-
# 自检显式"未通过"
|
|
731
|
+
# 自检显式"未通过"纳为报告级否决项:不能自检失败还顶部打绿章。
|
|
774
732
|
self_check_ok = self_check["status"] != "fail"
|
|
775
733
|
overall_passed = bool(trace_ok and binding_ok and self_check_ok)
|
|
776
734
|
|
|
@@ -787,7 +745,7 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
787
745
|
reasons.append(f"有 {len(missing_links)} 条正文依据没有原文链接或存档快照,无法回看")
|
|
788
746
|
|
|
789
747
|
if overall_passed and missing_links:
|
|
790
|
-
#
|
|
748
|
+
# 摘录可比对、结论成立,但确有材料无回看通道时,顶部表述要与事实一致
|
|
791
749
|
overall_label = f"核验完成,其中 {len(missing_links)} 条依据无原文或存档快照可回看"
|
|
792
750
|
else:
|
|
793
751
|
overall_label = "核验完成,正文依据逐条对过原文" if overall_passed else "核验未完全通过"
|
|
@@ -977,7 +935,7 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
|
|
|
977
935
|
if not jb:
|
|
978
936
|
return ""
|
|
979
937
|
if jb.get("url"):
|
|
980
|
-
btn_txt = "
|
|
938
|
+
btn_txt = "查看全文" if jb.get("url") else "查看存档全文"
|
|
981
939
|
link = (f'<a class="jb-src" href="{esc(jb["url"])}" target="_blank" rel="noopener noreferrer">'
|
|
982
940
|
f'{ARROW_SVG}<span>{btn_txt}</span></a>')
|
|
983
941
|
else:
|
|
@@ -1145,31 +1103,28 @@ def build_chip_data(sources: List[Dict[str, str]]) -> Dict[str, Dict[str, str]]:
|
|
|
1145
1103
|
continue
|
|
1146
1104
|
meta_bits = [v for v in [source.get("agency"), source.get("date")] if v and v != "未知来源"]
|
|
1147
1105
|
url = source.get("url") if (source.get("url") and source["url"] != "接口未返回") else (source.get("policy_url") or "")
|
|
1148
|
-
if source.get("link_dead"):
|
|
1149
|
-
url = source.get("snapshot") or ""
|
|
1150
1106
|
site_bits = ([source["doc_number"]] if source.get("doc_number") else []) + meta_bits
|
|
1151
1107
|
chip_map[cid] = {
|
|
1152
1108
|
"title": short(source.get("title") or "未命名来源文章", 30),
|
|
1153
1109
|
"site": " · ".join(site_bits) or "来源站点",
|
|
1154
1110
|
"url": url,
|
|
1155
1111
|
"snapshot": source.get("snapshot") or "",
|
|
1156
|
-
"dead": bool(source.get("link_dead")),
|
|
1157
1112
|
"excerpt": (source.get("excerpt") or "").strip(),
|
|
1158
1113
|
"segments": source.get("segments") or [],
|
|
1159
1114
|
}
|
|
1160
1115
|
return chip_map
|
|
1161
1116
|
|
|
1162
1117
|
|
|
1163
|
-
def render_source_links(url: str, policy_url: str = "", snapshot: str = ""
|
|
1164
|
-
"""
|
|
1165
|
-
|
|
1118
|
+
def render_source_links(url: str, policy_url: str = "", snapshot: str = "") -> str:
|
|
1119
|
+
"""链接区:原文可回看 / 无源网址但有快照。接口返回的链接原样展示(不做活性探测,
|
|
1120
|
+
2026-10-08 起);快照是接口对原文的存档副本,文案如实标注。"""
|
|
1166
1121
|
links = []
|
|
1167
|
-
if url and url != "接口未返回"
|
|
1122
|
+
if url and url != "接口未返回":
|
|
1168
1123
|
links.append(f'<a href="{esc(url)}" target="_blank" rel="noopener">查看全文 ↗</a>')
|
|
1169
1124
|
if snapshot:
|
|
1170
1125
|
# 有哪个显示哪个:快照统一展示"查看存档全文",不做原文失效的状态解释
|
|
1171
1126
|
links.append(f'<a class="snap" href="{esc(snapshot)}" target="_blank" rel="noopener">查看存档全文 ↗</a>')
|
|
1172
|
-
# 回看通道只有原网址与快照(2026-09-29
|
|
1127
|
+
# 回看通道只有原网址与快照(2026-09-29 起:外链知识专库属老能力,已移除)
|
|
1173
1128
|
if not links:
|
|
1174
1129
|
return ""
|
|
1175
1130
|
return '<div class="sc-links">' + "".join(f"<span>{link}</span>" for link in links) + "</div>"
|
|
@@ -1195,7 +1150,7 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1195
1150
|
f'<span class="d">每条素材摘录可比对,原文或存档快照可回看</span></div>')
|
|
1196
1151
|
elif tr["passed"] == tr["total"]:
|
|
1197
1152
|
# 摘录齐全但有材料没有回看通道:不得照写"原文或存档快照可回看"
|
|
1198
|
-
#
|
|
1153
|
+
# (此前 missing_links 算出却从未参与结论,属虚假背书)
|
|
1199
1154
|
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
1200
1155
|
f'<span class="d">摘录可比对,其中 {n_no_link} 条没有原文链接或存档快照、无法回看</span></div>')
|
|
1201
1156
|
else:
|
|
@@ -1222,13 +1177,13 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1222
1177
|
fr = v["freshness"]
|
|
1223
1178
|
if fr:
|
|
1224
1179
|
rng = f"{fr['min'][0]}-{fr['min'][1]:02d}~{fr['max'][0]}-{fr['max'][1]:02d}"
|
|
1225
|
-
# 2026-09-29
|
|
1180
|
+
# 2026-09-29 起:去掉"N 条年头较久,按参考口径使用"——对长期有效的
|
|
1226
1181
|
# 政策法规偏严,且"按参考口径使用"读者无从理解;old_count 仍照常计算留待后续。
|
|
1227
1182
|
fr_html = f'<div class="vi"><span class="s ok">✓ 材料新旧 已核</span><span class="d">材料日期 {esc(rng)}</span></div>'
|
|
1228
1183
|
else:
|
|
1229
1184
|
fr_html = '<div class="vi"><span class="s none">— 材料新旧 未记录</span><span class="d">材料没标发布日期</span></div>'
|
|
1230
1185
|
|
|
1231
|
-
#
|
|
1186
|
+
# 材料构成:材料类型四分类(政策依据型/数据支撑型/…)非本检索接口返回字段
|
|
1232
1187
|
# → 没有类型数据时**整行不显示**,不再渲染"材料没标类型"这种永远为空的占位行(2026-09-28 修复)。
|
|
1233
1188
|
cov = v["coverage"]
|
|
1234
1189
|
parts = [f"{KIND_CATALOG[k][0]} {cov[k]}" for k in ("policy", "data", "case", "reference") if cov.get(k)]
|
|
@@ -1256,7 +1211,7 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
1256
1211
|
else:
|
|
1257
1212
|
sc_html = '<div class="vi"><span class="s none">— 交付前检查 未记录</span><span class="d">本次溯源 JSON 没写入检查结果</span></div>'
|
|
1258
1213
|
|
|
1259
|
-
# "现行效力"
|
|
1214
|
+
# "现行效力"人工复核提示行已移除(2026-09-19 起):
|
|
1260
1215
|
# 政策是否现行有效无法自动判定,此提示对用户无操作价值;policy_count 仅保留在计算层不再展示。
|
|
1261
1216
|
manual = ""
|
|
1262
1217
|
|
|
@@ -1415,7 +1370,7 @@ def strip_leading_chain(text: str, chain: List[str]) -> str:
|
|
|
1415
1370
|
def render_crumb(chain: List[str]) -> str:
|
|
1416
1371
|
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1417
1372
|
段落本身无章节层级(链上只有文章名)时不显示——材料卡标题已是文章名,
|
|
1418
|
-
|
|
1373
|
+
单独一行重复文章名对定位无增量(2026-09-19 反馈)。"""
|
|
1419
1374
|
parts = [esc(level) for level in chain if level]
|
|
1420
1375
|
if len(parts) < 2:
|
|
1421
1376
|
return ""
|
|
@@ -1451,11 +1406,11 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1451
1406
|
reason = "待补原文链接" if not source.get("has_link") else "待补摘录"
|
|
1452
1407
|
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
1453
1408
|
note_html = ""
|
|
1454
|
-
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", "")
|
|
1409
|
+
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", ""))
|
|
1455
1410
|
# 关键性行:有文号(接口 policyFiles 匹配)时"文号 · 数据源 · 日期",否则"数据源 · 日期"。
|
|
1456
1411
|
# 文号必须是标准格式——政府公文"〔年份〕序号"(杭政函〔2022〕81号)、公告/令类"第X号"
|
|
1457
1412
|
# (财政部税务总局公告2023年第19号、主席令第三十五号、国务院令第765号,含汉字数字);
|
|
1458
|
-
# 描述性文字("XX印发"
|
|
1413
|
+
# 描述性文字("XX印发"类自造描述)不显示,当无文号处理。
|
|
1459
1414
|
_dn = source.get("doc_number") or ""
|
|
1460
1415
|
_dn = _dn if re.search(r"〔\d{4}〕\s*\d+\s*号|第\s*(?:\d+|[〇零一二三四五六七八九十百千]+)\s*号", _dn) else ""
|
|
1461
1416
|
meta_parts = [v for v in [_dn, source.get("agency"), source.get("date"), source.get("area")]
|
|
@@ -1593,7 +1548,7 @@ def render_toc(sections: List[Dict[str, Any]], extra: str = "") -> str:
|
|
|
1593
1548
|
"""章节目录(滚动 spy):长报告(≥6 个**有标题**的章节)显示,桌面端左侧浮动。
|
|
1594
1549
|
|
|
1595
1550
|
无标题节(正文开头的导语段)跳过——此前兜底成「第 N 节」占位项,且该锚点
|
|
1596
|
-
#sec-i 在 render_section_cards
|
|
1551
|
+
#sec-i 在 render_section_cards 里根本不生成(死链接),点它没反应。
|
|
1597
1552
|
extra 为附加条目 HTML(图表独立呈现时);门槛按有标题章节数计。
|
|
1598
1553
|
"""
|
|
1599
1554
|
items = []
|
|
@@ -1721,6 +1676,10 @@ a{color:var(--brand)}
|
|
|
1721
1676
|
box-shadow:0 2px 8px rgba(101,18,173,.22)}
|
|
1722
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)}
|
|
1723
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}
|
|
1724
1683
|
.hero-switch{margin-top:16px;display:flex;justify-content:center}
|
|
1725
1684
|
.hero-switch .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
|
|
1726
1685
|
.hero-switch .view-switch button{color:#70678a;padding:6px 22px;font-size:13px}
|
|
@@ -1932,7 +1891,6 @@ a.jb-quote{text-decoration:none}
|
|
|
1932
1891
|
.scard .sc-links{margin-top:4px}
|
|
1933
1892
|
.no-link{font-size:11.5px;color:var(--muted)}
|
|
1934
1893
|
.sc-links a.snap{background:#faf5ff;border-color:#d9c9f4;color:#5b21b6}
|
|
1935
|
-
.dead-link{font-size:11.5px;color:var(--warn)}
|
|
1936
1894
|
|
|
1937
1895
|
/* ===== 章节目录(spy,长报告) ===== */
|
|
1938
1896
|
.toc{position:fixed;left:calc((100vw - 1080px)/2 - 168px);top:120px;width:140px;max-height:60vh;overflow:auto;
|
|
@@ -1940,7 +1898,7 @@ a.jb-quote{text-decoration:none}
|
|
|
1940
1898
|
.toc a{color:var(--muted);text-decoration:none;padding:4px 10px;border-left:2px solid var(--line);
|
|
1941
1899
|
line-height:1.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1942
1900
|
.toc a.on{color:var(--brand);border-left-color:var(--brand);font-weight:700}
|
|
1943
|
-
/* 知识专库视图下隐藏章节目录(2026-09-29
|
|
1901
|
+
/* 知识专库视图下隐藏章节目录(2026-09-29 起):.toc 渲染在 .app 之外,
|
|
1944
1902
|
视图切换只由 .app[data-view] 驱动,此前无任何规则处理 .toc,专库视图下目录仍挂在左侧 */
|
|
1945
1903
|
.app[data-view="library"] ~ .toc,.app[data-view="library"] .toc{display:none}
|
|
1946
1904
|
@media (max-width:1460px){.toc{display:none}}
|
|
@@ -2384,7 +2342,7 @@ PAGE_JS = """
|
|
|
2384
2342
|
}
|
|
2385
2343
|
window.addEventListener("scroll", spy, { passive: true });
|
|
2386
2344
|
|
|
2387
|
-
/* 目录纵向定位(2026-09-29
|
|
2345
|
+
/* 目录纵向定位(2026-09-29 起):此前 CSS 写死 top:120px,目录顶部与页头
|
|
2388
2346
|
齐平、离正文很远。改为——直接跟随正文首节,只保留"不低于顶栏下方"的下限;首屏看不到
|
|
2389
2347
|
目录属正常,向下滚动后自然吸附在顶栏下方。目录过长由 CSS max-height:60vh+overflow:auto
|
|
2390
2348
|
内部滚动兜底。 */
|
|
@@ -2438,6 +2396,12 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2438
2396
|
jb_tables[key] = html
|
|
2439
2397
|
doc_title, sections = group_sections(blocks)
|
|
2440
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
|
+
)
|
|
2441
2405
|
|
|
2442
2406
|
jb_tables_json = json.dumps(jb_tables, ensure_ascii=False).replace("</", "<\\/")
|
|
2443
2407
|
jb_tables_script = (f'<script type="application/json" id="jb-tables">{jb_tables_json}</script>\n'
|
|
@@ -2533,6 +2497,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2533
2497
|
<div class="hero">
|
|
2534
2498
|
<div class="r-badge">溯源核验报告</div>
|
|
2535
2499
|
<h1>{esc(display_title)}</h1>
|
|
2500
|
+
{hero_question}
|
|
2536
2501
|
<div class="meta">{esc(meta_line)} | 素材来源:深知可信搜索</div>
|
|
2537
2502
|
<div class="hero-switch">
|
|
2538
2503
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
@@ -2617,7 +2582,7 @@ def renumber_citations(answer: str, sources: List[Dict[str, str]]) -> Tuple[str,
|
|
|
2617
2582
|
def align_sources_to_answer(answer: str, sources: List[Dict[str, str]]) -> List[Dict[str, str]]:
|
|
2618
2583
|
"""不再按位置给材料重编号。
|
|
2619
2584
|
|
|
2620
|
-
|
|
2585
|
+
修复历史实现缺陷:原实现会在"正文角标与素材 id 完全不相交"时按顺序把素材改号
|
|
2621
2586
|
迎合角标——正文写 [7] 而只有 1 篇来源文章时,会被洗成"✓ 引用对应 1/1",与
|
|
2622
2587
|
"未绑定角标绝不按位置猜测"的核验诚实性原则相反。现如实返回原素材,由核验单报未绑定。
|
|
2623
2588
|
角标 1..N 的连续重排由 renumber_citations 独立完成(按首现顺序,1.1.5 用户要求)。
|
|
@@ -2646,7 +2611,7 @@ def resolve_charts_data(value: str) -> Optional[Dict[str, Any]]:
|
|
|
2646
2611
|
|
|
2647
2612
|
|
|
2648
2613
|
def _next_version_path(path: Path) -> Path:
|
|
2649
|
-
"""输出文件已存在时不覆盖(1.4.0
|
|
2614
|
+
"""输出文件已存在时不覆盖(1.4.0 起):自动改为 原名_v2 / _v3 … 另存。
|
|
2650
2615
|
|
|
2651
2616
|
追加图表/修改答案后重跑渲染时,旧版本保留、新版本号递增——不覆盖已交付内容,
|
|
2652
2617
|
也不会再靠宿主目录里的 "名字 (2)" 兜底。命名与 deliver_outputs.py 的重名规则一致。
|
|
@@ -2656,7 +2621,7 @@ def _next_version_path(path: Path) -> Path:
|
|
|
2656
2621
|
for index in range(2, 100):
|
|
2657
2622
|
candidate = path.with_name(f"{path.stem}_v{index}{path.suffix}")
|
|
2658
2623
|
if not candidate.exists():
|
|
2659
|
-
print(f"提示:{path.name} 已存在,本次输出改为 {candidate.name}
|
|
2624
|
+
print(f"提示:{path.name} 已存在,本次输出改为 {candidate.name}(不覆盖旧版,1.4.0 起)。")
|
|
2660
2625
|
return candidate
|
|
2661
2626
|
raise SystemExit(f"错误:{path.name} 的版本号 _v2~_v99 均已占用,请清理 {path.parent} 后重试。")
|
|
2662
2627
|
|
|
@@ -2670,7 +2635,7 @@ def main() -> None:
|
|
|
2670
2635
|
parser.add_argument("--clean-md-output", help="输出干净 Markdown 路径;内容来自同一份最终答案,并移除 [1]、【1】等溯源角标。")
|
|
2671
2636
|
parser.add_argument("--question", default="", help="用户原始问题,用于自动生成文件名。")
|
|
2672
2637
|
parser.add_argument("--self-check-file", help="答案自检结果 JSON(五项:fact_basis/binding/consistency/freshness/no_gap,值写 通过/未通过:原因);未传时核验单如实显示'未记录'。")
|
|
2673
|
-
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 移除,接口返回的链接原样进报告")
|
|
2674
2639
|
parser.add_argument("--no-snapshot", action="store_true", help="关闭存档快照兜底展示(默认启用:原文失效时以 /A/ 修订后的存档快照回看)")
|
|
2675
2640
|
parser.add_argument("--charts-json", help="图表数据:official-docs/search-results/ 内的 JSON 文件名,或直接内联 JSON。传入后图表并入本报告(一体化,不另出独立 HTML)。")
|
|
2676
2641
|
args = parser.parse_args()
|
|
@@ -34,7 +34,7 @@ SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
|
34
34
|
# 命中后返回 quota_exhausted=true,Agent 必须停止重试并引导用户到 MaaS 处理,不得反复调用。
|
|
35
35
|
# 错误码语义按接口文档区分:401=密钥校验失败(可能失效,需重新获取);403=接口无权限(密钥类型不符);
|
|
36
36
|
# 402=余额类。429 接口文案为"繁忙/限流/余额不足"三义混合、无法归因——现阶段全部按额度用尽处理
|
|
37
|
-
# (2026-09-10
|
|
37
|
+
# (2026-09-10 起),待后端把服务端问题与余额拆分为不同错误码后再调整回区分逻辑。
|
|
38
38
|
MAAS_PLATFORM_URL = "https://platform.dknowc.cn/auth/#/login"
|
|
39
39
|
QUOTA_EXHAUSTED_HTTP_CODES = {402, 429}
|
|
40
40
|
QUOTA_EXHAUSTED_KEYWORDS = (
|
|
@@ -152,7 +152,7 @@ def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
|
152
152
|
"item": False if args.no_item else True,
|
|
153
153
|
"knowBase": False if args.no_know_base else True,
|
|
154
154
|
"return_full_content": args.return_full_content,
|
|
155
|
-
# simplified 默认 False
|
|
155
|
+
# simplified 默认 False:
|
|
156
156
|
# 实测同一 query 下 simplified=true 返回精简集(材料更少且无存档快照 screenShotPath),
|
|
157
157
|
# simplified=false 返回完整集(含快照字段,供核验报告原文失效时兜底回看)。
|
|
158
158
|
"simplified": bool(args.simplified),
|
|
@@ -178,7 +178,7 @@ def _post(url: str, api_key: str, payload: Dict[str, Any], timeout: int) -> Dict
|
|
|
178
178
|
req = urllib.request.Request(url, data=data, method="POST")
|
|
179
179
|
req.add_header("api-key", api_key)
|
|
180
180
|
req.add_header("Content-Type", "application/json")
|
|
181
|
-
# 来源声明(X-Dknowc-Attribution
|
|
181
|
+
# 来源声明(X-Dknowc-Attribution,仅统计用、不参与鉴权):
|
|
182
182
|
# 读包根 attribution.json + SKILL.md 的 version;读取失败不加头、不阻断请求。
|
|
183
183
|
try:
|
|
184
184
|
from attribution import build_attribution_header, ATTRIBUTION_HEADER
|