dknowc-dsh 1.0.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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/cordis.patch.yml +17 -0
  4. package/package.json +33 -0
  5. package/skills/dknowc-official-doc-writer/README.md +156 -0
  6. package/skills/dknowc-official-doc-writer/SKILL.md +462 -0
  7. package/skills/dknowc-official-doc-writer/config/format.json +101 -0
  8. package/skills/dknowc-official-doc-writer/config/user_profile.json.example +6 -0
  9. package/skills/dknowc-official-doc-writer/official-docs/input/mcp_intro_content.md +61 -0
  10. package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +113 -0
  11. package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +62 -0
  12. package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +138 -0
  13. package/skills/dknowc-official-doc-writer/reference/output_guide.md +288 -0
  14. package/skills/dknowc-official-doc-writer/reference/review_checklist.md +156 -0
  15. package/skills/dknowc-official-doc-writer/reference/search_guide.md +317 -0
  16. package/skills/dknowc-official-doc-writer/reference/search_intro.md +15 -0
  17. package/skills/dknowc-official-doc-writer/reference/search_policy.md +284 -0
  18. package/skills/dknowc-official-doc-writer/reference/standards/00_index.md +151 -0
  19. package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +51 -0
  20. package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +53 -0
  21. package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +48 -0
  22. package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +51 -0
  23. package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +55 -0
  24. package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +81 -0
  25. package/skills/dknowc-official-doc-writer/reference/standards/07_minutes.md +46 -0
  26. package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +53 -0
  27. package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +45 -0
  28. package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +44 -0
  29. package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +46 -0
  30. package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +46 -0
  31. package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +46 -0
  32. package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +41 -0
  33. package/skills/dknowc-official-doc-writer/reference/standards/15_business_docs.md +47 -0
  34. package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +47 -0
  35. package/skills/dknowc-official-doc-writer/reference/standards/17_resolution.md +45 -0
  36. package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +44 -0
  37. package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +45 -0
  38. package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +45 -0
  39. package/skills/dknowc-official-doc-writer/reference/standards/21_explanation.md +40 -0
  40. package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +47 -0
  41. package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +46 -0
  42. package/skills/dknowc-official-doc-writer/reference/standards/24_procurement.md +40 -0
  43. package/skills/dknowc-official-doc-writer/reference/standards/25_plan.md +42 -0
  44. package/skills/dknowc-official-doc-writer/reference/standards/26_summary.md +42 -0
  45. package/skills/dknowc-official-doc-writer/reference/standards/27_speech.md +43 -0
  46. package/skills/dknowc-official-doc-writer/reference/standards/28_rules.md +40 -0
  47. package/skills/dknowc-official-doc-writer/reference/standards/29_research.md +42 -0
  48. package/skills/dknowc-official-doc-writer/reference/standards/30_feasibility.md +42 -0
  49. package/skills/dknowc-official-doc-writer/reference/standards/31_review_material.md +40 -0
  50. package/skills/dknowc-official-doc-writer/reference/standards/32_ai_compute.md +41 -0
  51. package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +569 -0
  52. package/skills/dknowc-official-doc-writer/reference/task_router.md +119 -0
  53. package/skills/dknowc-official-doc-writer/scripts/adapt_mcp_result.py +241 -0
  54. package/skills/dknowc-official-doc-writer/scripts/check_release.py +78 -0
  55. package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +575 -0
  56. package/skills/dknowc-official-doc-writer/scripts/format_document.py +1756 -0
  57. package/skills/dknowc-official-doc-writer/scripts/initialize.py +178 -0
  58. package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +158 -0
  59. package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +223 -0
  60. package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +202 -0
  61. package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +242 -0
  62. package/skills/dknowc-official-doc-writer/scripts/register.mjs +218 -0
  63. package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +966 -0
  64. package/skills/dknowc-official-doc-writer/scripts/review_document.py +127 -0
  65. package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +180 -0
  66. package/skills/dknowc-official-doc-writer/scripts/template_generator.py +975 -0
  67. package/skills/dknowc-trusted-consulting/README.md +63 -0
  68. package/skills/dknowc-trusted-consulting/SKILL.md +172 -0
  69. package/skills/dknowc-trusted-consulting/scripts/adapt_mcp_result.py +241 -0
  70. package/skills/dknowc-trusted-consulting/scripts/check_release.py +66 -0
  71. package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +475 -0
  72. package/skills/dknowc-trusted-consulting/scripts/initialize.py +89 -0
  73. package/skills/dknowc-trusted-consulting/scripts/mcp_direct.py +158 -0
  74. package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +181 -0
  75. package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +990 -0
  76. package/skills/dknowc-trusted-search/README.md +63 -0
  77. package/skills/dknowc-trusted-search/SKILL.md +232 -0
  78. package/skills/dknowc-trusted-search/official-docs/output/.gitkeep +0 -0
  79. package/skills/dknowc-trusted-search/official-docs/search-results/.gitkeep +0 -0
  80. package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +241 -0
  81. package/skills/dknowc-trusted-search/scripts/check_release.py +79 -0
  82. package/skills/dknowc-trusted-search/scripts/deep_query.py +266 -0
  83. package/skills/dknowc-trusted-search/scripts/initialize.py +89 -0
  84. package/skills/dknowc-trusted-search/scripts/mcp_direct.py +158 -0
  85. package/skills/dknowc-trusted-search/scripts/register_key.mjs +181 -0
  86. package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +889 -0
  87. package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1011 -0
  88. package/skills/dknowc-trusted-search/scripts/trusted_search.py +325 -0
  89. package/src/index.js +103 -0
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env python3
2
+ """读取已有 DOCX,输出格式审查和内容核验的结构化基础结果。
3
+
4
+ 本脚本只负责安全读取 Word 结构和提取待核验文本,不调用搜索接口,也不改写原文件。
5
+ 内容核验由 Agent 根据 claims 设计搜索方案并调用 dkag_search.py 完成。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+ import re
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ try:
17
+ from docx import Document
18
+ except ImportError: # pragma: no cover
19
+ Document = None
20
+
21
+
22
+ SKILL_ROOT = Path(__file__).resolve().parent.parent
23
+ # 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
24
+ import os as _os
25
+ WS_ROOT = Path(_os.environ.get("DKNWOC_WS_ROOT") or _os.getcwd()).resolve()
26
+
27
+ INPUT_DIR = WS_ROOT / "official-docs" / "input"
28
+ OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
29
+
30
+
31
+ def safe_path(value: str, allowed: Path, suffix: str) -> Path:
32
+ raw = Path(value).expanduser()
33
+ path = raw.resolve() if raw.is_absolute() else (allowed / raw.name).resolve()
34
+ try:
35
+ path.relative_to(allowed.resolve())
36
+ except ValueError as exc:
37
+ raise ValueError(f"文件必须位于 {allowed}: {value}") from exc
38
+ if path.suffix.lower() != suffix:
39
+ raise ValueError(f"文件必须是 {suffix} 文件: {value}")
40
+ return path
41
+
42
+
43
+ def paragraph_text(paragraph) -> str:
44
+ return "".join(run.text for run in paragraph.runs).strip()
45
+
46
+
47
+ def inspect_document(path: Path) -> dict:
48
+ if Document is None:
49
+ raise RuntimeError("缺少 python-docx,请先按初始化流程安装依赖")
50
+ doc = Document(str(path))
51
+ paragraphs = []
52
+ claims = []
53
+ for index, paragraph in enumerate(doc.paragraphs, 1):
54
+ text = paragraph_text(paragraph)
55
+ if not text:
56
+ continue
57
+ style = paragraph.style.name if paragraph.style else ""
58
+ item = {"index": index, "text": text, "style": style}
59
+ paragraphs.append(item)
60
+ if re.search(r"政策|办法|条例|规定|标准|数据|达到|超过|占比|金额|亿元|万人|全国首个|唯一|领先|发布|印发|文号", text):
61
+ claims.append({"paragraph": index, "text": text, "reason": "包含政策、数据、案例或高风险事实表述,建议通过深知可信搜索核验"})
62
+
63
+ tables = []
64
+ for table_index, table in enumerate(doc.tables, 1):
65
+ rows = []
66
+ for row in table.rows:
67
+ rows.append([cell.text.strip() for cell in row.cells])
68
+ tables.append({"index": table_index, "rows": len(rows), "columns": max((len(row) for row in rows), default=0), "preview": rows[:3]})
69
+
70
+ sections = []
71
+ for index, section in enumerate(doc.sections, 1):
72
+ sections.append({
73
+ "index": index,
74
+ "page_width_twips": section.page_width.twips if section.page_width else None,
75
+ "page_height_twips": section.page_height.twips if section.page_height else None,
76
+ "top_margin_twips": section.top_margin.twips if section.top_margin else None,
77
+ "bottom_margin_twips": section.bottom_margin.twips if section.bottom_margin else None,
78
+ "left_margin_twips": section.left_margin.twips if section.left_margin else None,
79
+ "right_margin_twips": section.right_margin.twips if section.right_margin else None,
80
+ })
81
+
82
+ fonts = {}
83
+ for paragraph in doc.paragraphs:
84
+ for run in paragraph.runs:
85
+ name = run.font.name or "未明确设置"
86
+ fonts[name] = fonts.get(name, 0) + len(run.text or "")
87
+
88
+ return {
89
+ "source_file": path.name,
90
+ "format_review": {
91
+ "paragraph_count": len(paragraphs),
92
+ "table_count": len(tables),
93
+ "sections": sections,
94
+ "font_usage": fonts,
95
+ "paragraphs": paragraphs,
96
+ "tables": tables,
97
+ },
98
+ "content_review": {"claims": claims, "claim_count": len(claims)},
99
+ "next_step": "仅格式审查可直接根据 format_review 输出问题;涉及内容真实性时,先根据 claims 设计搜索方案并经用户确认,再调用深知搜索。",
100
+ }
101
+
102
+
103
+ def main() -> None:
104
+ parser = argparse.ArgumentParser(description="读取已有 DOCX 并输出结构化审查基础结果")
105
+ parser.add_argument("input", help="已有 DOCX,必须位于 official-docs/input")
106
+ parser.add_argument("--output", "-o", help="JSON 输出文件,默认写入 official-docs/output")
107
+ args = parser.parse_args()
108
+ input_path = safe_path(args.input, INPUT_DIR, ".docx")
109
+ if not input_path.exists():
110
+ raise FileNotFoundError(f"输入文件不存在: {input_path}")
111
+ output_path = safe_path(args.output, OUTPUT_DIR, ".json") if args.output else None
112
+ result = inspect_document(input_path)
113
+ rendered = json.dumps(result, ensure_ascii=False, indent=2)
114
+ if output_path:
115
+ output_path.parent.mkdir(parents=True, exist_ok=True)
116
+ output_path.write_text(rendered, encoding="utf-8")
117
+ print(f"审查基础结果已写入: {output_path}")
118
+ else:
119
+ print(rendered)
120
+
121
+
122
+ if __name__ == "__main__":
123
+ try:
124
+ main()
125
+ except Exception as exc:
126
+ print(f"错误: {exc}", file=sys.stderr)
127
+ raise SystemExit(1)
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env python3
2
+ """把写作流程的结构化正文/素材 JSON 转成可信搜索同款溯源报告。"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import importlib.util
8
+ import json
9
+ import re
10
+ import unicodedata
11
+ from pathlib import Path
12
+
13
+
14
+ SKILL_ROOT = Path(__file__).resolve().parent.parent
15
+ # 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
16
+ import os as _os
17
+ WS_ROOT = Path(_os.environ.get("DKNWOC_WS_ROOT") or _os.getcwd()).resolve()
18
+
19
+ INPUT_DIR = WS_ROOT / "official-docs" / "input"
20
+ OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
21
+ SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
22
+
23
+
24
+ def load_renderer():
25
+ path = Path(__file__).with_name("render_trace_html.py")
26
+ spec = importlib.util.spec_from_file_location("dknowc_trace_renderer", path)
27
+ if spec is None or spec.loader is None:
28
+ raise RuntimeError(f"无法加载可信溯源报告模板: {path}")
29
+ module = importlib.util.module_from_spec(spec)
30
+ spec.loader.exec_module(module)
31
+ return module
32
+
33
+
34
+ def resolve_input(value: str) -> Path:
35
+ raw = Path(value).expanduser()
36
+ path = raw.resolve() if raw.is_absolute() else (INPUT_DIR / raw.name).resolve()
37
+ if path.suffix.lower() != ".json":
38
+ raise ValueError("输入文件必须是 JSON")
39
+ try:
40
+ path.relative_to(INPUT_DIR.resolve())
41
+ except ValueError as exc:
42
+ raise ValueError(f"输入文件必须位于 official-docs/input/: {value}") from exc
43
+ if not path.exists():
44
+ raise FileNotFoundError(f"输入文件不存在: {path}")
45
+ return path
46
+
47
+
48
+ def safe_output(value: str, title: str) -> Path:
49
+ if value:
50
+ raw = Path(value).expanduser()
51
+ path = raw.resolve() if raw.is_absolute() else (OUTPUT_DIR / raw.name).resolve()
52
+ else:
53
+ safe_title = "".join("_" if char in '\\/:*?"<>| ' else char for char in title).strip("_")
54
+ path = (OUTPUT_DIR / f"{safe_title[:80] or '可信溯源报告'}_可信溯源报告.html").resolve()
55
+ if path.suffix.lower() not in {".html", ".htm"}:
56
+ path = path.with_suffix(".html")
57
+ try:
58
+ path.relative_to(OUTPUT_DIR.resolve())
59
+ except ValueError as exc:
60
+ raise ValueError("输出文件必须位于 official-docs/output/") from exc
61
+ path.parent.mkdir(parents=True, exist_ok=True)
62
+ return path
63
+
64
+
65
+ def first_value(item: dict, *keys: str) -> str:
66
+ for key in keys:
67
+ value = item.get(key)
68
+ if value not in (None, "", [], {}):
69
+ return str(value)
70
+ return ""
71
+
72
+
73
+ def normalize_title(value: str) -> str:
74
+ """仅用于兼容旧结果的标题兜底匹配;新流程优先使用素材中的 source_url。"""
75
+ text = unicodedata.normalize("NFKC", str(value or "")).lower()
76
+ text = re.sub(r"[《》〈〉「」『』\[\]【】()()]", "", text)
77
+ text = re.sub(r"\s+", "", text)
78
+ return text
79
+
80
+
81
+ def load_source_index() -> dict:
82
+ """从本地搜索结果按文章标题建立原文 URL 索引,补齐上游整理时遗漏的字段。"""
83
+ index = {}
84
+ if not SEARCH_RESULTS_DIR.exists():
85
+ return index
86
+ for path in SEARCH_RESULTS_DIR.glob("*.json"):
87
+ try:
88
+ data = json.loads(path.read_text(encoding="utf-8"))
89
+ except (OSError, ValueError):
90
+ continue
91
+ articles = data.get("articles", [])
92
+ if not isinstance(articles, list):
93
+ content = data.get("content", {})
94
+ payload = content.get("data", {}) if isinstance(content, dict) else {}
95
+ articles = payload.get("检索文章", []) if isinstance(payload, dict) else []
96
+ for article in articles:
97
+ if not isinstance(article, dict):
98
+ continue
99
+ title = first_value(article, "文章标题", "title", "标题")
100
+ if not title:
101
+ continue
102
+ source_url = first_value(article, "源网址", "原文链接", "sourceUrl", "source_url", "url")
103
+ policy_url = first_value(article, "知识专库原文", "policyUrl", "policy_url")
104
+ if source_url or policy_url:
105
+ record = {"source_url": source_url, "policy_url": policy_url}
106
+ index.setdefault(title, record)
107
+ index.setdefault(normalize_title(title), record)
108
+ return index
109
+
110
+
111
+ def to_trace_payload(data: dict) -> tuple[dict, str, str]:
112
+ title = first_value(data, "title", "标题") or "可信溯源报告"
113
+ answer = first_value(data, "document_content", "documentContent", "正文", "body", "answer", "content_markdown")
114
+ if isinstance(data.get("document_content"), list):
115
+ answer = "\n\n".join(first_value(item, "text", "content") for item in data["document_content"] if isinstance(item, dict))
116
+ materials = data.get("materials") or data.get("素材使用情况") or []
117
+ articles = []
118
+ source_index = load_source_index()
119
+ for index, item in enumerate(materials, 1):
120
+ if not isinstance(item, dict):
121
+ continue
122
+ material_name = first_value(item, "material_name", "材料名称", "title", "文章标题") or f"来源材料{index}"
123
+ # 新结果必须直接携带 source_url;标题匹配仅兼容历史 JSON。
124
+ matched = source_index.get(material_name) or source_index.get(normalize_title(material_name), {})
125
+ source_url = first_value(item, "source_url", "sourceUrl", "源网址", "原文链接", "url") or matched.get("source_url", "")
126
+ policy_url = first_value(item, "policyUrl", "policy_url", "knowledgeBase", "知识专库链接") or matched.get("policy_url", "")
127
+ articles.append({
128
+ "文章标题": material_name,
129
+ "来源": first_value(item, "source", "来源", "publisher"),
130
+ "发布日期": first_value(item, "date", "发布日期", "time"),
131
+ "相关段落": first_value(item, "excerpt", "摘录", "支撑内容", "support"),
132
+ "正文对应": first_value(item, "section", "正文对应"),
133
+ "源网址": source_url,
134
+ "知识专库原文": policy_url,
135
+ "policyUrl": first_value(item, "policyUrl", "policy_url"),
136
+ "类型": first_value(item, "type", "素材类型") or "材料",
137
+ })
138
+ knowledge_bases = data.get("knowledge_bases") or data.get("knowledgeBases") or data.get("知识专库链接") or []
139
+ kb_urls = []
140
+ kb_labels = []
141
+ for item in knowledge_bases if isinstance(knowledge_bases, list) else [knowledge_bases]:
142
+ if isinstance(item, dict):
143
+ url = first_value(item, "url", "knowledgeBase", "知识专库链接")
144
+ label = first_value(item, "label", "purpose", "搜索目的", "query") or "相关搜索来源"
145
+ else:
146
+ url = str(item)
147
+ label = "相关搜索来源"
148
+ if url and url not in kb_urls:
149
+ kb_urls.append(url)
150
+ kb_labels.append(label)
151
+ content = {"data": {"检索文章": articles}}
152
+ payload = {"answer": answer, "question": title, "content": content}
153
+ if kb_urls:
154
+ payload["knowledgeBase"] = kb_urls[0]
155
+ payload["knowledgeBases"] = kb_urls
156
+ payload["knowledgeBaseLabels"] = kb_labels
157
+ # 可信搜索渲染器会优先展开 content,必须在该层保留这些字段。
158
+ content["knowledgeBase"] = kb_urls[0]
159
+ content["knowledgeBases"] = kb_urls
160
+ content["knowledgeBaseLabels"] = kb_labels
161
+ return payload, title, answer
162
+
163
+
164
+ def main() -> None:
165
+ parser = argparse.ArgumentParser(description="生成深知可信搜索同款可信溯源报告 HTML")
166
+ parser.add_argument("input", help="结构化可信溯源 JSON,必须位于 official-docs/input")
167
+ parser.add_argument("--output", "-o", help="输出 HTML 文件名,默认写入 official-docs/output")
168
+ args = parser.parse_args()
169
+ input_path = resolve_input(args.input)
170
+ data = json.loads(input_path.read_text(encoding="utf-8"))
171
+ payload, title, answer = to_trace_payload(data)
172
+ output_path = safe_output(args.output, title)
173
+ renderer = load_renderer()
174
+ rendered = renderer.render_html(payload, title, answer_override=answer, question_override=title)
175
+ output_path.write_text(rendered, encoding="utf-8")
176
+ print(f"可信溯源报告 HTML 已生成: {output_path}")
177
+
178
+
179
+ if __name__ == "__main__":
180
+ main()