dknowc-dsh 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/package.json +2 -2
- package/skills/dk-trace-report/SKILL.md +288 -0
- package/skills/dk-trace-report/config/examples/doc.json +56 -0
- package/skills/dk-trace-report/config/examples/legal.json +51 -0
- package/skills/dk-trace-report/config/examples/ppt.json +47 -0
- package/skills/dk-trace-report/config/examples/tax.json +46 -0
- package/skills/dk-trace-report/config/examples/trusted.json +122 -0
- package/skills/dk-trace-report/reference/sample_input.json +60 -0
- package/skills/dk-trace-report/resources/ECHARTS-NOTICE.txt +10 -0
- package/skills/dk-trace-report/resources/echarts.custom.min.js +48 -0
- package/skills/dk-trace-report/scripts/build_report_input.py +333 -0
- package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/chart_embed.py +4 -1
- package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/render_trace_html.py +1071 -536
- package/skills/dk-trace-report/scripts/run_paths.py +95 -0
- package/skills/dk-trace-report/scripts/trust_digest.py +77 -0
- package/skills/dknowc-legal-assistant/README.md +95 -0
- package/skills/dknowc-legal-assistant/SKILL.md +122 -0
- package/skills/dknowc-legal-assistant/attribution.json +5 -0
- package/skills/dknowc-legal-assistant/reference/answer-and-report.md +221 -0
- package/skills/dknowc-legal-assistant/reference/capability-layer.md +143 -0
- package/skills/dknowc-legal-assistant/reference/legal_claims.example.json +96 -0
- package/skills/dknowc-legal-assistant/reference/onboarding_scripts.md +198 -0
- package/skills/dknowc-legal-assistant/reference/policy_tags.json +2002 -0
- package/skills/dknowc-legal-assistant/reference/retrieval-statute.md +81 -0
- package/skills/dknowc-legal-assistant/reference/retrieval-v2.md +133 -0
- package/skills/dknowc-legal-assistant/reference/sample_search_result.md +33 -0
- package/skills/dknowc-legal-assistant/reference/sample_trace_report.html +940 -0
- package/skills/dknowc-legal-assistant/reference/tags.md +53 -0
- package/skills/dknowc-legal-assistant/reference/troubleshooting.md +50 -0
- package/skills/dknowc-legal-assistant/reference/verification-pass.md +59 -0
- package/skills/dknowc-legal-assistant/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-legal-assistant/scripts/api_key.py +68 -0
- package/skills/dknowc-legal-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-legal-assistant/scripts/calc_legal.py +375 -0
- package/skills/dknowc-legal-assistant/scripts/calc_period.py +155 -0
- package/skills/dknowc-legal-assistant/scripts/check_answer.py +664 -0
- package/skills/dknowc-legal-assistant/scripts/initialize.py +188 -0
- package/skills/dknowc-legal-assistant/scripts/legal_client.py +208 -0
- package/skills/dknowc-legal-assistant/scripts/legal_search.py +1059 -0
- package/skills/dknowc-legal-assistant/scripts/merge_search_results.py +630 -0
- package/skills/dknowc-legal-assistant/scripts/path_guard.py +92 -0
- package/skills/dknowc-legal-assistant/scripts/question_profile.py +215 -0
- package/skills/dknowc-legal-assistant/scripts/register_key.mjs +1152 -0
- package/skills/dknowc-legal-assistant/scripts/run_eval.py +109 -0
- package/skills/dknowc-legal-assistant/scripts/source_cards.py +321 -0
- package/skills/dknowc-legal-assistant/scripts/tag_catalog.py +162 -0
- package/skills/dknowc-legal-assistant/scripts/trace_report.config.json +66 -0
- package/skills/dknowc-legal-assistant/scripts/verify_claims.py +448 -0
- package/skills/dknowc-legal-assistant/scripts/websearch_convert.py +396 -0
- package/skills/dknowc-official-doc-writer/README.md +32 -21
- package/skills/dknowc-official-doc-writer/SKILL.md +28 -15
- package/skills/dknowc-official-doc-writer/config/trace_report.config.json +56 -0
- package/skills/dknowc-official-doc-writer/official-docs/input//345/274/225/347/224/250/345/257/271/347/205/247_/351/252/214/346/224/266_materials.json +628 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_1555.json +345 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_my.json +728 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_wp.json +159 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_wp2.json +1006 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/test_tz.json +28 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/tmp_q.json +1419 -0
- package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +14 -2
- package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +4 -0
- package/skills/dknowc-official-doc-writer/reference/genre_writing_notes.md +4 -0
- package/skills/dknowc-official-doc-writer/reference/initialization.md +13 -8
- package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +21 -0
- package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +64 -7
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/outline_rules.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +13 -13
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +5 -3
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +6 -2
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +44 -32
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +63 -36
- package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +6 -3
- package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +12 -3
- package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +8 -2
- package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/25_plan.md +2 -1
- package/skills/dknowc-official-doc-writer/reference/standards/26_summary.md +7 -1
- package/skills/dknowc-official-doc-writer/reference/standards/27_speech.md +4 -1
- package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/working_principles.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/writing_method.md +166 -0
- package/skills/dknowc-official-doc-writer/reference/writing_rules.md +10 -4
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +22 -2
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +205 -13
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +367 -22
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +5 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +2 -1
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +20 -7
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +88 -30
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +232 -6
- package/skills/dknowc-official-doc-writer/scripts/local_memory.py +2 -6
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +100 -7
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +2 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +265 -32
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +117 -10
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/update_skill.py +339 -0
- package/skills/dknowc-official-doc-writer/scripts/websearch_convert.py +326 -0
- package/skills/dknowc-ppt-assistant/README.md +7 -9
- package/skills/dknowc-ppt-assistant/SKILL.md +28 -19
- package/skills/dknowc-ppt-assistant/config/trace_report.config.json +65 -0
- package/skills/dknowc-ppt-assistant/references/initialization.md +20 -8
- package/skills/dknowc-ppt-assistant/references/material_usage.md +46 -9
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +7 -5
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +372 -920
- package/skills/dknowc-ppt-assistant/references/search_intro.md +2 -2
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +2 -2
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +5 -28
- package/skills/dknowc-ppt-assistant/scripts/build_trace_input.py +188 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +238 -3
- package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +1 -10
- package/skills/dknowc-ppt-assistant/scripts/merge_search_results.py +604 -0
- package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +4 -11
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +224 -63
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +29 -12
- package/skills/dknowc-ppt-assistant/scripts/update_skill.py +314 -0
- package/skills/dknowc-ppt-assistant/scripts/websearch_convert.py +326 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +92 -29
- package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
- package/skills/dknowc-tax-assistant/README.md +54 -0
- package/skills/dknowc-tax-assistant/SKILL.md +99 -0
- package/skills/dknowc-tax-assistant/attribution.json +5 -0
- package/skills/dknowc-tax-assistant/reference/answer-and-report.md +100 -0
- package/skills/dknowc-tax-assistant/reference/capability-layer.md +205 -0
- package/skills/dknowc-tax-assistant/reference/onboarding_scripts.md +68 -0
- package/skills/dknowc-tax-assistant/reference/policy_tags.json +2002 -0
- package/skills/dknowc-tax-assistant/reference/retrieval-policy.md +43 -0
- package/skills/dknowc-tax-assistant/reference/retrieval-v2.md +58 -0
- package/skills/dknowc-tax-assistant/reference/tags.md +53 -0
- package/skills/dknowc-tax-assistant/reference/tax_claims.example.json +76 -0
- package/skills/dknowc-tax-assistant/reference/trace_report.config.json +46 -0
- package/skills/dknowc-tax-assistant/reference/troubleshooting.md +70 -0
- package/skills/dknowc-tax-assistant/reference/websearch-fallback.md +59 -0
- package/skills/dknowc-tax-assistant/resources/THIRD_PARTY_NOTICES.md +9 -0
- package/skills/dknowc-tax-assistant/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-tax-assistant/scripts/api_key.py +60 -0
- package/skills/dknowc-tax-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-tax-assistant/scripts/calc_period.py +156 -0
- package/skills/dknowc-tax-assistant/scripts/calc_tax.py +179 -0
- package/skills/dknowc-tax-assistant/scripts/check_answer.py +210 -0
- package/skills/dknowc-tax-assistant/scripts/initialize.py +208 -0
- package/skills/dknowc-tax-assistant/scripts/merge_search_results.py +631 -0
- package/skills/dknowc-tax-assistant/scripts/path_guard.py +23 -0
- package/skills/dknowc-tax-assistant/scripts/question_profile.py +444 -0
- package/skills/dknowc-tax-assistant/scripts/register_key.mjs +1173 -0
- package/skills/dknowc-tax-assistant/scripts/run_dir.py +149 -0
- package/skills/dknowc-tax-assistant/scripts/source_cards.py +372 -0
- package/skills/dknowc-tax-assistant/scripts/tag_catalog.py +164 -0
- package/skills/dknowc-tax-assistant/scripts/tax_client.py +218 -0
- package/skills/dknowc-tax-assistant/scripts/tax_search.py +403 -0
- package/skills/dknowc-tax-assistant/scripts/verify_claims.py +587 -0
- package/skills/dknowc-tax-assistant/scripts/websearch_convert.py +352 -0
- package/skills/dknowc-trusted-search/README.md +25 -19
- package/skills/dknowc-trusted-search/SKILL.md +205 -73
- package/skills/dknowc-trusted-search/config/trace_report.config.json +119 -0
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +3 -3
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +286 -191
- package/skills/dknowc-trusted-search/resources/ECHARTS-NOTICE.txt +10 -0
- package/skills/dknowc-trusted-search/scripts/api_key.py +0 -1
- package/skills/dknowc-trusted-search/scripts/attribution.py +1 -1
- package/skills/dknowc-trusted-search/scripts/build_trace_input.py +173 -0
- package/skills/dknowc-trusted-search/scripts/deep_convert.py +79 -30
- package/skills/dknowc-trusted-search/scripts/deep_query.py +22 -33
- package/skills/dknowc-trusted-search/scripts/initialize.py +343 -2
- package/skills/dknowc-trusted-search/scripts/merge_search_results.py +222 -35
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +241 -29
- package/skills/dknowc-trusted-search/scripts/source_display.py +59 -0
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +67 -34
- package/skills/dknowc-trusted-search/scripts/update_skill.py +300 -0
- package/skills/dknowc-trusted-search/scripts/websearch_convert.py +328 -0
- package/src/index.js +15 -0
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +0 -2574
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +0 -2642
- package/skills/dknowc-trusted-search/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-trusted-search/official-docs/search-results/.gitkeep +0 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""统一入口(1.0.1):把业务 Skill 的检索/装配产物映射为通用 JSON。
|
|
3
|
+
|
|
4
|
+
设计原则(上游单源化):
|
|
5
|
+
- 渲染器只认通用 JSON(materials + answer + question + selfCheck + verifyRecord);
|
|
6
|
+
- 一切输入形态差异在**这里**的 adapter 层消化:
|
|
7
|
+
* adapter=merged(默认):检索接口/merge 脚本产物(`content.data.检索文章` 或顶层 `检索文章`)
|
|
8
|
+
→ materials;可选 `--policy-files` 用 policyFiles 的 writtenText 回填发文字号。
|
|
9
|
+
* adapter=assembly:装配形态的溯源 JSON(materials/recalled_materials/document_content)
|
|
10
|
+
→ materials(字段映射见 SKILL.md「统一入口」表)。
|
|
11
|
+
- 接口调整时只改本脚本,渲染器不动(上游单源约定)。
|
|
12
|
+
|
|
13
|
+
用法:
|
|
14
|
+
python3 build_report_input.py merged.json --adapter merged \
|
|
15
|
+
--answer-file answer.txt --question-file question.txt \
|
|
16
|
+
--self-check-file selfcheck.json --verify-file verify.json \
|
|
17
|
+
--output input.json
|
|
18
|
+
|
|
19
|
+
python3 build_report_input.py 公文装配.json --adapter assembly \
|
|
20
|
+
--answer-file answer.txt --output input.json
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
27
|
+
import re
|
|
28
|
+
import sys
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from typing import Any, Dict, List
|
|
31
|
+
|
|
32
|
+
from run_paths import (RunPathError, SKILL_ROOT, is_within, resolve_input_path,
|
|
33
|
+
resolve_run_dir)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def first_str(*values: Any) -> str:
|
|
37
|
+
for value in values:
|
|
38
|
+
if isinstance(value, str) and value.strip():
|
|
39
|
+
return value.strip()
|
|
40
|
+
if value not in (None, "", [], {}) and not isinstance(value, (dict, list)):
|
|
41
|
+
return str(value).strip()
|
|
42
|
+
return ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _norm_title(value: str) -> str:
|
|
46
|
+
"""标题归一:去掉空白与常见标点,用于 policyFiles 匹配。"""
|
|
47
|
+
return re.sub(r"[\s ,。、;::,.·《》“”\"'()()【】\[\]—\-/]+", "",
|
|
48
|
+
str(value or "").lower())
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _paragraph_join(item: Dict[str, Any]) -> str:
|
|
52
|
+
"""段落数组 → 摘录文本(与渲染器 paragraph_text 同口径)。"""
|
|
53
|
+
paragraphs = item.get("段落") or item.get("paragraphs") or item.get("content")
|
|
54
|
+
chunks: List[str] = []
|
|
55
|
+
if isinstance(paragraphs, list):
|
|
56
|
+
for para in paragraphs:
|
|
57
|
+
if isinstance(para, dict):
|
|
58
|
+
chunk = first_str(para.get("内容"), para.get("text"), para.get("content"),
|
|
59
|
+
para.get("summary"), para.get("标题"), para.get("title"))
|
|
60
|
+
else:
|
|
61
|
+
chunk = str(para)
|
|
62
|
+
if chunk.strip():
|
|
63
|
+
chunks.append(chunk.strip())
|
|
64
|
+
if chunks:
|
|
65
|
+
return "\n".join(chunks)
|
|
66
|
+
return first_str(item.get("原文"), item.get("摘录"), item.get("excerpt"), item.get("support"),
|
|
67
|
+
item.get("摘要"), item.get("snippet"))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _is_unofficial(item: Dict[str, Any]) -> bool:
|
|
71
|
+
if item.get("非官方来源") is True:
|
|
72
|
+
return True
|
|
73
|
+
kind = str(item.get("来源性质") or item.get("source_kind") or "").strip().lower()
|
|
74
|
+
if kind in ("unofficial", "非官方", "非官方来源"):
|
|
75
|
+
return True
|
|
76
|
+
if str(item.get("数据权威性") or item.get("authority") or "").strip() in ("非权威", "non-authoritative"):
|
|
77
|
+
return True
|
|
78
|
+
return False
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def find_merged_articles(payload: Any) -> List[Dict[str, Any]]:
|
|
82
|
+
"""检索接口/merge 产物 → 文章数组。兼容 content.data.检索文章 与顶层 检索文章。"""
|
|
83
|
+
if isinstance(payload, list):
|
|
84
|
+
return [x for x in payload if isinstance(x, dict)]
|
|
85
|
+
if not isinstance(payload, dict):
|
|
86
|
+
return []
|
|
87
|
+
content = payload.get("content")
|
|
88
|
+
if isinstance(content, dict):
|
|
89
|
+
data = content.get("data")
|
|
90
|
+
if isinstance(data, dict) and isinstance(data.get("检索文章"), list):
|
|
91
|
+
return [x for x in data["检索文章"] if isinstance(x, dict)]
|
|
92
|
+
if isinstance(payload.get("检索文章"), list):
|
|
93
|
+
return [x for x in payload["检索文章"] if isinstance(x, dict)]
|
|
94
|
+
return []
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def map_merged_article(item: Dict[str, Any]) -> Dict[str, Any]:
|
|
98
|
+
"""单篇文章(接口形态)→ 通用材料。只改包装,不改内容。"""
|
|
99
|
+
number = item.get("编号") or item.get("index") or item.get("idx") or item.get("角标")
|
|
100
|
+
doc_number = first_str(item.get("文号"), item.get("发文字号"), item.get("writtenText"),
|
|
101
|
+
item.get("doc_number"))
|
|
102
|
+
material: Dict[str, Any] = {
|
|
103
|
+
"标题": first_str(item.get("文章标题"), item.get("material_name"), item.get("标题"),
|
|
104
|
+
item.get("title"), item.get("name")),
|
|
105
|
+
"源网址": first_str(item.get("源网址"), item.get("sourceUrl"), item.get("原文链接"),
|
|
106
|
+
item.get("url")),
|
|
107
|
+
"快照链接": first_str(item.get("快照链接"), item.get("screenShotPath"), item.get("snapshot")),
|
|
108
|
+
"发布机构": first_str(item.get("发布或实施机构"), item.get("发布机构"), item.get("发布机关"),
|
|
109
|
+
item.get("issuer")),
|
|
110
|
+
"发布日期": first_str(item.get("发布日期"), item.get("date"), item.get("发布时间")),
|
|
111
|
+
"发文字号": doc_number,
|
|
112
|
+
"可信度": first_str(item.get("发布日期可信度"), item.get("可信度"), item.get("confidence")),
|
|
113
|
+
"检索分组": first_str(item.get("搜索条件"), item.get("检索分组"), item.get("search_key")),
|
|
114
|
+
"检索通道": first_str(item.get("检索通道"), item.get("channel")),
|
|
115
|
+
"类型": first_str(item.get("文章类型"), item.get("类型"), item.get("type"), item.get("素材类型")),
|
|
116
|
+
"核验": first_str(item.get("核验"), item.get("核验说明"), item.get("verification")),
|
|
117
|
+
}
|
|
118
|
+
if number not in (None, "", []):
|
|
119
|
+
material["编号"] = number
|
|
120
|
+
paragraphs = item.get("段落") or item.get("paragraphs")
|
|
121
|
+
if isinstance(paragraphs, list) and paragraphs:
|
|
122
|
+
material["段落"] = paragraphs
|
|
123
|
+
else:
|
|
124
|
+
# 无段落数组时用摘录文本兜底;有段落时不再重复存全文(渲染器从段落读取)
|
|
125
|
+
material["原文"] = _paragraph_join(item)
|
|
126
|
+
if "可引用" in item:
|
|
127
|
+
material["可引用"] = item.get("可引用")
|
|
128
|
+
if "待核验" in item:
|
|
129
|
+
material["待核验"] = item.get("待核验")
|
|
130
|
+
if _is_unofficial(item):
|
|
131
|
+
material["来源性质"] = "unofficial"
|
|
132
|
+
return {k: v for k, v in material.items() if v not in (None, "")}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def map_assembly_material(item: Dict[str, Any], used: bool = True) -> Dict[str, Any]:
|
|
136
|
+
"""装配 JSON 的单条材料 → 通用材料(字段映射见 SKILL.md「统一入口」表)。"""
|
|
137
|
+
material: Dict[str, Any] = {
|
|
138
|
+
"标题": first_str(item.get("material_name"), item.get("材料名称"), item.get("标题"),
|
|
139
|
+
item.get("title")),
|
|
140
|
+
"源网址": first_str(item.get("source_url"), item.get("源网址"), item.get("url")),
|
|
141
|
+
"快照链接": first_str(item.get("snapshot_url"), item.get("快照链接"), item.get("snapshot")),
|
|
142
|
+
"发布机构": first_str(item.get("source"), item.get("发布机构"), item.get("issuer")),
|
|
143
|
+
"发布日期": first_str(item.get("date"), item.get("发布日期")),
|
|
144
|
+
"发文字号": first_str(item.get("doc_number"), item.get("文号"), item.get("发文字号")),
|
|
145
|
+
"检索分组": first_str(item.get("search_key"), item.get("检索分组")),
|
|
146
|
+
"类型": first_str(item.get("type"), item.get("类型")),
|
|
147
|
+
"核验": first_str(item.get("verification"), item.get("核验")),
|
|
148
|
+
"章节": first_str(item.get("section")),
|
|
149
|
+
}
|
|
150
|
+
paragraphs = item.get("段落") or item.get("paragraphs")
|
|
151
|
+
if isinstance(paragraphs, list) and paragraphs:
|
|
152
|
+
material["段落"] = paragraphs
|
|
153
|
+
else:
|
|
154
|
+
material["原文"] = _paragraph_join(item)
|
|
155
|
+
if not used:
|
|
156
|
+
material["已引用"] = False
|
|
157
|
+
if item.get("编号") not in (None, "", []):
|
|
158
|
+
material["编号"] = item.get("编号")
|
|
159
|
+
return {k: v for k, v in material.items() if v not in (None, "")}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def apply_policy_files(materials: List[Dict[str, Any]], payload: Any) -> int:
|
|
163
|
+
"""policyFiles → 发文字号回填:按标题归一匹配,只填空缺,不覆盖已有文号。"""
|
|
164
|
+
content = payload.get("content") if isinstance(payload, dict) else None
|
|
165
|
+
data = content.get("data") if isinstance(content, dict) else None
|
|
166
|
+
policy_files = data.get("policyFiles") if isinstance(data, dict) else None
|
|
167
|
+
if not isinstance(policy_files, list):
|
|
168
|
+
return 0
|
|
169
|
+
doc_map: Dict[str, str] = {}
|
|
170
|
+
for pf in policy_files:
|
|
171
|
+
if not isinstance(pf, dict):
|
|
172
|
+
continue
|
|
173
|
+
title = _norm_title(first_str(pf.get("title"), pf.get("标题"), pf.get("文章标题")))
|
|
174
|
+
written = first_str(pf.get("writtenText"), pf.get("发文字号"), pf.get("文号"))
|
|
175
|
+
if title and written:
|
|
176
|
+
doc_map[title] = written
|
|
177
|
+
filled = 0
|
|
178
|
+
for material in materials:
|
|
179
|
+
if material.get("发文字号"):
|
|
180
|
+
continue
|
|
181
|
+
written = doc_map.get(_norm_title(str(material.get("标题") or "")))
|
|
182
|
+
if written:
|
|
183
|
+
material["发文字号"] = written
|
|
184
|
+
filled += 1
|
|
185
|
+
return filled
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def load_json_file(path: Path) -> Any:
|
|
189
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def main() -> int:
|
|
193
|
+
parser = argparse.ArgumentParser(description="统一入口:业务产物 → 通用 JSON(渲染器唯一输入)")
|
|
194
|
+
parser.add_argument("source_json", help="业务 Skill 的产物 JSON(merge 结果或公文装配 JSON)")
|
|
195
|
+
parser.add_argument("--adapter", choices=("merged", "assembly"), default="merged",
|
|
196
|
+
help="输入适配器:merged=检索文章形态;assembly=公文装配 JSON(默认 merged)")
|
|
197
|
+
parser.add_argument("--run", help="本次运行的独立目录(输入/输出相对路径基准;必须在 Skill 目录之外)")
|
|
198
|
+
parser.add_argument("--output", help="输出通用 JSON 文件名;相对名落在 --run 目录(默认 input.json)")
|
|
199
|
+
parser.add_argument("--answer-file", help="最终答案文件(.txt/.md,关键结论带 [n] 角标)")
|
|
200
|
+
parser.add_argument("--answer", help="最终答案文本(与 --answer-file 二选一,文件优先)")
|
|
201
|
+
parser.add_argument("--question", help="用户原始问题(完整原文)")
|
|
202
|
+
parser.add_argument("--question-file", help="用户原始问题全文文件(多行问题必须用本参数)")
|
|
203
|
+
parser.add_argument("--self-check-file", help="答案自检结果 JSON(键集由业务配置决定)")
|
|
204
|
+
parser.add_argument("--verify-file", help="域内核验记录 JSON(verdict/record/issues),原样嵌入输出")
|
|
205
|
+
parser.add_argument("--title", help="报告标题;缺省取输入 JSON 的 title 或问题")
|
|
206
|
+
parser.add_argument("--stage", help="双版阶段标识(outline/final),原样写入输出 properties")
|
|
207
|
+
parser.add_argument("--policy-files", action="store_true",
|
|
208
|
+
help="merged 适配器:用 policyFiles 的 writtenText 回填空缺发文字号")
|
|
209
|
+
args = parser.parse_args()
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
run_dir = resolve_run_dir(args.run) if args.run else None
|
|
213
|
+
except RunPathError as exc:
|
|
214
|
+
print(f"错误:{exc}", file=sys.stderr)
|
|
215
|
+
return 2
|
|
216
|
+
|
|
217
|
+
try:
|
|
218
|
+
source_path = resolve_input_path(args.source_json, run_dir, {".json"})
|
|
219
|
+
source = load_json_file(source_path)
|
|
220
|
+
except (RunPathError, json.JSONDecodeError, OSError) as exc:
|
|
221
|
+
print(f"错误:输入无法读取({exc})", file=sys.stderr)
|
|
222
|
+
return 2
|
|
223
|
+
|
|
224
|
+
source_meta: Dict[str, Any] = source if isinstance(source, dict) else {}
|
|
225
|
+
materials: List[Dict[str, Any]] = []
|
|
226
|
+
|
|
227
|
+
if args.adapter == "merged":
|
|
228
|
+
articles = find_merged_articles(source)
|
|
229
|
+
if not articles:
|
|
230
|
+
print("错误:未在输入中找到「检索文章」(content.data.检索文章 或顶层 检索文章)。\n"
|
|
231
|
+
"请确认传入的是检索/merge 产物;已是通用 JSON 时无需本脚本,可直接给渲染器。",
|
|
232
|
+
file=sys.stderr)
|
|
233
|
+
return 2
|
|
234
|
+
materials = [map_merged_article(a) for a in articles]
|
|
235
|
+
if args.policy_files:
|
|
236
|
+
filled = apply_policy_files(materials, source)
|
|
237
|
+
if filled:
|
|
238
|
+
print(f"policyFiles 文号回填:{filled} 条")
|
|
239
|
+
else:
|
|
240
|
+
raw = source_meta.get("materials") if isinstance(source_meta.get("materials"), list) else []
|
|
241
|
+
recalled = source_meta.get("recalled_materials") if isinstance(source_meta.get("recalled_materials"), list) else []
|
|
242
|
+
materials = ([map_assembly_material(x, used=True) for x in raw if isinstance(x, dict)]
|
|
243
|
+
+ [map_assembly_material(x, used=False) for x in recalled if isinstance(x, dict)])
|
|
244
|
+
if not materials:
|
|
245
|
+
print("错误:装配 JSON 中没有 materials / recalled_materials。", file=sys.stderr)
|
|
246
|
+
return 2
|
|
247
|
+
|
|
248
|
+
# 编号缺省补齐(与渲染器口径一致:按数组顺序 1-based)
|
|
249
|
+
for idx, material in enumerate(materials):
|
|
250
|
+
if not first_str(material.get("编号")):
|
|
251
|
+
material["编号"] = str(idx + 1)
|
|
252
|
+
|
|
253
|
+
# 答案:文件 > 命令行 > 输入 JSON 自带
|
|
254
|
+
answer = ""
|
|
255
|
+
if args.answer_file:
|
|
256
|
+
try:
|
|
257
|
+
answer = resolve_input_path(args.answer_file, run_dir, {".txt", ".md"}).read_text(encoding="utf-8")
|
|
258
|
+
except (RunPathError, OSError) as exc:
|
|
259
|
+
print(f"错误:答案文件无法读取({exc})", file=sys.stderr)
|
|
260
|
+
return 2
|
|
261
|
+
elif args.answer:
|
|
262
|
+
answer = args.answer
|
|
263
|
+
else:
|
|
264
|
+
answer = first_str(source_meta.get("answer"), source_meta.get("答案"),
|
|
265
|
+
source_meta.get("document_content"))
|
|
266
|
+
|
|
267
|
+
question = ""
|
|
268
|
+
if args.question_file:
|
|
269
|
+
try:
|
|
270
|
+
question = resolve_input_path(args.question_file, run_dir, {".txt", ".md"}).read_text(encoding="utf-8").strip()
|
|
271
|
+
except (RunPathError, OSError) as exc:
|
|
272
|
+
print(f"错误:问题文件无法读取({exc})", file=sys.stderr)
|
|
273
|
+
return 2
|
|
274
|
+
else:
|
|
275
|
+
question = first_str(args.question, source_meta.get("question"), source_meta.get("问题"))
|
|
276
|
+
|
|
277
|
+
self_check: Any = None
|
|
278
|
+
if args.self_check_file:
|
|
279
|
+
try:
|
|
280
|
+
self_check = load_json_file(resolve_input_path(args.self_check_file, run_dir, {".json"}))
|
|
281
|
+
except (RunPathError, json.JSONDecodeError, OSError) as exc:
|
|
282
|
+
print(f"错误:自检文件无法读取({exc})", file=sys.stderr)
|
|
283
|
+
return 2
|
|
284
|
+
else:
|
|
285
|
+
self_check = source_meta.get("selfCheck") or source_meta.get("self_check")
|
|
286
|
+
|
|
287
|
+
verify_record: Any = None
|
|
288
|
+
if args.verify_file:
|
|
289
|
+
try:
|
|
290
|
+
verify_record = load_json_file(resolve_input_path(args.verify_file, run_dir, {".json"}))
|
|
291
|
+
except (RunPathError, json.JSONDecodeError, OSError) as exc:
|
|
292
|
+
print(f"错误:核验记录无法读取({exc})", file=sys.stderr)
|
|
293
|
+
return 2
|
|
294
|
+
|
|
295
|
+
payload: Dict[str, Any] = {
|
|
296
|
+
"title": first_str(args.title, source_meta.get("title")) or question,
|
|
297
|
+
"question": question,
|
|
298
|
+
"answer": answer,
|
|
299
|
+
"materials": materials,
|
|
300
|
+
}
|
|
301
|
+
if isinstance(self_check, dict) and self_check:
|
|
302
|
+
payload["selfCheck"] = self_check
|
|
303
|
+
if isinstance(verify_record, dict) and verify_record:
|
|
304
|
+
payload["verifyRecord"] = verify_record
|
|
305
|
+
if args.stage:
|
|
306
|
+
payload["stage"] = args.stage
|
|
307
|
+
|
|
308
|
+
# 中间产物允许覆盖同名(每次重新生成 input.json),不做 _v2 另存
|
|
309
|
+
output_name = args.output or "input.json"
|
|
310
|
+
raw_output = Path(output_name).expanduser()
|
|
311
|
+
if raw_output.is_absolute():
|
|
312
|
+
output = raw_output.resolve()
|
|
313
|
+
elif run_dir is not None:
|
|
314
|
+
output = (run_dir / raw_output).resolve()
|
|
315
|
+
else:
|
|
316
|
+
print("错误:相对 --output 必须同时用 --run 指定运行目录", file=sys.stderr)
|
|
317
|
+
return 2
|
|
318
|
+
if output.suffix.lower() != ".json":
|
|
319
|
+
output = output.with_suffix(".json")
|
|
320
|
+
if output == SKILL_ROOT or is_within(output, SKILL_ROOT):
|
|
321
|
+
print(f"错误:产物不能写入 Skill 安装目录:{output}", file=sys.stderr)
|
|
322
|
+
return 2
|
|
323
|
+
|
|
324
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
325
|
+
output.write_text(json.dumps(payload, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
326
|
+
print(f"已生成通用 JSON:{output}")
|
|
327
|
+
print(f" 材料 {len(materials)} 条 · 答案 {len(answer)} 字 · 自检 {'有' if payload.get('selfCheck') else '无'}"
|
|
328
|
+
f" · 核验记录 {'有' if payload.get('verifyRecord') else '无'}")
|
|
329
|
+
return 0
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
if __name__ == "__main__":
|
|
333
|
+
raise SystemExit(main())
|
|
@@ -341,8 +341,11 @@ def render_script(charts: List[Dict[str, Any]], echarts_src: str) -> str:
|
|
|
341
341
|
f"for(var id in O){{"
|
|
342
342
|
f"var el=document.getElementById(id);if(!el||!window.echarts)continue;"
|
|
343
343
|
f"var ec=window.echarts.default||window.echarts;"
|
|
344
|
+
f"function S(u){{try{{var x=new URL(u,window.location.href);"
|
|
345
|
+
f"if(x.protocol==='http:'||x.protocol==='https:')return x.href;}}catch(e){{}}return '';}}"
|
|
344
346
|
f"try{{var ch=ec.init(el);ch.setOption(O[id]);"
|
|
345
|
-
f"ch.on('click',function(p){{if(p&&p.data&&p.data.url)
|
|
347
|
+
f"ch.on('click',function(p){{if(p&&p.data&&p.data.url){{"
|
|
348
|
+
f"var u=S(p.data.url);if(u)window.open(u,'_blank');}}}});}}"
|
|
346
349
|
f"catch(e){{el.style.display='none';}}"
|
|
347
350
|
f"}}"
|
|
348
351
|
f"}})();</script>")
|