dknowc-dsh 2.2.1 → 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 +10 -38
- package/package.json +2 -2
- package/skills/dknowc-official-doc-writer/README.md +34 -31
- package/skills/dknowc-official-doc-writer/SKILL.md +87 -373
- package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +17 -2
- package/skills/dknowc-official-doc-writer/reference/genre_writing_notes.md +116 -0
- package/skills/dknowc-official-doc-writer/reference/initialization.md +69 -0
- package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +7 -0
- package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +42 -0
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +44 -33
- package/skills/dknowc-official-doc-writer/reference/outline_rules.md +36 -0
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +80 -12
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +6 -4
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +24 -0
- package/skills/dknowc-official-doc-writer/reference/revision_workflow.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +3 -3
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +35 -33
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +27 -19
- package/skills/dknowc-official-doc-writer/reference/standards/00_index.md +64 -78
- package/skills/dknowc-official-doc-writer/reference/standards/29_research.md +7 -0
- package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +3 -2
- package/skills/dknowc-official-doc-writer/reference/task_router.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/working_principles.md +32 -0
- package/skills/dknowc-official-doc-writer/reference/writing_rules.md +83 -0
- 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 +43 -11
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +123 -14
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +17 -14
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +3 -3
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +133 -55
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +43 -23
- 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 +36 -13
- 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 +540 -207
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +247 -44
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +20 -8
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -1
- package/skills/dknowc-ppt-assistant/README.md +21 -6
- package/skills/dknowc-ppt-assistant/SKILL.md +23 -68
- package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +3 -2
- package/skills/dknowc-ppt-assistant/references/initialization.md +106 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +12 -8
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +48 -17
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +3 -3
- 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/preview_slide_html.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 +207 -40
- 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 +63 -11
- package/skills/dknowc-ppt-assistant/scripts/update_spec.py +25 -1
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +30 -16
- package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
- package/skills/dknowc-trusted-search/README.md +13 -13
- package/skills/dknowc-trusted-search/SKILL.md +96 -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 +4 -2
- 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/merge_search_results.py +68 -10
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +617 -275
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +87 -19
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +109 -44
- package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +0 -272
- 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,272 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""把 MCP「深知可信工作台」trusted_search(include_details=true 形态)的返回
|
|
3
|
-
转换成与深知可信搜索脚本 `scripts/dkag_search.py --clean` **完全同构**的形态,
|
|
4
|
-
供本 Skill 全部下游流程复用。
|
|
5
|
-
|
|
6
|
-
背景(3.7.3):检测到宿主已连接 MCP「深知可信工作台」时,搜索走 MCP 通道
|
|
7
|
-
(免 API Key)。模型在对话层调用 MCP 工具后,把完整返回 JSON 保存到
|
|
8
|
-
official-docs/search-results/,再运行本脚本转换。
|
|
9
|
-
|
|
10
|
-
为什么必须与 `--clean` 同构:脚本通道的下游(模型整理溯源
|
|
11
|
-
JSON、`merge_search_results.py`、`source_note_html.py` 的历史索引回填)都按
|
|
12
|
-
`--clean` 的字段名读取——文章在**顶层 `articles`**、快照字段名是**`快照链接`**、
|
|
13
|
-
段落带自增 `id`。此前本脚本输出的是 REST 原始形态(`content.data.检索文章`),
|
|
14
|
-
导致 MCP 通道产物在下游:文章数组读空(被误判"未检索到相关文章")、快照链接
|
|
15
|
-
整条丢失(`快照链接` 键不存在,而 `source_note_html.py` 只认这个键名)。
|
|
16
|
-
现直接输出 `--clean` 形态,文档只描述一种形态。
|
|
17
|
-
|
|
18
|
-
字段映射:
|
|
19
|
-
title → 文章标题 source → 数据源 date → 发布日期
|
|
20
|
-
url → 源网址 / 原文链接 date_confidence → 发布日期可信度
|
|
21
|
-
snapshot → 快照链接
|
|
22
|
-
segments[{title,content}] → 段落[{id, 标题, 内容}](段落标题为标题链数据源;
|
|
23
|
-
segments 缺失时用 paragraph 兜底构造无标题单段;id 全局自增,同 --clean)
|
|
24
|
-
doc_number → 文章级 `文号`(标准格式,供整理溯源 JSON 时直接复制)+
|
|
25
|
-
顶层 `policyFiles[{title, writtenText}]`(与 --clean 的接口返回一致)
|
|
26
|
-
内容中的 </>/&/" HTML 实体顺手反转义(MCP 透传未清洗)。
|
|
27
|
-
|
|
28
|
-
用法:
|
|
29
|
-
python3 scripts/mcp_convert.py official-docs/search-results/mcp_raw.json \
|
|
30
|
-
--area 北京市 --purpose "搜索目的" \
|
|
31
|
-
--output official-docs/search-results/result_xxx.json
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
from __future__ import annotations
|
|
35
|
-
|
|
36
|
-
import argparse
|
|
37
|
-
import json
|
|
38
|
-
import sys
|
|
39
|
-
from pathlib import Path
|
|
40
|
-
|
|
41
|
-
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
42
|
-
SEARCH_RESULTS_DIR = SKILL_ROOT / "official-docs" / "search-results"
|
|
43
|
-
|
|
44
|
-
HTML_ENTITIES = (("&lt;", "<"), ("&gt;", ">"), ("&amp;", "&"), ("&quot;", '"'),
|
|
45
|
-
("<", "<"), (">", ">"), ("&", "&"), (""", '"'))
|
|
46
|
-
|
|
47
|
-
KNOWLEDGE_BASE_NOTE = ("知识专库链接来自深知可信搜索接口返回的 knowledgeBase;"
|
|
48
|
-
"MCP 通道由 mcp_convert.py 冗余复制到顶层,与 --clean 口径一致。")
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def clean_text(text: str) -> str:
|
|
52
|
-
"""反转义 MCP 透传内容中的 HTML 实体(全角/半角形式)并去首尾空白。"""
|
|
53
|
-
out = str(text or "")
|
|
54
|
-
for a, b in HTML_ENTITIES:
|
|
55
|
-
out = out.replace(a, b)
|
|
56
|
-
return out.strip()
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def first_value(item: dict, *keys: str) -> str:
|
|
60
|
-
for key in keys:
|
|
61
|
-
value = item.get(key)
|
|
62
|
-
if value not in (None, "", [], {}):
|
|
63
|
-
return str(value)
|
|
64
|
-
return ""
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def extract_materials(data) -> list:
|
|
68
|
-
"""从 MCP 返回中取出 materials 数组,兼容几种常见包裹形态。
|
|
69
|
-
|
|
70
|
-
直接形态:{"materials": [...]}
|
|
71
|
-
带信封:{"data": {"materials": [...]}}、{"content": [{"type": "text", "text": "{...}"}]}
|
|
72
|
-
纯数组:[{...}, {...}]
|
|
73
|
-
取不到时返回空列表,由调用方报错(不得静默产出 0 篇继续往下走)。
|
|
74
|
-
"""
|
|
75
|
-
if isinstance(data, list):
|
|
76
|
-
return data
|
|
77
|
-
if not isinstance(data, dict):
|
|
78
|
-
return []
|
|
79
|
-
|
|
80
|
-
materials = data.get("materials")
|
|
81
|
-
if isinstance(materials, list):
|
|
82
|
-
return materials
|
|
83
|
-
|
|
84
|
-
inner = data.get("data")
|
|
85
|
-
if isinstance(inner, dict) and isinstance(inner.get("materials"), list):
|
|
86
|
-
return inner["materials"]
|
|
87
|
-
|
|
88
|
-
# MCP 工具信封:content 数组里放 JSON 字符串
|
|
89
|
-
content = data.get("content")
|
|
90
|
-
if isinstance(content, list):
|
|
91
|
-
for block in content:
|
|
92
|
-
if not isinstance(block, dict):
|
|
93
|
-
continue
|
|
94
|
-
text = block.get("text") or block.get("content")
|
|
95
|
-
if isinstance(text, str) and text.strip().startswith(("{", "[")):
|
|
96
|
-
try:
|
|
97
|
-
return extract_materials(json.loads(text))
|
|
98
|
-
except json.JSONDecodeError:
|
|
99
|
-
continue
|
|
100
|
-
return []
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def parse_segments(material: dict, start_id: int) -> tuple[list, int]:
|
|
104
|
-
"""segments → 段落[{id,标题,内容}],与 --clean 一致。
|
|
105
|
-
|
|
106
|
-
兼容数组与(历史)字符串形态;缺失时用 paragraph 兜底构造无标题单段。
|
|
107
|
-
返回(段落列表, 下一个可用 id)。
|
|
108
|
-
"""
|
|
109
|
-
segments = material.get("segments")
|
|
110
|
-
if isinstance(segments, str) and segments.strip().startswith("["):
|
|
111
|
-
try: # 历史形态容错:repr 字符串
|
|
112
|
-
import ast
|
|
113
|
-
segments = ast.literal_eval(segments)
|
|
114
|
-
except (ValueError, SyntaxError):
|
|
115
|
-
segments = None
|
|
116
|
-
|
|
117
|
-
paragraphs: list = []
|
|
118
|
-
next_id = start_id
|
|
119
|
-
if isinstance(segments, list) and segments:
|
|
120
|
-
for seg in segments:
|
|
121
|
-
if not isinstance(seg, dict):
|
|
122
|
-
continue
|
|
123
|
-
title = clean_text(first_value(seg, "title", "标题"))
|
|
124
|
-
content = clean_text(first_value(seg, "content", "内容"))
|
|
125
|
-
if content:
|
|
126
|
-
paragraphs.append({"id": next_id, "标题": title, "内容": content})
|
|
127
|
-
next_id += 1
|
|
128
|
-
if not paragraphs:
|
|
129
|
-
fallback = clean_text(first_value(material, "paragraph"))
|
|
130
|
-
if fallback:
|
|
131
|
-
paragraphs.append({"id": next_id, "标题": "", "内容": fallback})
|
|
132
|
-
next_id += 1
|
|
133
|
-
return paragraphs, next_id
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def convert(data, area: str, purpose: str) -> dict:
|
|
137
|
-
materials = extract_materials(data)
|
|
138
|
-
articles: list = []
|
|
139
|
-
policy_files: list = []
|
|
140
|
-
seen_pf = set()
|
|
141
|
-
para_id = 1
|
|
142
|
-
|
|
143
|
-
for material in materials:
|
|
144
|
-
if not isinstance(material, dict):
|
|
145
|
-
continue
|
|
146
|
-
title = clean_text(first_value(material, "title", "文章标题"))
|
|
147
|
-
if not title:
|
|
148
|
-
continue
|
|
149
|
-
paragraphs, para_id = parse_segments(material, para_id)
|
|
150
|
-
source_url = clean_text(first_value(material, "url", "源网址", "sourceUrl"))
|
|
151
|
-
article = {
|
|
152
|
-
# 字段名与顺序对齐 --clean 白名单口径
|
|
153
|
-
"文章标题": title,
|
|
154
|
-
"发布日期": clean_text(first_value(material, "date", "发布日期")),
|
|
155
|
-
"数据源": clean_text(first_value(material, "source", "数据源")),
|
|
156
|
-
"段落": paragraphs,
|
|
157
|
-
}
|
|
158
|
-
if source_url:
|
|
159
|
-
article["源网址"] = source_url
|
|
160
|
-
article["原文链接"] = source_url
|
|
161
|
-
date_confidence = clean_text(first_value(material, "date_confidence", "发布日期可信度"))
|
|
162
|
-
if date_confidence:
|
|
163
|
-
article["发布日期可信度"] = date_confidence
|
|
164
|
-
snapshot = clean_text(first_value(material, "snapshot", "screenShotPath", "快照链接"))
|
|
165
|
-
if snapshot:
|
|
166
|
-
# 键名必须是"快照链接":source_note_html.py 读历史索引时只认这个键
|
|
167
|
-
article["快照链接"] = snapshot
|
|
168
|
-
doc_number = clean_text(first_value(material, "doc_number", "文号"))
|
|
169
|
-
if doc_number:
|
|
170
|
-
# 文号直写文章级(MCP 通道增量):整理溯源 JSON 时直接复制,
|
|
171
|
-
# 免跨文件翻 policyFiles——实测模型做跨文件标题匹配会跳过
|
|
172
|
-
article["文号"] = doc_number
|
|
173
|
-
articles.append(article)
|
|
174
|
-
|
|
175
|
-
if doc_number and title not in seen_pf:
|
|
176
|
-
seen_pf.add(title)
|
|
177
|
-
policy_files.append({"title": title, "writtenText": doc_number,
|
|
178
|
-
"sourceUrl": source_url or None,
|
|
179
|
-
"createDate": article["发布日期"] or None,
|
|
180
|
-
"createDateReliability": date_confidence or None})
|
|
181
|
-
|
|
182
|
-
raw_meta = {}
|
|
183
|
-
if isinstance(data, dict) and isinstance(data.get("search_meta"), dict):
|
|
184
|
-
raw_meta = data["search_meta"]
|
|
185
|
-
query = first_value(data, "query") if isinstance(data, dict) else ""
|
|
186
|
-
query = query or raw_meta.get("query", "")
|
|
187
|
-
knowledge_base = first_value(data, "knowledge_base_url", "knowledgeBase") if isinstance(data, dict) else ""
|
|
188
|
-
|
|
189
|
-
search_meta = {
|
|
190
|
-
"query": query,
|
|
191
|
-
"purpose": purpose,
|
|
192
|
-
"area": area or (first_value(data, "service_area") if isinstance(data, dict) else ""),
|
|
193
|
-
"time": raw_meta.get("eff_time", ""),
|
|
194
|
-
"requested_time": "",
|
|
195
|
-
"time_ignored": False,
|
|
196
|
-
"policy": True,
|
|
197
|
-
"full": False,
|
|
198
|
-
"clean": True,
|
|
199
|
-
"segmentCount": int(raw_meta.get("segment_count", 2) or 2),
|
|
200
|
-
"simplified": bool(raw_meta.get("simplified", False)),
|
|
201
|
-
"MaterialLength": "",
|
|
202
|
-
"searchType": [],
|
|
203
|
-
"searchChannel": [],
|
|
204
|
-
"knowledgeBase": knowledge_base,
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
"cleaned": True,
|
|
209
|
-
"articles": articles,
|
|
210
|
-
"total_articles": len(articles),
|
|
211
|
-
"total_paragraphs": para_id - 1,
|
|
212
|
-
"knowledgeBase": knowledge_base,
|
|
213
|
-
"knowledgeBasePath": "content.knowledgeBase",
|
|
214
|
-
"knowledgeBase_note": KNOWLEDGE_BASE_NOTE,
|
|
215
|
-
"policyFiles": policy_files,
|
|
216
|
-
"search_meta": search_meta,
|
|
217
|
-
# 通道标记(--clean 无此键,属增量):便于排查本文件出自哪条通道
|
|
218
|
-
"channel": "mcp",
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def main() -> None:
|
|
223
|
-
if hasattr(sys.stdout, "reconfigure"):
|
|
224
|
-
sys.stdout.reconfigure(encoding="utf-8")
|
|
225
|
-
parser = argparse.ArgumentParser(
|
|
226
|
-
description="MCP trusted_search 返回 → 与 dkag_search.py --clean 同构的形态(供全下游流程复用)")
|
|
227
|
-
parser.add_argument("input", help="MCP trusted_search 完整返回 JSON 文件(materials 形态)")
|
|
228
|
-
parser.add_argument("--area", default="", help="本次检索地域(写入 search_meta.area)")
|
|
229
|
-
parser.add_argument("--purpose", default="", help="搜索方案中的搜索目的(内部字段,不向用户展示)")
|
|
230
|
-
parser.add_argument("--output", "-o", help="输出文件名,默认写入 official-docs/search-results/")
|
|
231
|
-
args = parser.parse_args()
|
|
232
|
-
|
|
233
|
-
raw = Path(args.input).expanduser()
|
|
234
|
-
if not raw.is_absolute():
|
|
235
|
-
raw = (SEARCH_RESULTS_DIR / raw.name).resolve()
|
|
236
|
-
if not raw.is_file():
|
|
237
|
-
raise SystemExit(f"错误:输入文件不存在: {raw}")
|
|
238
|
-
try:
|
|
239
|
-
data = json.loads(raw.read_text(encoding="utf-8"))
|
|
240
|
-
except json.JSONDecodeError as exc:
|
|
241
|
-
raise SystemExit(
|
|
242
|
-
f"错误:{raw.name} 不是合法 JSON({exc})。请把 MCP 工具返回**完整原样**保存为文件——"
|
|
243
|
-
"内容里若含 ASCII 双引号,必须用 json.dump 写出,不要手工拼接字符串。") from None
|
|
244
|
-
|
|
245
|
-
converted = convert(data, args.area, args.purpose)
|
|
246
|
-
articles = converted["articles"]
|
|
247
|
-
if not articles:
|
|
248
|
-
raise SystemExit(
|
|
249
|
-
f"错误:从 {raw.name} 中解析出 0 篇材料,已停止(不写空结果,避免下游把「没取到材料」"
|
|
250
|
-
"当成「检索到 0 篇」继续走)。请确认保存的是 MCP trusted_search 的完整返回"
|
|
251
|
-
"(顶层含 materials 数组,且 include_details=true)。")
|
|
252
|
-
|
|
253
|
-
out_name = args.output or (raw.stem + "_converted.json")
|
|
254
|
-
out = Path(out_name).expanduser()
|
|
255
|
-
if not out.is_absolute():
|
|
256
|
-
out = (SEARCH_RESULTS_DIR / out.name).resolve()
|
|
257
|
-
try:
|
|
258
|
-
out.relative_to(SEARCH_RESULTS_DIR.resolve())
|
|
259
|
-
except ValueError:
|
|
260
|
-
raise SystemExit(f"错误:输出文件必须位于 {SEARCH_RESULTS_DIR}") from None
|
|
261
|
-
|
|
262
|
-
out.write_text(json.dumps(converted, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
263
|
-
with_doc = sum(1 for a in articles if a["段落"])
|
|
264
|
-
with_snap = sum(1 for a in articles if a.get("快照链接"))
|
|
265
|
-
print(f"✓ 转换完成:{len(articles)} 篇材料({with_doc} 篇带段落、{with_snap} 篇带快照)、"
|
|
266
|
-
f"{len(converted['policyFiles'])} 条文号 → {out}")
|
|
267
|
-
print(" 产物与 dkag_search.py --clean 同构(顶层 articles / 快照链接 / 段落 id),"
|
|
268
|
-
"研究资料、溯源 JSON、核验报告按现有流程执行。")
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if __name__ == "__main__":
|
|
272
|
-
main()
|