dknowc-dsh 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dknowc-dsh",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "深知可信办公全家桶:深知可信咨询、深知可信搜索、深知公文写作(skill + MCP 转接),面向 DeepSeek Harness (dsh)",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -7,7 +7,7 @@ description: "当用户咨询政策法规、政务办事、税务社保、公积
7
7
  description_zh: "深知可信咨询是由北京彩智科技有限公司旗下“深知可信智能”提供的可信咨询 Skill,面向政策法规、政务办事、税务社保、公积金、企业补贴、资质证照、行业标准、公共服务、合规义务、企业经营政策和办事导办等场景。它通过 MCP 调用可信统一问答接口,输出带权威来源角标和本地可点击溯源 HTML 的精准咨询结果。"
8
8
  description_en: "dknowc trusted consulting is a trusted consultation Skill provided by dknowc Trusted Intelligence under Beijing Caizhi Technology Co., Ltd. It answers policy, regulation, government service, tax, social security, housing fund, enterprise subsidy, licensing, industry standard, compliance and public-service questions through the trusted unified chat API (via MCP), with citation markers and local provenance HTML."
9
9
  category: 通用办公
10
- version: 1.0.3-dsh
10
+ version: 1.0.4-dsh
11
11
  author: 彩智科技
12
12
  permissions:
13
13
  network:
@@ -149,7 +149,7 @@ python3 <skillDir>/scripts/render_trace_html.py dknowc-output/${DSH_SESSION_ID:0
149
149
  --answer-file dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_consulting_answer.txt
150
150
  ```
151
151
 
152
- `render_trace_html.py` 会同时生成溯源 HTML 和同名 `.clean.md`(移除全部角标的干净 Markdown),输出到 `dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/output/`。如需指定干净 Markdown 路径,传 `--clean-md-output dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/output/xxx.md`。
152
+ `render_trace_html.py` 会同时生成溯源 HTML 和同名 `.clean.md`(移除全部角标的干净 Markdown),输出到 `dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/output/`。如需指定干净 Markdown 路径,传 `--clean-md-output dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/output/xxx.md`。"来源"清单只属于对话输出:即使答案文件末尾带了来源清单,脚本也会在生成 HTML 和 clean.md 前自动去除该块——HTML 的来源由右侧交互面板承载,clean.md 保持纯正文。
153
153
 
154
154
  8. 回复用户(三件套交付:带角标答案 + 溯源 HTML + 干净 Markdown):
155
155
 
@@ -13,12 +13,10 @@ from typing import Any, Dict, Iterable, List, Optional
13
13
 
14
14
 
15
15
  SKILL_ROOT = Path(__file__).resolve().parent.parent
16
- # 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd(会话工作区)
16
+ # 产物根:dsh 会话隔离 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/;DKNWOC_WS_ROOT 显式优先;无会话回退 _default
17
17
  import os as _os
18
18
  _ws = _os.environ.get("DKNWOC_WS_ROOT")
19
19
  if not _ws:
20
- # dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
21
- # 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
22
20
  _sid = _os.environ.get("DSH_SESSION_ID", "")
23
21
  _ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
24
22
  WS_ROOT = Path(_ws).resolve()
@@ -122,6 +120,42 @@ def strip_citation_markers(text: str) -> str:
122
120
  return text.strip() + ("\n" if text.strip() else "")
123
121
 
124
122
 
123
+ _SOURCE_HEADINGS = {"来源", "来源清单", "参考来源"}
124
+
125
+
126
+ def _normalize_source_heading(line: str) -> str:
127
+ value = line.strip()
128
+ value = re.sub(r"^[#>\s*\-]+", "", value)
129
+ value = re.sub(r"[\s:*#]+$", "", value)
130
+ return value
131
+
132
+
133
+ def _is_source_entry(line: str) -> bool:
134
+ value = line.strip()
135
+ if re.match(r"^(\[\^?\d+\^?\]|【\d+】)\s*", value):
136
+ return True
137
+ return value.startswith("《")
138
+
139
+
140
+ def strip_trailing_source_list(text: str) -> str:
141
+ """去除答案末尾的"来源"清单块。
142
+
143
+ 来源清单只应在对话输出中展示:HTML 由右侧交互来源面板承载来源,
144
+ clean.md 保持纯正文。仅当标题行之后全部非空行都是来源条目时才剥离,
145
+ 避免误删正文中恰好出现"来源"字样的段落。
146
+ """
147
+ lines = text.split("\n")
148
+ cut = -1
149
+ for i, line in enumerate(lines):
150
+ if _normalize_source_heading(line) in _SOURCE_HEADINGS:
151
+ tail = [l.strip() for l in lines[i + 1:] if l.strip()]
152
+ if tail and all(_is_source_entry(t) for t in tail):
153
+ cut = i
154
+ if cut < 0:
155
+ return text
156
+ return "\n".join(lines[:cut]).rstrip()
157
+
158
+
125
159
  def paragraph_text(item: Dict[str, Any]) -> str:
126
160
  paragraphs = item.get("content") or item.get("段落") or item.get("paragraphs") or item.get("paragraphList")
127
161
  if isinstance(paragraphs, list):
@@ -1005,6 +1039,8 @@ def main() -> None:
1005
1039
  answer_override = ""
1006
1040
  if args.answer_file:
1007
1041
  answer_override = _resolve_input(args.answer_file).read_text(encoding="utf-8")
1042
+ base_answer = answer_override or extract_answer(unwrap(payload))
1043
+ base_answer = strip_trailing_source_list(base_answer)
1008
1044
  question = args.question.strip() or extract_question(unwrap(payload))
1009
1045
  generated_at = datetime.now()
1010
1046
  if args.output:
@@ -1012,14 +1048,14 @@ def main() -> None:
1012
1048
  else:
1013
1049
  output = _resolve_output(safe_output_filename(question, generated_at))
1014
1050
  output.parent.mkdir(parents=True, exist_ok=True)
1015
- output.write_text(render_html(payload, args.title, answer_override=answer_override, question_override=args.question, generated_at=generated_at), encoding="utf-8")
1051
+ output.write_text(render_html(payload, args.title, answer_override=base_answer, question_override=args.question, generated_at=generated_at), encoding="utf-8")
1016
1052
  print(f"已生成:{output}")
1017
1053
  if args.clean_md_output:
1018
1054
  clean_output = _resolve_output_md(args.clean_md_output)
1019
1055
  else:
1020
1056
  clean_output = _resolve_output_md(output.with_suffix(".clean.md").name)
1021
1057
  clean_output.parent.mkdir(parents=True, exist_ok=True)
1022
- clean_answer = strip_citation_markers(answer_override or extract_answer(unwrap(payload)))
1058
+ clean_answer = strip_citation_markers(base_answer)
1023
1059
  clean_output.write_text(clean_answer, encoding="utf-8")
1024
1060
  print(f"已生成干净 Markdown:{clean_output}")
1025
1061