dknowc-dsh 2.3.0 → 2.3.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.
- package/README.md +3 -47
- package/package.json +2 -2
- package/skills/dknowc-official-doc-writer/README.md +23 -14
- package/skills/dknowc-official-doc-writer/SKILL.md +4 -3
- package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/initialization.md +19 -16
- package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
- package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +42 -31
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +10 -11
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/revision_workflow.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +7 -7
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/standards/00_index.md +63 -77
- package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +0 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/working_principles.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/writing_rules.md +1 -1
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +9 -2
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +11 -9
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +8 -5
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +4 -4
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +3 -2
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +30 -13
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +15 -7
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +2 -3
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +13 -6
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +7 -2
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +538 -205
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +10 -10
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +3 -3
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -1
- package/skills/dknowc-ppt-assistant/README.md +21 -7
- package/skills/dknowc-ppt-assistant/SKILL.md +5 -5
- package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +3 -2
- package/skills/dknowc-ppt-assistant/references/initialization.md +45 -6
- package/skills/dknowc-ppt-assistant/references/material_usage.md +7 -7
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +48 -17
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +1 -1
- package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +2 -0
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +7 -0
- package/skills/dknowc-ppt-assistant/scripts/attribution.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/config.py +9 -9
- package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +1 -2
- package/skills/dknowc-ppt-assistant/scripts/error_helper.py +3 -3
- package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +11 -13
- package/skills/dknowc-ppt-assistant/scripts/language_tags.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +17 -15
- package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +3 -2
- package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +3 -3
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/project_utils.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +710 -322
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +9 -9
- package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +2 -9
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +3 -3
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +9 -10
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +4 -4
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +9 -11
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +7 -5
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +2 -2
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +1 -1
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +22 -5
- package/skills/dknowc-ppt-assistant/scripts/update_spec.py +25 -1
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +11 -9
- package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
- package/skills/dknowc-trusted-search/README.md +8 -8
- package/skills/dknowc-trusted-search/SKILL.md +74 -56
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +40 -15
- package/skills/dknowc-trusted-search/scripts/api_key.py +11 -26
- package/skills/dknowc-trusted-search/scripts/attribution.py +1 -1
- package/skills/dknowc-trusted-search/scripts/deep_query.py +1 -1
- package/skills/dknowc-trusted-search/scripts/initialize.py +10 -10
- package/skills/dknowc-trusted-search/scripts/mcp_direct.py +3 -2
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +617 -275
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +4 -4
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +2 -2
- package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +0 -287
- package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +0 -842
- package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +0 -507
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +0 -346
- package/skills/dknowc-trusted-search/scripts/mcp_convert.py +0 -198
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""可信溯源核验报告渲染器:把搜索结果 JSON + 最终答案渲染为单文件可核验 HTML。
|
|
3
3
|
|
|
4
|
-
深知可信搜索
|
|
4
|
+
深知可信搜索 dsh 版(渲染层与深知系列核验报告同构,数据口径保持自有与真实)。
|
|
5
5
|
输入直读 trusted_search.py / deep_query.py 的 --json-only 输出(可信搜索 content.data
|
|
6
6
|
或深度搜索 deep-query/v3 格式),正文用 --answer-file 传入最终答案(关键结论带 [n] 角标),
|
|
7
7
|
成稿自检用 --self-check-file 传入五项结果。
|
|
@@ -447,7 +447,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
447
447
|
# 检索通道(深知深度搜索 / 深知可信搜索):由检索脚本在产物上打标、merge 透传,
|
|
448
448
|
# 供过程条/hero 按接口通道拆分计数;历史 JSON 无该字段时为空(渲染层回退旧文案)
|
|
449
449
|
source["channel"] = first_str(item.get("检索通道"), item.get("channel"))
|
|
450
|
-
#
|
|
450
|
+
# 非官方来源:联网路(searchChannel=webSearch)召回的非权威站点材料。
|
|
451
451
|
# 双口径判定:联网路脚本打标 非官方来源=True;或接口 dataAuthority 返回 数据权威性=非权威。
|
|
452
452
|
source["unofficial"] = bool(item.get("非官方来源")) or str(
|
|
453
453
|
item.get("数据权威性") or item.get("authority") or "").strip() in ("非权威", "non-authoritative")
|
|
@@ -2723,7 +2723,7 @@ def _next_version_path(path: Path) -> Path:
|
|
|
2723
2723
|
"""输出文件已存在时不覆盖(1.4.0 起):自动改为 原名_v2 / _v3 … 另存。
|
|
2724
2724
|
|
|
2725
2725
|
追加图表/修改答案后重跑渲染时,旧版本保留、新版本号递增——不覆盖已交付内容,
|
|
2726
|
-
也不会再靠宿主目录里的 "名字 (2)"
|
|
2726
|
+
也不会再靠宿主目录里的 "名字 (2)" 兜底。命名与交付重名规则一致(同名 _v2 副本化)。
|
|
2727
2727
|
"""
|
|
2728
2728
|
if not path.exists():
|
|
2729
2729
|
return path
|
|
@@ -2772,7 +2772,7 @@ def parse_research_notes(text: str) -> Dict[str, int]:
|
|
|
2772
2772
|
|
|
2773
2773
|
|
|
2774
2774
|
def main() -> None:
|
|
2775
|
-
parser = argparse.ArgumentParser(description="生成溯源核验报告 HTML(深知可信搜索
|
|
2775
|
+
parser = argparse.ArgumentParser(description="生成溯源核验报告 HTML(深知可信搜索 dsh 版)")
|
|
2776
2776
|
parser.add_argument("input_json", help="trusted_search.py / deep_query.py 的 --json-only 输出 JSON")
|
|
2777
2777
|
parser.add_argument("--output", help="输出 HTML 文件名(official-docs/output/,形如《标题.html》);不传时按问题自动生成《标题.html》。同题重跑自动 _v2 另存")
|
|
2778
2778
|
parser.add_argument("--title", default="溯源核验报告", help="页面标题")
|
|
@@ -188,7 +188,7 @@ def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
|
188
188
|
# item / knowBase 不传(1.5.2 口径延续:办事清单能力接口侧不可用、专库外链属已移除老能力)。
|
|
189
189
|
payload: Dict[str, Any] = {
|
|
190
190
|
"query": args.query,
|
|
191
|
-
#
|
|
191
|
+
# 联网搜索模式:searchChannel 单值传 webSearch,
|
|
192
192
|
# 返回真实互联网内容(网页正文段落+源网址,可溯源到原段);dataAuthority 随联网路自动开——
|
|
193
193
|
# 返回文章级 数据权威性 标注(实测联网结果为"非权威"),供渲染层打"非官方来源"徽标。
|
|
194
194
|
"dataAuthority": bool(args.data_authority or args.search_channel == "webSearch"),
|
|
@@ -421,7 +421,7 @@ def main() -> None:
|
|
|
421
421
|
os.environ.get("DKNOWC_API_KEY"),
|
|
422
422
|
)
|
|
423
423
|
if not api_key:
|
|
424
|
-
# 宿主进程读不到 shell 环境变量时,从专用配置文件兜底解析已持久化的 Key
|
|
424
|
+
# 宿主进程读不到 shell 环境变量时,从专用配置文件兜底解析已持久化的 Key
|
|
425
425
|
try:
|
|
426
426
|
from api_key import resolve_api_key
|
|
427
427
|
api_key, _source = resolve_api_key()
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""⚠ 本脚本自 3.7.5 起随 MCP 通道一同停用,仅保留待 MCP 侧落盘方案改造完成后恢复。
|
|
3
|
-
|
|
4
|
-
现行检索统一走纯脚本通道,规则层(SKILL.md / reference)不引用本脚本;
|
|
5
|
-
以下为停用前的机制说明,仅供恢复改造时参考。
|
|
6
|
-
|
|
7
|
-
--------------------------------------------------------------------------------
|
|
8
|
-
把 MCP「深知可信工作台」trusted_search(include_details=true 形态)的返回
|
|
9
|
-
转换成与深知可信搜索脚本 `scripts/dkag_search.py --clean` **完全同构**的形态,
|
|
10
|
-
供本 Skill 全部下游流程复用。
|
|
11
|
-
|
|
12
|
-
背景(3.7.3):检测到宿主已连接 MCP「深知可信工作台」时,搜索走 MCP 通道
|
|
13
|
-
(免 API Key)。模型在对话层调用 MCP 工具后,把完整返回 JSON 保存到
|
|
14
|
-
official-docs/search-results/,再运行本脚本转换。
|
|
15
|
-
|
|
16
|
-
为什么必须与 `--clean` 同构:脚本通道的下游(模型整理溯源
|
|
17
|
-
JSON、`merge_search_results.py`、`source_note_html.py` 的历史索引回填)都按
|
|
18
|
-
`--clean` 的字段名读取——文章在**顶层 `articles`**、快照字段名是**`快照链接`**、
|
|
19
|
-
段落带自增 `id`。此前本脚本输出的是 REST 原始形态(`content.data.检索文章`),
|
|
20
|
-
导致 MCP 通道产物在下游:文章数组读空(被误判"未检索到相关文章")、快照链接
|
|
21
|
-
整条丢失(`快照链接` 键不存在,而 `source_note_html.py` 只认这个键名)。
|
|
22
|
-
现直接输出 `--clean` 形态,文档只描述一种形态。
|
|
23
|
-
|
|
24
|
-
字段映射:
|
|
25
|
-
title → 文章标题 source → 数据源 date → 发布日期
|
|
26
|
-
url → 源网址 / 原文链接 date_confidence → 发布日期可信度
|
|
27
|
-
snapshot → 快照链接
|
|
28
|
-
segments[{title,content}] → 段落[{id, 标题, 内容}](段落标题为标题链数据源;
|
|
29
|
-
segments 缺失时用 paragraph 兜底构造无标题单段;id 全局自增,同 --clean)
|
|
30
|
-
doc_number → 文章级 `文号`(标准格式,供整理溯源 JSON 时直接复制)+
|
|
31
|
-
顶层 `policyFiles[{title, writtenText}]`(与 --clean 的接口返回一致)
|
|
32
|
-
内容中的 </>/&/" HTML 实体顺手反转义(MCP 透传未清洗)。
|
|
33
|
-
|
|
34
|
-
用法:
|
|
35
|
-
python3 scripts/mcp_convert.py official-docs/search-results/mcp_raw.json \
|
|
36
|
-
--area 北京市 --purpose "搜索目的" \
|
|
37
|
-
--output official-docs/search-results/result_xxx.json
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
from __future__ import annotations
|
|
41
|
-
|
|
42
|
-
import argparse
|
|
43
|
-
import json
|
|
44
|
-
import sys
|
|
45
|
-
from pathlib import Path
|
|
46
|
-
|
|
47
|
-
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
48
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd(SkillHub 兼容)
|
|
49
|
-
import os as _os
|
|
50
|
-
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
51
|
-
if not _ws:
|
|
52
|
-
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/,
|
|
53
|
-
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
54
|
-
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
55
|
-
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
56
|
-
WS_ROOT = Path(_ws).resolve()
|
|
57
|
-
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
58
|
-
|
|
59
|
-
HTML_ENTITIES = (("&lt;", "<"), ("&gt;", ">"), ("&amp;", "&"), ("&quot;", '"'),
|
|
60
|
-
("<", "<"), (">", ">"), ("&", "&"), (""", '"'))
|
|
61
|
-
|
|
62
|
-
KNOWLEDGE_BASE_NOTE = ("知识专库链接来自深知可信搜索接口返回的 knowledgeBase;"
|
|
63
|
-
"MCP 通道由 mcp_convert.py 冗余复制到顶层,与 --clean 口径一致。")
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def clean_text(text: str) -> str:
|
|
67
|
-
"""反转义 MCP 透传内容中的 HTML 实体(全角/半角形式)并去首尾空白。"""
|
|
68
|
-
out = str(text or "")
|
|
69
|
-
for a, b in HTML_ENTITIES:
|
|
70
|
-
out = out.replace(a, b)
|
|
71
|
-
return out.strip()
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def first_value(item: dict, *keys: str) -> str:
|
|
75
|
-
for key in keys:
|
|
76
|
-
value = item.get(key)
|
|
77
|
-
if value not in (None, "", [], {}):
|
|
78
|
-
return str(value)
|
|
79
|
-
return ""
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def extract_materials(data) -> list:
|
|
83
|
-
"""从 MCP 返回中取出 materials 数组,兼容几种常见包裹形态。
|
|
84
|
-
|
|
85
|
-
直接形态:{"materials": [...]}
|
|
86
|
-
带信封:{"data": {"materials": [...]}}、{"content": [{"type": "text", "text": "{...}"}]}
|
|
87
|
-
纯数组:[{...}, {...}]
|
|
88
|
-
取不到时返回空列表,由调用方报错(不得静默产出 0 篇继续往下走)。
|
|
89
|
-
"""
|
|
90
|
-
if isinstance(data, list):
|
|
91
|
-
return data
|
|
92
|
-
if not isinstance(data, dict):
|
|
93
|
-
return []
|
|
94
|
-
|
|
95
|
-
materials = data.get("materials")
|
|
96
|
-
if isinstance(materials, list):
|
|
97
|
-
return materials
|
|
98
|
-
|
|
99
|
-
inner = data.get("data")
|
|
100
|
-
if isinstance(inner, dict) and isinstance(inner.get("materials"), list):
|
|
101
|
-
return inner["materials"]
|
|
102
|
-
|
|
103
|
-
# MCP 工具信封:content 数组里放 JSON 字符串
|
|
104
|
-
content = data.get("content")
|
|
105
|
-
if isinstance(content, list):
|
|
106
|
-
for block in content:
|
|
107
|
-
if not isinstance(block, dict):
|
|
108
|
-
continue
|
|
109
|
-
text = block.get("text") or block.get("content")
|
|
110
|
-
if isinstance(text, str) and text.strip().startswith(("{", "[")):
|
|
111
|
-
try:
|
|
112
|
-
return extract_materials(json.loads(text))
|
|
113
|
-
except json.JSONDecodeError:
|
|
114
|
-
continue
|
|
115
|
-
return []
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def parse_segments(material: dict, start_id: int) -> tuple[list, int]:
|
|
119
|
-
"""segments → 段落[{id,标题,内容}],与 --clean 一致。
|
|
120
|
-
|
|
121
|
-
兼容数组与(历史)字符串形态;缺失时用 paragraph 兜底构造无标题单段。
|
|
122
|
-
返回(段落列表, 下一个可用 id)。
|
|
123
|
-
"""
|
|
124
|
-
segments = material.get("segments")
|
|
125
|
-
if isinstance(segments, str) and segments.strip().startswith("["):
|
|
126
|
-
try: # 历史形态容错:repr 字符串
|
|
127
|
-
import ast
|
|
128
|
-
segments = ast.literal_eval(segments)
|
|
129
|
-
except (ValueError, SyntaxError):
|
|
130
|
-
segments = None
|
|
131
|
-
|
|
132
|
-
paragraphs: list = []
|
|
133
|
-
next_id = start_id
|
|
134
|
-
if isinstance(segments, list) and segments:
|
|
135
|
-
for seg in segments:
|
|
136
|
-
if not isinstance(seg, dict):
|
|
137
|
-
continue
|
|
138
|
-
title = clean_text(first_value(seg, "title", "标题"))
|
|
139
|
-
content = clean_text(first_value(seg, "content", "内容"))
|
|
140
|
-
if content:
|
|
141
|
-
paragraphs.append({"id": next_id, "标题": title, "内容": content})
|
|
142
|
-
next_id += 1
|
|
143
|
-
if not paragraphs:
|
|
144
|
-
fallback = clean_text(first_value(material, "paragraph"))
|
|
145
|
-
if fallback:
|
|
146
|
-
paragraphs.append({"id": next_id, "标题": "", "内容": fallback})
|
|
147
|
-
next_id += 1
|
|
148
|
-
return paragraphs, next_id
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def convert(data, area: str, purpose: str) -> dict:
|
|
152
|
-
materials = extract_materials(data)
|
|
153
|
-
articles: list = []
|
|
154
|
-
policy_files: list = []
|
|
155
|
-
seen_pf = set()
|
|
156
|
-
para_id = 1
|
|
157
|
-
|
|
158
|
-
for material in materials:
|
|
159
|
-
if not isinstance(material, dict):
|
|
160
|
-
continue
|
|
161
|
-
title = clean_text(first_value(material, "title", "文章标题"))
|
|
162
|
-
if not title:
|
|
163
|
-
continue
|
|
164
|
-
paragraphs, para_id = parse_segments(material, para_id)
|
|
165
|
-
source_url = clean_text(first_value(material, "url", "源网址", "sourceUrl"))
|
|
166
|
-
article = {
|
|
167
|
-
# 字段名与顺序对齐 --clean 白名单口径
|
|
168
|
-
"文章标题": title,
|
|
169
|
-
"发布日期": clean_text(first_value(material, "date", "发布日期")),
|
|
170
|
-
"数据源": clean_text(first_value(material, "source", "数据源")),
|
|
171
|
-
"段落": paragraphs,
|
|
172
|
-
}
|
|
173
|
-
if source_url:
|
|
174
|
-
article["源网址"] = source_url
|
|
175
|
-
article["原文链接"] = source_url
|
|
176
|
-
date_confidence = clean_text(first_value(material, "date_confidence", "发布日期可信度"))
|
|
177
|
-
if date_confidence:
|
|
178
|
-
article["发布日期可信度"] = date_confidence
|
|
179
|
-
snapshot = clean_text(first_value(material, "snapshot", "screenShotPath", "快照链接"))
|
|
180
|
-
if snapshot:
|
|
181
|
-
# 键名必须是"快照链接":source_note_html.py 读历史索引时只认这个键
|
|
182
|
-
article["快照链接"] = snapshot
|
|
183
|
-
doc_number = clean_text(first_value(material, "doc_number", "文号"))
|
|
184
|
-
if doc_number:
|
|
185
|
-
# 文号直写文章级(MCP 通道增量):整理溯源 JSON 时直接复制,
|
|
186
|
-
# 免跨文件翻 policyFiles——避免模型跨文件标题匹配时跳过
|
|
187
|
-
article["文号"] = doc_number
|
|
188
|
-
articles.append(article)
|
|
189
|
-
|
|
190
|
-
if doc_number and title not in seen_pf:
|
|
191
|
-
seen_pf.add(title)
|
|
192
|
-
policy_files.append({"title": title, "writtenText": doc_number,
|
|
193
|
-
"sourceUrl": source_url or None,
|
|
194
|
-
"createDate": article["发布日期"] or None,
|
|
195
|
-
"createDateReliability": date_confidence or None})
|
|
196
|
-
|
|
197
|
-
raw_meta = {}
|
|
198
|
-
if isinstance(data, dict) and isinstance(data.get("search_meta"), dict):
|
|
199
|
-
raw_meta = data["search_meta"]
|
|
200
|
-
query = first_value(data, "query") if isinstance(data, dict) else ""
|
|
201
|
-
query = query or raw_meta.get("query", "")
|
|
202
|
-
knowledge_base = first_value(data, "knowledge_base_url", "knowledgeBase") if isinstance(data, dict) else ""
|
|
203
|
-
|
|
204
|
-
search_meta = {
|
|
205
|
-
"query": query,
|
|
206
|
-
"purpose": purpose,
|
|
207
|
-
"area": area or (first_value(data, "service_area") if isinstance(data, dict) else ""),
|
|
208
|
-
"time": raw_meta.get("eff_time", ""),
|
|
209
|
-
"requested_time": "",
|
|
210
|
-
"time_ignored": False,
|
|
211
|
-
"policy": True,
|
|
212
|
-
"full": False,
|
|
213
|
-
"clean": True,
|
|
214
|
-
"segmentCount": int(raw_meta.get("segment_count", 2) or 2),
|
|
215
|
-
"simplified": bool(raw_meta.get("simplified", False)),
|
|
216
|
-
"MaterialLength": "",
|
|
217
|
-
"searchType": [],
|
|
218
|
-
"searchChannel": [],
|
|
219
|
-
"knowledgeBase": knowledge_base,
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return {
|
|
223
|
-
"cleaned": True,
|
|
224
|
-
"articles": articles,
|
|
225
|
-
"total_articles": len(articles),
|
|
226
|
-
"total_paragraphs": para_id - 1,
|
|
227
|
-
"knowledgeBase": knowledge_base,
|
|
228
|
-
"knowledgeBasePath": "content.knowledgeBase",
|
|
229
|
-
"knowledgeBase_note": KNOWLEDGE_BASE_NOTE,
|
|
230
|
-
"policyFiles": policy_files,
|
|
231
|
-
"search_meta": search_meta,
|
|
232
|
-
# 通道标记(--clean 无此键,属增量):便于排查本文件出自哪条通道
|
|
233
|
-
"channel": "mcp",
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def main() -> None:
|
|
238
|
-
if hasattr(sys.stdout, "reconfigure"):
|
|
239
|
-
sys.stdout.reconfigure(encoding="utf-8")
|
|
240
|
-
parser = argparse.ArgumentParser(
|
|
241
|
-
description="MCP trusted_search 返回 → 与 dkag_search.py --clean 同构的形态(供全下游流程复用)")
|
|
242
|
-
parser.add_argument("input", help="MCP trusted_search 完整返回 JSON 文件(materials 形态)")
|
|
243
|
-
parser.add_argument("--area", default="", help="本次检索地域(写入 search_meta.area)")
|
|
244
|
-
parser.add_argument("--purpose", default="", help="搜索方案中的搜索目的(内部字段,不向用户展示)")
|
|
245
|
-
parser.add_argument("--output", "-o", help="输出文件名,默认写入 official-docs/search-results/")
|
|
246
|
-
args = parser.parse_args()
|
|
247
|
-
|
|
248
|
-
raw = Path(args.input).expanduser()
|
|
249
|
-
if not raw.is_absolute():
|
|
250
|
-
raw = (SEARCH_RESULTS_DIR / raw.name).resolve()
|
|
251
|
-
if not raw.is_file():
|
|
252
|
-
raise SystemExit(f"错误:输入文件不存在: {raw}")
|
|
253
|
-
try:
|
|
254
|
-
data = json.loads(raw.read_text(encoding="utf-8"))
|
|
255
|
-
except json.JSONDecodeError as exc:
|
|
256
|
-
raise SystemExit(
|
|
257
|
-
f"错误:{raw.name} 不是合法 JSON({exc})。请把 MCP 工具返回**完整原样**保存为文件——"
|
|
258
|
-
"内容里若含 ASCII 双引号,必须用 json.dump 写出,不要手工拼接字符串。") from None
|
|
259
|
-
|
|
260
|
-
converted = convert(data, args.area, args.purpose)
|
|
261
|
-
articles = converted["articles"]
|
|
262
|
-
if not articles:
|
|
263
|
-
raise SystemExit(
|
|
264
|
-
f"错误:从 {raw.name} 中解析出 0 篇材料,已停止(不写空结果,避免下游把「没取到材料」"
|
|
265
|
-
"当成「检索到 0 篇」继续走)。请确认保存的是 MCP trusted_search 的完整返回"
|
|
266
|
-
"(顶层含 materials 数组,且 include_details=true)。")
|
|
267
|
-
|
|
268
|
-
out_name = args.output or (raw.stem + "_converted.json")
|
|
269
|
-
out = Path(out_name).expanduser()
|
|
270
|
-
if not out.is_absolute():
|
|
271
|
-
out = (SEARCH_RESULTS_DIR / out.name).resolve()
|
|
272
|
-
try:
|
|
273
|
-
out.relative_to(SEARCH_RESULTS_DIR.resolve())
|
|
274
|
-
except ValueError:
|
|
275
|
-
raise SystemExit(f"错误:输出文件必须位于 {SEARCH_RESULTS_DIR}") from None
|
|
276
|
-
|
|
277
|
-
out.write_text(json.dumps(converted, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
278
|
-
with_doc = sum(1 for a in articles if a["段落"])
|
|
279
|
-
with_snap = sum(1 for a in articles if a.get("快照链接"))
|
|
280
|
-
print(f"✓ 转换完成:{len(articles)} 篇材料({with_doc} 篇带段落、{with_snap} 篇带快照)、"
|
|
281
|
-
f"{len(converted['policyFiles'])} 条文号 → {out}")
|
|
282
|
-
print(" 产物与 dkag_search.py --clean 同构(顶层 articles / 快照链接 / 段落 id),"
|
|
283
|
-
"研究资料、溯源 JSON、核验报告按现有流程执行。")
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if __name__ == "__main__":
|
|
287
|
-
main()
|