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
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
"""可信溯源核验报告渲染器:把结构化正文/素材 JSON 渲染为单文件可核验 HTML。
|
|
3
3
|
|
|
4
4
|
报告定位:不止展示"材料从哪来"(溯源),更要传达"我们查过了,可以交付"(核验)。
|
|
5
|
-
3.7.0
|
|
5
|
+
3.7.0 架构(交互形态参考自研原型,数据口径保持自有与真实):
|
|
6
6
|
- 顶栏:身份章 + 标题 + 工具组(只看正文 / 复制全文 / 打印归档)+ 阅读进度条
|
|
7
7
|
- Hero:大标题 + 真实统计(N 次检索 · M 条材料 · K 处引用)+ 双视图切换
|
|
8
8
|
- 过程回顾条:检索 → 入库 → 逐条比对 → 核验完成(静态回放,数字全部真实计算;
|
|
9
9
|
无思考流数据就不展示"思考"步骤——硬造即违背核验诚实性)
|
|
10
|
-
- 核验报告视图(默认):核验报告单 +
|
|
11
|
-
-
|
|
10
|
+
- 核验报告视图(默认):核验报告单 + 正文分节卡;角标点击跳知识专库定位
|
|
11
|
+
- 知识专库视图(全屏):大搜索 + 热词(标题/正文高频词真实计算)+ 检索分组 tabs + 材料卡
|
|
12
12
|
三个核验层次:报告级(核验报告单)/材料级(来源卡核验链标记)/引用级(角标一一绑定)。
|
|
13
|
-
|
|
13
|
+
诚实原则:脚本真实计算的结果才打勾;无法自动判定的项不虚构展示("现行效力"人工复核提示行已按产品要求移除)。
|
|
14
14
|
布局为单文件静态 HTML;打印归档模式单栏全展开并附材料附录。
|
|
15
15
|
"""
|
|
16
16
|
|
|
@@ -226,7 +226,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
226
226
|
item.get("name"),
|
|
227
227
|
vo.get("showTitle"),
|
|
228
228
|
vo.get("title"),
|
|
229
|
-
"
|
|
229
|
+
"未命名来源文章",
|
|
230
230
|
),
|
|
231
231
|
"agency": first_str(
|
|
232
232
|
item.get("unit") if not isinstance(item.get("unit"), list) else "、".join(str(x) for x in item.get("unit")[:3]),
|
|
@@ -336,7 +336,18 @@ def extract_sources(payload: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
|
336
336
|
# 一篇材料一张卡:段落合并为摘录(paragraph_text 拼接全部段落),不按段落拆卡——
|
|
337
337
|
# 溯源 JSON 的 materials 与正文角标按"材料"粒度一一对应,拆段会使编号错位。
|
|
338
338
|
source = source_from_article(item, len(sources) + 1)
|
|
339
|
-
|
|
339
|
+
# 去重键(2026-10-08 修复):按归一化「标题 + URL」判同一篇,不含 source["id"]——
|
|
340
|
+
# id 是递增序号、每条都不同,旧键含 id 等于从不去重;可信搜索对同一篇文章按段落
|
|
341
|
+
# 返回多条片段时会全部出卡(曾出现同一篇文章同名卡片重复十余张的情况)。
|
|
342
|
+
# 标题或 URL 单独可用时退用其一,均缺失退用摘录前缀。
|
|
343
|
+
_t = re.sub(r"\s+", "", source["title"] or "")
|
|
344
|
+
_u = (source["url"] or "").strip().rstrip("/")
|
|
345
|
+
if _t and _u:
|
|
346
|
+
key = ("tu", _t, _u)
|
|
347
|
+
elif _t:
|
|
348
|
+
key = ("t", _t)
|
|
349
|
+
else:
|
|
350
|
+
key = ("x", (source["excerpt"] or "")[:120])
|
|
340
351
|
if key in seen:
|
|
341
352
|
continue
|
|
342
353
|
seen.add(key)
|
|
@@ -357,18 +368,18 @@ def extract_answer(payload: Dict[str, Any]) -> str:
|
|
|
357
368
|
return normalize_citations(answer)
|
|
358
369
|
articles = extract_articles_from_search(payload)
|
|
359
370
|
if articles:
|
|
360
|
-
rows = ["
|
|
371
|
+
rows = ["可信搜索召回了以下重点来源文章:"]
|
|
361
372
|
for idx, item in enumerate(articles[:8], start=1):
|
|
362
|
-
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '
|
|
373
|
+
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '未命名来源文章')}")
|
|
363
374
|
return "\n".join(rows)
|
|
364
375
|
deep_articles = extract_articles_from_deep(payload)
|
|
365
376
|
if deep_articles:
|
|
366
|
-
rows = ["
|
|
377
|
+
rows = ["深度搜索召回了以下重点来源文章:"]
|
|
367
378
|
for idx, item in enumerate(deep_articles[:8], start=1):
|
|
368
379
|
vo = item.get("vo") if isinstance(item.get("vo"), dict) else {}
|
|
369
|
-
rows.append(f"[{idx}] {first_str(vo.get('showTitle'), vo.get('title'), item.get('title'), '
|
|
380
|
+
rows.append(f"[{idx}] {first_str(vo.get('showTitle'), vo.get('title'), item.get('title'), '未命名来源文章')}")
|
|
370
381
|
return "\n".join(rows)
|
|
371
|
-
return "
|
|
382
|
+
return "接口返回中未识别到正文内容;请查看知识专库或原始 JSON。"
|
|
372
383
|
|
|
373
384
|
|
|
374
385
|
def extract_question(payload: Dict[str, Any]) -> str:
|
|
@@ -416,8 +427,9 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
416
427
|
"""把自检项的值解析为(状态, 核验说明)。
|
|
417
428
|
|
|
418
429
|
兼容多种写法:`pass` / `true` / `通过` / `通过:说明文字` / `✓` 等;
|
|
419
|
-
|
|
420
|
-
|
|
430
|
+
值后面的说明文字保留下来供核验单展示。红项(fail)只给显式声明的
|
|
431
|
+
"未通过";无法识别的描述性文本按"未记录"(none)处理不判红——
|
|
432
|
+
自检书写格式走样不应被放大成核验红项(模型写入"备注"等额外键曾导致交付前检查误判)。
|
|
421
433
|
"""
|
|
422
434
|
text = str(raw or "").strip()
|
|
423
435
|
lowered = text.lower()
|
|
@@ -427,7 +439,7 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
427
439
|
for prefix in ("已通过", "通过", "合格", "pass", "ok", "true", "是", "✓", "yes"):
|
|
428
440
|
if lowered.startswith(prefix):
|
|
429
441
|
return "pass", text[len(prefix):].lstrip("::,,、 ").strip()
|
|
430
|
-
return "
|
|
442
|
+
return "none", text
|
|
431
443
|
|
|
432
444
|
|
|
433
445
|
def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
@@ -435,8 +447,13 @@ def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
|
435
447
|
return None
|
|
436
448
|
items: Dict[str, Tuple[str, str]] = {}
|
|
437
449
|
for key, value in raw.items():
|
|
450
|
+
# 只认五项标准自检键(英文/中文变体映射);白名单外的键(备注、待核验、
|
|
451
|
+
# 下一步补充等描述性额外键)不计入核验单——分母不被撑大,多余键不构成
|
|
452
|
+
# "交付前检查"定义的核验项。
|
|
453
|
+
label = SELF_CHECK_LABELS.get(key) or SELF_CHECK_LABELS.get(str(key))
|
|
454
|
+
if label is None:
|
|
455
|
+
continue
|
|
438
456
|
status, note = classify_check_value(value)
|
|
439
|
-
label = SELF_CHECK_LABELS.get(key, SELF_CHECK_LABELS.get(str(key), str(key)))
|
|
440
457
|
items[label] = (status, note)
|
|
441
458
|
return items or None
|
|
442
459
|
|
|
@@ -465,8 +482,13 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
465
482
|
unbound = [cid for cid in unbound_ids for _ in range(all_marks.count(cid))]
|
|
466
483
|
no_citation = bool(sources) and not cited
|
|
467
484
|
|
|
468
|
-
# ③
|
|
469
|
-
|
|
485
|
+
# ③ 时效检查:**正文依据**的日期范围与历史材料计数。
|
|
486
|
+
# 核验单五项都应只针对正文依据;① 依据溯源、② 引用对应 本就按正文角标计算,而 ③④ 此前
|
|
487
|
+
# 误用全部召回(sources 同时含未引用的 recalled_materials),口径不一致。
|
|
488
|
+
# 修复:43 篇正文依据的日期范围是 2020-01~2026-09,却因未引用
|
|
489
|
+
# 材料里有两篇接口标注 2027-09 的条目,核验单显示成 2016-03~2027-09 —— 把"未来日期"
|
|
490
|
+
# 和 11 年跨度算进了交付物的时效说明里。
|
|
491
|
+
dated = [parse_year_month(s.get("date")) for s in cited_sources]
|
|
470
492
|
dated = [d for d in dated if d]
|
|
471
493
|
freshness = None
|
|
472
494
|
old_count = 0
|
|
@@ -477,9 +499,9 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
477
499
|
"old_count": sum(1 for y, _ in dated if y <= generated_at.year - 3),
|
|
478
500
|
}
|
|
479
501
|
|
|
480
|
-
# ④
|
|
502
|
+
# ④ 类型覆盖:**正文依据**的四分类分布
|
|
481
503
|
coverage = {key: 0 for key in KIND_CATALOG}
|
|
482
|
-
for s in
|
|
504
|
+
for s in cited_sources:
|
|
483
505
|
coverage[s.get("type_key", "material")] = coverage.get(s.get("type_key", "material"), 0) + 1
|
|
484
506
|
|
|
485
507
|
# ⑤ 成稿自检:由溯源 JSON 的 self_check 传入,未传入如实显示未记录
|
|
@@ -490,32 +512,50 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
490
512
|
self_check = None
|
|
491
513
|
if self_items:
|
|
492
514
|
passed = sum(1 for status, _ in self_items.values() if status == "pass")
|
|
493
|
-
|
|
494
|
-
|
|
515
|
+
fails = sum(1 for status, _ in self_items.values() if status == "fail")
|
|
516
|
+
# 状态由显式 fail 决定;none(描述性值/未记录)不判红也不拖垮通过
|
|
517
|
+
status = "fail" if fails else ("pass" if passed else "missing")
|
|
518
|
+
# 分母固定为五项标准检查项,不取"实际写入的键数"——否则只写 1 个键会显示
|
|
519
|
+
# "✓ 1/1",把"只做了一项"显示成满通过
|
|
520
|
+
missing_items = [label for key, label in SELF_CHECK_ITEMS if label not in self_items]
|
|
521
|
+
self_check = {"items": self_items, "passed": passed, "total": len(SELF_CHECK_ITEMS),
|
|
522
|
+
"missing_items": missing_items, "status": status}
|
|
495
523
|
else:
|
|
496
|
-
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS),
|
|
524
|
+
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS),
|
|
525
|
+
"missing_items": [label for _, label in SELF_CHECK_ITEMS], "status": "missing"}
|
|
497
526
|
|
|
498
527
|
# 政策效力:无法自动判定现行效力,列出建议人工复核
|
|
499
528
|
policy_count = coverage.get("policy", 0)
|
|
500
529
|
|
|
501
530
|
trace_ok = cited_sources and not missing_excerpts
|
|
502
531
|
binding_ok = (not unbound) and not no_citation
|
|
503
|
-
|
|
532
|
+
# 成稿自检显式写"未通过"时必须否决报告级结论:自检发现未闭环(规则要求先补搜闭环,
|
|
533
|
+
# 补不到停下与用户确认),不得照样打「已核验」章
|
|
534
|
+
self_check_ok = self_check["status"] != "fail"
|
|
535
|
+
overall_passed = bool(trace_ok and binding_ok and self_check_ok)
|
|
504
536
|
|
|
505
537
|
reasons = []
|
|
506
538
|
if not sources:
|
|
507
|
-
reasons.append("
|
|
539
|
+
reasons.append("没有找到来源文章")
|
|
508
540
|
if no_citation:
|
|
509
|
-
reasons.append("
|
|
541
|
+
reasons.append("正文里没有来源角标,对不上来源文章")
|
|
510
542
|
if unbound:
|
|
511
|
-
reasons.append(f"有 {len(unbound)}
|
|
543
|
+
reasons.append(f"有 {len(unbound)} 处角标找不到对应来源文章")
|
|
512
544
|
if self_check["status"] == "fail":
|
|
513
545
|
reasons.append("交付前检查有没过的项")
|
|
546
|
+
if missing_links:
|
|
547
|
+
reasons.append(f"有 {len(missing_links)} 条正文依据没有原文链接或存档快照,无法回看")
|
|
548
|
+
|
|
549
|
+
if overall_passed and missing_links:
|
|
550
|
+
# 摘录可比对、结论成立,但确有材料无回看通道时,顶部表述要与事实一致
|
|
551
|
+
overall_label = f"核验完成,其中 {len(missing_links)} 条依据无原文或存档快照可回看"
|
|
552
|
+
else:
|
|
553
|
+
overall_label = "核验完成,正文依据逐条对过原文" if overall_passed else "核验未完全通过"
|
|
514
554
|
|
|
515
555
|
return {
|
|
516
556
|
"overall": {
|
|
517
557
|
"passed": overall_passed,
|
|
518
|
-
"label":
|
|
558
|
+
"label": overall_label,
|
|
519
559
|
"reasons": reasons,
|
|
520
560
|
},
|
|
521
561
|
"traceability": {"total": len(cited_sources), "passed": trace_passed,
|
|
@@ -578,7 +618,7 @@ HOT_STOP = {
|
|
|
578
618
|
|
|
579
619
|
|
|
580
620
|
def extract_hot_terms(answer: str, sources: List[Dict[str, str]], top: int = 8) -> List[str]:
|
|
581
|
-
"""
|
|
621
|
+
"""知识专库热词:材料标题(加权)+ 检索条件 + 正文的高频 2-4 字词,真实统计。
|
|
582
622
|
|
|
583
623
|
泛词过滤:出现在超过 60% 材料标题中的词(如库内全部材料共有的主题词)
|
|
584
624
|
无法筛出子集,没有筛选价值,剔除。
|
|
@@ -768,8 +808,10 @@ def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str
|
|
|
768
808
|
idx += 1
|
|
769
809
|
continue
|
|
770
810
|
# 引文胶囊位置规范:角标与后随标点换位——标点紧跟文字,胶囊放标点之后
|
|
771
|
-
#
|
|
772
|
-
|
|
811
|
+
# (避免胶囊把句号挤到下一行孤悬,保持"…内容。~出处"形态)
|
|
812
|
+
# 注意:须把连续角标序列整体换位(如 [13][14];),否则标点被夹在两个胶囊
|
|
813
|
+
# 中间——[13];[14] 会让分号"跑到胶囊后边"。
|
|
814
|
+
block = re.sub(r"((?:\[\d+\])+)([。;,、!?:;,.])", r"\2\1", block)
|
|
773
815
|
ids = citation_ids(block)
|
|
774
816
|
repl = make_block_repl(block)
|
|
775
817
|
heading_match = re.match(r"^(#{1,4})\s+(.+)$", block)
|
|
@@ -869,7 +911,7 @@ def build_chip_data(sources: List[Dict[str, str]]) -> Dict[str, Dict[str, str]]:
|
|
|
869
911
|
url = source.get("snapshot") or ""
|
|
870
912
|
site_bits = ([source["doc_number"]] if source.get("doc_number") else []) + meta_bits
|
|
871
913
|
chip_map[cid] = {
|
|
872
|
-
"title": short(source.get("title") or "
|
|
914
|
+
"title": short(source.get("title") or "未命名来源文章", 30),
|
|
873
915
|
"site": " · ".join(site_bits) or "来源站点",
|
|
874
916
|
"url": url,
|
|
875
917
|
"snapshot": source.get("snapshot") or "",
|
|
@@ -907,25 +949,34 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
907
949
|
reasons_html = '<div class="v-reasons">' + ";".join(esc(r) for r in ov["reasons"]) + "</div>"
|
|
908
950
|
|
|
909
951
|
tr = v["traceability"]
|
|
952
|
+
n_no_link = len(tr.get("missing_links") or [])
|
|
910
953
|
if not tr["total"]:
|
|
911
954
|
tr_html = ('<div class="vi"><span class="s fail">✗ 依据溯源 0/0</span>'
|
|
912
|
-
'<span class="d"
|
|
913
|
-
elif tr["passed"] == tr["total"]:
|
|
955
|
+
'<span class="d">未识别到来源文章</span></div>')
|
|
956
|
+
elif tr["passed"] == tr["total"] and not n_no_link:
|
|
914
957
|
tr_html = (f'<div class="vi"><span class="s ok">✓ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
915
|
-
f'<span class="d"
|
|
958
|
+
f'<span class="d">每篇来源文章的摘录可比对,原文或存档快照可回看</span></div>')
|
|
959
|
+
elif tr["passed"] == tr["total"]:
|
|
960
|
+
# 摘录齐全但有材料没有回看通道:不得照写"原文或存档快照可回看"
|
|
961
|
+
# (此前 missing_links 算出却从未参与结论,属虚假背书)
|
|
962
|
+
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
963
|
+
f'<span class="d">摘录可比对,其中 {n_no_link} 条没有原文链接或存档快照、无法回看</span></div>')
|
|
916
964
|
else:
|
|
965
|
+
detail = f'待补摘录 {len(tr.get("missing_excerpts") or [])} 条'
|
|
966
|
+
if n_no_link:
|
|
967
|
+
detail += f';{n_no_link} 条无原文链接或快照'
|
|
917
968
|
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
918
|
-
f'<span class="d"
|
|
969
|
+
f'<span class="d">{detail}</span></div>')
|
|
919
970
|
|
|
920
971
|
bd = v["binding"]
|
|
921
972
|
if bd.get("no_citation"):
|
|
922
973
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 0/0</span>'
|
|
923
|
-
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]}
|
|
974
|
+
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]} 篇来源文章对不上正文</span></div>')
|
|
924
975
|
elif not bd["total"]:
|
|
925
976
|
bd_html = '<div class="vi"><span class="s none">— 引用对应 0/0</span><span class="d">正文里没有来源角标</span></div>'
|
|
926
977
|
elif not bd["unbound"]:
|
|
927
978
|
bd_html = (f'<div class="vi"><span class="s ok">✓ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
928
|
-
f'<span class="d">正文每处 [n]
|
|
979
|
+
f'<span class="d">正文每处 [n] 都能找到对应来源文章</span></div>')
|
|
929
980
|
else:
|
|
930
981
|
unbound_text = "、".join(f"[{esc(x)}]" for x in bd["unbound"][:8])
|
|
931
982
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
@@ -934,8 +985,11 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
934
985
|
fr = v["freshness"]
|
|
935
986
|
if fr:
|
|
936
987
|
rng = f"{fr['min'][0]}-{fr['min'][1]:02d}~{fr['max'][0]}-{fr['max'][1]:02d}"
|
|
937
|
-
|
|
938
|
-
|
|
988
|
+
# 不再输出"N 条年头较久,按参考口径使用"——"年头较久"按
|
|
989
|
+
# "发布日期年份 ≤ 生成年份 − 3"划线,对长期有效的政策法规偏严(如 2020 年出台、
|
|
990
|
+
# 至今有效的条例会被判为"较久"),且"参考口径"一说读者无从理解。只保留日期范围。
|
|
991
|
+
# old_count 仍在 freshness 中照常计算,留待后续需要时使用。
|
|
992
|
+
fr_html = f'<div class="vi"><span class="s ok">✓ 材料新旧 已核</span><span class="d">材料日期 {esc(rng)}</span></div>'
|
|
939
993
|
else:
|
|
940
994
|
fr_html = '<div class="vi"><span class="s none">— 材料新旧 未记录</span><span class="d">材料没标发布日期</span></div>'
|
|
941
995
|
|
|
@@ -949,13 +1003,22 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
949
1003
|
if sc["status"] == "pass":
|
|
950
1004
|
notes = ";".join(note for _, note in sc["items"].values() if note)
|
|
951
1005
|
title_attr = f' title="{esc(notes)}"' if notes else ""
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1006
|
+
missing = sc.get("missing_items") or []
|
|
1007
|
+
none_count = sum(1 for status, _ in sc["items"].values() if status == "none")
|
|
1008
|
+
unrecorded = len(missing) + none_count
|
|
1009
|
+
none_note = f"({unrecorded} 项未记录)" if unrecorded else ""
|
|
1010
|
+
# 缺项点名,避免"只写了一项"与"五项都过"在视觉上等同
|
|
1011
|
+
if missing:
|
|
1012
|
+
detail = f"缺少:{'、'.join(missing)}"
|
|
1013
|
+
else:
|
|
1014
|
+
item_names = "、".join(sc["items"].keys())
|
|
1015
|
+
detail = item_names + (" · 悬停查看说明" if notes else "")
|
|
1016
|
+
sc_html = (f'<div class="vi"><span class="s ok"{title_attr}>✓ 交付前检查 {sc["passed"]}/{sc["total"]}{esc(none_note)}</span>'
|
|
1017
|
+
f'<span class="d">{esc(detail)}</span></div>')
|
|
955
1018
|
elif sc["status"] == "fail":
|
|
956
1019
|
failed_parts = []
|
|
957
1020
|
for label, (status, note) in sc["items"].items():
|
|
958
|
-
if status
|
|
1021
|
+
if status == "fail":
|
|
959
1022
|
suffix = f"({note[:40]}…)" if len(note) > 40 else (f"({note})" if note else "")
|
|
960
1023
|
failed_parts.append(label + suffix)
|
|
961
1024
|
sc_html = (f'<div class="vi"><span class="s fail">✗ 交付前检查 {sc["passed"]}/{sc["total"]}</span>'
|
|
@@ -963,19 +1026,17 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
963
1026
|
else:
|
|
964
1027
|
sc_html = '<div class="vi"><span class="s none">— 交付前检查 未记录</span><span class="d">本次溯源 JSON 没写入检查结果</span></div>'
|
|
965
1028
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
manual = (f'<div class="vi"><span class="s man">◐ 现行效力</span>'
|
|
969
|
-
f'<span class="d">{v["policy_count"]} 份政策文件建议按官方发布确认是否现行有效</span></div>')
|
|
1029
|
+
# "现行效力"人工复核提示行已按产品要求移除:政策是否现行有效
|
|
1030
|
+
# 无法自动判定,此提示对用户无操作价值;policy_count 仅保留在计算层不再展示。
|
|
970
1031
|
|
|
971
1032
|
return f"""
|
|
972
1033
|
<div class="verify {state}">
|
|
973
1034
|
<div class="v-head"><span class="v-shield">{'✓' if ov['passed'] else '!'}</span>{esc(ov['label'])}{stamp}</div>
|
|
974
1035
|
{reasons_html}
|
|
975
1036
|
<div class="v-grid">
|
|
976
|
-
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}
|
|
1037
|
+
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}
|
|
977
1038
|
</div>
|
|
978
|
-
<div class="v-note"
|
|
1039
|
+
<div class="v-note">核验方式:先用深知可信搜索找权威来源,再把正文每处依据和原文逐条比对(都能点开原文回看),最后做了交付前五项检查。{manual_checks_html}</div>
|
|
979
1040
|
</div>"""
|
|
980
1041
|
|
|
981
1042
|
|
|
@@ -1082,9 +1143,11 @@ def strip_leading_chain(text: str, chain: List[str]) -> str:
|
|
|
1082
1143
|
|
|
1083
1144
|
|
|
1084
1145
|
def render_crumb(chain: List[str]) -> str:
|
|
1085
|
-
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1146
|
+
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1147
|
+
段落本身无章节层级(链上只有文章名)时不显示——材料卡标题已是文章名,
|
|
1148
|
+
单独一行重复文章名对定位无增量。"""
|
|
1086
1149
|
parts = [esc(level) for level in chain if level]
|
|
1087
|
-
if
|
|
1150
|
+
if len(parts) < 2:
|
|
1088
1151
|
return ""
|
|
1089
1152
|
return '<span class="crumb">' + ' <i>›</i> '.join(parts) + "</span>"
|
|
1090
1153
|
|
|
@@ -1119,8 +1182,14 @@ def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
|
1119
1182
|
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
1120
1183
|
note_html = ""
|
|
1121
1184
|
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", ""), source.get("link_dead", False))
|
|
1122
|
-
# 关键性行:有文号(接口 policyFiles 匹配)时"文号 · 数据源 · 日期",否则"数据源 · 日期"
|
|
1123
|
-
|
|
1185
|
+
# 关键性行:有文号(接口 policyFiles 匹配)时"文号 · 数据源 · 日期",否则"数据源 · 日期"。
|
|
1186
|
+
# 文号必须是标准格式(〔年份〕序号);描述性文字("XX印发"类自造描述)不显示,当无文号处理。
|
|
1187
|
+
_dn = source.get("doc_number") or ""
|
|
1188
|
+
# 只显示标准文号形式,拦掉模型自造的描述性文字("中办、国办 2026 年印发"类)。
|
|
1189
|
+
# 除"〔年份〕序号"外,主席令/国务院令/部令等法定令号同样合规,一并放行
|
|
1190
|
+
# (真实任务里《社会保险法》《国务院令第765号》曾被整条丢弃)
|
|
1191
|
+
_dn = _dn if re.search(r"〔\d{4}〕\s*\d+\s*号|第\s*(?:\d+|[〇零一二三四五六七八九十百千]+)\s*号", _dn) else ""
|
|
1192
|
+
meta_parts = [v for v in [_dn, source.get("agency"), source.get("date"), source.get("area")]
|
|
1124
1193
|
if v and v != "未知来源"]
|
|
1125
1194
|
meta = " | ".join(meta_parts)
|
|
1126
1195
|
# 高可信徽标:仅"发布日期可信度=高"(模型治理入库、标题模型精抽)的材料;"较高"(门户抓取)不标。
|
|
@@ -1179,7 +1248,7 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
|
|
|
1179
1248
|
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1180
1249
|
<li class="p-step">
|
|
1181
1250
|
<span class="p-no">2</span>
|
|
1182
|
-
<div class="p-txt"><b
|
|
1251
|
+
<div class="p-txt"><b>来源文章入库 {stats['n_materials']} 篇</b><i>正文采用 {stats['used_count']} · 召回未采用 {stats['unused_count']}</i></div>
|
|
1183
1252
|
</li>
|
|
1184
1253
|
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1185
1254
|
<li class="p-step">
|
|
@@ -1197,10 +1266,10 @@ def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> s
|
|
|
1197
1266
|
|
|
1198
1267
|
|
|
1199
1268
|
def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) -> str:
|
|
1200
|
-
"""
|
|
1269
|
+
"""知识专库全屏视图:大搜索 + 热词 + 检索分组 tabs + 材料卡列表。"""
|
|
1201
1270
|
if not sources:
|
|
1202
|
-
return ('<section class="view" id="view-library" aria-label="
|
|
1203
|
-
'<div class="lib-empty"
|
|
1271
|
+
return ('<section class="view" id="view-library" aria-label="知识专库">'
|
|
1272
|
+
'<div class="lib-empty">接口返回中未识别到可展示的来源文章。</div></section>')
|
|
1204
1273
|
used_sources = [s for s in sources if s.get("used", True)]
|
|
1205
1274
|
unused_sources = [s for s in sources if not s.get("used", True)]
|
|
1206
1275
|
|
|
@@ -1233,33 +1302,40 @@ def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) ->
|
|
|
1233
1302
|
cited_verified = sum(1 for s in used_sources if s.get("verified"))
|
|
1234
1303
|
badge = "全部已核验" if used_sources and cited_verified == len(used_sources) else f"{cited_verified}/{len(used_sources)} 已核验"
|
|
1235
1304
|
return f"""
|
|
1236
|
-
<section class="view" id="view-library" aria-label="
|
|
1305
|
+
<section class="view" id="view-library" aria-label="知识专库">
|
|
1237
1306
|
<div class="lib-head">
|
|
1238
|
-
<div class="lib-title"><b
|
|
1307
|
+
<div class="lib-title"><b>知识专库</b>
|
|
1239
1308
|
<span>共 {len(sources)} 条 · 已引用 {len(used_sources)} · {esc(badge)}</span>
|
|
1240
1309
|
</div>
|
|
1241
1310
|
<div class="lib-searchWrap">
|
|
1242
1311
|
<span class="lib-searchIcon" aria-hidden="true">⌕</span>
|
|
1243
|
-
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="
|
|
1312
|
+
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="搜索来源文章">
|
|
1244
1313
|
</div>
|
|
1245
1314
|
{hot_html}
|
|
1246
1315
|
<div class="lib-tabs" role="tablist" aria-label="按检索分组筛选">{"".join(tabs)}</div>
|
|
1247
1316
|
</div>
|
|
1248
1317
|
<div class="lib-list" id="lib-list">{cards_html}</div>
|
|
1249
|
-
<div class="lib-empty hide" id="lib-empty"
|
|
1250
|
-
<div class="lib-foot"
|
|
1318
|
+
<div class="lib-empty hide" id="lib-empty">没有符合当前筛选的来源文章。</div>
|
|
1319
|
+
<div class="lib-foot">来源:深知可信搜索 · 每段摘录均取自原文原段</div>
|
|
1251
1320
|
</section>"""
|
|
1252
1321
|
|
|
1253
1322
|
|
|
1254
1323
|
def render_toc(sections: List[Dict[str, Any]]) -> str:
|
|
1255
|
-
"""章节目录(滚动 spy):长报告(≥6
|
|
1256
|
-
if len(sections) < 6:
|
|
1257
|
-
return ""
|
|
1324
|
+
"""章节目录(滚动 spy):长报告(≥6 个有标题的章节)显示,桌面端左侧浮动。"""
|
|
1258
1325
|
items = []
|
|
1259
1326
|
for i, sec in enumerate(sections, 1):
|
|
1260
|
-
|
|
1261
|
-
|
|
1327
|
+
title = (sec.get("title") or "").strip()
|
|
1328
|
+
if not title:
|
|
1329
|
+
# 无标题节=正文开头的导语/摘要段(第一个章节标题之前的内容),不是正式章节。
|
|
1330
|
+
# 修复:此前会被兜底成「第 N 节」列进目录,页面上表现为一条灰色
|
|
1331
|
+
# 占位项,读者不知道那是什么。内容仍照常
|
|
1332
|
+
# 在正文里展示,只是不占目录条目、不参与滚动高亮。
|
|
1333
|
+
continue
|
|
1334
|
+
number, title_text = split_heading_number(title)
|
|
1335
|
+
label = f"{number} {title_text}" if (number and title_text) else title_text
|
|
1262
1336
|
items.append(f'<a href="#sec-{i}">{esc(short(label, 16))}</a>')
|
|
1337
|
+
if len(items) < 6:
|
|
1338
|
+
return ""
|
|
1263
1339
|
return f'<nav class="toc" aria-label="章节目录">{"".join(items)}</nav>'
|
|
1264
1340
|
|
|
1265
1341
|
|
|
@@ -1268,8 +1344,8 @@ def render_print_appendix(sources: List[Dict[str, str]]) -> str:
|
|
|
1268
1344
|
if not sources:
|
|
1269
1345
|
return ""
|
|
1270
1346
|
cards = "".join(render_source_card(s, for_print=True) for s in sources)
|
|
1271
|
-
return (f'<section class="print-appendix" aria-label="
|
|
1272
|
-
f'<h3
|
|
1347
|
+
return (f'<section class="print-appendix" aria-label="来源文章附录(打印归档)">'
|
|
1348
|
+
f'<h3>来源文章(全 {len(sources)} 篇)</h3>{cards}</section>')
|
|
1273
1349
|
|
|
1274
1350
|
|
|
1275
1351
|
def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dknowc_search_trace", suffix_ext: str = ".html") -> str:
|
|
@@ -1348,6 +1424,10 @@ a{color:var(--brand)}
|
|
|
1348
1424
|
box-shadow:0 2px 8px rgba(101,18,173,.22)}
|
|
1349
1425
|
.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)}
|
|
1350
1426
|
.hero .meta{color:var(--muted);font-size:13px;letter-spacing:.5px}
|
|
1427
|
+
/* 原问题行:报告须含完整原问题才能独立使用 */
|
|
1428
|
+
.hero .orig-q{margin-top:8px;padding:8px 14px;background:rgba(255,255,255,.72);border:1px solid var(--line);
|
|
1429
|
+
border-radius:10px;color:var(--ink);font-size:13.5px;line-height:1.7;text-align:left}
|
|
1430
|
+
.hero .orig-q b{color:var(--brand);margin-right:2px}
|
|
1351
1431
|
.hero-switch{margin-top:16px;display:flex;justify-content:center}
|
|
1352
1432
|
.hero-switch .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
|
|
1353
1433
|
.hero-switch .view-switch button{color:#70678a;padding:6px 22px;font-size:13px}
|
|
@@ -1489,7 +1569,7 @@ a.jb-quote{text-decoration:none}
|
|
|
1489
1569
|
.sc-links a{display:inline-flex;align-items:center;min-height:24px;padding:3px 9px;border-radius:6px;
|
|
1490
1570
|
background:var(--brand-soft);color:var(--brand);font-weight:700;text-decoration:none;font-size:12px}
|
|
1491
1571
|
|
|
1492
|
-
/* =====
|
|
1572
|
+
/* ===== 知识专库视图 ===== */
|
|
1493
1573
|
#view-library{padding:26px 0 30px}
|
|
1494
1574
|
.lib-head{max-width:860px;margin:0 auto 16px;text-align:center}
|
|
1495
1575
|
.lib-title{margin-bottom:14px}
|
|
@@ -1567,6 +1647,9 @@ a.jb-quote{text-decoration:none}
|
|
|
1567
1647
|
.toc a{color:var(--muted);text-decoration:none;padding:4px 10px;border-left:2px solid var(--line);
|
|
1568
1648
|
line-height:1.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1569
1649
|
.toc a.on{color:var(--brand);border-left-color:var(--brand);font-weight:700}
|
|
1650
|
+
/* 切到知识专库视图时隐藏章节目录(避免进入专库页后左侧仍残留目录栏)。
|
|
1651
|
+
目录节点渲染在 .app 之后(.app 的兄弟节点),故主规则用兄弟选择器;同时兼容其被移入 .app 内的情况。 */
|
|
1652
|
+
.app[data-view="library"] ~ .toc,.app[data-view="library"] .toc{display:none}
|
|
1570
1653
|
@media (max-width:1460px){.toc{display:none}}
|
|
1571
1654
|
|
|
1572
1655
|
.foot{text-align:center;color:var(--muted);font-size:11.5px;padding:16px 0 4px;line-height:1.8}
|
|
@@ -1733,7 +1816,7 @@ PAGE_JS = """
|
|
|
1733
1816
|
var on = document.body.classList.toggle("reading");
|
|
1734
1817
|
readBtn.setAttribute("aria-pressed", on ? "true" : "false");
|
|
1735
1818
|
readBtn.textContent = on ? "显示核验" : "只看正文";
|
|
1736
|
-
/*
|
|
1819
|
+
/* 只看正文只作用于核验报告视图:正在知识专库时切回报告,专库不受影响 */
|
|
1737
1820
|
if (on && app && app.getAttribute("data-view") !== "report") setView("report");
|
|
1738
1821
|
});
|
|
1739
1822
|
}
|
|
@@ -1888,7 +1971,7 @@ PAGE_JS = """
|
|
|
1888
1971
|
name.addEventListener("click", function () { toggleJb(name.closest(".jb")); });
|
|
1889
1972
|
});
|
|
1890
1973
|
|
|
1891
|
-
/* 引文条目点击 →
|
|
1974
|
+
/* 引文条目点击 → 知识专库定位对应卡:库内导航看完整材料;
|
|
1892
1975
|
外部原文跳转只保留 jb-head 的"查看全文"按钮,动线分离 */
|
|
1893
1976
|
function jumpToLibrary(id) {
|
|
1894
1977
|
var card = byId[id];
|
|
@@ -1934,7 +2017,7 @@ PAGE_JS = """
|
|
|
1934
2017
|
});
|
|
1935
2018
|
});
|
|
1936
2019
|
|
|
1937
|
-
/* ===== 7.
|
|
2020
|
+
/* ===== 7. 知识专库:tabs + 搜索 + 热词 ===== */
|
|
1938
2021
|
var cond = "";
|
|
1939
2022
|
var kw = "";
|
|
1940
2023
|
function applyFilter() {
|
|
@@ -1991,7 +2074,14 @@ PAGE_JS = """
|
|
|
1991
2074
|
a.addEventListener("click", function (e) {
|
|
1992
2075
|
e.preventDefault();
|
|
1993
2076
|
var target = document.querySelector(a.getAttribute("href"));
|
|
1994
|
-
if (target)
|
|
2077
|
+
if (!target) return;
|
|
2078
|
+
/* 手动定位而非 scrollIntoView({block:"start"}):后者把标题顶到视口 y=0,
|
|
2079
|
+
会被 sticky 顶栏盖住(点"四、…"后一级标题看不见)。
|
|
2080
|
+
偏移量与目录吸顶位置同一基准(顶栏高 + 20px)。 */
|
|
2081
|
+
var bar = document.querySelector(".topbar");
|
|
2082
|
+
var offset = (bar ? bar.offsetHeight : 0) + 20;
|
|
2083
|
+
var y = target.getBoundingClientRect().top + window.scrollY - offset;
|
|
2084
|
+
window.scrollTo({ top: Math.max(0, y), behavior: "smooth" });
|
|
1995
2085
|
});
|
|
1996
2086
|
});
|
|
1997
2087
|
function spy() {
|
|
@@ -2002,15 +2092,55 @@ PAGE_JS = """
|
|
|
2002
2092
|
}
|
|
2003
2093
|
window.addEventListener("scroll", spy, { passive: true });
|
|
2004
2094
|
spy();
|
|
2095
|
+
/* 目录纵向定位:此前 CSS 写死 top:120px,目录顶部与页头齐平、离正文很远。
|
|
2096
|
+
改为——初始与正文首节对齐,滚动时吸附在顶栏下方。 */
|
|
2097
|
+
var topbar = document.querySelector(".topbar");
|
|
2098
|
+
function placeToc() {
|
|
2099
|
+
var first = secs[0];
|
|
2100
|
+
if (!first) return;
|
|
2101
|
+
var stick = (topbar ? topbar.offsetHeight : 0) + 20;
|
|
2102
|
+
var want = Math.round(first.getBoundingClientRect().top);
|
|
2103
|
+
/* 不再按"视口内放不放得下"压缩位置:正文首节上方还有页头、
|
|
2104
|
+
过程回顾和核验单,首屏内它常位于视口之外;若按 innerHeight 把目录上移,目录会被
|
|
2105
|
+
顶到页面中上部,反而显得"悬得过高",与正文脱节。直接跟随正文首节——首屏看不到
|
|
2106
|
+
目录属正常,向下滚动后它自然吸附在顶栏下方。目录过长时由 CSS 的
|
|
2107
|
+
max-height:60vh + overflow:auto 内部滚动兜底。 */
|
|
2108
|
+
toc.style.top = Math.max(stick, want) + "px";
|
|
2109
|
+
}
|
|
2110
|
+
window.addEventListener("scroll", placeToc, { passive: true });
|
|
2111
|
+
window.addEventListener("resize", placeToc);
|
|
2112
|
+
placeToc();
|
|
2005
2113
|
}
|
|
2006
2114
|
})();
|
|
2007
2115
|
"""
|
|
2008
2116
|
|
|
2009
2117
|
|
|
2118
|
+
def normalize_body_quotes(text: str) -> str:
|
|
2119
|
+
"""报告正文引号归一:复用 `format_document.normalize_chinese_quotes`,与 Word 同源。
|
|
2120
|
+
|
|
2121
|
+
背景:`format_document.py` 生成 Word 时会统一把 ASCII 直引号转为
|
|
2122
|
+
中文全角引号,但溯源报告直接读溯源 JSON 里的 document_content —— 模型落盘时若把
|
|
2123
|
+
中文引号写成半角,报告就会与 Word 交付物不一致,而这条路径此前没有兜底
|
|
2124
|
+
(此前靠任务侧手工跑引号脚本规避,机制上没有保障)。取不到该函数时原样返回,
|
|
2125
|
+
不阻断渲染。
|
|
2126
|
+
"""
|
|
2127
|
+
if not text:
|
|
2128
|
+
return text
|
|
2129
|
+
try:
|
|
2130
|
+
from format_document import normalize_chinese_quotes
|
|
2131
|
+
except Exception:
|
|
2132
|
+
return text
|
|
2133
|
+
try:
|
|
2134
|
+
return normalize_chinese_quotes(text)
|
|
2135
|
+
except Exception:
|
|
2136
|
+
return text
|
|
2137
|
+
|
|
2138
|
+
|
|
2010
2139
|
def render_html(payload: Dict[str, Any], title: str, answer_override: str = "", question_override: str = "",
|
|
2011
2140
|
generated_at: Optional[datetime] = None) -> str:
|
|
2012
2141
|
payload = unwrap(payload)
|
|
2013
2142
|
answer = normalize_citations(answer_override) if answer_override.strip() else extract_answer(payload)
|
|
2143
|
+
answer = normalize_body_quotes(answer)
|
|
2014
2144
|
sources = align_sources_to_answer(answer, extract_sources(payload))
|
|
2015
2145
|
used = citation_ids(answer)
|
|
2016
2146
|
generated_at = generated_at or datetime.now()
|
|
@@ -2023,7 +2153,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2023
2153
|
if sources and not used:
|
|
2024
2154
|
citation_warning = (
|
|
2025
2155
|
'<div class="warn-box"><b>生成检查未通过:正文没有来源角标。</b>'
|
|
2026
|
-
'本报告无法建立"
|
|
2156
|
+
'本报告无法建立"结论-来源文章"核验对应,仅作来源文章清单参考。'
|
|
2027
2157
|
'请修正溯源 JSON:在 document_content 的关键结论后标注 [1]、[2] 等角标并逐条对应 materials,'
|
|
2028
2158
|
'然后重新运行 source_note_html.py 生成核验报告。</div>'
|
|
2029
2159
|
)
|
|
@@ -2036,6 +2166,14 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2036
2166
|
jb_tables[key] = html
|
|
2037
2167
|
doc_title, sections = group_sections(blocks)
|
|
2038
2168
|
display_title = doc_title or title
|
|
2169
|
+
# 原问题行:溯源报告须含完整原问题才能独立使用。
|
|
2170
|
+
# 只认调用方显式传入的 question_override(source_note_html 读溯源 JSON 顶层
|
|
2171
|
+
# question,即 build_trace_json --question 写入的用户原话)——不取 payload 内的
|
|
2172
|
+
# question 字段兜底(该字段历史上常被报告标题冒充,显示了反而误导);为空或与
|
|
2173
|
+
# 标题相同时不显示该行(历史 JSON 兼容)。
|
|
2174
|
+
question_text = (question_override or "").strip()
|
|
2175
|
+
orig_q_html = (f'<div class="orig-q"><b>原问题</b>:{esc(question_text)}</div>'
|
|
2176
|
+
if question_text and question_text != display_title else "")
|
|
2039
2177
|
|
|
2040
2178
|
jb_tables_json = json.dumps(jb_tables, ensure_ascii=False).replace("</", "<\\/")
|
|
2041
2179
|
jb_tables_script = (f'<script type="application/json" id="jb-tables">{jb_tables_json}</script>\n'
|
|
@@ -2045,7 +2183,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2045
2183
|
if process_stats["n_searches"]:
|
|
2046
2184
|
meta_bits.append(f"深知检索 {process_stats['n_searches']} 次")
|
|
2047
2185
|
if sources:
|
|
2048
|
-
meta_bits.append(f"
|
|
2186
|
+
meta_bits.append(f"来源文章 {len(sources)} 篇")
|
|
2049
2187
|
if process_stats["n_cite_marks"]:
|
|
2050
2188
|
meta_bits.append(f"正文引用 {process_stats['n_cite_marks']} 处")
|
|
2051
2189
|
meta_bits.append(f"生成于 {generated}")
|
|
@@ -2069,7 +2207,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2069
2207
|
<div class="tb-right">
|
|
2070
2208
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2071
2209
|
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2072
|
-
<button data-view="library" type="button"
|
|
2210
|
+
<button data-view="library" type="button">知识专库</button>
|
|
2073
2211
|
</div>
|
|
2074
2212
|
<div class="tb-tools">
|
|
2075
2213
|
<button id="btn-reading" type="button" aria-pressed="false" title="隐藏核验元素,纯阅读正文">只看正文</button>
|
|
@@ -2078,7 +2216,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2078
2216
|
<button id="btn-print" type="button" aria-haspopup="true" title="浏览器打印/另存为 PDF">打印归档 ▾</button>
|
|
2079
2217
|
<span class="print-drop" id="print-drop" hidden>
|
|
2080
2218
|
<button id="print-body" type="button">只打印正文</button>
|
|
2081
|
-
<button id="print-full" type="button"
|
|
2219
|
+
<button id="print-full" type="button">完整归档(含来源文章)</button>
|
|
2082
2220
|
</span>
|
|
2083
2221
|
</span>
|
|
2084
2222
|
</div>
|
|
@@ -2089,11 +2227,12 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2089
2227
|
<div class="hero">
|
|
2090
2228
|
<div class="r-badge">溯源核验报告</div>
|
|
2091
2229
|
<h1>{esc(display_title)}</h1>
|
|
2092
|
-
<div class="meta">{esc(meta_line)} |
|
|
2230
|
+
<div class="meta">{esc(meta_line)} | 来源:深知可信搜索</div>
|
|
2231
|
+
{orig_q_html}
|
|
2093
2232
|
<div class="hero-switch">
|
|
2094
2233
|
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2095
2234
|
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2096
|
-
<button data-view="library" type="button"
|
|
2235
|
+
<button data-view="library" type="button">知识专库({len(sources)})</button>
|
|
2097
2236
|
</div>
|
|
2098
2237
|
</div>
|
|
2099
2238
|
</div>
|
|
@@ -2107,7 +2246,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2107
2246
|
<div class="doc-paper">
|
|
2108
2247
|
{render_section_cards(sections, sources)}
|
|
2109
2248
|
</div>
|
|
2110
|
-
<div class="foot">深知公文写作 · 溯源核验报告 | 内容由 AI
|
|
2249
|
+
<div class="foot">深知公文写作 · 溯源核验报告 | 内容由 AI 生成,仅供参考</div>
|
|
2111
2250
|
</main>
|
|
2112
2251
|
|
|
2113
2252
|
{render_library_view(sources, hot_terms)}
|
|
@@ -2118,7 +2257,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2118
2257
|
|
|
2119
2258
|
<div class="ev-panel" id="ev-pop" hidden></div>
|
|
2120
2259
|
{jb_tables_script}<div class="sheet-mask" aria-hidden="true"></div>
|
|
2121
|
-
<div class="sheet" role="dialog" aria-label="
|
|
2260
|
+
<div class="sheet" role="dialog" aria-label="来源文章">
|
|
2122
2261
|
<div class="sheet-grab"></div>
|
|
2123
2262
|
<div class="sheet-head"><b>依据对照</b><button class="sheet-close" type="button">收起</button></div>
|
|
2124
2263
|
<div class="sheet-body"></div>
|
|
@@ -2130,21 +2269,47 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
2130
2269
|
|
|
2131
2270
|
|
|
2132
2271
|
def align_sources_to_answer(answer: str, sources: List[Dict[str, str]]) -> List[Dict[str, str]]:
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2272
|
+
"""不再按位置给材料重编号。
|
|
2273
|
+
|
|
2274
|
+
原实现会在"正文角标与素材 id 完全不相交"时按顺序把素材改号
|
|
2275
|
+
迎合角标——正文写 `[7]` 而只有 1 条材料时,会被洗成"✓ 引用对应 1/1",与本文件
|
|
2276
|
+
"未绑定角标绝不按位置猜测"的设计原则相反。现如实返回原素材,由核验单报未绑定。
|
|
2277
|
+
"""
|
|
2278
|
+
return sources
|
|
2279
|
+
|
|
2280
|
+
|
|
2281
|
+
def _check_degraded_input(payload: Dict[str, Any], path: str) -> None:
|
|
2282
|
+
"""渲染前硬校验:发现会产出"残缺核验报告"的输入直接报错,阻断静默降级。
|
|
2283
|
+
|
|
2284
|
+
手写溯源 JSON 曾出现缺 recalled_materials、self_check 结构
|
|
2285
|
+
不完整,渲染器静默显示"依据溯源 0/24 / 材料新旧 未记录 / 交付前检查 未记录"。
|
|
2286
|
+
这里只拦截两个必然导致报告失真的情况;完整校验用 scripts/check_materials.py。
|
|
2287
|
+
"""
|
|
2288
|
+
problems = []
|
|
2289
|
+
# ① 执行过搜索的任务必须有未引用召回材料(recalled 空 = 材料层缺全量召回)
|
|
2290
|
+
recalled = payload.get("recalled_materials") or payload.get("未引用素材") or []
|
|
2291
|
+
has_materials = bool(payload.get("materials") or payload.get("素材使用情况"))
|
|
2292
|
+
if has_materials and not recalled:
|
|
2293
|
+
problems.append("recalled_materials 为空——执行过搜索的任务必须包含全部未引用召回材料(可运行 scripts/check_materials.py 校验)")
|
|
2294
|
+
# ② self_check 必须五项齐全(dict 或 list),否则核验单五项失真
|
|
2295
|
+
sc = None
|
|
2296
|
+
for holder in (payload, payload.get("content") if isinstance(payload.get("content"), dict) else {}):
|
|
2297
|
+
sc = sc or holder.get("selfCheck") or holder.get("self_check")
|
|
2298
|
+
if sc is None:
|
|
2299
|
+
problems.append("self_check 缺失——核验单将显示五项'未记录',必须如实写入五项检查结果")
|
|
2300
|
+
elif isinstance(sc, dict):
|
|
2301
|
+
keys = {re.sub(r"\s+", "", k) for k in sc.keys()}
|
|
2302
|
+
expected = {re.sub(r"\s+", "", label) for _, label in SELF_CHECK_ITEMS}
|
|
2303
|
+
missing = expected - keys
|
|
2304
|
+
if missing:
|
|
2305
|
+
problems.append(f"self_check 缺 {len(missing)} 项({sorted(missing)})——核验单会显示'未记录'")
|
|
2306
|
+
if problems:
|
|
2307
|
+
raise SystemExit(
|
|
2308
|
+
"错误:溯源 JSON 存在会导致核验报告失真的问题,已停止生成。\n - "
|
|
2309
|
+
+ "\n - ".join(problems)
|
|
2310
|
+
+ "\n请修正后重跑,或先运行 scripts/check_materials.py 定位问题。"
|
|
2311
|
+
)
|
|
2312
|
+
|
|
2148
2313
|
|
|
2149
2314
|
|
|
2150
2315
|
|
|
@@ -2170,6 +2335,8 @@ def main() -> None:
|
|
|
2170
2335
|
args = parser.parse_args()
|
|
2171
2336
|
|
|
2172
2337
|
payload = load_json(Path(args.input_json))
|
|
2338
|
+
# 3.7.5 修复:渲染前硬校验残缺输入(recalled 空 / self_check 缺项),阻断静默降级
|
|
2339
|
+
_check_degraded_input(payload, args.input_json)
|
|
2173
2340
|
answer_override = ""
|
|
2174
2341
|
if args.answer_file:
|
|
2175
2342
|
answer_override = Path(args.answer_file).expanduser().read_text(encoding="utf-8")
|