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
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
- outline 提纲版:结构方案确认门前的提纲答案文件(页面规划表 + 口径事项清单)→ 事前核验
|
|
6
6
|
- final 成稿版:交付时的页面级结论文本 → 事后溯源
|
|
7
7
|
|
|
8
|
-
3.7.
|
|
8
|
+
3.7.x 同源架构(对齐公文写作 3.7.5/3.7.6,参考深知晓交互原型,数据口径保持自有与真实):
|
|
9
9
|
- 顶栏:身份章 + 标题 + 工具组(只看正文 / 复制全文 / 打印归档)+ 阅读进度条
|
|
10
10
|
- Hero:大标题 + 真实统计(N 次检索 · M 条材料 · K 处引用)+ 双视图切换
|
|
11
11
|
- 过程回顾条:检索 → 入库 → 逐条比对 → 核验完成(静态回放,数字全部真实计算)
|
|
12
12
|
- 核验报告视图(默认):核验报告单 + 正文文档流(章节标题 + 句后引文胶囊,点击原地展开溯源卡)
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
13
|
+
- 知识专库视图(全屏):大搜索 + 热词(真实计算)+ 检索分组 tabs + 来源文章卡
|
|
14
|
+
- 链接给出方式:接口返回的原文链接**原样进报告**(不做连通性检测、不隐藏);
|
|
15
|
+
接口提供存档快照(screenShotPath)时作为**附加回看入口**与原文链接并存
|
|
16
|
+
(路径容错补 /A/、纯本地格式校验)
|
|
16
17
|
|
|
17
|
-
PPT
|
|
18
|
+
PPT 特有口径(与公文写作版本的既定差异):
|
|
18
19
|
- 提醒制:数据缺口(缺原文链接/缺摘录)不判不通过、指标恒绿附温和提醒;只有无素材/
|
|
19
20
|
正文无角标/角标未绑定三种真实错误才判不通过
|
|
20
21
|
- 双版 stage:提纲版(事前核验)与成稿版(事后溯源)同脚本同形式,标题与身份章带版本后缀
|
|
@@ -29,13 +30,10 @@ PPT 特有口径(与公文写作的差异,均为产品决策):
|
|
|
29
30
|
from __future__ import annotations
|
|
30
31
|
|
|
31
32
|
import argparse
|
|
32
|
-
import concurrent.futures
|
|
33
33
|
import html
|
|
34
34
|
import json
|
|
35
35
|
import re
|
|
36
36
|
import sys
|
|
37
|
-
import urllib.error
|
|
38
|
-
import urllib.request
|
|
39
37
|
from datetime import datetime
|
|
40
38
|
from pathlib import Path
|
|
41
39
|
from typing import Any, Dict, List, Optional, Tuple
|
|
@@ -292,7 +290,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
292
290
|
item.get("name"),
|
|
293
291
|
vo.get("showTitle"),
|
|
294
292
|
vo.get("title"),
|
|
295
|
-
"
|
|
293
|
+
"未命名来源文章",
|
|
296
294
|
),
|
|
297
295
|
"agency": first_str(
|
|
298
296
|
item.get("unit") if not isinstance(item.get("unit"), list) else "、".join(str(x) for x in item.get("unit")[:3]),
|
|
@@ -329,24 +327,27 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
329
327
|
first_chain = segments[0]["chain"][1:] if segments else []
|
|
330
328
|
source["doc_section"] = " › ".join(first_chain)
|
|
331
329
|
source["chain_full"] = " › ".join(segments[0]["chain"]) if segments else ""
|
|
332
|
-
#
|
|
333
|
-
|
|
330
|
+
# 发文字号:必须是标准格式(〔年份〕序号号);描述性文字("XX印发"类自造
|
|
331
|
+
# 描述)不显示、当无文号处理(对齐公文写作 3.7.3,实测模型把文号写成
|
|
332
|
+
# "中办、国办 2026 年印发"类描述导致关键性行失真)。
|
|
333
|
+
_dn = first_str(item.get("文号"), item.get("发文字号"), item.get("doc_number"))
|
|
334
|
+
source["doc_number"] = _dn if re.search(r"〔\d{4}〕\s*\d+\s*号", _dn) else ""
|
|
334
335
|
# 所属搜索条件(多路检索分组)与引用状态(未引用=接口召回但正文未采用)
|
|
335
336
|
source["search_key"] = first_str(item.get("搜索条件"), item.get("search_key"))
|
|
336
337
|
source["used"] = item.get("已引用", item.get("used", True))
|
|
337
338
|
if not isinstance(source["used"], bool):
|
|
338
339
|
source["used"] = True
|
|
339
|
-
#
|
|
340
|
-
#
|
|
340
|
+
# 存档快照(接口 screenShotPath):**附加回看入口**,与原文链接并存展示。
|
|
341
|
+
# 2026-10-08 起不做链接连通性检测(链接原样给出):接口返回的链接
|
|
342
|
+
# 原样进报告,"打不开"不再由脚本判定、也不隐藏链接。
|
|
341
343
|
source["snapshot"] = first_str(item.get("快照链接"), item.get("snapshot"), item.get("screenShotPath"))
|
|
342
|
-
source["link_dead"] = item.get("链接失效") is True or item.get("link_dead") is True
|
|
343
344
|
# 发布日期可信度(实测:「高」=模型治理入库、标题模型精抽;「较高」=门户抓取、标题规则提取)
|
|
344
345
|
source["conf"] = first_str(item.get("发布日期可信度"), item.get("可信度"), item.get("confidence"))
|
|
345
346
|
key, label = normalize_kind(source["kind"])
|
|
346
347
|
source["type_key"] = key
|
|
347
348
|
source["type_label"] = label
|
|
348
349
|
source["type_css"] = KIND_CATALOG[key][1]
|
|
349
|
-
live_url = bool(source["url"] and source["url"] != "接口未返回")
|
|
350
|
+
live_url = bool(source["url"] and source["url"] != "接口未返回")
|
|
350
351
|
source["has_link"] = live_url or bool(source["policy_url"]) or bool(source["snapshot"])
|
|
351
352
|
# 核验状态只看摘录可比对;原文链接死活与快照有无是回看通道问题,不影响核验结论
|
|
352
353
|
# (PPT 提醒制:数据缺口不判不通过,卡片与指标行温和提醒)
|
|
@@ -356,7 +357,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
356
357
|
|
|
357
358
|
def extract_articles_from_search(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
358
359
|
# 兼容两种形态:原始接口的 content.data.检索文章(嵌套)与手工合并 JSON 的
|
|
359
|
-
# 顶层 检索文章(Agent 合并时常剥掉接口包装,与
|
|
360
|
+
# 顶层 检索文章(Agent 合并时常剥掉接口包装,与 self_check 平级)。
|
|
360
361
|
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
361
362
|
data = content.get("data") if isinstance(content.get("data"), dict) else content.get("data")
|
|
362
363
|
articles: List[Dict[str, Any]] = []
|
|
@@ -408,7 +409,27 @@ def collect_raw_articles(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
|
408
409
|
return raws
|
|
409
410
|
|
|
410
411
|
|
|
411
|
-
def
|
|
412
|
+
def _dedupe_key(source: Dict[str, Any]) -> tuple:
|
|
413
|
+
"""归一去重键:标题 + 原网址(对齐公文 3.7.8 / 可信搜索 1.4.4 的同款修复)。
|
|
414
|
+
|
|
415
|
+
旧键含 id(材料编号),而 id 要么是位置兜底序号、要么是角标号——同一篇文章被
|
|
416
|
+
多路召回或按段落返回多条片段时,各条 id 不同,含 id 的键**等于从不去重**,
|
|
417
|
+
同名卡片会成批出现(实测《医疗保障法》重复 17 张)。改为:
|
|
418
|
+
标题去空白、URL 去尾斜杠后组键;单边缺失退用其一,均缺失退用摘录前缀
|
|
419
|
+
(避免把"信息都缺"的不同材料并成一张)。
|
|
420
|
+
"""
|
|
421
|
+
title = re.sub(r"\s+", "", str(source.get("title") or ""))
|
|
422
|
+
url = str(source.get("url") or "").strip().rstrip("/")
|
|
423
|
+
if title and url:
|
|
424
|
+
return ("t+u", title, url)
|
|
425
|
+
if title:
|
|
426
|
+
return ("t", title)
|
|
427
|
+
if url:
|
|
428
|
+
return ("u", url)
|
|
429
|
+
return ("x", re.sub(r"\s+", "", (source.get("excerpt") or "")[:80]))
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def extract_sources(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
412
433
|
raw_sources: List[Dict[str, Any]] = []
|
|
413
434
|
raw_sources.extend(extract_reference_materials(payload))
|
|
414
435
|
raw_sources.extend(extract_articles_from_search(payload))
|
|
@@ -419,30 +440,39 @@ def extract_sources(payload: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
|
419
440
|
if isinstance(recalled, list):
|
|
420
441
|
raw_sources.extend({**{"已引用": False}, **x} for x in recalled if isinstance(x, dict))
|
|
421
442
|
|
|
422
|
-
sources: List[Dict[str,
|
|
423
|
-
|
|
443
|
+
sources: List[Dict[str, Any]] = []
|
|
444
|
+
by_key: Dict[tuple, Dict[str, Any]] = {}
|
|
424
445
|
for item in raw_sources:
|
|
425
|
-
# 一篇材料一张卡:段落合并为摘录(paragraph_text
|
|
426
|
-
# 素材清单与正文角标按「材料」粒度一一对应,拆段会使编号错位。
|
|
446
|
+
# 一篇材料一张卡:段落合并为摘录(paragraph_text 拼接全部段落),不按段落拆卡。
|
|
427
447
|
source = source_from_article(item, len(sources) + 1)
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
448
|
+
key = _dedupe_key(source)
|
|
449
|
+
existing = by_key.get(key)
|
|
450
|
+
if existing is not None:
|
|
451
|
+
# 同文再次出现:**不新建卡**(消除重复卡片),把它的编号并入已有卡——
|
|
452
|
+
# 提纲里同一篇文章可能占多个角标(如 [8] 与 [13]),合并后卡上并列显示
|
|
453
|
+
# 全部编号,正文引用任一编号都能定位到这张卡(既去重、又不产生"未绑定"红项)。
|
|
454
|
+
sid = str(source["id"] or "").strip()
|
|
455
|
+
if sid and sid not in existing["all_ids"]:
|
|
456
|
+
existing["all_ids"].append(sid)
|
|
457
|
+
# 已引用优先:未引用召回与已引用同名同链时,以已引用为准(不留两张卡)
|
|
458
|
+
if source.get("used", True) and not existing.get("used", True):
|
|
459
|
+
existing["used"] = True
|
|
438
460
|
continue
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
source["id"] = str(len(sources) + 1)
|
|
461
|
+
source["all_ids"] = [str(source["id"])] if source.get("id") else []
|
|
462
|
+
by_key[key] = source
|
|
442
463
|
sources.append(source)
|
|
443
464
|
return sources
|
|
444
465
|
|
|
445
466
|
|
|
467
|
+
def collect_material_ids(source: Dict[str, Any]) -> List[str]:
|
|
468
|
+
"""材料的全部编号(主编号 + 同文异号并入的其它编号),用于角标绑定与卡片显示。"""
|
|
469
|
+
ids = [str(i) for i in (source.get("all_ids") or []) if str(i).strip()]
|
|
470
|
+
main = str(source.get("id") or "").strip()
|
|
471
|
+
if main and main not in ids:
|
|
472
|
+
ids.insert(0, main)
|
|
473
|
+
return ids
|
|
474
|
+
|
|
475
|
+
|
|
446
476
|
def extract_answer(payload: Dict[str, Any]) -> str:
|
|
447
477
|
resp = payload.get("resp")
|
|
448
478
|
if isinstance(resp, dict):
|
|
@@ -454,18 +484,18 @@ def extract_answer(payload: Dict[str, Any]) -> str:
|
|
|
454
484
|
return normalize_citations(answer)
|
|
455
485
|
articles = extract_articles_from_search(payload)
|
|
456
486
|
if articles:
|
|
457
|
-
rows = ["
|
|
487
|
+
rows = ["可信搜索召回了以下重点来源文章:"]
|
|
458
488
|
for idx, item in enumerate(articles[:8], start=1):
|
|
459
489
|
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '未命名材料')}")
|
|
460
490
|
return "\n".join(rows)
|
|
461
491
|
deep_articles = extract_articles_from_deep(payload)
|
|
462
492
|
if deep_articles:
|
|
463
|
-
rows = ["
|
|
493
|
+
rows = ["深度搜索召回了以下重点来源文章:"]
|
|
464
494
|
for idx, item in enumerate(deep_articles[:8], start=1):
|
|
465
495
|
vo = item.get("vo") if isinstance(item.get("vo"), dict) else {}
|
|
466
496
|
rows.append(f"[{idx}] {first_str(vo.get('showTitle'), vo.get('title'), item.get('title'), '未命名材料')}")
|
|
467
497
|
return "\n".join(rows)
|
|
468
|
-
return "
|
|
498
|
+
return "接口返回中未识别到正文内容;请查看知识专库或原始 JSON。"
|
|
469
499
|
|
|
470
500
|
|
|
471
501
|
def extract_question(payload: Dict[str, Any]) -> str:
|
|
@@ -481,19 +511,6 @@ def extract_question(payload: Dict[str, Any]) -> str:
|
|
|
481
511
|
)
|
|
482
512
|
|
|
483
513
|
|
|
484
|
-
def extract_knowledge_bases(payload: Dict[str, Any]) -> List[str]:
|
|
485
|
-
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
486
|
-
data = content.get("data") if isinstance(content.get("data"), dict) else {}
|
|
487
|
-
values: List[str] = []
|
|
488
|
-
for value in (payload.get("knowledgeBases"), content.get("knowledgeBases"),
|
|
489
|
-
payload.get("knowledgeBase"), content.get("knowledgeBase"), data.get("knowledgeBase")):
|
|
490
|
-
if isinstance(value, list):
|
|
491
|
-
values.extend(str(item).strip() for item in value if str(item).strip())
|
|
492
|
-
elif isinstance(value, str) and value.strip():
|
|
493
|
-
values.append(value.strip())
|
|
494
|
-
return list(dict.fromkeys(values))
|
|
495
|
-
|
|
496
|
-
|
|
497
514
|
def citation_ids(answer: str) -> List[str]:
|
|
498
515
|
ids: List[str] = []
|
|
499
516
|
for match in re.finditer(r"\[(\d+)\]", answer):
|
|
@@ -526,8 +543,10 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
526
543
|
"""把自检项的值解析为(状态, 核验说明)。
|
|
527
544
|
|
|
528
545
|
兼容多种写法:`pass` / `true` / `通过` / `通过:说明文字` / `✓` 等;
|
|
529
|
-
|
|
530
|
-
|
|
546
|
+
值后面的说明文字保留下来供核验单展示。红项(fail)只给显式声明的
|
|
547
|
+
"未通过";无法识别的描述性文本按"未记录"(none)处理不判红——
|
|
548
|
+
自检书写格式走样不应被放大成核验红项(对齐公文写作 3.7.3,实测
|
|
549
|
+
模型写入"备注"等额外键导致交付前检查误判红)。
|
|
531
550
|
"""
|
|
532
551
|
text = str(raw or "").strip()
|
|
533
552
|
lowered = text.lower()
|
|
@@ -537,7 +556,7 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
537
556
|
for prefix in ("已通过", "通过", "合格", "pass", "ok", "true", "是", "✓", "yes"):
|
|
538
557
|
if lowered.startswith(prefix):
|
|
539
558
|
return "pass", text[len(prefix):].lstrip("::,,、 ").strip()
|
|
540
|
-
return "
|
|
559
|
+
return "none", text
|
|
541
560
|
|
|
542
561
|
|
|
543
562
|
def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
@@ -545,8 +564,13 @@ def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
|
545
564
|
return None
|
|
546
565
|
items: Dict[str, Tuple[str, str]] = {}
|
|
547
566
|
for key, value in raw.items():
|
|
567
|
+
# 只认五项标准自检键(英文/中文变体映射);白名单外的键(备注、待核验、
|
|
568
|
+
# 下一步补充等描述性额外键)不计入核验单——分母不被撑大,多余键不构成
|
|
569
|
+
# "交付前检查"定义的核验项。
|
|
570
|
+
label = SELF_CHECK_LABELS.get(key) or SELF_CHECK_LABELS.get(str(key))
|
|
571
|
+
if label is None:
|
|
572
|
+
continue
|
|
548
573
|
status, note = classify_check_value(value)
|
|
549
|
-
label = SELF_CHECK_LABELS.get(key, SELF_CHECK_LABELS.get(str(key), str(key)))
|
|
550
574
|
items[label] = (status, note)
|
|
551
575
|
return items or None
|
|
552
576
|
|
|
@@ -569,13 +593,17 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
569
593
|
# ② 引用绑定:正文角标与来源卡一一对应(按角标出现次数计,与用户在正文中数到的一致)
|
|
570
594
|
cited = citation_ids(answer)
|
|
571
595
|
all_marks = re.findall(r"\[(\d+)\]", answer)
|
|
572
|
-
source_ids =
|
|
596
|
+
source_ids = set()
|
|
597
|
+
for s in sources:
|
|
598
|
+
source_ids.update(collect_material_ids(s))
|
|
573
599
|
unbound_ids = [cid for cid in cited if cid not in source_ids]
|
|
574
600
|
unbound = [cid for cid in unbound_ids for _ in range(all_marks.count(cid))]
|
|
575
601
|
no_citation = bool(sources) and not cited
|
|
576
602
|
|
|
577
603
|
# ③ 时效检查:材料日期范围与历史材料计数
|
|
578
|
-
|
|
604
|
+
# 统计口径(对齐公文 3.7.6):③材料新旧/④材料构成只算正文引用的来源文章——
|
|
605
|
+
# sources 含未引用召回,其未来日期/类型会把时效范围与构成写歪。
|
|
606
|
+
dated = [parse_year_month(s.get("date")) for s in cited_sources]
|
|
579
607
|
dated = [d for d in dated if d]
|
|
580
608
|
freshness = None
|
|
581
609
|
old_count = 0
|
|
@@ -588,7 +616,7 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
588
616
|
|
|
589
617
|
# ④ 类型覆盖:素材四分类分布
|
|
590
618
|
coverage = {key: 0 for key in KIND_CATALOG}
|
|
591
|
-
for s in
|
|
619
|
+
for s in cited_sources:
|
|
592
620
|
coverage[s.get("type_key", "material")] = coverage.get(s.get("type_key", "material"), 0) + 1
|
|
593
621
|
|
|
594
622
|
# ⑤ 交付前检查:由检索/溯源 JSON 的 self_check 传入,未传入如实显示未记录
|
|
@@ -599,8 +627,11 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
599
627
|
self_check = None
|
|
600
628
|
if self_items:
|
|
601
629
|
passed = sum(1 for status, _ in self_items.values() if status == "pass")
|
|
630
|
+
fails = sum(1 for status, _ in self_items.values() if status == "fail")
|
|
631
|
+
# 状态由显式 fail 决定;none(描述性值/未记录)不判红也不拖垮通过
|
|
632
|
+
status = "fail" if fails else ("pass" if passed else "missing")
|
|
602
633
|
self_check = {"items": self_items, "passed": passed, "total": len(self_items),
|
|
603
|
-
"status":
|
|
634
|
+
"status": status}
|
|
604
635
|
else:
|
|
605
636
|
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS), "status": "missing"}
|
|
606
637
|
|
|
@@ -615,11 +646,11 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
615
646
|
|
|
616
647
|
reasons = []
|
|
617
648
|
if not sources:
|
|
618
|
-
reasons.append("
|
|
649
|
+
reasons.append("没有找到来源文章")
|
|
619
650
|
if no_citation:
|
|
620
|
-
reasons.append("
|
|
651
|
+
reasons.append("正文里没有来源角标,对不上来源文章")
|
|
621
652
|
if unbound:
|
|
622
|
-
reasons.append(f"有 {len(unbound)}
|
|
653
|
+
reasons.append(f"有 {len(unbound)} 处角标找不到对应来源文章")
|
|
623
654
|
if self_check["status"] == "fail":
|
|
624
655
|
reasons.append("交付前检查有没过的项")
|
|
625
656
|
|
|
@@ -689,7 +720,7 @@ HOT_STOP = {
|
|
|
689
720
|
|
|
690
721
|
|
|
691
722
|
def extract_hot_terms(answer: str, sources: List[Dict[str, str]], top: int = 8) -> List[str]:
|
|
692
|
-
"""
|
|
723
|
+
"""知识专库热词:材料标题(加权)+ 检索条件 + 正文的高频 2-4 字词,真实统计。
|
|
693
724
|
|
|
694
725
|
泛词过滤:出现在超过 60% 材料标题中的词(如库内全部材料共有的主题词)
|
|
695
726
|
无法筛出子集,没有筛选价值,剔除。
|
|
@@ -812,10 +843,13 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
|
|
|
812
843
|
jb = chip_map.get(cid)
|
|
813
844
|
if not jb:
|
|
814
845
|
return ""
|
|
846
|
+
# 链接原样给出(不做死活检测);无原文链接但有存档快照时,快照作为附加入口
|
|
815
847
|
if jb.get("url"):
|
|
816
|
-
btn_txt = "查看存档全文" if jb.get("dead") else "查看全文"
|
|
817
848
|
link = (f'<a class="jb-src" href="{esc(jb["url"])}" target="_blank" rel="noopener noreferrer">'
|
|
818
|
-
f'{ARROW_SVG}<span
|
|
849
|
+
f'{ARROW_SVG}<span>查看全文</span></a>')
|
|
850
|
+
elif jb.get("snapshot"):
|
|
851
|
+
link = (f'<a class="jb-src" href="{esc(jb["snapshot"])}" target="_blank" rel="noopener noreferrer">'
|
|
852
|
+
f'{ARROW_SVG}<span>查看存档全文</span></a>')
|
|
819
853
|
else:
|
|
820
854
|
link = ""
|
|
821
855
|
# 原文直达区展示标题链(多段分块,各段带链——快速人工核验的核心抓手)
|
|
@@ -885,7 +919,9 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
|
|
|
885
919
|
continue
|
|
886
920
|
# 引文胶囊位置规范:角标与后随标点换位——标点紧跟文字,胶囊放标点之后
|
|
887
921
|
# (避免胶囊把句号挤到下一行孤悬,对齐深知晓原型"…内容。~出处"形态)
|
|
888
|
-
|
|
922
|
+
# 连续角标序列整体换位(如 [13][14];→ ;[13][14]):只换单个角标会让标点
|
|
923
|
+
# 被夹在两个胶囊之间(实测截图反馈)。
|
|
924
|
+
block = re.sub(r"((?:\[\d+\])+)([。;,、!?:;,.])", r"\2\1", block)
|
|
889
925
|
ids = citation_ids(block)
|
|
890
926
|
repl = make_block_repl(block)
|
|
891
927
|
heading_match = re.match(r"^(#{1,4})\s+(.+)$", block)
|
|
@@ -975,35 +1011,34 @@ def build_chip_data(sources: List[Dict[str, str]]) -> Dict[str, Dict[str, Any]]:
|
|
|
975
1011
|
原文原段、不截断——块内去重后重复量可控,核对场景下就地读全文。
|
|
976
1012
|
"""
|
|
977
1013
|
chip_map: Dict[str, Dict[str, Any]] = {}
|
|
1014
|
+
material_ids = []
|
|
978
1015
|
for source in sources:
|
|
979
|
-
cid
|
|
1016
|
+
for cid in collect_material_ids(source):
|
|
1017
|
+
material_ids.append((cid, source))
|
|
1018
|
+
for cid, source in material_ids:
|
|
980
1019
|
if cid in chip_map:
|
|
981
1020
|
continue
|
|
982
1021
|
meta_bits = [v for v in [source.get("agency"), source.get("date")] if v and v != "未知来源"]
|
|
983
1022
|
url = source.get("url") if (source.get("url") and source["url"] != "接口未返回") else (source.get("policy_url") or "")
|
|
984
|
-
if source.get("link_dead"):
|
|
985
|
-
url = source.get("snapshot") or ""
|
|
986
1023
|
site_bits = ([source["doc_number"]] if source.get("doc_number") else []) + meta_bits
|
|
987
1024
|
chip_map[cid] = {
|
|
988
|
-
"title": short(source.get("title") or "
|
|
1025
|
+
"title": short(source.get("title") or "未命名来源文章", 30),
|
|
989
1026
|
"site": " · ".join(site_bits) or "来源站点",
|
|
990
1027
|
"url": url,
|
|
991
1028
|
"snapshot": source.get("snapshot") or "",
|
|
992
|
-
"dead": bool(source.get("link_dead")),
|
|
993
1029
|
"excerpt": (source.get("excerpt") or "").strip(),
|
|
994
1030
|
"segments": source.get("segments") or [],
|
|
995
1031
|
}
|
|
996
1032
|
return chip_map
|
|
997
1033
|
|
|
998
1034
|
|
|
999
|
-
def render_source_links(url: str, policy_url: str = "", snapshot: str = ""
|
|
1000
|
-
"""
|
|
1001
|
-
|
|
1035
|
+
def render_source_links(url: str, policy_url: str = "", snapshot: str = "") -> str:
|
|
1036
|
+
"""链接区:接口返回的链接**原样展示**(不做连通性检测、不隐藏);
|
|
1037
|
+
存档快照作为**附加回看入口**与原文链接并存,文案如实区分不冒充原文。"""
|
|
1002
1038
|
links = []
|
|
1003
|
-
if url and url != "接口未返回"
|
|
1039
|
+
if url and url != "接口未返回":
|
|
1004
1040
|
links.append(f'<a href="{esc(url)}" target="_blank" rel="noopener">查看全文 ↗</a>')
|
|
1005
1041
|
if snapshot:
|
|
1006
|
-
# 有哪个显示哪个:快照统一展示"查看存档全文",不做原文失效的状态解释
|
|
1007
1042
|
links.append(f'<a class="snap" href="{esc(snapshot)}" target="_blank" rel="noopener">查看存档全文 ↗</a>')
|
|
1008
1043
|
if policy_url:
|
|
1009
1044
|
links.append(f'<a href="{esc(policy_url)}" target="_blank" rel="noopener">知识专库原文 ↗</a>')
|
|
@@ -1027,24 +1062,24 @@ def render_verify_panel(v: Dict[str, Any], stage: str = "final") -> str:
|
|
|
1027
1062
|
n_missing = len(set(tr["missing_links"]) | set(tr["missing_excerpts"]))
|
|
1028
1063
|
if not tr["total"]:
|
|
1029
1064
|
tr_html = ('<div class="vi"><span class="s fail">✗ 依据溯源 0/0</span>'
|
|
1030
|
-
'<span class="d"
|
|
1065
|
+
'<span class="d">未识别到来源文章</span></div>')
|
|
1031
1066
|
elif n_missing:
|
|
1032
1067
|
# PPT 提醒制:数据缺口恒绿,附温和提醒(缺口明细在材料卡上如实标注)
|
|
1033
1068
|
tr_html = (f'<div class="vi"><span class="s ok">✓ 依据溯源 {tr["total"]}/{tr["total"]}</span>'
|
|
1034
|
-
f'<span class="d"
|
|
1069
|
+
f'<span class="d">每篇来源文章的摘录可比对;{n_missing} 篇原文链接或摘录待补,卡片已标注,汇报前请注意核对</span></div>')
|
|
1035
1070
|
else:
|
|
1036
1071
|
tr_html = (f'<div class="vi"><span class="s ok">✓ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
1037
|
-
f'<span class="d"
|
|
1072
|
+
f'<span class="d">每篇来源文章的摘录可比对,原文或存档快照可回看</span></div>')
|
|
1038
1073
|
|
|
1039
1074
|
bd = v["binding"]
|
|
1040
1075
|
if bd.get("no_citation"):
|
|
1041
1076
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 0/0</span>'
|
|
1042
|
-
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]}
|
|
1077
|
+
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]} 篇来源文章对不上正文</span></div>')
|
|
1043
1078
|
elif not bd["total"]:
|
|
1044
1079
|
bd_html = '<div class="vi"><span class="s none">— 引用对应 0/0</span><span class="d">正文里没有来源角标</span></div>'
|
|
1045
1080
|
elif not bd["unbound"]:
|
|
1046
1081
|
bd_html = (f'<div class="vi"><span class="s ok">✓ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
1047
|
-
f'<span class="d">正文每处 [n]
|
|
1082
|
+
f'<span class="d">正文每处 [n] 都能找到对应来源文章</span></div>')
|
|
1048
1083
|
else:
|
|
1049
1084
|
unbound_text = "、".join(f"[{esc(x)}]" for x in bd["unbound"][:8])
|
|
1050
1085
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
@@ -1053,8 +1088,9 @@ def render_verify_panel(v: Dict[str, Any], stage: str = "final") -> str:
|
|
|
1053
1088
|
fr = v["freshness"]
|
|
1054
1089
|
if fr:
|
|
1055
1090
|
rng = f"{fr['min'][0]}-{fr['min'][1]:02d}~{fr['max'][0]}-{fr['max'][1]:02d}"
|
|
1056
|
-
|
|
1057
|
-
|
|
1091
|
+
# 「N 条年头较久,按参考口径使用」半句已移除(长期有效的政策法规会被误判"年头较久",
|
|
1092
|
+
# 且"按参考口径使用"读者无从理解);old_count 仍在 freshness 中照常计算。
|
|
1093
|
+
fr_html = f'<div class="vi"><span class="s ok">✓ 材料新旧 已核</span><span class="d">材料日期 {esc(rng)}</span></div>'
|
|
1058
1094
|
else:
|
|
1059
1095
|
fr_html = '<div class="vi"><span class="s none">— 材料新旧 未记录</span><span class="d">材料没标发布日期</span></div>'
|
|
1060
1096
|
|
|
@@ -1069,12 +1105,14 @@ def render_verify_panel(v: Dict[str, Any], stage: str = "final") -> str:
|
|
|
1069
1105
|
notes = ";".join(note for _, note in sc["items"].values() if note)
|
|
1070
1106
|
title_attr = f' title="{esc(notes)}"' if notes else ""
|
|
1071
1107
|
item_names = "、".join(sc["items"].keys()) if sc["items"] else "、".join(label for _, label in SELF_CHECK_ITEMS)
|
|
1072
|
-
|
|
1108
|
+
none_count = sum(1 for status, _ in sc["items"].values() if status == "none")
|
|
1109
|
+
none_note = f"({none_count} 项未记录)" if none_count else ""
|
|
1110
|
+
sc_html = (f'<div class="vi"><span class="s ok"{title_attr}>✓ 交付前检查 {sc["passed"]}/{sc["total"]}{esc(none_note)}</span>'
|
|
1073
1111
|
f'<span class="d">{esc(item_names)}{esc(" · 悬停查看说明" if notes else "")}</span></div>')
|
|
1074
1112
|
elif sc["status"] == "fail":
|
|
1075
1113
|
failed_parts = []
|
|
1076
1114
|
for label, (status, note) in sc["items"].items():
|
|
1077
|
-
if status
|
|
1115
|
+
if status == "fail":
|
|
1078
1116
|
suffix = f"({note[:40]}…)" if len(note) > 40 else (f"({note})" if note else "")
|
|
1079
1117
|
failed_parts.append(label + suffix)
|
|
1080
1118
|
sc_html = (f'<div class="vi"><span class="s fail">✗ 交付前检查 {sc["passed"]}/{sc["total"]}</span>'
|
|
@@ -1084,10 +1122,8 @@ def render_verify_panel(v: Dict[str, Any], stage: str = "final") -> str:
|
|
|
1084
1122
|
sc_html = (f'<div class="vi"><span class="s none">— 交付前检查 未记录</span>'
|
|
1085
1123
|
f'<span class="d">检索 JSON 没写入 self_check(默认查:{esc(default_names)})</span></div>')
|
|
1086
1124
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
manual = (f'<div class="vi"><span class="s man">◐ 现行效力</span>'
|
|
1090
|
-
f'<span class="d">{v["policy_count"]} 份政策文件建议按官方发布确认是否现行有效</span></div>')
|
|
1125
|
+
# 3.7.2 起「现行效力」提示行移除:该提示对用户无操作价值,policy_count
|
|
1126
|
+
# 保留在计算层不再展示(对齐公文写作 3.7.2 口径)。
|
|
1091
1127
|
|
|
1092
1128
|
what = "提纲页面规划" if stage == "outline" else "页面级结论"
|
|
1093
1129
|
return f"""
|
|
@@ -1095,9 +1131,9 @@ def render_verify_panel(v: Dict[str, Any], stage: str = "final") -> str:
|
|
|
1095
1131
|
<div class="v-head"><span class="v-shield">{'✓' if ov['passed'] else '!'}</span>{esc(ov['label'])}({esc(stage_label)}){stamp}</div>
|
|
1096
1132
|
{reasons_html}
|
|
1097
1133
|
<div class="v-grid">
|
|
1098
|
-
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}
|
|
1134
|
+
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}
|
|
1099
1135
|
</div>
|
|
1100
|
-
<div class="v-note">核验方式:先用深知可信搜索找权威来源,再把{esc(what)}
|
|
1136
|
+
<div class="v-note">核验方式:先用深知可信搜索找权威来源,再把{esc(what)}的每处依据和原文逐条比对(都能点开原文回看),最后做了交付前五项检查。{manual_checks_html}</div>
|
|
1101
1137
|
</div>"""
|
|
1102
1138
|
|
|
1103
1139
|
|
|
@@ -1185,9 +1221,13 @@ def strip_leading_chain(text: str, chain: List[str]) -> str:
|
|
|
1185
1221
|
|
|
1186
1222
|
|
|
1187
1223
|
def render_crumb(chain: List[str]) -> str:
|
|
1188
|
-
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1224
|
+
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1225
|
+
|
|
1226
|
+
降级规则(对齐公文写作 3.7.2):段落本身无章节层级(链上只有文章名)时不显示
|
|
1227
|
+
标题链行——材料卡标题已是文章名,单独一行重复文章名对定位无增量。
|
|
1228
|
+
"""
|
|
1189
1229
|
parts = [esc(level) for level in chain if level]
|
|
1190
|
-
if
|
|
1230
|
+
if len(parts) <= 1:
|
|
1191
1231
|
return ""
|
|
1192
1232
|
return '<span class="crumb">' + ' <i>›</i> '.join(parts) + "</span>"
|
|
1193
1233
|
|
|
@@ -1214,7 +1254,7 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1214
1254
|
else '<span class="sc-vk warn">待补链接</span>')
|
|
1215
1255
|
note_html = ""
|
|
1216
1256
|
elif source.get("verified"):
|
|
1217
|
-
note = source.get("verify_note") or "
|
|
1257
|
+
note = source.get("verify_note") or "摘录可比对,可回看原文"
|
|
1218
1258
|
if not source.get("has_link"):
|
|
1219
1259
|
# PPT 提醒制:无原文链接不改变核验状态,卡片附温和提醒
|
|
1220
1260
|
note = "摘录可比对;本条无原文链接,请留意核对"
|
|
@@ -1226,7 +1266,7 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1226
1266
|
reason = "待补原文链接" if not source.get("has_link") else "待补摘录"
|
|
1227
1267
|
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
1228
1268
|
note_html = ""
|
|
1229
|
-
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", "")
|
|
1269
|
+
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", ""))
|
|
1230
1270
|
# 关键性行:有文号(接口字段或合并 JSON)时"文号 · 数据源 · 日期",否则"数据源 · 日期"
|
|
1231
1271
|
meta_parts = [v for v in [source.get("doc_number"), source.get("agency"), source.get("date"), source.get("area")]
|
|
1232
1272
|
if v and v != "未知来源"]
|
|
@@ -1236,8 +1276,12 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1236
1276
|
if source.get("conf") == "高":
|
|
1237
1277
|
conf_badge = ('<span class="sc-conf" title="发布日期可信度:高。内容经模型治理入库,'
|
|
1238
1278
|
'标题为模型从原文动态抽取,非规则提取">高可信</span>')
|
|
1239
|
-
#
|
|
1240
|
-
|
|
1279
|
+
# 已引用材料显示角标编号(同文异号时并列显示全部,如 [8][13]);未引用召回材料显示"未引用"灰标
|
|
1280
|
+
if source.get("used", True):
|
|
1281
|
+
ids = sorted(collect_material_ids(source), key=lambda x: (int(x) if x.isdigit() else 10 ** 9, x))
|
|
1282
|
+
id_html = "".join(f'<span class="sc-id">[{esc(i)}]</span>' for i in ids)
|
|
1283
|
+
else:
|
|
1284
|
+
id_html = '<span class="sc-unused">未引用</span>'
|
|
1241
1285
|
body_html = (f'<div class="sc-head">{id_html}'
|
|
1242
1286
|
f'<span class="sc-type">{esc(source["type_label"])}</span>{conf_badge}{vk}</div>'
|
|
1243
1287
|
f'<h4>{esc(source.get("title"))}</h4>'
|
|
@@ -1249,9 +1293,11 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1249
1293
|
# 打印附录版:无交互属性,避免与专库卡片 id 冲突
|
|
1250
1294
|
return f'<article class="scard print-only {source["type_css"]}">{body_html}</article>'
|
|
1251
1295
|
unused_attr = "" if source.get("used", True) else ' data-unused="1"'
|
|
1296
|
+
all_ids_attr = ",".join(collect_material_ids(source))
|
|
1252
1297
|
return (
|
|
1253
1298
|
f'<article class="scard {source["type_css"]}" id="src-{esc(source["id"])}" data-type="{esc(source["type_key"])}" '
|
|
1254
|
-
f'data-cite-id="{esc(source["id"])}" data-
|
|
1299
|
+
f'data-cite-id="{esc(source["id"])}" data-cite-ids="{esc(all_ids_attr)}" '
|
|
1300
|
+
f'data-search="{esc(source.get("search_key", ""))}"{unused_attr}>{body_html}</article>'
|
|
1255
1301
|
)
|
|
1256
1302
|
|
|
1257
1303
|
|
|
@@ -1282,12 +1328,12 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
|
|
|
1282
1328
|
<ol class="p-steps">
|
|
1283
1329
|
<li class="p-step expandable" id="p-step-search" role="button" tabindex="0" title="展开各路检索明细">
|
|
1284
1330
|
<span class="p-no">1</span>
|
|
1285
|
-
<div class="p-txt"><b>深知检索 {stats['n_searches']}
|
|
1331
|
+
<div class="p-txt"><b>深知检索 {stats['n_searches']} 路</b><i>{step1_sub}</i></div>
|
|
1286
1332
|
</li>
|
|
1287
1333
|
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1288
1334
|
<li class="p-step">
|
|
1289
1335
|
<span class="p-no">2</span>
|
|
1290
|
-
<div class="p-txt"><b
|
|
1336
|
+
<div class="p-txt"><b>来源文章入库 {stats['n_materials']} 篇</b><i>正文采用 {stats['used_count']} · 召回未采用 {stats['unused_count']}</i></div>
|
|
1291
1337
|
</li>
|
|
1292
1338
|
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1293
1339
|
<li class="p-step">
|
|
@@ -1304,11 +1350,11 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
|
|
|
1304
1350
|
</section>"""
|
|
1305
1351
|
|
|
1306
1352
|
|
|
1307
|
-
def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]
|
|
1308
|
-
"""
|
|
1353
|
+
def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) -> str:
|
|
1354
|
+
"""知识专库全屏视图:大搜索 + 热词 + 检索分组 tabs + 材料卡列表。"""
|
|
1309
1355
|
if not sources:
|
|
1310
|
-
return ('<section class="view" id="view-library" aria-label="
|
|
1311
|
-
'<div class="lib-empty"
|
|
1356
|
+
return ('<section class="view" id="view-library" aria-label="知识专库">'
|
|
1357
|
+
'<div class="lib-empty">接口返回中未识别到可展示的来源文章。</div></section>')
|
|
1312
1358
|
used_sources = [s for s in sources if s.get("used", True)]
|
|
1313
1359
|
unused_sources = [s for s in sources if not s.get("used", True)]
|
|
1314
1360
|
|
|
@@ -1341,34 +1387,40 @@ def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str], kb_
|
|
|
1341
1387
|
cited_verified = sum(1 for s in used_sources if s.get("verified"))
|
|
1342
1388
|
badge = "全部已核验" if used_sources and cited_verified == len(used_sources) else f"{cited_verified}/{len(used_sources)} 已核验"
|
|
1343
1389
|
return f"""
|
|
1344
|
-
<section class="view" id="view-library" aria-label="
|
|
1390
|
+
<section class="view" id="view-library" aria-label="知识专库">
|
|
1345
1391
|
<div class="lib-head">
|
|
1346
|
-
<div class="lib-title"><b
|
|
1392
|
+
<div class="lib-title"><b>知识专库</b>
|
|
1347
1393
|
<span>共 {len(sources)} 条 · 已引用 {len(used_sources)} · {esc(badge)}</span>
|
|
1348
1394
|
</div>
|
|
1349
1395
|
<div class="lib-searchWrap">
|
|
1350
1396
|
<span class="lib-searchIcon" aria-hidden="true">⌕</span>
|
|
1351
|
-
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="
|
|
1397
|
+
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="搜索来源文章">
|
|
1352
1398
|
</div>
|
|
1353
1399
|
{hot_html}
|
|
1354
1400
|
<div class="lib-tabs" role="tablist" aria-label="按检索分组筛选">{"".join(tabs)}</div>
|
|
1355
1401
|
</div>
|
|
1356
1402
|
<div class="lib-list" id="lib-list">{cards_html}</div>
|
|
1357
|
-
<div class="lib-empty hide" id="lib-empty"
|
|
1358
|
-
{kb_zone}
|
|
1403
|
+
<div class="lib-empty hide" id="lib-empty">没有符合当前筛选的来源文章。</div>
|
|
1359
1404
|
<div class="lib-foot">材料来源:深知可信搜索 · 每条摘录均取自原文原段</div>
|
|
1360
1405
|
</section>"""
|
|
1361
1406
|
|
|
1362
1407
|
|
|
1363
1408
|
def render_toc(sections: List[Dict[str, Any]]) -> str:
|
|
1364
|
-
"""章节目录(滚动 spy):长报告(≥6
|
|
1365
|
-
if len(sections) < 6:
|
|
1366
|
-
return ""
|
|
1409
|
+
"""章节目录(滚动 spy):长报告(≥6 个有标题的章节)显示,桌面端左侧浮动。"""
|
|
1367
1410
|
items = []
|
|
1368
1411
|
for i, sec in enumerate(sections, 1):
|
|
1369
|
-
|
|
1370
|
-
|
|
1412
|
+
title = (sec.get("title") or "").strip()
|
|
1413
|
+
if not title:
|
|
1414
|
+
# 无标题节=正文开头的导语/摘要段(第一个章节标题之前的内容),不是正式章节。
|
|
1415
|
+
# 此前会被兜底成「第 N 节」列进目录(一条读者看不懂的灰色占位项),且该节
|
|
1416
|
+
# 不生成 <section id="sec-i">、锚点根本不存在,点了没反应=死链。内容仍照常
|
|
1417
|
+
# 在正文里展示,只是不占目录条目、不参与滚动高亮。
|
|
1418
|
+
continue
|
|
1419
|
+
number, title_text = split_heading_number(title)
|
|
1420
|
+
label = f"{number} {title_text}" if (number and title_text) else title_text
|
|
1371
1421
|
items.append(f'<a href="#sec-{i}">{esc(short(label, 16))}</a>')
|
|
1422
|
+
if len(items) < 6:
|
|
1423
|
+
return ""
|
|
1372
1424
|
return f'<nav class="toc" aria-label="章节目录">{"".join(items)}</nav>'
|
|
1373
1425
|
|
|
1374
1426
|
|
|
@@ -1377,29 +1429,24 @@ def render_print_appendix(sources: List[Dict[str, str]]) -> str:
|
|
|
1377
1429
|
if not sources:
|
|
1378
1430
|
return ""
|
|
1379
1431
|
cards = "".join(render_source_card(s, for_print=True) for s in sources)
|
|
1380
|
-
return (f'<section class="print-appendix" aria-label="
|
|
1381
|
-
f'<h3
|
|
1432
|
+
return (f'<section class="print-appendix" aria-label="来源文章附录(打印归档)">'
|
|
1433
|
+
f'<h3>来源文章(全 {len(sources)} 篇)</h3>{cards}</section>')
|
|
1382
1434
|
|
|
1383
1435
|
|
|
1384
|
-
def
|
|
1385
|
-
"""
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
'<div class="kb-zone"><div class="kb-title">原始召回存档(深知知识专库)</div>'
|
|
1399
|
-
'<div class="kb-desc">以下链接可回看每次搜索的完整召回结果(含未写入正文的材料);'
|
|
1400
|
-
'原文页面改版或下线时可回看当时召回的快照。逐条材料的核验请点击材料卡上的"查看全文"直达官方页面。</div>'
|
|
1401
|
-
f'<div class="kb-list">{"".join(chips)}</div></div>'
|
|
1402
|
-
)
|
|
1436
|
+
def _next_version_path(path: Path) -> Path:
|
|
1437
|
+
"""输出文件已存在时不覆盖:自动改为 原名_v2 / _v3 … 另存。
|
|
1438
|
+
|
|
1439
|
+
追加修改后重跑渲染时,旧版本保留、新版本号递增——不覆盖已交付内容,
|
|
1440
|
+
也不会再靠宿主目录里的 "名字 (2)" 兜底。命名与 deliver_outputs.py 的重名规则一致。
|
|
1441
|
+
"""
|
|
1442
|
+
if not path.exists():
|
|
1443
|
+
return path
|
|
1444
|
+
for index in range(2, 100):
|
|
1445
|
+
candidate = path.with_name(f"{path.stem}_v{index}{path.suffix}")
|
|
1446
|
+
if not candidate.exists():
|
|
1447
|
+
print(f"提示:{path.name} 已存在,本次输出改为 {candidate.name}(不覆盖旧版)。")
|
|
1448
|
+
return candidate
|
|
1449
|
+
raise SystemExit(f"错误:{path.name} 的版本号 _v2~_v99 均已占用,请清理 {path.parent} 后重试。")
|
|
1403
1450
|
|
|
1404
1451
|
|
|
1405
1452
|
def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dknowc_search_trace", suffix_ext: str = ".html") -> str:
|
|
@@ -1418,65 +1465,15 @@ def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dk
|
|
|
1418
1465
|
# 链接活性检测与快照兜底(生成时真实检测,就地改写材料 dict)
|
|
1419
1466
|
# ============================================================
|
|
1420
1467
|
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
连接失败、超时、403、5xx 等一律视为"无法确认"按有效处理——政府站
|
|
1431
|
-
常对脚本请求反爬,凭这些判死会误杀可用链接。
|
|
1432
|
-
"""
|
|
1433
|
-
for method in ("HEAD", "GET"):
|
|
1434
|
-
try:
|
|
1435
|
-
req = urllib.request.Request(
|
|
1436
|
-
url, method=method,
|
|
1437
|
-
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"},
|
|
1438
|
-
)
|
|
1439
|
-
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
1440
|
-
if resp.status in (404, 410):
|
|
1441
|
-
return False
|
|
1442
|
-
if method == "GET":
|
|
1443
|
-
chunk = resp.read(4096).decode("utf-8", errors="replace")
|
|
1444
|
-
title = re.search(r"<title>(.*?)</title>", chunk, re.I | re.S)
|
|
1445
|
-
text = title.group(1) if title else chunk[:200]
|
|
1446
|
-
lowered = text.lower()
|
|
1447
|
-
return not any(k in text or k in lowered for k in SOFT_404_KEYWORDS)
|
|
1448
|
-
except urllib.error.HTTPError as e:
|
|
1449
|
-
if method == "GET":
|
|
1450
|
-
return e.code not in (404, 410)
|
|
1451
|
-
except Exception:
|
|
1452
|
-
if method == "GET":
|
|
1453
|
-
return True
|
|
1454
|
-
return True
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
def normalize_snapshot_url(url: str) -> str:
|
|
1458
|
-
"""快照路径容错:接口部分返回值缺 /A/ 层级(实测拼接 bug),统一规范化为
|
|
1459
|
-
https://attach.dknowc.cn/snapshot/A/<2位>/<2位>/<哈希>.jpg。"""
|
|
1460
|
-
u = (url or "").strip()
|
|
1461
|
-
if u.startswith("https://attach.dknowc.cn/snapshot/") and "/snapshot/A/" not in u:
|
|
1462
|
-
return u.replace("/snapshot/", "/snapshot/A/", 1)
|
|
1463
|
-
return u
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
def mark_dead_links(articles: List[Dict[str, Any]]) -> int:
|
|
1467
|
-
"""并发检测全部材料的原文链接,404/410(含软 404)的标记 链接失效=True。返回失效数。"""
|
|
1468
|
-
targets = [(i, a) for i, a in enumerate(articles) if (first_str(a.get("源网址"), a.get("sourceUrl"), a.get("source_url"), a.get("原文链接"), a.get("url")) or "").strip()]
|
|
1469
|
-
if not targets:
|
|
1470
|
-
return 0
|
|
1471
|
-
urls = [first_str(a.get("源网址"), a.get("sourceUrl"), a.get("source_url"), a.get("原文链接"), a.get("url")) for _, a in targets]
|
|
1472
|
-
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
|
|
1473
|
-
alive = dict(zip((i for i, _ in targets), pool.map(check_link_alive, urls)))
|
|
1474
|
-
dead = 0
|
|
1475
|
-
for i, _ in targets:
|
|
1476
|
-
if not alive.get(i, True):
|
|
1477
|
-
articles[i]["链接失效"] = True
|
|
1478
|
-
dead += 1
|
|
1479
|
-
return dead
|
|
1468
|
+
def normalize_snapshot_url(raw: str) -> str:
|
|
1469
|
+
"""快照链接规范化:补全 /A/ 层级;非 attach 域原样返回(由调用方弃用)。"""
|
|
1470
|
+
s = (raw or "").strip()
|
|
1471
|
+
base = "https://attach.dknowc.cn/snapshot/"
|
|
1472
|
+
if s.startswith(base + "A/"):
|
|
1473
|
+
return s
|
|
1474
|
+
if s.startswith(base):
|
|
1475
|
+
return base + "A/" + s[len(base):]
|
|
1476
|
+
return s
|
|
1480
1477
|
|
|
1481
1478
|
|
|
1482
1479
|
def apply_snapshots(articles: List[Dict[str, Any]]) -> Tuple[int, int]:
|
|
@@ -1564,6 +1561,12 @@ a{color:var(--brand)}
|
|
|
1564
1561
|
box-shadow:0 2px 8px rgba(101,18,173,.22)}
|
|
1565
1562
|
.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)}
|
|
1566
1563
|
.hero .meta{color:var(--muted);font-size:13px;letter-spacing:.5px}
|
|
1564
|
+
/* 「原问题」行:用户原始需求全文(不能独立使用时最容易被问"这是回答什么的") */
|
|
1565
|
+
.hero-q{display:flex;gap:9px;align-items:flex-start;max-width:860px;margin:2px auto 10px;
|
|
1566
|
+
padding:9px 14px;border:1px dashed var(--tint-bd-strong);border-radius:10px;background:#fff;text-align:left}
|
|
1567
|
+
.hero-q .q-tag{flex:none;font-size:11px;font-weight:800;color:#fff;background:var(--grad);
|
|
1568
|
+
border-radius:5px;padding:1px 8px;margin-top:3px;letter-spacing:1px}
|
|
1569
|
+
.hero-q .q-txt{font-size:13px;line-height:1.75;color:#4b4658;word-break:break-word}
|
|
1567
1570
|
.hero-switch{margin-top:16px;display:flex;justify-content:center}
|
|
1568
1571
|
.hero-switch .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
|
|
1569
1572
|
.hero-switch .view-switch button{color:#70678a;padding:6px 22px;font-size:13px}
|
|
@@ -1572,6 +1575,9 @@ a{color:var(--brand)}
|
|
|
1572
1575
|
/* ===== 容器与视图 ===== */
|
|
1573
1576
|
.container{max-width:1080px;margin:0 auto;padding:0 18px}
|
|
1574
1577
|
.app[data-view="library"] #view-report{display:none}
|
|
1578
|
+
/* 专库视图下隐藏章节目录(toc 渲染在 .app 之外,视图切换只驱动 .app[data-view],
|
|
1579
|
+
此前切到专库后目录仍挂在左侧;兄弟选择器为主、括号内写法兼容目录日后移入 .app 内) */
|
|
1580
|
+
.app[data-view="library"] ~ .toc,.app[data-view="library"] .toc{display:none}
|
|
1575
1581
|
#view-library{display:none}
|
|
1576
1582
|
.app[data-view="library"] #view-library{display:block}
|
|
1577
1583
|
|
|
@@ -1693,7 +1699,7 @@ a.jb-quote{text-decoration:none}
|
|
|
1693
1699
|
.sc-links a{display:inline-flex;align-items:center;min-height:24px;padding:3px 9px;border-radius:6px;
|
|
1694
1700
|
background:var(--brand-soft);color:var(--brand);font-weight:700;text-decoration:none;font-size:12px}
|
|
1695
1701
|
|
|
1696
|
-
/* =====
|
|
1702
|
+
/* ===== 知识专库视图 ===== */
|
|
1697
1703
|
#view-library{padding:26px 0 30px}
|
|
1698
1704
|
.lib-head{max-width:860px;margin:0 auto 16px;text-align:center}
|
|
1699
1705
|
.lib-title{margin-bottom:14px}
|
|
@@ -1766,19 +1772,6 @@ a.jb-quote{text-decoration:none}
|
|
|
1766
1772
|
.sc-links a.snap{background:#faf5ff;border-color:#d9c9f4;color:#5b21b6}
|
|
1767
1773
|
.dead-link{font-size:11.5px;color:var(--warn)}
|
|
1768
1774
|
|
|
1769
|
-
/* ===== PPT:原始召回存档(深知知识专库) ===== */
|
|
1770
|
-
.kb-zone{max-width:860px;margin:18px auto 0;text-align:left;border:1px dashed var(--line-strong);
|
|
1771
|
-
border-radius:12px;padding:14px 16px;background:#fff}
|
|
1772
|
-
.kb-title{font-size:13px;font-weight:800;color:var(--navy);margin-bottom:4px}
|
|
1773
|
-
.kb-desc{font-size:11.5px;color:var(--muted);line-height:1.7;margin-bottom:10px}
|
|
1774
|
-
.kb-list{display:flex;flex-wrap:wrap;gap:8px}
|
|
1775
|
-
.kb-chip{display:inline-flex;flex-direction:column;gap:2px;border:1px solid var(--line);border-radius:9px;
|
|
1776
|
-
padding:8px 12px;text-decoration:none;background:#faf9fd;max-width:100%}
|
|
1777
|
-
.kb-chip:hover{border-color:var(--brand)}
|
|
1778
|
-
.kb-label{font-size:12.5px;font-weight:700;color:var(--brand)}
|
|
1779
|
-
.kb-count{font-size:10.5px;color:var(--muted)}
|
|
1780
|
-
.kb-arrow{font-size:11px;color:var(--brand)}
|
|
1781
|
-
|
|
1782
1775
|
/* ===== 章节目录(spy,长报告) ===== */
|
|
1783
1776
|
.toc{position:fixed;left:calc((100vw - 1080px)/2 - 168px);top:120px;width:140px;max-height:60vh;overflow:auto;
|
|
1784
1777
|
display:flex;flex-direction:column;gap:2px;font-size:12px}
|
|
@@ -1815,6 +1808,8 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
|
|
|
1815
1808
|
.jb-name{max-width:calc(100vw - 72px)}
|
|
1816
1809
|
.r-badge{font-size:13.5px;letter-spacing:6px;text-indent:6px;gap:10px}
|
|
1817
1810
|
.hero h1{font-size:18.5px}
|
|
1811
|
+
.hero-q{padding:8px 11px;gap:7px}
|
|
1812
|
+
.hero-q .q-txt{font-size:12.5px}
|
|
1818
1813
|
.hero .meta{font-size:11.5px;line-height:1.7}
|
|
1819
1814
|
.hero-switch .view-switch button{padding:6px 16px;font-size:12.5px}
|
|
1820
1815
|
.process{margin-top:-30px;padding:12px 12px 11px}
|
|
@@ -1840,7 +1835,6 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
|
|
|
1840
1835
|
.scard{padding:10px 11px}
|
|
1841
1836
|
.crumb{font-size:11px}
|
|
1842
1837
|
.sc-excerpt{font-size:11.5px}
|
|
1843
|
-
.kb-zone{margin:14px 12px 0}
|
|
1844
1838
|
/* 移动端材料底部弹层:点角标就地弹出材料卡,不跳转打断阅读 */
|
|
1845
1839
|
.sheet-mask{display:block;position:fixed;inset:0;background:rgba(11,31,58,.45);z-index:99;opacity:0;
|
|
1846
1840
|
pointer-events:none;transition:opacity .2s}
|
|
@@ -1877,6 +1871,7 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
|
|
|
1877
1871
|
#view-report{display:block!important}
|
|
1878
1872
|
.app[data-view="library"] #view-report{display:block!important}
|
|
1879
1873
|
.hero{background:none;border:0;color:var(--ink);padding:10px 0 4px}
|
|
1874
|
+
.hero-q{border-color:#bbb;break-inside:avoid}
|
|
1880
1875
|
.hero .meta{color:var(--muted)}
|
|
1881
1876
|
*{-webkit-print-color-adjust:exact;print-color-adjust:exact}
|
|
1882
1877
|
.process{box-shadow:none;margin:6px 0 12px}
|
|
@@ -1946,7 +1941,7 @@ PAGE_JS = """
|
|
|
1946
1941
|
var on = document.body.classList.toggle("reading");
|
|
1947
1942
|
readBtn.setAttribute("aria-pressed", on ? "true" : "false");
|
|
1948
1943
|
readBtn.textContent = on ? "显示核验" : "只看正文";
|
|
1949
|
-
/*
|
|
1944
|
+
/* 只看正文只作用于核验报告视图:正在知识专库时切回报告,专库不受影响 */
|
|
1950
1945
|
if (on && app && app.getAttribute("data-view") !== "report") setView("report");
|
|
1951
1946
|
});
|
|
1952
1947
|
}
|
|
@@ -2021,8 +2016,12 @@ PAGE_JS = """
|
|
|
2021
2016
|
var cards = $$("#lib-list .scard");
|
|
2022
2017
|
var byId = {};
|
|
2023
2018
|
cards.forEach(function (c) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2019
|
+
/* 同文异号的多编号都指向同一张卡(data-cite-ids),任一编号都能定位 */
|
|
2020
|
+
var ids = (c.getAttribute("data-cite-ids") || c.getAttribute("data-cite-id") || "").split(",");
|
|
2021
|
+
ids.forEach(function (id) {
|
|
2022
|
+
id = (id || "").trim();
|
|
2023
|
+
if (id) byId[id] = c;
|
|
2024
|
+
});
|
|
2026
2025
|
});
|
|
2027
2026
|
|
|
2028
2027
|
/* 移动端底部弹层:正文表述 ↔ 原文原段 对照 + 材料卡 */
|
|
@@ -2101,7 +2100,7 @@ PAGE_JS = """
|
|
|
2101
2100
|
name.addEventListener("click", function () { toggleJb(name.closest(".jb")); });
|
|
2102
2101
|
});
|
|
2103
2102
|
|
|
2104
|
-
/* 引文条目点击 →
|
|
2103
|
+
/* 引文条目点击 → 知识专库定位对应卡:库内导航看完整材料;
|
|
2105
2104
|
外部原文跳转只保留 jb-head 的"查看全文"按钮,动线分离 */
|
|
2106
2105
|
function jumpToLibrary(id) {
|
|
2107
2106
|
var card = byId[id];
|
|
@@ -2137,7 +2136,7 @@ PAGE_JS = """
|
|
|
2137
2136
|
});
|
|
2138
2137
|
});
|
|
2139
2138
|
|
|
2140
|
-
/* ===== 7.
|
|
2139
|
+
/* ===== 7. 知识专库:tabs + 搜索 + 热词 ===== */
|
|
2141
2140
|
var cond = "";
|
|
2142
2141
|
var kw = "";
|
|
2143
2142
|
function applyFilter() {
|
|
@@ -2194,7 +2193,13 @@ PAGE_JS = """
|
|
|
2194
2193
|
a.addEventListener("click", function (e) {
|
|
2195
2194
|
e.preventDefault();
|
|
2196
2195
|
var target = document.querySelector(a.getAttribute("href"));
|
|
2197
|
-
if (target)
|
|
2196
|
+
if (!target) return;
|
|
2197
|
+
/* 手动定位而非 scrollIntoView({block:"start"}):后者把标题顶到视口 y=0,
|
|
2198
|
+
会被 sticky 顶栏盖住。偏移量与目录吸顶位置同一基准(顶栏高 + 20px)。 */
|
|
2199
|
+
var bar = document.querySelector(".topbar");
|
|
2200
|
+
var offset = (bar ? bar.offsetHeight : 0) + 20;
|
|
2201
|
+
var y = target.getBoundingClientRect().top + window.scrollY - offset;
|
|
2202
|
+
window.scrollTo({ top: Math.max(0, y), behavior: "smooth" });
|
|
2198
2203
|
});
|
|
2199
2204
|
});
|
|
2200
2205
|
function spy() {
|
|
@@ -2205,6 +2210,20 @@ PAGE_JS = """
|
|
|
2205
2210
|
}
|
|
2206
2211
|
window.addEventListener("scroll", spy, { passive: true });
|
|
2207
2212
|
spy();
|
|
2213
|
+
/* 目录纵向定位:此前 CSS 写死 top:120px,目录顶部与页头齐平、离正文很远。
|
|
2214
|
+
改为——初始与正文首节对齐,滚动时吸附在顶栏下方(正文首节上方还有页头、
|
|
2215
|
+
过程回顾与核验报告单,首屏内看不到目录属正常,滚动后自然吸附)。 */
|
|
2216
|
+
var topbar = document.querySelector(".topbar");
|
|
2217
|
+
function placeToc() {
|
|
2218
|
+
var first = secs[0];
|
|
2219
|
+
if (!first) return;
|
|
2220
|
+
var stick = (topbar ? topbar.offsetHeight : 0) + 20;
|
|
2221
|
+
var want = Math.round(first.getBoundingClientRect().top);
|
|
2222
|
+
toc.style.top = Math.max(stick, want) + "px";
|
|
2223
|
+
}
|
|
2224
|
+
window.addEventListener("scroll", placeToc, { passive: true });
|
|
2225
|
+
window.addEventListener("resize", placeToc);
|
|
2226
|
+
placeToc();
|
|
2208
2227
|
}
|
|
2209
2228
|
})();
|
|
2210
2229
|
"""
|
|
@@ -2217,7 +2236,6 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2217
2236
|
raw_payload = payload
|
|
2218
2237
|
payload = unwrap(payload)
|
|
2219
2238
|
for key in ("selfCheck", "self_check", "verificationChecks", "verification_checks",
|
|
2220
|
-
"knowledgeBases", "knowledgeBase", "knowledgeBaseLabels",
|
|
2221
2239
|
"recalled_materials", "召回材料", "检索文章"):
|
|
2222
2240
|
if key in raw_payload and key not in payload:
|
|
2223
2241
|
payload[key] = raw_payload[key]
|
|
@@ -2227,10 +2245,12 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2227
2245
|
# 未引用判定双通道 = JSON 标记(recalled_materials)∪ 正文角标未引用:
|
|
2228
2246
|
# 进「未引用」分组,不占角标语义,不参与核验统计。
|
|
2229
2247
|
for s in sources:
|
|
2230
|
-
|
|
2248
|
+
# 一篇文章可能有多个编号(同文异号):正文引用任一编号即视为已引用
|
|
2249
|
+
if not any(i in used for i in collect_material_ids(s)):
|
|
2231
2250
|
s["used"] = False
|
|
2232
|
-
|
|
2233
|
-
|
|
2251
|
+
# 3.7.2 起知识专库原始召回存档(kb_zone)移除:并行检索下接口返回的
|
|
2252
|
+
# knowledgeBase 链接会错乱不可靠,且未引用召回材料已在专库全量展示,
|
|
2253
|
+
# 对齐公文写作「知识专库链接不进报告」的前提(检索并行化的前置)。
|
|
2234
2254
|
generated_at = generated_at or datetime.now()
|
|
2235
2255
|
generated = generated_at.strftime("%Y-%m-%d %H:%M")
|
|
2236
2256
|
stage_label = STAGE_LABELS.get(stage, "成稿版")
|
|
@@ -2242,7 +2262,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2242
2262
|
if sources and not used:
|
|
2243
2263
|
citation_warning = (
|
|
2244
2264
|
'<div class="warn-box"><b>生成检查未通过:正文没有来源角标。</b>'
|
|
2245
|
-
'本报告无法建立"
|
|
2265
|
+
'本报告无法建立"结论-来源文章"核验对应,仅作来源文章清单参考。'
|
|
2246
2266
|
'请修正答案文件(提纲版 _outline.md / 成稿版 _answer.txt):在关键事实后标注 [1]、[2] 等角标'
|
|
2247
2267
|
'并逐条对应素材清单,然后重新运行 render_trace_html.py 生成核验报告。</div>'
|
|
2248
2268
|
)
|
|
@@ -2256,7 +2276,14 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2256
2276
|
doc_title, sections = group_sections(blocks)
|
|
2257
2277
|
display_title = doc_title or title
|
|
2258
2278
|
report_label = f"{REPORT_NAME}({stage_label})"
|
|
2259
|
-
|
|
2279
|
+
# 「原问题」行(2026-10-05 反馈:要加上完整的原问题,否则报告无法独立使用):
|
|
2280
|
+
# **只采信 --question 显式传入的用户原话**,不得用报告/演示标题冒充
|
|
2281
|
+
# (标题是正文首行或文件名的来源,不是用户问的话);未传入时整行不渲染。
|
|
2282
|
+
origin_question = (question_override or "").strip()
|
|
2283
|
+
origin_html = ""
|
|
2284
|
+
if origin_question:
|
|
2285
|
+
origin_html = (f'<div class="hero-q"><span class="q-tag">原问题</span>'
|
|
2286
|
+
f'<span class="q-txt">{esc(origin_question)}</span></div>')
|
|
2260
2287
|
|
|
2261
2288
|
jb_tables_json = json.dumps(jb_tables, ensure_ascii=False).replace("</", "<\\/")
|
|
2262
2289
|
jb_tables_script = (f'<script type="application/json" id="jb-tables">{jb_tables_json}</script>\n'
|
|
@@ -2264,9 +2291,9 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2264
2291
|
|
|
2265
2292
|
meta_bits = []
|
|
2266
2293
|
if process_stats["n_searches"]:
|
|
2267
|
-
meta_bits.append(f"深知检索 {process_stats['n_searches']}
|
|
2294
|
+
meta_bits.append(f"深知检索 {process_stats['n_searches']} 路")
|
|
2268
2295
|
if sources:
|
|
2269
|
-
meta_bits.append(f"
|
|
2296
|
+
meta_bits.append(f"来源文章 {len(sources)} 篇")
|
|
2270
2297
|
if process_stats["n_cite_marks"]:
|
|
2271
2298
|
meta_bits.append(f"正文引用 {process_stats['n_cite_marks']} 处")
|
|
2272
2299
|
meta_bits.append(f"生成于 {generated}")
|
|
@@ -2290,7 +2317,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2290
2317
|
<div class="tb-right">
|
|
2291
2318
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2292
2319
|
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2293
|
-
<button data-view="library" type="button"
|
|
2320
|
+
<button data-view="library" type="button">知识专库</button>
|
|
2294
2321
|
</div>
|
|
2295
2322
|
<div class="tb-tools">
|
|
2296
2323
|
<button id="btn-reading" type="button" aria-pressed="false" title="隐藏核验元素,纯阅读正文">只看正文</button>
|
|
@@ -2310,11 +2337,12 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2310
2337
|
<div class="hero">
|
|
2311
2338
|
<div class="r-badge">{esc(report_label)}</div>
|
|
2312
2339
|
<h1>{esc(display_title)}</h1>
|
|
2340
|
+
{origin_html}
|
|
2313
2341
|
<div class="meta">{esc(meta_line)} | 素材来源:深知可信搜索</div>
|
|
2314
2342
|
<div class="hero-switch">
|
|
2315
2343
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2316
2344
|
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2317
|
-
<button data-view="library" type="button"
|
|
2345
|
+
<button data-view="library" type="button">知识专库({len(sources)})</button>
|
|
2318
2346
|
</div>
|
|
2319
2347
|
</div>
|
|
2320
2348
|
</div>
|
|
@@ -2328,10 +2356,10 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2328
2356
|
<div class="doc-paper">
|
|
2329
2357
|
{render_section_cards(sections, sources)}
|
|
2330
2358
|
</div>
|
|
2331
|
-
<div class="foot">深知可信PPT · 溯源核验报告 | 内容由 AI
|
|
2359
|
+
<div class="foot">深知可信PPT · 溯源核验报告 | 内容由 AI 生成,仅供参考</div>
|
|
2332
2360
|
</main>
|
|
2333
2361
|
|
|
2334
|
-
{render_library_view(sources, hot_terms
|
|
2362
|
+
{render_library_view(sources, hot_terms)}
|
|
2335
2363
|
{render_print_appendix(sources)}
|
|
2336
2364
|
</div>
|
|
2337
2365
|
|
|
@@ -2362,6 +2390,7 @@ def align_sources_to_answer(answer: str, sources: List[Dict[str, str]]) -> List[
|
|
|
2362
2390
|
if idx >= len(aligned):
|
|
2363
2391
|
break
|
|
2364
2392
|
aligned[idx]["id"] = citation
|
|
2393
|
+
aligned[idx]["all_ids"] = [str(citation)]
|
|
2365
2394
|
aligned[idx]["type_key"] = aligned[idx].get("type_key", "material")
|
|
2366
2395
|
aligned[idx]["type_label"] = aligned[idx].get("type_label", "材料")
|
|
2367
2396
|
aligned[idx]["type_css"] = aligned[idx].get("type_css", "mat")
|
|
@@ -2379,7 +2408,7 @@ def main() -> None:
|
|
|
2379
2408
|
parser.add_argument("--stage", choices=["outline", "final"], default="final",
|
|
2380
2409
|
help="报告版本:outline 提纲版(确认门前事前核验)/ final 成稿版(交付时事后溯源),默认 final。")
|
|
2381
2410
|
parser.add_argument("--skip-link-check", action="store_true",
|
|
2382
|
-
help="
|
|
2411
|
+
help="(已废弃,兼容保留)链接活性检测已于 2026-10-08 整体移除,本参数不再有任何作用")
|
|
2383
2412
|
parser.add_argument("--disable-snapshot", action="store_true",
|
|
2384
2413
|
help="关闭快照兜底展示(默认启用:原文失效时以存档快照回看)")
|
|
2385
2414
|
args = parser.parse_args()
|
|
@@ -2394,12 +2423,8 @@ def main() -> None:
|
|
|
2394
2423
|
question = args.question.strip() or extract_question(unwrap(payload))
|
|
2395
2424
|
unwrapped = unwrap(payload)
|
|
2396
2425
|
|
|
2397
|
-
#
|
|
2426
|
+
# 存档快照预处理(纯本地路径校验,不发网络请求);接口返回的链接原样进报告
|
|
2398
2427
|
raw_articles = collect_raw_articles(unwrapped)
|
|
2399
|
-
if not args.skip_link_check and raw_articles:
|
|
2400
|
-
dead = mark_dead_links(raw_articles)
|
|
2401
|
-
if dead:
|
|
2402
|
-
print(f"链接检测:{dead} 条原文链接已失效(404/410),将改用存档快照或如实标注")
|
|
2403
2428
|
if SNAPSHOT_ENABLED and raw_articles:
|
|
2404
2429
|
fixed, dropped = apply_snapshots(raw_articles)
|
|
2405
2430
|
total_snap = sum(1 for a in raw_articles if (a.get("快照链接") or "").strip())
|
|
@@ -2419,7 +2444,7 @@ def main() -> None:
|
|
|
2419
2444
|
if citation_ids(pre_answer) and not pre_sources:
|
|
2420
2445
|
print("生成检查未通过:输入 JSON 未识别到任何素材,但正文包含 [N] 角标。", file=sys.stderr)
|
|
2421
2446
|
print("请检查合并 JSON 结构:素材数组须为顶层 {\"检索文章\": [...]} 或原始接口的 content.data.检索文章 形态;"
|
|
2422
|
-
"
|
|
2447
|
+
"self_check/verification_checks 放顶层。修正后重新运行本脚本。", file=sys.stderr)
|
|
2423
2448
|
raise SystemExit(2)
|
|
2424
2449
|
|
|
2425
2450
|
generated_at = datetime.now()
|
|
@@ -2427,6 +2452,7 @@ def main() -> None:
|
|
|
2427
2452
|
output = _safe_output_path(args.output, {".html", ".htm"}, ".html")
|
|
2428
2453
|
else:
|
|
2429
2454
|
output = _safe_output_path(safe_output_filename(question, generated_at), {".html", ".htm"}, ".html")
|
|
2455
|
+
output = _next_version_path(output)
|
|
2430
2456
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
2431
2457
|
output.write_text(render_html(payload, args.title, answer_override=answer_override,
|
|
2432
2458
|
question_override=args.question, generated_at=generated_at, stage=args.stage), encoding="utf-8")
|
|
@@ -2435,6 +2461,7 @@ def main() -> None:
|
|
|
2435
2461
|
clean_output = _safe_output_path(args.clean_md_output, {".md"}, ".md")
|
|
2436
2462
|
else:
|
|
2437
2463
|
clean_output = _safe_output_path(output.with_suffix(".clean.md").name, {".md"}, ".md")
|
|
2464
|
+
clean_output = _next_version_path(clean_output)
|
|
2438
2465
|
clean_output.parent.mkdir(parents=True, exist_ok=True)
|
|
2439
2466
|
clean_answer = strip_citation_markers(answer_override or extract_answer(unwrap(payload)))
|
|
2440
2467
|
clean_output.write_text(clean_answer, encoding="utf-8")
|