dknowc-dsh 2.1.0 → 2.2.1

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.
Files changed (45) hide show
  1. package/README.md +29 -8
  2. package/package.json +3 -3
  3. package/skills/dknowc-official-doc-writer/README.md +17 -8
  4. package/skills/dknowc-official-doc-writer/SKILL.md +31 -29
  5. package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +2 -0
  6. package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +1 -1
  7. package/skills/dknowc-official-doc-writer/reference/output_guide.md +4 -4
  8. package/skills/dknowc-official-doc-writer/reference/research_notes.md +6 -2
  9. package/skills/dknowc-official-doc-writer/reference/review_checklist.md +11 -11
  10. package/skills/dknowc-official-doc-writer/reference/revision_workflow.md +4 -4
  11. package/skills/dknowc-official-doc-writer/reference/sample_search_result.md +1 -1
  12. package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +387 -430
  13. package/skills/dknowc-official-doc-writer/reference/search_guide.md +8 -8
  14. package/skills/dknowc-official-doc-writer/reference/search_intro.md +2 -2
  15. package/skills/dknowc-official-doc-writer/reference/search_policy.md +4 -4
  16. package/skills/dknowc-official-doc-writer/reference/task_router.md +77 -34
  17. package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
  18. package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +9 -1
  19. package/skills/dknowc-official-doc-writer/scripts/check_materials.py +57 -23
  20. package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +27 -4
  21. package/skills/dknowc-official-doc-writer/scripts/deep_query.py +1 -1
  22. package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +5 -2
  23. package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -1
  24. package/skills/dknowc-official-doc-writer/scripts/format_document.py +1 -1
  25. package/skills/dknowc-official-doc-writer/scripts/initialize.py +1 -1
  26. package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +102 -2
  27. package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +1 -1
  28. package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +253 -246
  29. package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -1
  30. package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +9 -7
  31. package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -1
  32. package/skills/dknowc-ppt-assistant/README.md +10 -12
  33. package/skills/dknowc-ppt-assistant/SKILL.md +8 -8
  34. package/skills/dknowc-ppt-assistant/scripts/initialize.py +1 -1
  35. package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +6 -3
  36. package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +19 -23
  37. package/skills/dknowc-trusted-search/README.md +11 -12
  38. package/skills/dknowc-trusted-search/SKILL.md +30 -26
  39. package/skills/dknowc-trusted-search/scripts/deep_convert.py +124 -0
  40. package/skills/dknowc-trusted-search/scripts/deep_query.py +10 -0
  41. package/skills/dknowc-trusted-search/scripts/initialize.py +1 -0
  42. package/skills/dknowc-trusted-search/scripts/merge_search_results.py +109 -12
  43. package/skills/dknowc-trusted-search/scripts/render_trace_html.py +333 -253
  44. package/skills/dknowc-trusted-search/scripts/trusted_search.py +7 -0
  45. package/src/index.js +3 -3
@@ -73,7 +73,7 @@ def _safe_input_path(value: str, allowed_suffixes: set) -> Path:
73
73
  candidate = SKILL_ROOT / raw
74
74
  if not candidate.exists() and (SEARCH_RESULTS_DIR / raw.name).exists():
75
75
  raw = SEARCH_RESULTS_DIR / raw.name
76
- resolved = raw.resolve() if raw.is_absolute() else raw.resolve()
76
+ resolved = raw.resolve() if raw.is_absolute() else (SKILL_ROOT / raw).resolve()
77
77
  if resolved.suffix.lower() not in allowed_suffixes:
78
78
  raise ValueError(f"输入文件后缀必须是 {sorted(allowed_suffixes)} 之一: {value}")
79
79
  if not (_is_within(resolved, SEARCH_RESULTS_DIR) or _is_within(resolved, SKILL_ROOT / "config") or resolved == SKILL_ROOT / "SKILL.md"):
@@ -311,6 +311,12 @@ def clean_paragraph_noise(text: str) -> str:
311
311
  摘录只保留 URL 之后的正文;无该前缀时兜底剔除文本中的裸 URL。
312
312
  """
313
313
  value = str(text or "")
314
+ # 接口 kb 元数据段剔除(2026-10-14):部分公告类材料把"生效时间:…\n所属地域:…
315
+ # \n成文日期:…\n修订说明:【…】相关文件有下面这些版本:…"这类结构化字段串当段落返回,
316
+ # 展示为摘录是纯噪音(日期/属地已在卡片 meta 行)——段首即"生效时间:"且含
317
+ # "所属地域:"标签行的整段剔除
318
+ if value.startswith("生效时间:") and "所属地域:" in value:
319
+ return ""
314
320
  m = re.search(r"https?://\S*attach\.dknowc\.cn/file/", value)
315
321
  if m:
316
322
  return value[m.end():].strip()
@@ -438,6 +444,9 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
438
444
  source["doc_number"] = first_str(item.get("文号"), item.get("doc_number"))
439
445
  # 所属搜索条件(多路检索分组)与引用状态(未引用=接口召回但正文未采用)
440
446
  source["search_key"] = first_str(item.get("搜索条件"), item.get("search_key"))
447
+ # 检索通道(深知深度搜索 / 深知可信搜索):由检索脚本在产物上打标、merge 透传,
448
+ # 供过程条/hero 按接口通道拆分计数;历史 JSON 无该字段时为空(渲染层回退旧文案)
449
+ source["channel"] = first_str(item.get("检索通道"), item.get("channel"))
441
450
  source["used"] = item.get("已引用", item.get("used", True))
442
451
  if not isinstance(source["used"], bool):
443
452
  source["used"] = True
@@ -785,18 +794,30 @@ def compute_process_stats(sources: List[Dict[str, str]], answer: str) -> Dict[st
785
794
  cond_rows = []
786
795
  for key in order:
787
796
  group = [s for s in sources if (s.get("search_key") or "").strip() == key]
797
+ # 该路检索的接口通道(深知深度搜索/深知可信搜索):取组内多数通道
798
+ chan_counts: Dict[str, int] = {}
799
+ for s in group:
800
+ ch = (s.get("channel") or "").strip()
801
+ if ch:
802
+ chan_counts[ch] = chan_counts.get(ch, 0) + 1
803
+ channel = max(chan_counts, key=chan_counts.get) if chan_counts else ""
788
804
  cond_rows.append({
789
805
  "key": key,
790
806
  "total": len(group),
791
807
  "used": sum(1 for s in group if s.get("used", True)),
808
+ "channel": channel,
792
809
  })
793
810
  n_searches = len(cond_rows) or (1 if sources else 0)
811
+ deep_routes = sum(1 for r in cond_rows if "深度" in r.get("channel", ""))
812
+ trusted_routes = sum(1 for r in cond_rows if "可信" in r.get("channel", ""))
794
813
  used_count = sum(1 for s in sources if s.get("used", True))
795
814
  unused_count = len(sources) - used_count
796
815
  n_cite_marks = len(re.findall(r"\[(\d+)\]", answer))
797
816
  return {
798
817
  "conds": cond_rows,
799
818
  "n_searches": n_searches,
819
+ "deep_routes": deep_routes,
820
+ "trusted_routes": trusted_routes,
800
821
  "has_cond_detail": bool(cond_rows),
801
822
  "n_materials": len(sources),
802
823
  "used_count": used_count,
@@ -805,66 +826,6 @@ def compute_process_stats(sources: List[Dict[str, str]], answer: str) -> Dict[st
805
826
  }
806
827
 
807
828
 
808
- HOT_STOP = {
809
- "关于", "通知", "工作", "意见", "方案", "实施", "有关", "问题", "情况", "报告", "总结",
810
- "制度", "体系", "机制", "指导", "贯彻", "落实", "进一步", "以及", "其他", "相关", "以下",
811
- "以上", "共和国", "人民", "中华", "国务院", "人民政府", "办公厅", "印发", "试行",
812
- "办法", "条例", "若干", "的重点", "有所", "一个", "方面", "方式", "内容", "基本",
813
- "发展", "建设", "政策", "产业", "企业", "应用", "改革", "目标", "任务", "规划",
814
- "领域", "措施", "支持", "行动", "服务", "管理", "政府",
815
- }
816
-
817
-
818
- def extract_hot_terms(answer: str, sources: List[Dict[str, str]], top: int = 8) -> List[str]:
819
- """知识专库热词:材料标题(加权)+ 检索条件 + 正文的高频 2-4 字词,真实统计。
820
-
821
- 泛词过滤:出现在超过 60% 材料标题中的词(如库内全部材料共有的主题词)
822
- 无法筛出子集,没有筛选价值,剔除。
823
- """
824
- corpus_parts: List[str] = []
825
- for s in sources:
826
- if s.get("title"):
827
- corpus_parts.extend([s["title"]] * 3)
828
- if s.get("search_key"):
829
- corpus_parts.extend([s["search_key"]] * 2)
830
- clean_answer = re.sub(r"\[\d+\]", "", answer or "")
831
- corpus_parts.append(clean_answer)
832
- corpus = "\n".join(corpus_parts)
833
-
834
- counts: Dict[str, int] = {}
835
- for run in re.findall(r"[一-鿿]{2,}", corpus):
836
- for n in (2, 3, 4):
837
- for i in range(len(run) - n + 1):
838
- gram = run[i:i + n]
839
- counts[gram] = counts.get(gram, 0) + 1
840
-
841
- titles = [s.get("title") or "" for s in sources]
842
- n_titles = max(1, len(titles))
843
- df_limit = max(1, int(n_titles * 0.6))
844
-
845
- cands = [(g, c) for g, c in counts.items()
846
- if c >= 2 and g not in HOT_STOP and "的" not in g and not any(ch.isdigit() for ch in g)
847
- and sum(1 for t in titles if g in t) <= df_limit]
848
- cands.sort(key=lambda x: (-x[1], -len(x[0])))
849
- kept: List[Tuple[str, int]] = []
850
- for gram, count in cands:
851
- redundant = False
852
- for kgram, kcount in kept:
853
- # 短词是已入选高频长词的子串且计数接近 → 被长词覆盖,剔除
854
- if gram in kgram and kcount >= count * 0.6:
855
- redundant = True
856
- break
857
- if not redundant:
858
- kept.append((gram, count))
859
- if len(kept) >= top:
860
- break
861
- return [g for g, _ in kept]
862
-
863
-
864
- # ============================================================
865
- # 正文解析与分节
866
- # ============================================================
867
-
868
829
  def render_inline_markdown(text: str, citation_repl) -> str:
869
830
  body = esc(text)
870
831
  body = re.sub(r"`([^`]+)`", r"<code>\1</code>", body)
@@ -923,7 +884,8 @@ def render_excerpt_html(text: str) -> str:
923
884
  return f'<div class="sc-excerpt rich">{sanitize_table_html(value)}</div>'
924
885
 
925
886
 
926
- def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str, str]] = None) -> Tuple[List[Dict[str, Any]], set]:
887
+ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str, str]] = None,
888
+ strip_cites: bool = False) -> Tuple[List[Dict[str, Any]], set]:
927
889
  """把正文 Markdown 解析为结构化块;同时收集全部角标。
928
890
 
929
891
  角标渲染为原型式 sup.cite 上标胶囊;段落对应的溯源卡(src-card)由
@@ -980,7 +942,10 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
980
942
 
981
943
  def make_block_repl(block_text: str):
982
944
  """按块构造角标替换器:同段同材料只保留最后一次出现的角标(前处整体删除),
983
- 最后一处挂数字角标 + 引文胶囊——一段中同一材料只出现一次。"""
945
+ 最后一处挂数字角标 + 引文胶囊——一段中同一材料只出现一次。
946
+ 正文页(strip_cites=True)直接删掉全部角标,输出干净正文。"""
947
+ if strip_cites:
948
+ return lambda match: ""
984
949
  remaining: Dict[str, int] = {}
985
950
  for cid in re.findall(r"\[(\d+)\]", block_text):
986
951
  remaining[cid] = remaining.get(cid, 0) + 1
@@ -1007,8 +972,9 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
1007
972
  continue
1008
973
  # 引文胶囊位置规范:角标与后随标点换位——标点紧跟文字,胶囊放标点之后
1009
974
  # (避免胶囊把句号挤到下一行孤悬,对齐深知晓原型"…内容。~出处"形态)
1010
- block = re.sub(r"\[(\d+)\]([。;,、!?:;,.])", r"\2[\1]", block)
1011
- ids = citation_ids(block)
975
+ # 连续角标序列须整体换位(如 [13][14];),否则标点被夹在两个胶囊中间
976
+ block = re.sub(r"((?:\[\d+\])+)([。;,、!?:;,.])", r"\2\1", block)
977
+ ids = [] if strip_cites else citation_ids(block)
1012
978
  repl = make_block_repl(block)
1013
979
  heading_match = re.match(r"^(#{1,4})\s+(.+)$", block)
1014
980
  if heading_match:
@@ -1022,7 +988,8 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
1022
988
  table_lines.append(lines[idx].strip())
1023
989
  idx += 1
1024
990
  repl = make_block_repl("\n".join(table_lines))
1025
- blocks.append({"kind": "table", "html": render_markdown_table(table_lines, repl), "cites": citation_ids("\n".join(table_lines))})
991
+ blocks.append({"kind": "table", "html": render_markdown_table(table_lines, repl),
992
+ "cites": [] if strip_cites else citation_ids("\n".join(table_lines))})
1026
993
  elif block in {"---", "***"}:
1027
994
  blocks.append({"kind": "hr", "html": '<hr class="doc-divider">', "cites": []})
1028
995
  idx += 1
@@ -1132,7 +1099,13 @@ def render_source_links(url: str, policy_url: str = "", snapshot: str = "") -> s
1132
1099
 
1133
1100
  def render_verify_panel(v: Dict[str, Any]) -> str:
1134
1101
  """核验报告单:报告级核验结论 + 五项指标。"""
1135
- manual_checks_html = "".join("<br>· " + esc(x) for x in v.get("manual_checks", []))
1102
+ # 核验明细(逐条"已完成…"文本可能很长)默认折叠,点开才展开——不用悬浮 tooltip(触屏不可用)
1103
+ _checks = [str(x) for x in (v.get("manual_checks") or []) if str(x).strip()]
1104
+ manual_checks_html = ""
1105
+ if _checks:
1106
+ _items = "".join(f"<li>{esc(x)}</li>" for x in _checks)
1107
+ manual_checks_html = (f'<details class="v-checks"><summary>查看核验明细({len(_checks)} 项)</summary>'
1108
+ f'<ul>{_items}</ul></details>')
1136
1109
  ov = v["overall"]
1137
1110
  state = "ok" if ov["passed"] else "fail"
1138
1111
  stamp = '<span class="v-stamp">已核验</span>' if ov["passed"] else '<span class="v-stamp bad">核验未通过</span>'
@@ -1168,7 +1141,7 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
1168
1141
  bd_html = '<div class="vi"><span class="s none">— 引用对应 0/0</span><span class="d">正文里没有来源角标</span></div>'
1169
1142
  elif not bd["unbound"]:
1170
1143
  bd_html = (f'<div class="vi"><span class="s ok">✓ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
1171
- f'<span class="d">正文每处 [n] 都能找到对应来源文章</span></div>')
1144
+ f'<span class="d">正文每一处引用都已对回来源文章,点开即可核对原文</span></div>')
1172
1145
  else:
1173
1146
  unbound_text = "、".join(f"[{esc(x)}]" for x in bd["unbound"][:8])
1174
1147
  bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
@@ -1191,15 +1164,20 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
1191
1164
  f'<span class="d">{esc(" · ".join(parts))}</span></div>') if parts else ""
1192
1165
 
1193
1166
  sc = v["self_check"]
1167
+ selfcheck_notes_html = ""
1194
1168
  if sc["status"] == "pass":
1195
- notes = ";".join(note for _, note in sc["items"].values() if note)
1196
- title_attr = f' title="{esc(notes)}"' if notes else ""
1197
1169
  item_names = "、".join(sc["items"].keys()) if sc["items"] else "、".join(label for _, label in SELF_CHECK_ITEMS)
1198
1170
  unrecorded = sc["total"] - sc["passed"] - sc.get("failed", 0)
1199
1171
  sc_head = f'✓ 交付前检查 {sc["passed"]}/{sc["total"]}' if not unrecorded else \
1200
1172
  f'✓ 交付前检查 通过({unrecorded} 项未记录)'
1201
- sc_html = (f'<div class="vi"><span class="s ok"{title_attr}>{sc_head}</span>'
1202
- f'<span class="d">{esc(item_names)}{esc(" · 悬停查看说明" if notes else "")}</span></div>')
1173
+ sc_html = (f'<div class="vi"><span class="s ok">{sc_head}</span>'
1174
+ f'<span class="d">{esc(item_names)}</span></div>')
1175
+ # 逐项说明默认折叠(触屏可用),不再用鼠标悬浮 tooltip
1176
+ note_items = [(label, note) for label, (status, note) in sc["items"].items() if note]
1177
+ if note_items:
1178
+ _li = "".join(f"<li><b>{esc(label)}</b>:{esc(note)}</li>" for label, note in note_items)
1179
+ selfcheck_notes_html = (f'<details class="v-checks"><summary>查看交付前检查说明({len(note_items)} 项)</summary>'
1180
+ f'<ul>{_li}</ul></details>')
1203
1181
  elif sc["status"] == "fail":
1204
1182
  failed_parts = []
1205
1183
  for label, (status, note) in sc["items"].items():
@@ -1222,7 +1200,7 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
1222
1200
  <div class="v-grid">
1223
1201
  {tr_html}{bd_html}{fr_html}{cov_html}{sc_html}{manual}
1224
1202
  </div>
1225
- <div class="v-note">核验方式:先用深知可信搜索找权威来源,再把正文每处依据和原文逐条比对(都能点开原文回看),最后做了交付前五项检查。{manual_checks_html}</div>
1203
+ <div class="v-note">AI 已完成自验收,正文依据可逐条点开原文复核。{selfcheck_notes_html}{manual_checks_html}</div>
1226
1204
  </div>"""
1227
1205
 
1228
1206
 
@@ -1290,7 +1268,8 @@ def resolve_chart_anchor(sections: List[Dict[str, Any]], anchor: Any) -> int:
1290
1268
 
1291
1269
 
1292
1270
  def render_section_cards(sections: List[Dict[str, Any]], sources: List[Dict[str, str]],
1293
- charts_by_section: Optional[Dict[int, str]] = None) -> str:
1271
+ charts_by_section: Optional[Dict[int, str]] = None,
1272
+ id_prefix: str = "sec") -> str:
1294
1273
  """正文渲染(原型复刻):chapter(h2)+ lead/para 段落 + 段后 src-card 溯源卡。
1295
1274
 
1296
1275
  溯源卡按段内角标顺序输出;同一材料在同段只出一张,跨段重复出现标记 dup-card(灰化)。
@@ -1316,7 +1295,7 @@ def render_section_cards(sections: List[Dict[str, Any]], sources: List[Dict[str,
1316
1295
  state = "bad" if unbound else ""
1317
1296
  text = f"本章引用 {len(sec_cites)} 处" + (f" · {unbound} 处未绑定" if unbound else " · 已核验")
1318
1297
  badge_html = f'<span class="sec-badge {state}">{esc(text)}</span>'
1319
- parts.append(f'<section class="chapter" id="sec-{sec_idx}">'
1298
+ parts.append(f'<section class="chapter" id="{id_prefix}-{sec_idx}">'
1320
1299
  f'<header class="ch-head"><h2>{esc(chapter_title)}</h2>{badge_html}</header>')
1321
1300
  for b in sec["blocks"]:
1322
1301
  if b["kind"] == "heading":
@@ -1445,9 +1424,22 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
1445
1424
  ov = verification["overall"]
1446
1425
  tr = verification["traceability"]
1447
1426
  first_query = stats["conds"][0]["key"] if stats["conds"] else ""
1427
+ # 步骤一标题按接口通道拆分(深度搜索与可信搜索是两个接口,不混计成一个数);
1428
+ # 无通道信息(历史 JSON)时退回"深知检索 N 路"
1429
+ deep_n = stats.get("deep_routes", 0)
1430
+ trusted_n = stats.get("trusted_routes", 0)
1431
+ if deep_n and trusted_n:
1432
+ step1_title = f"深度搜索 {deep_n} 路 · 可信补搜 {trusted_n} 次"
1433
+ elif deep_n:
1434
+ step1_title = f"深知深度搜索 {deep_n} 路"
1435
+ elif trusted_n:
1436
+ step1_title = f"深知可信搜索 {trusted_n} 次"
1437
+ else:
1438
+ step1_title = f"深知检索 {stats['n_searches']} 路"
1448
1439
  detail_rows = "".join(
1449
- f'<div class="pd-row"><b>{esc(row["key"])}</b>'
1450
- f'<span>召回 {row["total"]} 条 · 正文采用 {row["used"]} 条</span></div>'
1440
+ f'<div class="pd-row"><b>{esc(row["key"])}'
1441
+ + (f'({"深度搜索" if "深度" in row.get("channel", "") else "可信搜索"})' if row.get("channel") else "")
1442
+ + f'</b><span>召回 {row["total"]} 条 · 正文采用 {row["used"]} 条</span></div>'
1451
1443
  for row in stats["conds"]
1452
1444
  ) or '<div class="pd-row"><span>本次溯源 JSON 未记录各次检索条件</span></div>'
1453
1445
  detail_hint = f'{esc(short(first_query, 26))}…' if (stats["n_searches"] > 1 and first_query) else "查看检索明细"
@@ -1461,18 +1453,25 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
1461
1453
  step4_icon = "✓" if ov["passed"] else "!"
1462
1454
  step4_label = "核验完成" if ov["passed"] else "核验未完全通过"
1463
1455
  step4_sub = "结论:正文依据逐条对过原文" if ov["passed"] else esc(short(";".join(ov["reasons"]) or "见核验报告单", 30))
1456
+ # 研究资料统计(1.5.0):--research-notes-file 传入时在步骤 2 体现(事实/口径行数);
1457
+ # 未传不显示(如实,不虚构)
1458
+ rn = stats.get("research_notes") or {}
1459
+ rn_bits = ""
1460
+ if rn.get("facts") is not None:
1461
+ rn_bits = f"研究资料 {rn['facts']} 项事实 · {rn.get('calibers', 0)} 项口径 | "
1462
+
1464
1463
  return f"""
1465
- <section class="process" aria-label="生成过程回顾">
1466
- <div class="p-head"><b>过程回顾</b><span>数字来自本次任务的真实记录</span></div>
1464
+ <section class="process" aria-label="AI 自验收">
1465
+ <div class="p-head"><b>AI 自验收</b><span>交付前由 AI 自动完成,数字来自本次任务的真实记录</span></div>
1467
1466
  <ol class="p-steps">
1468
1467
  <li class="p-step expandable" id="p-step-search" role="button" tabindex="0" title="展开各路检索明细">
1469
1468
  <span class="p-no">1</span>
1470
- <div class="p-txt"><b>深知检索 {stats['n_searches']} 路</b><i>{step1_sub}</i></div>
1469
+ <div class="p-txt"><b>{esc(step1_title)}</b><i>{step1_sub}</i></div>
1471
1470
  </li>
1472
1471
  <li class="p-arrow" aria-hidden="true">›</li>
1473
1472
  <li class="p-step">
1474
1473
  <span class="p-no">2</span>
1475
- <div class="p-txt"><b>来源文章入库 {stats['n_materials']} 篇</b><i>正文采用 {stats['used_count']} · 召回未采用 {stats['unused_count']}</i></div>
1474
+ <div class="p-txt"><b>来源文章入库 {stats['n_materials']} 篇</b><i>{rn_bits}正文采用 {stats['used_count']} · 召回未采用 {stats['unused_count']}</i></div>
1476
1475
  </li>
1477
1476
  <li class="p-arrow" aria-hidden="true">›</li>
1478
1477
  <li class="p-step">
@@ -1489,8 +1488,8 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
1489
1488
  </section>"""
1490
1489
 
1491
1490
 
1492
- def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) -> str:
1493
- """知识专库全屏视图:大搜索 + 热词 + 检索分组 tabs + 材料卡列表。"""
1491
+ def render_library_view(sources: List[Dict[str, str]], doc_title: str = "") -> str:
1492
+ """知识专库全屏视图:大搜索 + 检索分组 tabs + 材料卡列表。"""
1494
1493
  if not sources:
1495
1494
  return ('<section class="view" id="view-library" aria-label="知识专库">'
1496
1495
  '<div class="lib-empty">接口返回中未识别到可展示的来源文章。</div></section>')
@@ -1510,37 +1509,41 @@ def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) ->
1510
1509
  else:
1511
1510
  conds.append((key, 1))
1512
1511
  tabs = [f'<button class="on" data-cond="" type="button">全部({len(sources)})</button>']
1513
- for name, count in conds:
1512
+ # 分组过多时折叠(2026-10-14):多轮检索+补搜会产生 10+ 个分组 tab 平铺拥挤;
1513
+ # 按材料数降序保留前 6 组,其余收进"更多分组(N)"展开区(筛选功能不变)
1514
+ shown, folded = conds, []
1515
+ if len(conds) > 6:
1516
+ ranked = sorted(range(len(conds)), key=lambda i: -conds[i][1])
1517
+ keep = set(ranked[:6])
1518
+ shown = [c for i, c in enumerate(conds) if i in keep]
1519
+ folded = [c for i, c in enumerate(conds) if i not in keep]
1520
+ for name, count in shown:
1514
1521
  tabs.append(f'<button data-cond="{esc(name)}" type="button">{esc(name)}({count})</button>')
1515
- if unused_sources:
1516
- tabs.append(f'<button data-cond="__unused__" type="button">未引用({len(unused_sources)})</button>')
1517
-
1518
- hot_html = ""
1519
- if hot_terms:
1520
- hot_items = "".join(f'<button class="hot-term" type="button">{esc(term)}</button>' for term in hot_terms)
1521
- hot_html = f'<div class="hot-terms" aria-label="热门搜索词"><span class="hot-label">大家都在搜</span>{hot_items}</div>'
1522
+ if folded:
1523
+ fold_btns = "".join(f'<button data-cond="{esc(name)}" type="button">{esc(name)}({count})</button>'
1524
+ for name, count in folded)
1525
+ tabs.append(f'<button class="tabs-toggle" type="button" aria-expanded="false">更多分组({len(folded)})</button>'
1526
+ f'<span class="tabs-fold">{fold_btns}</span>')
1527
+ # 「未引用(N)」筛选胶囊已删(3.8.1 起整行占位、信息由卡片"未引用"灰标自表达);
1528
+ # JS 的 __unused__ 过滤分支保留为兼容死代码
1522
1529
 
1523
1530
  cards_html = "".join(render_source_card(s) for s in used_sources)
1524
1531
  cards_html += "".join(render_source_card(s) for s in unused_sources)
1525
1532
 
1526
- cited_verified = sum(1 for s in used_sources if s.get("verified"))
1527
- badge = "全部已核验" if used_sources and cited_verified == len(used_sources) else f"{cited_verified}/{len(used_sources)} 已核验"
1533
+ lib_title = f"知识专库:{doc_title}" if doc_title.strip() else "知识专库"
1528
1534
  return f"""
1529
1535
  <section class="view" id="view-library" aria-label="知识专库">
1530
1536
  <div class="lib-head">
1531
- <div class="lib-title"><b>知识专库</b>
1532
- <span>共 {len(sources)} 条 · 已引用 {len(used_sources)} · {esc(badge)}</span>
1533
- </div>
1537
+ <div class="lib-title"><b>{esc(lib_title)}</b></div>
1534
1538
  <div class="lib-searchWrap">
1535
1539
  <span class="lib-searchIcon" aria-hidden="true">⌕</span>
1536
1540
  <input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="搜索来源文章">
1537
1541
  </div>
1538
- {hot_html}
1539
1542
  <div class="lib-tabs" role="tablist" aria-label="按检索分组筛选">{"".join(tabs)}</div>
1540
1543
  </div>
1541
1544
  <div class="lib-list" id="lib-list">{cards_html}</div>
1542
1545
  <div class="lib-empty hide" id="lib-empty">没有符合当前筛选的来源文章。</div>
1543
- <div class="lib-foot">来源:深知可信搜索 · 每条摘录均取自原文原段</div>
1546
+ <div class="lib-foot">来源:深知可信搜索 · 每段摘录均取自原文原段</div>
1544
1547
  </section>"""
1545
1548
 
1546
1549
 
@@ -1558,7 +1561,7 @@ def render_toc(sections: List[Dict[str, Any]], extra: str = "") -> str:
1558
1561
  continue # 导语内容照常在正文展示,只是不占目录条目
1559
1562
  number, title_text = split_heading_number(title)
1560
1563
  label = f"{number} {title_text}" if (number and title_text) else title_text
1561
- items.append(f'<a href="#sec-{i}">{esc(short(label, 16))}</a>')
1564
+ items.append(f'<a href="#sec-{i}" data-sec="{i}">{esc(short(label, 16))}</a>')
1562
1565
  if len(items) < 6 and not extra:
1563
1566
  return ""
1564
1567
  items.append(extra)
@@ -1594,9 +1597,10 @@ def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dk
1594
1597
  normalized = normalized.strip("._-")
1595
1598
  if not normalized:
1596
1599
  normalized = fallback
1597
- suffix = timestamp.strftime("%Y%m%d_%H%M")
1600
+ # 1.5.0:产物名即《标题.html》(无"_溯源核验报告"后缀、无时间戳);同题重跑的
1601
+ # _v2/_v3 版本化由 unique_output_path 的同名检测负责,不依赖时间戳
1598
1602
  stem = normalized[:32].strip("._-") or fallback
1599
- return f"{stem}_{suffix}{suffix_ext}"
1603
+ return f"{stem}{suffix_ext}"
1600
1604
 
1601
1605
 
1602
1606
  # ============================================================
@@ -1638,15 +1642,20 @@ a{color:var(--brand)}
1638
1642
  @media(max-width:900px){.viz-duo{grid-template-columns:1fr}}
1639
1643
 
1640
1644
  /* ===== 顶栏 ===== */
1641
- .topbar{position:sticky;top:0;z-index:50;display:flex;justify-content:space-between;align-items:center;gap:10px;
1642
- padding:9px 22px;background:rgba(255,255,255,.92);backdrop-filter:blur(10px);
1643
- border-bottom:1px solid var(--line)}
1644
- .tb-left{display:flex;align-items:center;gap:10px;min-width:0}
1645
- .tb-stamp{flex:none;font-size:12.5px;font-weight:800;color:var(--navy);letter-spacing:4px;text-indent:4px}
1646
- .tb-stamp::before,.tb-stamp::after{content:"";display:inline-block;width:22px;border-top:1px solid var(--line-strong);
1645
+ .banner{position:sticky;top:0;z-index:50;background:rgba(255,255,255,.94);backdrop-filter:blur(10px);
1646
+ border-bottom:1px solid var(--line);padding:8px 22px 9px}
1647
+ .banner-bar{display:flex;align-items:center;gap:14px;max-width:1080px;margin:0 auto}
1648
+ .banner-bar .tb-title{flex:0 1 auto;min-width:0;max-width:30%;overflow:hidden;text-overflow:ellipsis;
1649
+ white-space:nowrap;color:var(--muted);font-size:12.5px}
1650
+ .banner-bar .view-switch{margin:0 auto}
1651
+ .banner-bar .tb-tools{flex:0 0 auto}
1652
+ .banner-bar .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
1653
+ .banner-bar .view-switch button{color:#70678a;padding:6px 18px;font-size:13px}
1654
+ .banner-bar .view-switch button.on{background:var(--grad);color:#fff}
1655
+ .banner .orig-q{max-width:1080px;margin:7px auto 0;color:var(--ink);font-size:13.5px;line-height:1.6;text-align:center}
1656
+ .banner .orig-q b{color:var(--brand);margin-right:2px}
1657
+ .banner .meta{max-width:1080px;margin:3px auto 0;color:var(--muted);font-size:11.5px;letter-spacing:.3px;text-align:center}
1647
1658
  vertical-align:middle;margin:0 6px}
1648
- .tb-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted);font-size:13px}
1649
- .tb-right{display:flex;align-items:center;gap:8px;flex:none}
1650
1659
  .view-switch{display:inline-flex;border:1px solid var(--line);border-radius:999px;overflow:hidden;background:#fff}
1651
1660
  .view-switch button{border:0;background:transparent;color:var(--muted);font-size:12.5px;font-weight:700;
1652
1661
  padding:5px 14px;cursor:pointer}
@@ -1667,33 +1676,21 @@ a{color:var(--brand)}
1667
1676
  .progress{position:absolute;left:0;right:0;bottom:-1px;height:2px;background:transparent}
1668
1677
  .progress i{display:block;height:100%;width:0;background:linear-gradient(90deg,#6512ad,#8b5cf6)}
1669
1678
 
1670
- /* ===== Hero ===== */
1671
- .hero{position:relative;background:linear-gradient(180deg,#fbfaff 0%,#f7f4fd 100%);
1672
- color:var(--ink);padding:32px 22px 58px;text-align:center;border-bottom:1px solid var(--line)}
1673
- .r-badge{display:inline-flex;align-items:center;gap:14px;margin:0 0 8px;
1674
- background:var(--grad);color:#fff;border-radius:999px;padding:4px 22px;
1675
- font-size:15px;font-weight:800;letter-spacing:7px;text-indent:7px;line-height:1.6;
1676
- box-shadow:0 2px 8px rgba(101,18,173,.22)}
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)}
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}
1683
- .hero-switch{margin-top:16px;display:flex;justify-content:center}
1684
- .hero-switch .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
1685
- .hero-switch .view-switch button{color:#70678a;padding:6px 22px;font-size:13px}
1686
- .hero-switch .view-switch button.on{background:var(--grad);color:#fff}
1687
1679
 
1688
1680
  /* ===== 容器与视图 ===== */
1689
1681
  .container{max-width:1080px;margin:0 auto;padding:0 18px}
1690
- .app[data-view="library"] #view-report{display:none}
1691
- #view-library{display:none}
1682
+ #view-body,#view-report,#view-library{display:none}
1683
+ .app[data-view="body"] #view-body{display:block}
1684
+ .app[data-view="report"] #view-report{display:block}
1692
1685
  .app[data-view="library"] #view-library{display:block}
1686
+ #view-body{padding-bottom:26px}
1687
+ /* 文头标题(正文页/报告页各自成档的居中标题) */
1688
+ .paper-title{margin:14px 0 18px;font-size:20px;font-weight:800;color:var(--ink);text-align:center;line-height:1.55;letter-spacing:.3px}
1689
+ @media (max-width:680px){.paper-title{font-size:17.5px;margin-bottom:16px}}
1693
1690
 
1694
1691
  /* ===== 过程回顾条 ===== */
1695
1692
  .process{background:#fff;border:1px solid var(--line);border-radius:14px;box-shadow:var(--shadow-1);
1696
- padding:15px 20px 13px;margin:-36px auto 16px;position:relative}
1693
+ padding:15px 20px 13px;margin:0 auto 16px;position:relative}
1697
1694
  .p-head{display:flex;align-items:baseline;gap:10px;margin-bottom:10px}
1698
1695
  .p-head b{font-size:14.5px;color:var(--navy);letter-spacing:1px}
1699
1696
  .p-head span{font-size:11.5px;color:var(--muted)}
@@ -1745,6 +1742,13 @@ a{color:var(--brand)}
1745
1742
  .vi .s.none{color:var(--muted)}
1746
1743
  .vi .d{color:var(--muted);min-width:0}
1747
1744
  .v-note{margin-top:11px;padding-top:9px;border-top:1px dashed var(--line);font-size:11.5px;color:var(--muted);line-height:1.7}
1745
+ .v-checks{margin-top:9px}
1746
+ .v-checks summary{cursor:pointer;color:var(--brand);font-weight:700;font-size:12.5px;list-style:none;display:inline-flex;align-items:center;gap:5px}
1747
+ .v-checks summary::-webkit-details-marker{display:none}
1748
+ .v-checks summary::before{content:"+";font-weight:700;font-size:12px}
1749
+ .v-checks[open] summary::before{content:"-"}
1750
+ .v-checks ul{margin:7px 0 0 4px;padding-left:16px}
1751
+ .v-checks li{font-size:12.5px;color:var(--sub);line-height:1.72;margin:5px 0}
1748
1752
 
1749
1753
  /* 正文(原型复刻):章节 / 段落 / 角标 / 句后溯源卡 */
1750
1754
  .doc-paper{background:#fff;border-radius:14px;box-shadow:var(--shadow-1);padding:26px 34px 22px;margin:0 0 16px}
@@ -1825,29 +1829,23 @@ a.jb-quote{text-decoration:none}
1825
1829
  #view-library{padding:26px 0 30px}
1826
1830
  .lib-head{max-width:860px;margin:0 auto 16px;text-align:center}
1827
1831
  .lib-title{margin-bottom:14px}
1828
- .lib-title b{font-size:17px;color:var(--navy);letter-spacing:2px}
1829
- .lib-title span{display:block;font-size:12px;color:var(--muted);margin-top:2px}
1832
+ .lib-title b{font-size:16px;color:var(--navy);letter-spacing:.5px;line-height:1.5}
1830
1833
  .lib-searchWrap{position:relative;max-width:620px;margin:0 auto}
1831
1834
  .lib-searchIcon{position:absolute;left:14px;top:50%;transform:translateY(-50%);color:#a6adbd;font-size:16px;font-weight:700}
1832
1835
  .lib-search{width:100%;padding:11px 16px 11px 38px;border:1.5px solid var(--line-strong);border-radius:999px;
1833
1836
  font-size:14px;background:#fff;box-shadow:var(--shadow-1);outline:none}
1834
1837
  .lib-search:focus{border-color:var(--brand-2);box-shadow:0 0 0 3px rgba(139,92,246,.18)}
1835
- .hot-terms{display:flex;flex-wrap:wrap;justify-content:center;gap:7px;margin-top:12px;align-items:center}
1836
- .hot-label{font-size:12px;color:var(--muted)}
1837
- .hot-term{border:0;border-radius:999px;background:var(--brand-soft);color:var(--brand);
1838
- font-size:12.3px;font-weight:700;padding:3px 13px;cursor:pointer}
1839
- .hot-term:hover{background:var(--grad);color:#fff}
1840
1838
  .lib-tabs{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin-top:14px}
1841
1839
  .lib-tabs button{border:1px solid var(--line);border-radius:999px;background:#fff;color:var(--muted);
1842
1840
  padding:4px 13px;font-size:12.3px;cursor:pointer}
1843
1841
  .lib-tabs button.on{background:var(--grad);border-color:var(--brand);color:#fff;font-weight:700}
1844
- .lib-list{max-width:860px;margin:0 auto;display:grid;grid-template-columns:1fr;gap:14px}
1842
+ .lib-list{max-width:860px;margin:0 auto;display:grid;grid-template-columns:minmax(0,1fr);gap:14px}
1845
1843
  .lib-empty{max-width:860px;margin:30px auto;text-align:center;color:var(--muted);font-size:13.5px}
1846
1844
  .lib-empty.hide{display:none}
1847
1845
  .lib-foot{text-align:center;color:var(--muted);font-size:11.5px;padding:18px 0 0;line-height:1.8}
1848
1846
 
1849
1847
  /* ===== 材料卡 ===== */
1850
- .scard{border:1px solid var(--line);border-left-width:3px;border-radius:12px;padding:14px 18px;
1848
+ .scard{min-width:0;border:1px solid var(--line);border-left-width:3px;border-radius:12px;padding:14px 18px;
1851
1849
  background:#fff;box-shadow:var(--shadow-1);transition:box-shadow .25s}
1852
1850
  .scard:hover{box-shadow:var(--shadow-2)}
1853
1851
  .scard.pol{border-left-color:var(--policy)}
@@ -1905,9 +1903,6 @@ a.jb-quote{text-decoration:none}
1905
1903
 
1906
1904
  .foot{text-align:center;color:var(--muted);font-size:11.5px;padding:16px 0 4px;line-height:1.8}
1907
1905
 
1908
- /* ===== 只看正文(纯净阅读态) ===== */
1909
- body.reading .process,body.reading .verify,body.reading .jb,body.reading .sec-badge,
1910
- body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!important}
1911
1906
 
1912
1907
  /* ===== 打印附录 ===== */
1913
1908
  .print-appendix{display:none}
@@ -1917,23 +1912,20 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
1917
1912
  .sheet{display:none}
1918
1913
  @media (max-width:680px){
1919
1914
  body{font-size:14px;line-height:1.8}
1920
- .topbar{padding:7px 10px;gap:6px}
1921
- .tb-stamp{font-size:11px;letter-spacing:2px;text-indent:2px}
1922
- .tb-stamp::before,.tb-stamp::after{width:12px;margin:0 4px}
1923
- .tb-title{display:none}
1924
- .topbar .view-switch{display:none}
1915
+ .banner{padding:6px 10px 7px}
1916
+ .banner-bar{flex-wrap:wrap;justify-content:center;gap:7px}
1917
+ .banner-bar .tb-title{display:none}
1918
+ .banner-bar .view-switch{margin:0}
1919
+ .banner-bar .view-switch button{padding:5px 11px;font-size:12px}
1925
1920
  .tb-tools button{font-size:11.5px;padding:4px 8px}
1926
- .hero{padding:24px 14px 50px}
1927
1921
  .ch-head{gap:8px;margin-bottom:14px;flex-wrap:nowrap}
1928
1922
  .ch-head h2{font-size:17px;line-height:1.45}
1929
1923
  .ch-head::after{display:none}
1930
1924
  .ch-head .sec-badge{font-size:10.5px;padding:2px 7px;white-space:nowrap}
1931
1925
  .jb-name{max-width:calc(100vw - 72px)}
1932
- .r-badge{font-size:13.5px;letter-spacing:6px;text-indent:6px;gap:10px}
1933
- .hero h1{font-size:18.5px}
1934
- .hero .meta{font-size:11.5px;line-height:1.7}
1935
- .hero-switch .view-switch button{padding:6px 16px;font-size:12.5px}
1936
- .process{margin-top:-30px;padding:12px 12px 11px}
1926
+ .banner .meta{font-size:11px;line-height:1.6}
1927
+ .banner .orig-q{font-size:12.5px}
1928
+ .process{padding:12px 12px 11px}
1937
1929
  .p-step{flex:1 1 100%}
1938
1930
  .p-arrow{display:none}
1939
1931
  .verify{padding:13px 14px}
@@ -1958,7 +1950,7 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
1958
1950
  -webkit-overflow-scrolling:touch;scrollbar-width:none}
1959
1951
  .lib-tabs::-webkit-scrollbar{display:none}
1960
1952
  .lib-tabs button{flex:none}
1961
- .lib-list{grid-template-columns:1fr;gap:10px}
1953
+ .lib-list{grid-template-columns:minmax(0,1fr);gap:10px}
1962
1954
  .scard{padding:10px 11px}
1963
1955
  .crumb{font-size:11px}
1964
1956
  .sc-excerpt{font-size:11.5px}
@@ -1992,19 +1984,26 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
1992
1984
 
1993
1985
  /* ===== 打印归档 ===== */
1994
1986
  @media print{
1995
- .topbar,.process .p-detail,.hero-switch,.tb-tools,.view-switch,.lib-head,.toc,.sheet,.sheet-mask,
1987
+ .banner-bar,.process .p-detail,.lib-head,.toc,.sheet,.sheet-mask,
1996
1988
  .progress{display:none!important}
1997
- #view-library{display:none!important}
1998
- #view-report{display:block!important}
1999
- .app[data-view="library"] #view-report{display:block!important}
2000
- .hero{background:none;border:0;color:var(--ink);padding:10px 0 4px}
2001
- .hero .meta{color:var(--muted)}
1989
+ .banner{position:static;background:none;border:0;padding:0 0 6px}
1990
+ .banner .orig-q{text-align:left;font-size:13px}
1991
+ .banner .meta{color:var(--muted);text-align:left}
1992
+ /* 完整归档:三页顺序打印(正文 → 溯源核验报告 → 知识专库)+ 来源附录;
1993
+ 仅正文模式(body.print-body-only)只保留 #view-body */
1994
+ #view-body,#view-report,#view-library{display:block!important}
1995
+ .app[data-view] #view-body,.app[data-view] #view-report,.app[data-view] #view-library{display:block!important}
1996
+ body.print-body-only #view-report,body.print-body-only #view-library,body.print-body-only .print-appendix,
1997
+ body.print-body-only .jb,body.print-body-only .foot{display:none!important}
1998
+ #view-body .doc-paper,#view-report .doc-paper{break-after:page}
1999
+
2002
2000
  *{-webkit-print-color-adjust:exact;print-color-adjust:exact}
2003
2001
  .process{box-shadow:none;margin:6px 0 12px}
2004
2002
  .verify{border-color:#bbb;box-shadow:none;break-inside:avoid}
2005
2003
  .doc-paper{box-shadow:none;border-radius:0;padding:0}
2006
2004
  body{background:#fff;font-size:12.5px}
2007
2005
  .sc-excerpt{display:block;-webkit-line-clamp:unset;cursor:auto}
2006
+ .sc-excerpt.rich table,.print-appendix .sc-excerpt.rich table{width:100%!important;min-width:0}
2008
2007
  .scard{break-inside:avoid}
2009
2008
  .cite{background:none!important;color:#333!important;text-decoration:none!important}
2010
2009
  .cite::before{content:"["}.cite::after{content:"]"}
@@ -2015,8 +2014,6 @@ body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!importa
2015
2014
  .jb.active{break-inside:avoid}
2016
2015
  .jb.active .jb-body{display:block!important}
2017
2016
  .jb.active .jb-body .jb-quote{break-inside:avoid}
2018
- body.reading .verify,body.reading .process,body.reading .ev-row,body.reading .sec-badge,
2019
- body.reading .cite{display:none!important}
2020
2017
  .print-appendix{display:block;break-before:page}
2021
2018
  body.print-body-only .verify,body.print-body-only .process,body.print-body-only .print-appendix,
2022
2019
  body.print-body-only .jb,body.print-body-only .foot{display:none!important}
@@ -2034,8 +2031,9 @@ PAGE_JS = """
2034
2031
  var app = $(".app");
2035
2032
  var isMobile = function () { return window.matchMedia("(max-width:680px)").matches; };
2036
2033
 
2037
- /* ===== 1. 双视图切换(保存/恢复各自滚动位置) ===== */
2038
- var savedScroll = { report: 0, library: 0 };
2034
+ /* ===== 1. 三页切换(正文 / 溯源核验报告 / 知识专库;保存/恢复各自滚动位置) ===== */
2035
+ var savedScroll = { body: 0, report: 0, library: 0 };
2036
+ var viewChangeHook = null; /* 切页后重算目录锚点等 */
2039
2037
  function setView(view) {
2040
2038
  if (!app || app.getAttribute("data-view") === view) return;
2041
2039
  savedScroll[app.getAttribute("data-view") || "report"] = window.scrollY;
@@ -2044,6 +2042,7 @@ PAGE_JS = """
2044
2042
  b.classList.toggle("on", b.getAttribute("data-view") === view);
2045
2043
  });
2046
2044
  window.scrollTo(0, Math.max(0, savedScroll[view] || 0));
2045
+ if (viewChangeHook) viewChangeHook(view);
2047
2046
  }
2048
2047
  $$(".view-switch button").forEach(function (b) {
2049
2048
  b.addEventListener("click", function () { setView(b.getAttribute("data-view")); });
@@ -2060,26 +2059,14 @@ PAGE_JS = """
2060
2059
  window.addEventListener("scroll", updateProgress, { passive: true });
2061
2060
  updateProgress();
2062
2061
 
2063
- /* ===== 3. 只看正文(纯净阅读态切换) ===== */
2064
- var readBtn = $("#btn-reading");
2065
- if (readBtn) {
2066
- readBtn.addEventListener("click", function () {
2067
- var on = document.body.classList.toggle("reading");
2068
- readBtn.setAttribute("aria-pressed", on ? "true" : "false");
2069
- readBtn.textContent = on ? "显示核验" : "只看正文";
2070
- /* 只看正文只作用于核验报告视图:正在知识专库时切回报告,专库不受影响 */
2071
- if (on && app && app.getAttribute("data-view") !== "report") setView("report");
2072
- });
2073
- }
2074
-
2075
- /* ===== 4. 复制全文(章节标题 + 段落 + 表格,去角标) ===== */
2062
+ /* ===== 3. 复制全文(从正文页取:章节标题 + 段落 + 表格,干净无角标) ===== */
2076
2063
  var copyBtn = $("#btn-copy");
2077
2064
  if (copyBtn) {
2078
2065
  copyBtn.addEventListener("click", function () {
2079
2066
  var parts = [];
2080
2067
  /* 按文档流顺序收集章节标题/段落/表格;克隆后剔除引文胶囊与角标,
2081
2068
  只复制正文本身(胶囊标题/展开摘录/编号数字均不带出) */
2082
- var nodes = $$("#view-report .ch-head h2, #view-report .lead, #view-report .para, #view-report .tbl-wrap");
2069
+ var nodes = $$("#view-body .ch-head h2, #view-body .lead, #view-body .para, #view-body .tbl-wrap");
2083
2070
  nodes.sort(function (a, b) { return (a.compareDocumentPosition(b) & 4) ? -1 : 1; });
2084
2071
  nodes.forEach(function (el) {
2085
2072
  var clone = el.cloneNode(true);
@@ -2114,26 +2101,45 @@ PAGE_JS = """
2114
2101
  });
2115
2102
  }
2116
2103
 
2117
- /* ===== 5. 打印归档(PDF):下拉双选项——只打印正文 / 完整归档 ===== */
2118
- var printBtn = $("#btn-print");
2119
- var printDrop = $("#print-drop");
2104
+ /* ===== 5. 导出:正文 Markdown / PDF(浏览器打印另存为 PDF) ===== */
2105
+ var exportBtn = $("#btn-export");
2106
+ var exportDrop = $("#export-drop");
2107
+ function docTitleForFile() {
2108
+ var t = $(".tb-title");
2109
+ var name = (t ? t.textContent.trim() : "") || document.title || "文稿";
2110
+ return name.replace(/[\\/:*?"<>|]+/g, "_").trim() || "文稿";
2111
+ }
2112
+ function exportMarkdown() {
2113
+ var el = document.getElementById("doc-export");
2114
+ var data = { title: docTitleForFile(), markdown: "" };
2115
+ if (el) { try { data = JSON.parse(el.textContent) || data; } catch (err) {} }
2116
+ var blob = new Blob([data.markdown || ""], { type: "text/markdown;charset=utf-8" });
2117
+ var url = URL.createObjectURL(blob);
2118
+ var a = document.createElement("a");
2119
+ a.href = url;
2120
+ a.download = (data.title || docTitleForFile()) + ".md";
2121
+ document.body.appendChild(a);
2122
+ a.click();
2123
+ setTimeout(function () { URL.revokeObjectURL(url); if (a.parentNode) a.parentNode.removeChild(a); }, 800);
2124
+ }
2120
2125
  function printBy(mode) {
2121
2126
  if (mode === "body") document.body.classList.add("print-body-only");
2122
- if (printDrop) printDrop.hidden = true;
2127
+ if (exportDrop) exportDrop.hidden = true;
2123
2128
  window.print();
2124
2129
  }
2125
- if (printBtn && printDrop) {
2126
- printBtn.addEventListener("click", function (e) {
2130
+ if (exportBtn && exportDrop) {
2131
+ exportBtn.addEventListener("click", function (e) {
2127
2132
  e.stopPropagation();
2128
- printDrop.hidden = !printDrop.hidden;
2133
+ exportDrop.hidden = !exportDrop.hidden;
2129
2134
  });
2130
- printDrop.addEventListener("click", function (e) {
2135
+ exportDrop.addEventListener("click", function (e) {
2131
2136
  e.stopPropagation();
2132
2137
  var t = e.target.closest("button");
2133
2138
  if (!t) return;
2134
- printBy(t.id === "print-body" ? "body" : "full");
2139
+ if (t.id === "export-md") { exportMarkdown(); exportDrop.hidden = true; return; }
2140
+ printBy(t.id === "export-pdf-body" ? "body" : "full");
2135
2141
  });
2136
- document.addEventListener("click", function () { printDrop.hidden = true; });
2142
+ document.addEventListener("click", function () { exportDrop.hidden = true; });
2137
2143
  /* 打印结束移除临时模式(浏览器打印窗口关闭后触发) */
2138
2144
  window.addEventListener("afterprint", function () { document.body.classList.remove("print-body-only"); });
2139
2145
  }
@@ -2295,15 +2301,6 @@ PAGE_JS = """
2295
2301
  });
2296
2302
  var search = $(".lib-search");
2297
2303
  if (search) search.addEventListener("input", function () { kw = search.value.trim().toLowerCase(); applyFilter(); });
2298
- $$(".hot-term").forEach(function (t) {
2299
- t.addEventListener("click", function () {
2300
- if (!search) return;
2301
- search.value = t.textContent.trim();
2302
- kw = search.value.toLowerCase();
2303
- applyFilter();
2304
- if (search.focus) search.focus();
2305
- });
2306
- });
2307
2304
 
2308
2305
  /* ===== 8. 过程回顾条:检索步骤展开 ===== */
2309
2306
  var pStep = $("#p-step-search");
@@ -2320,15 +2317,26 @@ PAGE_JS = """
2320
2317
  var toc = $(".toc");
2321
2318
  if (toc) {
2322
2319
  var links = $$("a", toc);
2323
- var secs = links.map(function (a) { return document.querySelector(a.getAttribute("href")); });
2320
+ /* 正文页锚 sec-N / 报告页锚 rsec-N:href 只是兜底,实际按当前视图前缀定位 */
2321
+ function tocPrefix() {
2322
+ var v = app ? app.getAttribute("data-view") : "";
2323
+ return v === "report" ? "rsec" : (v === "body" ? "sec" : "");
2324
+ }
2325
+ function tocSecs() {
2326
+ var pfx = tocPrefix();
2327
+ if (!pfx) return [];
2328
+ return links.map(function (a) { return document.getElementById(pfx + "-" + a.getAttribute("data-sec")); });
2329
+ }
2330
+ var secs = tocSecs();
2324
2331
  links.forEach(function (a) {
2325
2332
  a.addEventListener("click", function (e) {
2326
2333
  e.preventDefault();
2327
- var target = document.querySelector(a.getAttribute("href"));
2334
+ var pfx = tocPrefix();
2335
+ var target = pfx ? document.getElementById(pfx + "-" + a.getAttribute("data-sec")) : null;
2328
2336
  if (!target) return;
2329
2337
  /* 手动定位而非 scrollIntoView({block:"start"}):后者把标题顶到视口 y=0,
2330
2338
  会被 sticky 顶栏盖住。偏移量与目录吸顶位置同一基准(顶栏高 + 20px)。 */
2331
- var bar = document.querySelector(".topbar");
2339
+ var bar = document.querySelector(".banner");
2332
2340
  var offset = (bar ? bar.offsetHeight : 0) + 20;
2333
2341
  var y = target.getBoundingClientRect().top + window.scrollY - offset;
2334
2342
  window.scrollTo({ top: Math.max(0, y), behavior: "smooth" });
@@ -2346,16 +2354,18 @@ PAGE_JS = """
2346
2354
  齐平、离正文很远。改为——直接跟随正文首节,只保留"不低于顶栏下方"的下限;首屏看不到
2347
2355
  目录属正常,向下滚动后自然吸附在顶栏下方。目录过长由 CSS max-height:60vh+overflow:auto
2348
2356
  内部滚动兜底。 */
2349
- var topbar = document.querySelector(".topbar");
2357
+ var bannerEl = document.querySelector(".banner");
2350
2358
  function placeToc() {
2351
2359
  var first = secs[0];
2352
2360
  if (!first) return;
2353
- var stick = (topbar ? topbar.offsetHeight : 0) + 20;
2361
+ var stick = (bannerEl ? bannerEl.offsetHeight : 0) + 20;
2354
2362
  var want = Math.round(first.getBoundingClientRect().top);
2355
2363
  toc.style.top = Math.max(stick, want) + "px";
2356
2364
  }
2357
2365
  window.addEventListener("scroll", placeToc, { passive: true });
2358
2366
  window.addEventListener("resize", placeToc);
2367
+ /* 切页时重算锚点集合与高亮(正文页 sec-N / 报告页 rsec-N;专库页隐藏目录) */
2368
+ viewChangeHook = function () { secs = tocSecs(); spy(); placeToc(); };
2359
2369
  placeToc();
2360
2370
  spy();
2361
2371
  }
@@ -2366,9 +2376,20 @@ PAGE_JS = """
2366
2376
  def render_html(payload: Dict[str, Any], title: str, answer_override: str = "", question_override: str = "",
2367
2377
  generated_at: Optional[datetime] = None,
2368
2378
  skip_link_check: bool = False, snapshot_enabled: bool = True,
2369
- charts_data: Optional[Dict[str, Any]] = None) -> str:
2379
+ charts_data: Optional[Dict[str, Any]] = None,
2380
+ research_notes: Optional[Dict[str, int]] = None) -> str:
2370
2381
  payload = unwrap(payload)
2371
2382
  answer = normalize_citations(answer_override) if answer_override.strip() else extract_answer(payload)
2383
+ # 无 markdown 标题的答案:首个非空行若为短标题形态(≤60 字、非列表/表格/标题语法、
2384
+ # 不以句读结尾),升格为 `# 标题` 行——文头标题、章节卡、TOC、图表锚点全链路随 heading
2385
+ # 自然工作,标题行不再在正文重复渲染(2026-10-14 修复:实测纯文本首行答案的报告页
2386
+ # 文头显示"溯源核验报告:溯源核验报告"、图表锚点随之失配)
2387
+ if not re.search(r"(?m)^#{1,4}\s", answer):
2388
+ _first = next((ln.strip() for ln in answer.splitlines() if ln.strip()), "")
2389
+ if (_first and len(_first) <= 60 and not re.match(r"^[-*>|#\d|\|]", _first)
2390
+ and not _first.endswith(("。", ";", "!", "?", "!", "?", ".", ";"))):
2391
+ _rest = answer[answer.index(_first) + len(_first):].lstrip("\n")
2392
+ answer = f"# {_first}\n{_rest}"
2372
2393
  sources = align_sources_to_answer(answer, extract_sources(payload, skip_link_check=skip_link_check, snapshot_enabled=snapshot_enabled))
2373
2394
  # 角标按首次出现顺序重排为 1..N(含材料卡同步重编号与未引用分组),WorkBuddy 实测反馈要求
2374
2395
  answer, sources = renumber_citations(answer, sources)
@@ -2378,7 +2399,8 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
2378
2399
 
2379
2400
  verification = compute_verification(answer, sources, payload, generated_at)
2380
2401
  process_stats = compute_process_stats(sources, answer)
2381
- hot_terms = extract_hot_terms(answer, sources)
2402
+ if research_notes:
2403
+ process_stats["research_notes"] = research_notes
2382
2404
  citation_warning = ""
2383
2405
  if sources and not used:
2384
2406
  citation_warning = (
@@ -2396,26 +2418,55 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
2396
2418
  jb_tables[key] = html
2397
2419
  doc_title, sections = group_sections(blocks)
2398
2420
  display_title = doc_title or title
2421
+ # 正文页:同一份正文去掉全部角标/引文胶囊,输出干净正式内容(核验内容归"溯源核验报告"页)
2422
+ clean_blocks, _ = parse_answer_blocks(answer, {s["id"] for s in sources}, chip_map, strip_cites=True)
2423
+ _, clean_sections = group_sections(clean_blocks)
2399
2424
  # 原问题行(2026-10-08 起):只显示 --question 显式传入的原始问题,
2400
- # 不用文档标题冒充(标题是答案的成稿名,不是用户原话)。未传则整行不渲染。
2425
+ # 不用文档标题冒充(标题是答案的成稿名,不是用户原话);为空或与标题相同时不显示
2426
+ question_text = (question_override or "").strip()
2401
2427
  hero_question = (
2402
- f'<div class="hero-q"><span class="q-label">原问题</span>{esc(question_override.strip())}</div>'
2403
- if question_override.strip() else ""
2428
+ f'<div class="orig-q" title="{esc(question_text)}"><b>原问题</b>:{esc(question_text)}</div>'
2429
+ if question_text and question_text != display_title else ""
2404
2430
  )
2405
2431
 
2406
2432
  jb_tables_json = json.dumps(jb_tables, ensure_ascii=False).replace("</", "<\\/")
2407
2433
  jb_tables_script = (f'<script type="application/json" id="jb-tables">{jb_tables_json}</script>\n'
2408
2434
  if jb_tables else "")
2435
+ # 导出用正文 Markdown(去角标,干净正文),供顶部"导出 ▾ → 导出 Markdown(正文)"下载
2436
+ export_payload = {"title": display_title, "markdown": strip_citation_markers(answer)}
2437
+ export_json = json.dumps(export_payload, ensure_ascii=False).replace("</", "<\\/")
2438
+ export_script = f'<script type="application/json" id="doc-export">{export_json}</script>\n'
2409
2439
 
2410
2440
  meta_bits = []
2411
2441
  if process_stats["n_searches"]:
2412
- meta_bits.append(f"深知检索 {process_stats['n_searches']} 路")
2442
+ # 检索计数按接口通道拆分显示(深度搜索与可信搜索是两个接口来源)
2443
+ _deep_n = process_stats.get("deep_routes", 0)
2444
+ _trusted_n = process_stats.get("trusted_routes", 0)
2445
+ if _deep_n and _trusted_n:
2446
+ meta_bits.append(f"深度搜索 {_deep_n} 路 · 可信补搜 {_trusted_n} 次")
2447
+ elif _deep_n:
2448
+ meta_bits.append(f"深知深度搜索 {_deep_n} 路")
2449
+ elif _trusted_n:
2450
+ meta_bits.append(f"深知可信搜索 {_trusted_n} 次")
2451
+ else:
2452
+ meta_bits.append(f"深知检索 {process_stats['n_searches']} 路")
2413
2453
  if sources:
2414
- meta_bits.append(f"来源文章 {len(sources)} 篇")
2454
+ meta_bits.append(f"知识专库文章 {len(sources)} 篇")
2415
2455
  if process_stats["n_cite_marks"]:
2416
- meta_bits.append(f"正文引用 {process_stats['n_cite_marks']} 处")
2456
+ meta_bits.append(f"正文实际引用 {process_stats['n_cite_marks']} 处")
2417
2457
  meta_bits.append(f"生成于 {generated}")
2418
2458
  meta_line = " · ".join(meta_bits)
2459
+ # 来源=材料实际使用的检索通道(深知深度搜索 / 深知可信搜索,动态汇总);
2460
+ # 历史产物无通道信息时保留旧文案
2461
+ # 通道 token 汇总:单条材料可能是双通道拼接值("深知深度搜索、深知可信搜索"),
2462
+ # 按 、 和 · 拆 token 去重再拼接,避免来源行出现重复或拼接串
2463
+ _channels: List[str] = []
2464
+ for s in sources:
2465
+ for _tok in re.split(r"[、·]", (s.get("channel") or "").strip()):
2466
+ _tok = _tok.strip()
2467
+ if _tok and _tok not in _channels:
2468
+ _channels.append(_tok)
2469
+ source_line = " · ".join(_channels) if _channels else "深知可信搜索"
2419
2470
 
2420
2471
  # 图表并入核验报告(1.4.0 一体化):有图表数据且包内 ECharts 可用时,
2421
2472
  # 图表并入核验报告(1.4.0 一体化)——交付物始终是**一个** HTML,不再另出独立图表报告。
@@ -2464,70 +2515,66 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
2464
2515
  <head>
2465
2516
  <meta charset="utf-8">
2466
2517
  <meta name="viewport" content="width=device-width, initial-scale=1">
2467
- <title>{esc(display_title)} · 溯源核验报告</title>
2518
+ <title>{esc(display_title)}</title>
2468
2519
  <style>{PAGE_CSS}</style>
2469
2520
  </head>
2470
2521
  <body>
2471
2522
 
2472
- <header class="topbar">
2473
- <div class="tb-left">
2474
- <span class="tb-stamp">溯源核验报告</span>
2523
+ <header class="banner">
2524
+ <div class="banner-bar">
2475
2525
  <span class="tb-title">{esc(display_title)}</span>
2476
- </div>
2477
- <div class="tb-right">
2478
- <div class="view-switch" role="tablist" aria-label="视图切换">
2479
- <button class="on" data-view="report" type="button">核验报告</button>
2480
- <button data-view="library" type="button">知识专库</button>
2526
+ <div class="view-switch" role="tablist" aria-label="页面切换">
2527
+ <button data-view="body" type="button">正文(去索引)</button>
2528
+ <button class="on" data-view="report" type="button">溯源核验报告</button>
2529
+ <button data-view="library" type="button">知识专库({len(sources)})</button>
2481
2530
  </div>
2482
2531
  <div class="tb-tools">
2483
- <button id="btn-reading" type="button" aria-pressed="false" title="隐藏核验元素,纯阅读正文">只看正文</button>
2484
2532
  <button id="btn-copy" type="button" title="复制正文纯文本">复制全文</button>
2485
2533
  <span class="print-menu">
2486
- <button id="btn-print" type="button" aria-haspopup="true" title="浏览器打印/另存为 PDF">打印归档 ▾</button>
2487
- <span class="print-drop" id="print-drop" hidden>
2488
- <button id="print-body" type="button">只打印正文</button>
2489
- <button id="print-full" type="button">完整归档(含来源文章)</button>
2534
+ <button id="btn-export" type="button" aria-haspopup="true" title="导出正文 Markdown 或 PDF">导出 ▾</button>
2535
+ <span class="print-drop" id="export-drop" hidden>
2536
+ <button id="export-md" type="button">导出 Markdown(正文)</button>
2537
+ <button id="export-pdf-body" type="button">导出 PDF(正文)</button>
2538
+ <button id="export-pdf-full" type="button">导出 PDF(溯源核验报告)</button>
2490
2539
  </span>
2491
2540
  </span>
2492
2541
  </div>
2493
2542
  </div>
2543
+ {hero_question}
2544
+ <div class="meta">{esc(meta_line)} | 来源:{esc(source_line)}</div>
2494
2545
  <div class="progress" aria-hidden="true"><i></i></div>
2495
2546
  </header>
2496
2547
 
2497
- <div class="hero">
2498
- <div class="r-badge">溯源核验报告</div>
2499
- <h1>{esc(display_title)}</h1>
2500
- {hero_question}
2501
- <div class="meta">{esc(meta_line)} | 素材来源:深知可信搜索</div>
2502
- <div class="hero-switch">
2503
- <div class="view-switch" role="tablist" aria-label="视图切换">
2504
- <button class="on" data-view="report" type="button">核验报告</button>
2505
- <button data-view="library" type="button">知识专库({len(sources)})</button>
2506
- </div>
2507
- </div>
2508
- </div>
2509
-
2510
2548
  <div class="app container" data-view="report">
2511
- {render_process_bar(process_stats, verification)}
2512
2549
 
2513
- <main class="view" id="view-report" aria-label="核验报告正文">
2550
+ <main class="view" id="view-body" aria-label="正文">
2551
+ <h2 class="paper-title">{esc(display_title)}</h2>
2552
+ <div class="doc-paper">
2553
+ {render_section_cards(clean_sections, sources, id_prefix="sec")}
2554
+ </div>
2555
+ <div class="foot">深知可信搜索 · 正文 | 内容由 AI 生成,仅供参考</div>
2556
+ </main>
2557
+
2558
+ <main class="view" id="view-report" aria-label="溯源核验报告">
2559
+ <h2 class="paper-title">溯源核验报告:{esc(display_title)}</h2>
2514
2560
  {citation_warning}
2561
+ {render_process_bar(process_stats, verification)}
2515
2562
  {render_verify_panel(verification)}
2516
2563
  {charts_html}
2517
2564
  <div class="doc-paper">
2518
- {render_section_cards(sections, sources, charts_by_section)}
2565
+ {render_section_cards(sections, sources, charts_by_section, id_prefix="rsec")}
2519
2566
  </div>
2520
2567
  <div class="foot">深知可信搜索 · 溯源核验报告 | 内容由 AI 生成,仅供参考</div>
2521
2568
  </main>
2522
2569
 
2523
- {render_library_view(sources, hot_terms)}
2570
+ {render_library_view(sources, display_title)}
2524
2571
  {render_print_appendix(sources)}
2525
2572
  </div>
2526
2573
 
2527
2574
  {render_toc(sections, chart_toc)}
2528
2575
 
2529
2576
  <div class="ev-panel" id="ev-pop" hidden></div>
2530
- {jb_tables_script}<div class="sheet-mask" aria-hidden="true"></div>
2577
+ {export_script}{jb_tables_script}<div class="sheet-mask" aria-hidden="true"></div>
2531
2578
  <div class="sheet" role="dialog" aria-label="来源文章">
2532
2579
  <div class="sheet-grab"></div>
2533
2580
  <div class="sheet-head"><b>依据对照</b><button class="sheet-close" type="button">收起</button></div>
@@ -2626,18 +2673,54 @@ def _next_version_path(path: Path) -> Path:
2626
2673
  raise SystemExit(f"错误:{path.name} 的版本号 _v2~_v99 均已占用,请清理 {path.parent} 后重试。")
2627
2674
 
2628
2675
 
2676
+ def parse_research_notes(text: str) -> Dict[str, int]:
2677
+ """统计研究资料 Markdown 的两张表行数:核心事实总表 / 数据口径表。
2678
+ 按二级/三级标题分节识别,表格行以 | 开头(跳过表头与 --- 分隔行);未识别到相应节时计 0。"""
2679
+ facts = 0
2680
+ calibers = 0
2681
+ current: Optional[str] = None
2682
+ lines = (text or "").splitlines()
2683
+ for i, line in enumerate(lines):
2684
+ stripped = line.strip()
2685
+ if stripped.startswith("#"):
2686
+ head = stripped.lstrip("#").strip()
2687
+ if "事实" in head:
2688
+ current = "facts"
2689
+ elif "口径" in head or "数据" in head:
2690
+ current = "calibers"
2691
+ else:
2692
+ current = None
2693
+ continue
2694
+ if not (current and stripped.startswith("|")):
2695
+ continue
2696
+ cells = [c.strip() for c in stripped.strip("|").split("|")]
2697
+ if cells and all(re.fullmatch(r":?-{2,}:?", c or "") for c in cells):
2698
+ continue # 表头分隔行
2699
+ prev = lines[i - 1].strip() if i > 0 else ""
2700
+ if prev.startswith("|") and i >= 2 and all(
2701
+ re.fullmatch(r":?-{2,}:?", c or "") for c in [x.strip() for x in prev.strip("|").split("|")]
2702
+ ):
2703
+ continue # 分隔行的前一行=表头行,不计数据
2704
+ if any(cells):
2705
+ if current == "facts":
2706
+ facts += 1
2707
+ else:
2708
+ calibers += 1
2709
+ return {"facts": facts, "calibers": calibers}
2710
+
2711
+
2629
2712
  def main() -> None:
2630
2713
  parser = argparse.ArgumentParser(description="生成溯源核验报告 HTML(深知可信搜索 SkillHub 版)")
2631
2714
  parser.add_argument("input_json", help="trusted_search.py / deep_query.py 的 --json-only 输出 JSON")
2632
- parser.add_argument("--output", help="输出 HTML 文件名(official-docs/output/);不传时按问题自动生成《标题_溯源核验报告_时间戳.html》")
2715
+ parser.add_argument("--output", help="输出 HTML 文件名(official-docs/output/,形如《标题.html》);不传时按问题自动生成《标题.html》。同题重跑自动 _v2 另存")
2633
2716
  parser.add_argument("--title", default="溯源核验报告", help="页面标题")
2634
2717
  parser.add_argument("--answer-file", help="最终答案文件(关键结论带 [1][2] 角标)。复杂任务综合后必须传入,确保 HTML 展示的答案与交付一致。")
2635
- parser.add_argument("--clean-md-output", help="输出干净 Markdown 路径;内容来自同一份最终答案,并移除 [1]、【1】等溯源角标。")
2636
2718
  parser.add_argument("--question", default="", help="用户原始问题,用于自动生成文件名。")
2637
2719
  parser.add_argument("--self-check-file", help="答案自检结果 JSON(五项:fact_basis/binding/consistency/freshness/no_gap,值写 通过/未通过:原因);未传时核验单如实显示'未记录'。")
2638
2720
  parser.add_argument("--skip-link-check", action="store_true", help="(兼容 no-op)链接活性检测已于 2026-10-08 移除,接口返回的链接原样进报告")
2639
2721
  parser.add_argument("--no-snapshot", action="store_true", help="关闭存档快照兜底展示(默认启用:原文失效时以 /A/ 修订后的存档快照回看)")
2640
2722
  parser.add_argument("--charts-json", help="图表数据:official-docs/search-results/ 内的 JSON 文件名,或直接内联 JSON。传入后图表并入本报告(一体化,不另出独立 HTML)。")
2723
+ parser.add_argument("--research-notes-file", help="研究资料 Markdown(核心事实总表 + 数据口径表);传入后 AI 自验收过程条体现整理规模,未传不显示该统计。")
2641
2724
  args = parser.parse_args()
2642
2725
 
2643
2726
  input_path = _safe_input_path(args.input_json, {".json"})
@@ -2689,21 +2772,18 @@ def main() -> None:
2689
2772
 
2690
2773
  output = _next_version_path(output)
2691
2774
  output.parent.mkdir(parents=True, exist_ok=True)
2775
+ research_notes = None
2776
+ if args.research_notes_file:
2777
+ _rn_path = _safe_input_path(args.research_notes_file, {".md", ".txt"})
2778
+ research_notes = parse_research_notes(_rn_path.read_text(encoding="utf-8"))
2779
+ print(f"研究资料统计:{research_notes['facts']} 项事实 · {research_notes['calibers']} 项口径")
2692
2780
  output.write_text(
2693
2781
  render_html(payload, args.title, answer_override=answer_override, question_override=args.question,
2694
2782
  generated_at=generated_at, skip_link_check=args.skip_link_check,
2695
- snapshot_enabled=snapshot_enabled, charts_data=resolve_charts_data(args.charts_json)),
2783
+ snapshot_enabled=snapshot_enabled, charts_data=resolve_charts_data(args.charts_json),
2784
+ research_notes=research_notes),
2696
2785
  encoding="utf-8")
2697
2786
  print(f"已生成:{output}")
2698
- if args.clean_md_output:
2699
- clean_output = _safe_output_path(args.clean_md_output, {".md"}, ".md")
2700
- else:
2701
- clean_output = _safe_output_path(output.with_suffix(".clean.md").name, {".md"}, ".md")
2702
- clean_output = _next_version_path(clean_output)
2703
- clean_output.parent.mkdir(parents=True, exist_ok=True)
2704
- clean_answer = strip_citation_markers(final_answer)
2705
- clean_output.write_text(clean_answer, encoding="utf-8")
2706
- print(f"已生成干净 Markdown:{clean_output}")
2707
2787
 
2708
2788
 
2709
2789
  if __name__ == "__main__":