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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"""把深知可信搜索 deep-query/v3(深度搜索)的返回转换成与 dkag_search.py --clean 同构的形态,
|
|
3
3
|
供本 Skill 全部下游流程复用(素材分类、研究资料、溯源 JSON、核验报告)。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
背景:首轮检索改用深度搜索做广度召回——分 3 路(政策依据型/数据支撑型/参考案例型),
|
|
6
6
|
每路一次深度搜索,query 用「对象+关注方向」句式(不列举具体信息需求);拿到材料后,
|
|
7
7
|
政策原文/快照等缺口由可信搜索按需补搜;文号已由深搜自带(2026-10-23 起文章级 writtenText,映射为「发文字号」),不再为拿文号而必补。
|
|
8
8
|
|
|
@@ -34,7 +34,7 @@ import sys
|
|
|
34
34
|
from pathlib import Path
|
|
35
35
|
|
|
36
36
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
37
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
37
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
38
38
|
import os as _os
|
|
39
39
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
40
40
|
if not _ws:
|
|
@@ -62,7 +62,7 @@ def strip_html(text) -> str:
|
|
|
62
62
|
"""去掉深度搜索段落内容里的 HTML 标签并反转义实体(真实返回含表格等标签)。
|
|
63
63
|
|
|
64
64
|
表格标签(table/thead/tbody/tr/td/th/br)原样保留:深度返回的
|
|
65
|
-
|
|
65
|
+
标准限值表/名单表曾被整体拍平成空格分隔文本,知识专库与引文胶囊无法按表格
|
|
66
66
|
形态展示(渲染端 sanitize_table_html / render_excerpt_html 对表格做白名单清洗与
|
|
67
67
|
展示,可信搜索通道 dkag_search 亦原样保留表格,两通道口径一致)。"""
|
|
68
68
|
raw = str(text or "")
|
|
@@ -179,7 +179,7 @@ def convert(data, area: str, purpose: str) -> dict:
|
|
|
179
179
|
raw_query = first_value(data, "query") if isinstance(data, dict) else ""
|
|
180
180
|
search_meta = {
|
|
181
181
|
"query": raw_query,
|
|
182
|
-
# purpose
|
|
182
|
+
# purpose 兜底--purpose 为空时用该路 query 兜底——
|
|
183
183
|
# 留空会导致合并产物文章"搜索目的"缺失,溯源分组键退化成地域碎片。
|
|
184
184
|
"purpose": purpose or raw_query,
|
|
185
185
|
"area": area,
|
|
@@ -22,7 +22,7 @@ from typing import Any, Dict, List, Optional
|
|
|
22
22
|
|
|
23
23
|
DEFAULT_ENDPOINT = "https://open.dknowc.cn/api/services/deep-query/v3"
|
|
24
24
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
25
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
25
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
26
26
|
import os as _os
|
|
27
27
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
28
28
|
if not _ws:
|
|
@@ -4,7 +4,7 @@ DKAG 素材召回接口脚本
|
|
|
4
4
|
用于根据查询关键词召回相关公文素材
|
|
5
5
|
|
|
6
6
|
使用深知可信搜索 V2 接口:/open-api/maas/dependable/v2/search
|
|
7
|
-
(
|
|
7
|
+
(V2 接口;不保留 V1 代码路径)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import argparse
|
|
@@ -34,7 +34,7 @@ QUERY_TOO_SHORT_ERROR = f"错误:查询关键词过短,最少需要 {MIN_QUE
|
|
|
34
34
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
35
35
|
API_KEY_ENV = "DKNOWC_API_KEY"
|
|
36
36
|
DEFAULT_BASE_URL = "https://open.dknowc.cn/open-api/maas/dependable/v2/search"
|
|
37
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
37
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
38
38
|
import os as _os
|
|
39
39
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
40
40
|
if not _ws:
|
|
@@ -549,6 +549,7 @@ def dkag_search(
|
|
|
549
549
|
|
|
550
550
|
# 发送请求(429/402 全部按额度用尽处理,不重试——见 detect_quota_exhausted 注释)
|
|
551
551
|
try:
|
|
552
|
+
# 可信搜索为轻量补搜,默认 30 秒;深度搜索(deep_query.py)单次召回量大,默认 600 秒,两者按调用类型分别设定
|
|
552
553
|
response = requests.post(DEFAULT_BASE_URL, data=json.dumps(payload), headers=headers, timeout=30)
|
|
553
554
|
response.raise_for_status()
|
|
554
555
|
result = response.json()
|
|
@@ -31,7 +31,7 @@ import sys
|
|
|
31
31
|
from pathlib import Path
|
|
32
32
|
|
|
33
33
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
34
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
34
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
35
35
|
import os as _os
|
|
36
36
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
37
37
|
if not _ws:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""
|
|
3
3
|
公文排版脚本 v2.0.0
|
|
4
|
-
|
|
4
|
+
严格按照 config/format.json 与 reference/standards/ 的格式规范进行自动排版
|
|
5
5
|
|
|
6
6
|
【v2.0.0 更新说明】
|
|
7
7
|
- 删除所有红头文件相关代码(红头+尾表由 template_generator.py 处理)
|
|
@@ -17,7 +17,10 @@ import sys
|
|
|
17
17
|
from datetime import datetime
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
try:
|
|
21
|
+
import docx
|
|
22
|
+
except ImportError: # 顶层导入失败时给出可执行的安装提示,而不是堆栈
|
|
23
|
+
raise SystemExit("缺少依赖 python-docx,请先执行:python3 -m pip install python-docx")
|
|
21
24
|
import docx.opc.constants
|
|
22
25
|
from docx.enum.section import WD_ORIENT, WD_SECTION
|
|
23
26
|
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT, WD_TABLE_ALIGNMENT
|
|
@@ -189,13 +192,29 @@ def get_configured_output_dir():
|
|
|
189
192
|
|
|
190
193
|
|
|
191
194
|
def is_path_within(path, parent):
|
|
192
|
-
"""判断 path 是否位于 parent
|
|
195
|
+
"""判断 path 是否位于 parent 目录内(按真实路径比较,解析符号链接)。"""
|
|
193
196
|
try:
|
|
194
197
|
return os.path.commonpath([os.path.realpath(path), os.path.realpath(parent)]) == os.path.realpath(parent)
|
|
195
198
|
except ValueError:
|
|
196
199
|
return False
|
|
197
200
|
|
|
198
201
|
|
|
202
|
+
def read_text_auto(path):
|
|
203
|
+
"""按 utf-8-sig → utf-8 → gb18030 依次尝试读取正文,全部失败时给出明确提示。
|
|
204
|
+
|
|
205
|
+
中文材料常由 Word/WPS 另存为 GBK,硬用 utf-8 会直接抛 UnicodeDecodeError;
|
|
206
|
+
这里统一回退,并提示用户另存为 UTF-8 以便排查。
|
|
207
|
+
"""
|
|
208
|
+
raw = open(path, "rb").read()
|
|
209
|
+
for enc in ("utf-8-sig", "utf-8", "gb18030"):
|
|
210
|
+
try:
|
|
211
|
+
return raw.decode(enc)
|
|
212
|
+
except UnicodeDecodeError:
|
|
213
|
+
continue
|
|
214
|
+
raise SystemExit(
|
|
215
|
+
f"错误:无法识别正文文件编码({path})。请用文本编辑器另存为 UTF-8 后重试。")
|
|
216
|
+
|
|
217
|
+
|
|
199
218
|
def resolve_input_text_path(input_path):
|
|
200
219
|
"""只允许读取 skill 工作目录内的正文文本文件(符号链接解析后校验)。"""
|
|
201
220
|
raw_path = os.path.expanduser(str(input_path).strip())
|
|
@@ -223,7 +242,7 @@ def _looks_like_path(text):
|
|
|
223
242
|
|
|
224
243
|
用于路径解析失败时的兜底判定:含路径分隔符,或以常见正文扩展名结尾时
|
|
225
244
|
视为路径——此时若文件读不到,宁可报错也不要把路径字符串当成正文写进 Word
|
|
226
|
-
|
|
245
|
+
(否则会静默生成一份正文只有一行路径的"正式公文")。
|
|
227
246
|
"""
|
|
228
247
|
value = (text or "").strip()
|
|
229
248
|
if not value or "\n" in value:
|
|
@@ -989,8 +1008,8 @@ def strip_citation_markers(content_text: str) -> str:
|
|
|
989
1008
|
|
|
990
1009
|
背景:素材清单先行要求写作时边写边标 [n] 角标——但角标只服务于
|
|
991
1010
|
build_trace_json 装配溯源 JSON、在溯源核验报告 HTML 中变成可点击跳转;
|
|
992
|
-
**正式 Word
|
|
993
|
-
|
|
1011
|
+
**正式 Word 交付的正文不应内嵌来源角标**(见 reference/output_guide.md 交付规则)。
|
|
1012
|
+
模型常把同一份带角标正文直接交给本脚本,导致 Word 交付物残留
|
|
994
1013
|
[1]…[23] 角标(带角标正文两用时,交付物曾残留 86~141 个角标)。
|
|
995
1014
|
本函数作为兜底,在排版前统一剥离半角 [n] 与全角 【n】 形式。
|
|
996
1015
|
"""
|
|
@@ -1721,7 +1740,7 @@ def create_document(content_text, output_path=None):
|
|
|
1721
1740
|
# 署名右空相应增加——两分支均满足"日期首字=署名首字右移2字"。
|
|
1722
1741
|
# 右缩进是"距右缘的字数",右移=更靠右=字数更小:设日期首字距右缘为 date_len+date_indent、
|
|
1723
1742
|
# 署名首字为 unit_len+unit_indent,右移二字即 date_len+date_indent = unit_len+unit_indent-2。
|
|
1724
|
-
#
|
|
1743
|
+
# 修正:两分支旧实现均少算 4 字(写成 unit_len+4-date_len 与 date_len-unit_len),
|
|
1725
1744
|
# 导致每份稿子的成文日期都比规则要求偏左。
|
|
1726
1745
|
if should_right_align_date(lines, i):
|
|
1727
1746
|
last_sign_date = stripped
|
|
@@ -1810,10 +1829,9 @@ def main():
|
|
|
1810
1829
|
text_path = None
|
|
1811
1830
|
if text_path and os.path.exists(text_path) and os.path.isfile(text_path):
|
|
1812
1831
|
print(f'⚠ 检测到 --text 参数是文件路径,自动读取文件内容: {text_path}')
|
|
1813
|
-
|
|
1814
|
-
content = f.read()
|
|
1832
|
+
content = read_text_auto(text_path)
|
|
1815
1833
|
elif _looks_like_path(args.text):
|
|
1816
|
-
#
|
|
1834
|
+
# 路径解析失败时不得把路径字符串当正文——旧实现会生成一份
|
|
1817
1835
|
# 正文只有一行路径的"正式公文",且打印成功、退出码 0,用户与模型都无从察觉
|
|
1818
1836
|
raise SystemExit(
|
|
1819
1837
|
f'错误:--text 收到的是文件路径而非正文({args.text}),且该文件无法读取。\n'
|
|
@@ -1829,8 +1847,7 @@ def main():
|
|
|
1829
1847
|
elif args.input:
|
|
1830
1848
|
input_path = resolve_input_text_path(args.input)
|
|
1831
1849
|
if os.path.exists(input_path):
|
|
1832
|
-
|
|
1833
|
-
content = f.read()
|
|
1850
|
+
content = read_text_auto(input_path)
|
|
1834
1851
|
else:
|
|
1835
1852
|
raise FileNotFoundError(f"输入文件不存在: {input_path}")
|
|
1836
1853
|
else:
|
|
@@ -1848,7 +1865,7 @@ def main():
|
|
|
1848
1865
|
print(f'✗ 生成失败: {e}')
|
|
1849
1866
|
import traceback
|
|
1850
1867
|
traceback.print_exc()
|
|
1851
|
-
#
|
|
1868
|
+
# 旧实现失败分支不设退出码,宿主按退出码判断成败时会把
|
|
1852
1869
|
# 失败当成功继续走交付话术,用户收到不存在的路径
|
|
1853
1870
|
sys.exit(1)
|
|
1854
1871
|
|
|
@@ -70,10 +70,9 @@ def check_environment():
|
|
|
70
70
|
"api_key_source": config_status["api_key_source"],
|
|
71
71
|
"api_key_hint": config_status["api_key_hint"],
|
|
72
72
|
"config_issue": None if config_status["api_key_configured"] else "api_key_missing",
|
|
73
|
-
# channel_note
|
|
73
|
+
# channel_note:检索通道提示(常驻,面向使用者,不含内部路线图)。
|
|
74
74
|
"channel_note": (
|
|
75
|
-
"检索与大纲统一走本 Skill 脚本通道(deep_query.py / dkag_search.py / outline_reference.py
|
|
76
|
-
"需要 API Key。MCP「深知可信工作台」通道于 3.7.5 停用,待其大结果落盘方案改造完成后另行加回。"
|
|
75
|
+
"检索与大纲统一走本 Skill 脚本通道(deep_query.py / dkag_search.py / outline_reference.py),需要 API Key。"
|
|
77
76
|
),
|
|
78
77
|
"search_ready": config_status["api_key_configured"] and requests_available,
|
|
79
78
|
"search_blocking_issues": search_blocking_issues,
|
|
@@ -91,7 +90,7 @@ def check_environment():
|
|
|
91
90
|
"font_note": "Word 文档会写入公文常用字体名称;打开端如缺少对应字体,Word/WPS 可能自动替换,需以本机打开后的显示为准。",
|
|
92
91
|
"blocking_issues": blocking_issues,
|
|
93
92
|
"ready": not blocking_issues,
|
|
94
|
-
"search_ready_note": None if config_status["api_key_configured"] else "仅需要搜索的任务需先完成 MaaS 注册获取 API Key
|
|
93
|
+
"search_ready_note": None if config_status["api_key_configured"] else "仅需要搜索的任务需先完成 MaaS 注册获取 API Key(写入本机 Key 专用配置文件或注入环境变量);无需搜索的任务可先直接写作。",
|
|
95
94
|
"local_memory": {
|
|
96
95
|
"knowledge_base_materials": kb_count,
|
|
97
96
|
"knowledge_base_dir": "knowledge-base/",
|
|
@@ -152,7 +151,7 @@ def _in_dsh() -> bool:
|
|
|
152
151
|
def check_api_key_config():
|
|
153
152
|
if _in_dsh():
|
|
154
153
|
# dsh:优先 DSH_DKNOWC_API_KEY(与 MCP Bearer 同源);缺失时 resolve_api_key 兜底
|
|
155
|
-
# (环境变量 →
|
|
154
|
+
# (环境变量 → 专用配置文件)。配置文件读取不受 dsh 环境清理影响,
|
|
156
155
|
# 注册后本会话脚本立即可用。无 Key 仅暂停搜索,不阻断纯写作。
|
|
157
156
|
api_key = os.environ.get("DSH_DKNOWC_API_KEY", "").strip()
|
|
158
157
|
source = "environment"
|
|
@@ -166,7 +165,7 @@ def check_api_key_config():
|
|
|
166
165
|
pass
|
|
167
166
|
if not _valid_api_key(api_key):
|
|
168
167
|
return {"api_key_configured": False, "api_key_source": None,
|
|
169
|
-
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}
|
|
168
|
+
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(环境变量与专用配置文件均未找到)。运行注册脚本开通后 Key 自动写入 ~/.config/dknowc/api_key,本会话立即可用。仅搜索任务受影响,不涉及搜索的写作任务可继续。"}
|
|
170
169
|
return {"api_key_configured": True, "api_key_source": source, "api_key_hint": None}
|
|
171
170
|
|
|
172
171
|
|
|
@@ -191,7 +190,16 @@ def check_api_key_config():
|
|
|
191
190
|
|
|
192
191
|
|
|
193
192
|
def _valid_api_key(value):
|
|
194
|
-
|
|
193
|
+
"""判断 Key 是否像一份真实的检索密钥。
|
|
194
|
+
|
|
195
|
+
只做本地格式校验(不发网络请求):MaaS 密钥为 sk- 开头、长度不小于 20。
|
|
196
|
+
真实可用性(过期/无权限/额度用尽)由首次搜索调用的 401/403/429 分支处理,
|
|
197
|
+
避免每次初始化都多打一次接口。
|
|
198
|
+
"""
|
|
199
|
+
key = (value or "").strip()
|
|
200
|
+
if len(key) < 20 or not key.startswith("sk-"):
|
|
201
|
+
return False
|
|
202
|
+
return key not in {"your_api_key_here", "你的深知搜索 API Key"}
|
|
195
203
|
|
|
196
204
|
|
|
197
205
|
def main():
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
本地代理(127.0.0.1,路径带会话级 hash),内部持有真实凭据转发到云端 mcp.dknowc.cn。
|
|
7
7
|
环境变量 `CODEBUDDY_MCP_CONFIG` 内联 JSON 里含各 MCP server 的 url + headers
|
|
8
8
|
(Bearer 会话令牌)。脚本从该变量动态拿到 dknowc-mcp 的地址与头,直连代理发 JSON-RPC,
|
|
9
|
-
返回的完整 JSON 由脚本写入文件——模型不抄写大 JSON
|
|
10
|
-
(此前模型调 MCP 工具会把 60-170KB 返回抄进上下文再落盘,实测丢失 83%)。
|
|
9
|
+
返回的完整 JSON 由脚本写入文件——模型不抄写大 JSON,避免转写大返回时的内容丢失问题。
|
|
11
10
|
|
|
12
11
|
只负责"调用 + 落盘原始返回";转换仍走现有 deep_convert.py / mcp_convert.py。
|
|
13
12
|
|
|
@@ -31,7 +30,7 @@ import urllib.request
|
|
|
31
30
|
from pathlib import Path
|
|
32
31
|
|
|
33
32
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
34
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill
|
|
33
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录
|
|
35
34
|
import os as _os
|
|
36
35
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
37
36
|
if not _ws:
|
|
@@ -12,7 +12,7 @@ from pathlib import Path
|
|
|
12
12
|
from typing import List, Dict
|
|
13
13
|
|
|
14
14
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
15
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
15
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
16
16
|
import os as _os
|
|
17
17
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
18
18
|
if not _ws:
|
|
@@ -102,6 +102,12 @@ def merge_results(result_files: List[str]) -> Dict:
|
|
|
102
102
|
print(f"警告: 无法读取文件 {file_path}: {e}", file=sys.stderr)
|
|
103
103
|
continue
|
|
104
104
|
|
|
105
|
+
# 兼容顶层直接是文章数组的输入(部分接口/手工整理产物)
|
|
106
|
+
if isinstance(data, list):
|
|
107
|
+
data = {"cleaned": True, "articles": data}
|
|
108
|
+
if not isinstance(data, dict):
|
|
109
|
+
print(f"警告: 无法识别的文件结构,已跳过 {file_path}", file=sys.stderr)
|
|
110
|
+
continue
|
|
105
111
|
# 检查是否是清洗后的格式
|
|
106
112
|
if data.get("cleaned") and "articles" in data:
|
|
107
113
|
articles = data["articles"]
|
|
@@ -117,7 +123,7 @@ def merge_results(result_files: List[str]) -> Dict:
|
|
|
117
123
|
# 本文件处理前的文章/段落基线:用于计算每次调用真实新增量
|
|
118
124
|
before_article_count = len(all_articles)
|
|
119
125
|
before_para_total = sum(len(a.get("段落") or []) for a in all_articles)
|
|
120
|
-
#
|
|
126
|
+
# 搜索目的兜底该路 --purpose 为空时用该路 query 兜底——
|
|
121
127
|
# 若留空,文章"搜索目的"缺失,溯源报告分组键(search_key)会退化成
|
|
122
128
|
# "中国"/"浙江省"等地域碎片,材料面板筛选胶囊失去意义(避免大量篇目退化)。
|
|
123
129
|
purpose_val = search_meta.get("purpose") or search_meta.get("query") or ""
|
|
@@ -148,7 +154,7 @@ def merge_results(result_files: List[str]) -> Dict:
|
|
|
148
154
|
})
|
|
149
155
|
|
|
150
156
|
# 规范性文件清单(policyFiles,含发文字号):可信搜索补搜产物携带,
|
|
151
|
-
# 是溯源核验报告匹配"文号"
|
|
157
|
+
# 是溯源核验报告匹配"文号"的唯一来源,合并时必须带下去(旧实现被整体丢弃,
|
|
152
158
|
# 导致合并产物 policyFiles 恒为空、政策文件无法显示发文字号)。
|
|
153
159
|
for pf in (data.get("policyFiles") or []):
|
|
154
160
|
if not isinstance(pf, dict):
|
|
@@ -159,10 +165,11 @@ def merge_results(result_files: List[str]) -> Dict:
|
|
|
159
165
|
seen_policies.add(key)
|
|
160
166
|
all_policy_files.append(pf)
|
|
161
167
|
|
|
162
|
-
#
|
|
163
|
-
#
|
|
168
|
+
# 去重合并:合并式去重,不按标题整体丢弃后篇。
|
|
169
|
+
# 同一材料多次搜索返回时,标题相同但召回段落可能不同(各次搜索命中不同相关段落),
|
|
164
170
|
# 按标题丢弃会丢掉其他搜索带来的段落;标题微小差异(空格/全半角/赘词)又可能漏去重。
|
|
165
|
-
#
|
|
171
|
+
# 做法:以"规范化标题"为主键(标题为空时退回源网址)判同一材料,合并段落、字段取并集:
|
|
172
|
+
# 同标题不同网址视为同一材料的不同抓取/镜像,保留先到的源网址,缺失时由后篇补齐。
|
|
166
173
|
for article in articles:
|
|
167
174
|
title = article.get("文章标题", "")
|
|
168
175
|
url = article.get("源网址") or article.get("sourceUrl") or article.get("原文链接") or ""
|
|
@@ -14,7 +14,7 @@ import requests
|
|
|
14
14
|
|
|
15
15
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
16
16
|
API_KEY_ENV = "DKNOWC_API_KEY"
|
|
17
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
17
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
18
18
|
import os as _os
|
|
19
19
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
20
20
|
if not _ws:
|
|
@@ -119,8 +119,13 @@ def read_docx(path: Path) -> str:
|
|
|
119
119
|
pieces.append(elem.text)
|
|
120
120
|
elif tag in {"p", "br"}:
|
|
121
121
|
pieces.append("\n")
|
|
122
|
-
except (zipfile.BadZipFile, ElementTree.ParseError, OSError):
|
|
123
|
-
|
|
122
|
+
except (zipfile.BadZipFile, ElementTree.ParseError, OSError) as exc:
|
|
123
|
+
# 读不出内容时不能当成“无风险”:报错退出,避免把损坏/加密的 docx 判为通过
|
|
124
|
+
raise SystemExit(
|
|
125
|
+
f"无法读取 {path}:{exc}。请确认它是未加密的 .docx;"
|
|
126
|
+
"如需检查 .doc 请先另存为 .docx 或 .txt。")
|
|
127
|
+
if not pieces:
|
|
128
|
+
raise SystemExit(f"{path} 中没有可扫描的文本(可能是图片型或空文档),未做质检。")
|
|
124
129
|
return "".join(pieces)
|
|
125
130
|
|
|
126
131
|
|