dknowc-dsh 1.0.1 → 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/README.md +14 -9
- package/package.json +1 -1
- package/skills/dknowc-official-doc-writer/README.md +1 -1
- package/skills/dknowc-official-doc-writer/SKILL.md +73 -17
- package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/task_router.md +14 -13
- package/skills/dknowc-official-doc-writer/scripts/check_release.py +7 -2
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +8 -2
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +8 -2
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +36 -4
- package/skills/dknowc-official-doc-writer/scripts/local_memory.py +351 -0
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +9 -3
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +8 -2
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +7 -1
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +7 -1
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +9 -3
- package/skills/dknowc-trusted-consulting/README.md +3 -3
- package/skills/dknowc-trusted-consulting/SKILL.md +24 -19
- package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +17 -4
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +82 -8
- package/skills/dknowc-trusted-search/SKILL.md +29 -27
- package/skills/dknowc-trusted-search/scripts/deep_query.py +8 -2
- package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +7 -1
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +7 -1
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +8 -2
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""深知公文写作 - 本地个人记忆管理:个人素材库与写作偏好。
|
|
3
|
+
|
|
4
|
+
两类本地状态均只保存在本机、不随公开包分发、不上传:
|
|
5
|
+
- 个人素材库 knowledge-base/:用户确认保存的长期材料,按用途分类并打场景标签。
|
|
6
|
+
- 写作偏好 config/writing_preferences.json:用户沉淀的内容、排版、表达习惯。
|
|
7
|
+
|
|
8
|
+
用法示例:
|
|
9
|
+
python3 scripts/local_memory.py kb save <文件> --category policy --tags 通知,请示 --note 说明
|
|
10
|
+
python3 scripts/local_memory.py kb list [--category policy] [--tag 通知]
|
|
11
|
+
python3 scripts/local_memory.py kb search 关键词 [--category policy]
|
|
12
|
+
python3 scripts/local_memory.py kb remove kb-001
|
|
13
|
+
python3 scripts/local_memory.py pref save --type format --scope 通知 --rule "标题不使用问句"
|
|
14
|
+
python3 scripts/local_memory.py pref list [--type format] [--scope 通知]
|
|
15
|
+
python3 scripts/local_memory.py pref remove wp-001
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import argparse
|
|
21
|
+
import json
|
|
22
|
+
import shutil
|
|
23
|
+
import sys
|
|
24
|
+
import zipfile
|
|
25
|
+
from datetime import date
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from xml.etree import ElementTree
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
31
|
+
# dsh 场景:个人素材库与写作偏好属于跨会话持久数据,锚定用户主目录固定位置
|
|
32
|
+
# (~/.dknowc-writer/),跨工作区共享、插件升级不丢失;可经 DKNWOC_HOME_DIR 覆盖。
|
|
33
|
+
import os as _os
|
|
34
|
+
DATA_ROOT = Path(_os.environ.get("DKNWOC_HOME_DIR") or str(Path.home() / ".dknowc-writer")).resolve()
|
|
35
|
+
KB_ROOT = DATA_ROOT / "knowledge-base"
|
|
36
|
+
INDEX_PATH = KB_ROOT / "_index.json"
|
|
37
|
+
PREF_PATH = DATA_ROOT / "config" / "writing_preferences.json"
|
|
38
|
+
|
|
39
|
+
KB_CATEGORIES = {
|
|
40
|
+
"unit-profile": "单位资料",
|
|
41
|
+
"policy": "政策文件",
|
|
42
|
+
"data": "数据资料",
|
|
43
|
+
"past-docs": "历史文稿",
|
|
44
|
+
"business-rules": "业务口径",
|
|
45
|
+
"misc": "其他",
|
|
46
|
+
}
|
|
47
|
+
PREF_TYPES = {
|
|
48
|
+
"content": "内容习惯",
|
|
49
|
+
"format": "排版习惯",
|
|
50
|
+
"phrasing": "表达习惯",
|
|
51
|
+
}
|
|
52
|
+
STORABLE_SUFFIXES = {".txt", ".md", ".json", ".csv", ".docx"}
|
|
53
|
+
TEXT_SEARCH_SUFFIXES = {".txt", ".md", ".json", ".csv", ".docx"}
|
|
54
|
+
MAX_STORE_BYTES = 20 * 1024 * 1024
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def load_kb_index() -> dict:
|
|
58
|
+
if not INDEX_PATH.exists():
|
|
59
|
+
return {"version": 1, "items": []}
|
|
60
|
+
try:
|
|
61
|
+
data = json.loads(INDEX_PATH.read_text(encoding="utf-8"))
|
|
62
|
+
except (OSError, json.JSONDecodeError):
|
|
63
|
+
return {"version": 1, "items": []}
|
|
64
|
+
if not isinstance(data, dict) or not isinstance(data.get("items"), list):
|
|
65
|
+
return {"version": 1, "items": []}
|
|
66
|
+
return data
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def save_kb_index(data: dict) -> None:
|
|
70
|
+
KB_ROOT.mkdir(parents=True, exist_ok=True)
|
|
71
|
+
INDEX_PATH.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def load_prefs() -> dict:
|
|
75
|
+
empty = {key: [] for key in PREF_TYPES}
|
|
76
|
+
if not PREF_PATH.exists():
|
|
77
|
+
return empty
|
|
78
|
+
try:
|
|
79
|
+
data = json.loads(PREF_PATH.read_text(encoding="utf-8"))
|
|
80
|
+
except (OSError, json.JSONDecodeError):
|
|
81
|
+
return empty
|
|
82
|
+
if not isinstance(data, dict):
|
|
83
|
+
return empty
|
|
84
|
+
return {
|
|
85
|
+
key: data.get(key) if isinstance(data.get(key), list) else []
|
|
86
|
+
for key in PREF_TYPES
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def save_prefs(data: dict) -> None:
|
|
91
|
+
PREF_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
92
|
+
PREF_PATH.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def next_id(prefix: str, items: list) -> str:
|
|
96
|
+
max_no = 0
|
|
97
|
+
for item in items:
|
|
98
|
+
no = str(item.get("id", "")).rsplit("-", 1)[-1]
|
|
99
|
+
if no.isdigit():
|
|
100
|
+
max_no = max(max_no, int(no))
|
|
101
|
+
return f"{prefix}-{max_no + 1:03d}"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def read_docx_text(path: Path) -> str:
|
|
105
|
+
pieces = []
|
|
106
|
+
try:
|
|
107
|
+
with zipfile.ZipFile(path) as zf:
|
|
108
|
+
if "word/document.xml" not in zf.namelist():
|
|
109
|
+
return ""
|
|
110
|
+
root = ElementTree.fromstring(zf.read("word/document.xml"))
|
|
111
|
+
for elem in root.iter():
|
|
112
|
+
tag = elem.tag.rsplit("}", 1)[-1]
|
|
113
|
+
if tag == "t" and elem.text:
|
|
114
|
+
pieces.append(elem.text)
|
|
115
|
+
elif tag in {"p", "br"}:
|
|
116
|
+
pieces.append("\n")
|
|
117
|
+
except (zipfile.BadZipFile, ElementTree.ParseError, OSError):
|
|
118
|
+
return ""
|
|
119
|
+
return "".join(pieces)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def searchable_text(path: Path) -> str:
|
|
123
|
+
if path.suffix.lower() not in TEXT_SEARCH_SUFFIXES:
|
|
124
|
+
return ""
|
|
125
|
+
if path.suffix.lower() == ".docx":
|
|
126
|
+
return read_docx_text(path)
|
|
127
|
+
try:
|
|
128
|
+
return path.read_text(encoding="utf-8", errors="ignore")
|
|
129
|
+
except OSError:
|
|
130
|
+
return ""
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def unique_dest(category_dir: Path, filename: str) -> Path:
|
|
134
|
+
dest = category_dir / filename
|
|
135
|
+
if not dest.exists():
|
|
136
|
+
return dest
|
|
137
|
+
stem, suffix = dest.stem, dest.suffix
|
|
138
|
+
for i in range(1, 1000):
|
|
139
|
+
candidate = category_dir / f"{stem}_{i}{suffix}"
|
|
140
|
+
if not candidate.exists():
|
|
141
|
+
return candidate
|
|
142
|
+
raise SystemExit("ERROR: 无法生成唯一文件名")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def emit(result: dict) -> None:
|
|
146
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def cmd_kb_save(args) -> dict:
|
|
150
|
+
src = Path(args.file).expanduser()
|
|
151
|
+
if not src.is_file():
|
|
152
|
+
raise SystemExit(f"ERROR: 文件不存在: {src}")
|
|
153
|
+
if src.suffix.lower() not in STORABLE_SUFFIXES:
|
|
154
|
+
raise SystemExit(f"ERROR: 暂不支持保存 {src.suffix} 文件,支持: {', '.join(sorted(STORABLE_SUFFIXES))}")
|
|
155
|
+
if src.stat().st_size > MAX_STORE_BYTES:
|
|
156
|
+
raise SystemExit("ERROR: 文件超过 20MB,不宜存入素材库")
|
|
157
|
+
category = args.category
|
|
158
|
+
if category not in KB_CATEGORIES:
|
|
159
|
+
raise SystemExit(f"ERROR: 分类必须是 {', '.join(KB_CATEGORIES)} 之一")
|
|
160
|
+
|
|
161
|
+
tags = [t.strip() for t in (args.tags or "").replace(",", ",").split(",") if t.strip()]
|
|
162
|
+
category_dir = KB_ROOT / category
|
|
163
|
+
category_dir.mkdir(parents=True, exist_ok=True)
|
|
164
|
+
dest = unique_dest(category_dir, Path(src.name).name)
|
|
165
|
+
shutil.copy2(src, dest)
|
|
166
|
+
|
|
167
|
+
index = load_kb_index()
|
|
168
|
+
item = {
|
|
169
|
+
"id": next_id("kb", index["items"]),
|
|
170
|
+
"title": args.title or Path(src).stem,
|
|
171
|
+
"category": category,
|
|
172
|
+
"category_label": KB_CATEGORIES[category],
|
|
173
|
+
"tags": tags,
|
|
174
|
+
"note": args.note or "",
|
|
175
|
+
"file": str(dest.relative_to(DATA_ROOT)),
|
|
176
|
+
"size": dest.stat().st_size,
|
|
177
|
+
"added": date.today().isoformat(),
|
|
178
|
+
}
|
|
179
|
+
index["items"].append(item)
|
|
180
|
+
save_kb_index(index)
|
|
181
|
+
return {"saved": True, "material": item}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def cmd_kb_list(args) -> dict:
|
|
185
|
+
items = load_kb_index()["items"]
|
|
186
|
+
if args.category:
|
|
187
|
+
items = [i for i in items if i.get("category") == args.category]
|
|
188
|
+
if args.tag:
|
|
189
|
+
tag = args.tag.strip()
|
|
190
|
+
items = [i for i in items if tag in (i.get("tags") or [])]
|
|
191
|
+
return {"count": len(items), "materials": items}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def cmd_kb_search(args) -> dict:
|
|
195
|
+
keyword = args.keyword.strip()
|
|
196
|
+
if not keyword:
|
|
197
|
+
raise SystemExit("ERROR: 关键词不能为空")
|
|
198
|
+
items = load_kb_index()["items"]
|
|
199
|
+
if args.category:
|
|
200
|
+
items = [i for i in items if i.get("category") == args.category]
|
|
201
|
+
lowered = keyword.lower()
|
|
202
|
+
results = []
|
|
203
|
+
for item in items:
|
|
204
|
+
matched_in = []
|
|
205
|
+
if lowered in str(item.get("title", "")).lower():
|
|
206
|
+
matched_in.append("标题")
|
|
207
|
+
if any(lowered in str(t).lower() for t in item.get("tags") or []):
|
|
208
|
+
matched_in.append("标签")
|
|
209
|
+
if lowered in str(item.get("note", "")).lower():
|
|
210
|
+
matched_in.append("备注")
|
|
211
|
+
path = DATA_ROOT / str(item.get("file", ""))
|
|
212
|
+
if path.is_file() and lowered in searchable_text(path).lower():
|
|
213
|
+
matched_in.append("正文")
|
|
214
|
+
if matched_in:
|
|
215
|
+
results.append({**item, "matched_in": matched_in})
|
|
216
|
+
return {"count": len(results), "materials": results}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def cmd_kb_remove(args) -> dict:
|
|
220
|
+
index = load_kb_index()
|
|
221
|
+
target = None
|
|
222
|
+
for item in index["items"]:
|
|
223
|
+
if item.get("id") == args.id:
|
|
224
|
+
target = item
|
|
225
|
+
break
|
|
226
|
+
if target is None:
|
|
227
|
+
raise SystemExit(f"ERROR: 素材不存在: {args.id}")
|
|
228
|
+
path = (DATA_ROOT / str(target.get("file", ""))).resolve()
|
|
229
|
+
try:
|
|
230
|
+
path.relative_to(KB_ROOT.resolve())
|
|
231
|
+
except ValueError:
|
|
232
|
+
path = None # 索引指向异常路径时只删索引,不动文件
|
|
233
|
+
if path and path.is_file():
|
|
234
|
+
path.unlink()
|
|
235
|
+
index["items"] = [i for i in index["items"] if i.get("id") != args.id]
|
|
236
|
+
save_kb_index(index)
|
|
237
|
+
return {"removed": True, "id": args.id}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def cmd_pref_save(args) -> dict:
|
|
241
|
+
if args.type not in PREF_TYPES:
|
|
242
|
+
raise SystemExit(f"ERROR: 偏好类型必须是 {', '.join(PREF_TYPES)} 之一")
|
|
243
|
+
rule = args.rule.strip()
|
|
244
|
+
if not rule:
|
|
245
|
+
raise SystemExit("ERROR: 偏好内容不能为空")
|
|
246
|
+
scope = args.scope or "通用"
|
|
247
|
+
prefs = load_prefs()
|
|
248
|
+
for existing in prefs[args.type]:
|
|
249
|
+
if existing.get("rule") == rule and existing.get("scope") == scope:
|
|
250
|
+
return {"saved": False, "reason": "已有相同偏好", "preference": existing}
|
|
251
|
+
item = {
|
|
252
|
+
"id": next_id("wp", prefs[args.type]),
|
|
253
|
+
"type": args.type,
|
|
254
|
+
"type_label": PREF_TYPES[args.type],
|
|
255
|
+
"scope": scope,
|
|
256
|
+
"rule": rule,
|
|
257
|
+
"source": args.source or "用户确认保存",
|
|
258
|
+
"created": date.today().isoformat(),
|
|
259
|
+
}
|
|
260
|
+
prefs[args.type].append(item)
|
|
261
|
+
save_prefs(prefs)
|
|
262
|
+
return {"saved": True, "preference": item}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def cmd_pref_list(args) -> dict:
|
|
266
|
+
prefs = load_prefs()
|
|
267
|
+
out = []
|
|
268
|
+
for ptype, items in prefs.items():
|
|
269
|
+
if args.type and ptype != args.type:
|
|
270
|
+
continue
|
|
271
|
+
for item in items:
|
|
272
|
+
if args.scope and item.get("scope") != args.scope:
|
|
273
|
+
continue
|
|
274
|
+
out.append(item)
|
|
275
|
+
return {"count": len(out), "preferences": out}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def cmd_pref_remove(args) -> dict:
|
|
279
|
+
prefs = load_prefs()
|
|
280
|
+
for ptype, items in prefs.items():
|
|
281
|
+
for item in items:
|
|
282
|
+
if item.get("id") == args.id:
|
|
283
|
+
prefs[ptype] = [i for i in items if i.get("id") != args.id]
|
|
284
|
+
save_prefs(prefs)
|
|
285
|
+
return {"removed": True, "id": args.id}
|
|
286
|
+
raise SystemExit(f"ERROR: 偏好不存在: {args.id}")
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
290
|
+
parser = argparse.ArgumentParser(description="深知公文写作本地个人记忆管理(素材库与写作偏好)")
|
|
291
|
+
commands = parser.add_subparsers(dest="group", required=True)
|
|
292
|
+
|
|
293
|
+
kb = commands.add_parser("kb", help="个人素材库管理")
|
|
294
|
+
kb_commands = kb.add_subparsers(dest="action", required=True)
|
|
295
|
+
|
|
296
|
+
kb_save = kb_commands.add_parser("save", help="保存材料到素材库(经用户确认后执行)")
|
|
297
|
+
kb_save.add_argument("file", help="要保存的材料文件路径")
|
|
298
|
+
kb_save.add_argument("--category", required=True,
|
|
299
|
+
help=f"用途分类: {'/'.join(KB_CATEGORIES)}")
|
|
300
|
+
kb_save.add_argument("--tags", help="场景标签,逗号分隔,如: 通知,请示")
|
|
301
|
+
kb_save.add_argument("--note", help="备注说明")
|
|
302
|
+
kb_save.add_argument("--title", help="素材标题,默认取文件名")
|
|
303
|
+
kb_save.set_defaults(func=cmd_kb_save)
|
|
304
|
+
|
|
305
|
+
kb_list = kb_commands.add_parser("list", help="列出素材库条目")
|
|
306
|
+
kb_list.add_argument("--category", help="按用途分类过滤")
|
|
307
|
+
kb_list.add_argument("--tag", help="按场景标签过滤")
|
|
308
|
+
kb_list.set_defaults(func=cmd_kb_list)
|
|
309
|
+
|
|
310
|
+
kb_search = kb_commands.add_parser("search", help="按关键词检索素材(标题/标签/备注/正文)")
|
|
311
|
+
kb_search.add_argument("keyword", help="检索关键词")
|
|
312
|
+
kb_search.add_argument("--category", help="按用途分类过滤")
|
|
313
|
+
kb_search.set_defaults(func=cmd_kb_search)
|
|
314
|
+
|
|
315
|
+
kb_remove = kb_commands.add_parser("remove", help="删除素材条目及文件(必须先经用户确认)")
|
|
316
|
+
kb_remove.add_argument("id", help="素材 ID,如 kb-001")
|
|
317
|
+
kb_remove.set_defaults(func=cmd_kb_remove)
|
|
318
|
+
|
|
319
|
+
pref = commands.add_parser("pref", help="写作偏好管理")
|
|
320
|
+
pref_commands = pref.add_subparsers(dest="action", required=True)
|
|
321
|
+
|
|
322
|
+
pref_save = pref_commands.add_parser("save", help="保存写作偏好(经用户确认后执行)")
|
|
323
|
+
pref_save.add_argument("--type", required=True, help=f"偏好类型: {'/'.join(PREF_TYPES)}")
|
|
324
|
+
pref_save.add_argument("--scope", help="适用范围:通用或具体文种,默认通用")
|
|
325
|
+
pref_save.add_argument("--rule", required=True, help="偏好内容描述")
|
|
326
|
+
pref_save.add_argument("--source", help="来源说明,如:2026-08-19 用户修改反馈")
|
|
327
|
+
pref_save.set_defaults(func=cmd_pref_save)
|
|
328
|
+
|
|
329
|
+
pref_list = pref_commands.add_parser("list", help="列出写作偏好")
|
|
330
|
+
pref_list.add_argument("--type", help="按类型过滤: content/format/phrasing")
|
|
331
|
+
pref_list.add_argument("--scope", help="按适用范围过滤")
|
|
332
|
+
pref_list.set_defaults(func=cmd_pref_list)
|
|
333
|
+
|
|
334
|
+
pref_remove = pref_commands.add_parser("remove", help="删除写作偏好(必须先经用户确认)")
|
|
335
|
+
pref_remove.add_argument("id", help="偏好 ID,如 wp-001")
|
|
336
|
+
pref_remove.set_defaults(func=cmd_pref_remove)
|
|
337
|
+
|
|
338
|
+
return parser
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def main(argv: list[str] | None = None) -> int:
|
|
342
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
343
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
344
|
+
args = build_parser().parse_args(argv)
|
|
345
|
+
result = args.func(args)
|
|
346
|
+
emit(result)
|
|
347
|
+
return 0
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
if __name__ == "__main__":
|
|
351
|
+
raise SystemExit(main())
|
|
@@ -13,7 +13,13 @@ from typing import List, Dict
|
|
|
13
13
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
14
14
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
|
|
15
15
|
import os as _os
|
|
16
|
-
|
|
16
|
+
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
17
|
+
if not _ws:
|
|
18
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
19
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
20
|
+
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
21
|
+
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
22
|
+
WS_ROOT = Path(_ws).resolve()
|
|
17
23
|
|
|
18
24
|
OFFICIAL_DOCS_DIR = WS_ROOT / "official-docs"
|
|
19
25
|
SEARCH_RESULTS_DIR = OFFICIAL_DOCS_DIR / "search-results"
|
|
@@ -41,7 +47,7 @@ def resolve_input_json(file_path: str) -> Path:
|
|
|
41
47
|
elif raw_path.parent == Path("."):
|
|
42
48
|
resolved = (SEARCH_RESULTS_DIR / raw_path.name).resolve()
|
|
43
49
|
else:
|
|
44
|
-
resolved =
|
|
50
|
+
resolved = raw_path.resolve()
|
|
45
51
|
|
|
46
52
|
if resolved.suffix.lower() != ".json":
|
|
47
53
|
raise ValueError(f"只允许读取 JSON 文件: {file_path}")
|
|
@@ -58,7 +64,7 @@ def resolve_output_json(output_path: str) -> Path:
|
|
|
58
64
|
elif raw_path.parent == Path("."):
|
|
59
65
|
resolved = (SEARCH_RESULTS_DIR / raw_path.name).resolve()
|
|
60
66
|
else:
|
|
61
|
-
resolved =
|
|
67
|
+
resolved = raw_path.resolve()
|
|
62
68
|
|
|
63
69
|
if resolved.suffix.lower() != ".json":
|
|
64
70
|
resolved = resolved.with_suffix(".json")
|
|
@@ -15,7 +15,13 @@ import requests
|
|
|
15
15
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
16
16
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
|
|
17
17
|
import os as _os
|
|
18
|
-
|
|
18
|
+
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
19
|
+
if not _ws:
|
|
20
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
21
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
22
|
+
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
23
|
+
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
24
|
+
WS_ROOT = Path(_ws).resolve()
|
|
19
25
|
|
|
20
26
|
API_KEY_ENV = "DKNOWC_API_KEY"
|
|
21
27
|
OUTLINE_RESULTS_DIR = WS_ROOT / "official-docs" / "outline-results"
|
|
@@ -58,7 +64,7 @@ def resolve_output_json(output_path: Optional[str], query: str) -> Path:
|
|
|
58
64
|
elif raw_path.parent == Path("."):
|
|
59
65
|
resolved = (OUTLINE_RESULTS_DIR / raw_path.name).resolve()
|
|
60
66
|
else:
|
|
61
|
-
resolved =
|
|
67
|
+
resolved = raw_path.resolve()
|
|
62
68
|
|
|
63
69
|
if resolved.suffix.lower() != ".json":
|
|
64
70
|
resolved = resolved.with_suffix(".json")
|
|
@@ -22,7 +22,13 @@ except ImportError: # pragma: no cover
|
|
|
22
22
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
23
23
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
|
|
24
24
|
import os as _os
|
|
25
|
-
|
|
25
|
+
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
26
|
+
if not _ws:
|
|
27
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
28
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
29
|
+
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
30
|
+
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
31
|
+
WS_ROOT = Path(_ws).resolve()
|
|
26
32
|
|
|
27
33
|
INPUT_DIR = WS_ROOT / "official-docs" / "input"
|
|
28
34
|
OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
|
|
@@ -14,7 +14,13 @@ from pathlib import Path
|
|
|
14
14
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
15
15
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
|
|
16
16
|
import os as _os
|
|
17
|
-
|
|
17
|
+
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
18
|
+
if not _ws:
|
|
19
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
20
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
21
|
+
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
22
|
+
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
23
|
+
WS_ROOT = Path(_ws).resolve()
|
|
18
24
|
|
|
19
25
|
INPUT_DIR = WS_ROOT / "official-docs" / "input"
|
|
20
26
|
OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
|
|
@@ -32,7 +32,13 @@ AI_DISCLAIMER_TEXT = "【AI生成提示】内容由AI生成,内容仅供参考
|
|
|
32
32
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
33
33
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
|
|
34
34
|
import os as _os
|
|
35
|
-
|
|
35
|
+
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
36
|
+
if not _ws:
|
|
37
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
38
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
39
|
+
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
40
|
+
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
41
|
+
WS_ROOT = Path(_ws).resolve()
|
|
36
42
|
|
|
37
43
|
OFFICIAL_DOCS_DIR = WS_ROOT / "official-docs"
|
|
38
44
|
INPUT_DIR = OFFICIAL_DOCS_DIR / "input"
|
|
@@ -75,7 +81,7 @@ def resolve_input_docx(input_path) -> Path:
|
|
|
75
81
|
elif raw_path.parent == Path("."):
|
|
76
82
|
resolved = (OUTPUT_DIR / raw_path.name).resolve()
|
|
77
83
|
else:
|
|
78
|
-
resolved =
|
|
84
|
+
resolved = raw_path.resolve()
|
|
79
85
|
|
|
80
86
|
if resolved.suffix.lower() != ".docx":
|
|
81
87
|
raise ValueError(f"只允许读取 .docx 文件: {input_path}")
|
|
@@ -93,7 +99,7 @@ def resolve_output_docx(output_path) -> Path:
|
|
|
93
99
|
elif raw_path.parent == Path("."):
|
|
94
100
|
resolved = (OUTPUT_DIR / raw_path.name).resolve()
|
|
95
101
|
else:
|
|
96
|
-
resolved =
|
|
102
|
+
resolved = raw_path.resolve()
|
|
97
103
|
|
|
98
104
|
if resolved.suffix.lower() != ".docx":
|
|
99
105
|
resolved = resolved.with_suffix(".docx")
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# 深知可信咨询(dsh 版)
|
|
2
2
|
|
|
3
|
-
这是深知可信咨询的 dsh 分发版本,通过深知可信工作台 MCP
|
|
3
|
+
这是深知可信咨询的 dsh 分发版本,通过深知可信工作台 MCP 转接(mcp__dknowc__credible_chat)。功能逻辑与 full 版 1.0.1 对齐:调用深知可信统一问答接口回答咨询问题,输出带真实来源角标的答案,并默认生成本轮本地可信溯源 HTML。Public 版不内置深知可信统一接口 API Key;首次调用时必须先确认环境变量 `DKNOWC_API_KEY` 已配置。未配置时,应说明本 Skill 需要通过 `DKNOWC_API_KEY` 获取深知可信内容,并引导用户注册或登录深知可信智能 MaaS 账号获取 Key;持久化环境变量是独立步骤,必须在用户明确同意后再处理。
|
|
4
4
|
|
|
5
5
|
## 能力范围
|
|
6
6
|
|
|
7
7
|
- 可信咨询导办:回答政策法规、政务办事、税务社保、公积金、企业补贴、证照资质、行业标准、公共服务和合规义务问题。
|
|
8
8
|
- 统一问答:固定调用 `scripts/gov_chat.py` 的 `credibleChat` 能力,不调用可信搜索、深度搜索或政策可视化流程。
|
|
9
|
-
- 带角标答案:关键事实、条件、金额、比例、办理路径和风险判断必须带 `[数字]`
|
|
10
|
-
- 默认溯源 HTML:每轮调用统一问答后,默认用 `scripts/render_trace_html.py` 生成本轮可点击溯源 HTML
|
|
9
|
+
- 带角标答案:关键事实、条件、金额、比例、办理路径和风险判断必须带 `[数字]` 来源角标,答案末尾附来源清单。
|
|
10
|
+
- 默认溯源 HTML 与干净 Markdown:每轮调用统一问答后,默认用 `scripts/render_trace_html.py` 生成本轮可点击溯源 HTML 和移除角标的同名 `.clean.md`。
|
|
11
11
|
|
|
12
12
|
## 首次启动初始化
|
|
13
13
|
|
|
@@ -3,11 +3,11 @@ name: dknowc-trusted-consulting
|
|
|
3
3
|
slug: dknowc-trusted-consulting
|
|
4
4
|
display_name: 深知可信咨询
|
|
5
5
|
display_name_en: dknowc trusted consulting
|
|
6
|
-
description: "当用户咨询政策法规、政务办事、税务社保、公积金、企业补贴、资质证照、行业标准、公共服务、合规义务、企业经营政策、投资技改税惠、办事条件、材料清单、申请路径、风险判断,或要求权威依据、可信溯源、带角标答案、深知可信咨询时,使用深知可信咨询。本 dsh 版通过深知可信工作台 MCP 工具 credible_chat
|
|
6
|
+
description: "当用户咨询政策法规、政务办事、税务社保、公积金、企业补贴、资质证照、行业标准、公共服务、合规义务、企业经营政策、投资技改税惠、办事条件、材料清单、申请路径、风险判断,或要求权威依据、可信溯源、带角标答案、深知可信咨询时,使用深知可信咨询。本 dsh 版通过深知可信工作台 MCP 工具 credible_chat 获取答案和参考材料,输出带真实来源角标和来源清单的咨询答案,并默认生成本轮交互式可信溯源 HTML 与移除角标的干净 Markdown。API Key 通过环境变量 DKNOWC_API_KEY 注入(供 MCP Bearer 认证)。"
|
|
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.
|
|
10
|
+
version: 1.0.4-dsh
|
|
11
11
|
author: 彩智科技
|
|
12
12
|
permissions:
|
|
13
13
|
network:
|
|
@@ -67,7 +67,7 @@ node <skillDir>/scripts/register_key.mjs register --phone <手机号> --vcode <
|
|
|
67
67
|
|
|
68
68
|
脚本自动使用 dsh 渠道码 `46A3BA1D-3E1A-4E8C-BD50-A6DCBEE1DB05` 并固定携带 `source="agent"`。成功后返回 `apiKey`(打码展示)与完整 Key(仅供当前任务临时使用);不得向用户展示完整 API Key。默认不得重新生成 Key;只有用户明确要求时才追加 `--new-key`。
|
|
69
69
|
|
|
70
|
-
**临时直连完成当前任务(不依赖 dsh 的 mcp-client,也不要求立即持久化)**:注册拿到 Key 后,当前会话的 MCP Bearer 认证已冻结(无法热注入新 Key),因此本轮任务改用**临时 Key 直调 MCP** 完成——用 `DKNOWC_API_KEY=<临时Key> python3 <skillDir>/scripts/mcp_direct.py credible_chat '<JSON参数>' --output official-docs/search-results/dknowc_mcp_raw.json` 形式,把临时 Key 通过 bash 前缀赋值传给脚本(绕过 dsh 的环境清理),由 mcp_direct.py 直接 HTTP 调 MCP server 的 tools/call,产出与 dsh mcp-client 一致的 MCP 返回结构;随后照常走 `adapt_mcp_result.py` 规范化 → `render_trace_html.py` 生成溯源 HTML。**不要把临时 Key 写入环境变量或任何配置文件**。
|
|
70
|
+
**临时直连完成当前任务(不依赖 dsh 的 mcp-client,也不要求立即持久化)**:注册拿到 Key 后,当前会话的 MCP Bearer 认证已冻结(无法热注入新 Key),因此本轮任务改用**临时 Key 直调 MCP** 完成——用 `DKNOWC_API_KEY=<临时Key> python3 <skillDir>/scripts/mcp_direct.py credible_chat '<JSON参数>' --output dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_mcp_raw.json` 形式,把临时 Key 通过 bash 前缀赋值传给脚本(绕过 dsh 的环境清理),由 mcp_direct.py 直接 HTTP 调 MCP server 的 tools/call,产出与 dsh mcp-client 一致的 MCP 返回结构;随后照常走 `adapt_mcp_result.py` 规范化 → `render_trace_html.py` 生成溯源 HTML。**不要把临时 Key 写入环境变量或任何配置文件**。
|
|
71
71
|
|
|
72
72
|
**任务完成后的持久化(一次性,之后免注册)**:当前任务交付完成后,再询问用户是否需要把 `DKNOWC_API_KEY` 保存为后续可复用的环境变量(如追加到 `~/.zshrc`)。只有用户明确同意后,Agent 才能执行持久化写入;写入后建议用户重启 dsh 或新开会话,之后新会话会通过 MCP 转接正常使用。
|
|
73
73
|
|
|
@@ -78,15 +78,17 @@ node <skillDir>/scripts/register_key.mjs register --phone <手机号> --vcode <
|
|
|
78
78
|
- 角标必须与接口返回的材料真实对应。不能用主题相近但未支撑该结论的材料挂角标;找不到依据时,应删除该结论、标为“需进一步核验”,或重新调用接口补证。
|
|
79
79
|
- 每次咨询后,默认必须生成本轮 HTML 溯源报告。只有用户明确说“不要生成 HTML/不要文件”时才跳过。
|
|
80
80
|
- HTML 报告应展示本轮最终答案正文、答案中的角标、右侧可信来源、段落下可展开的来源摘录,以及接口返回的知识专库入口(如有)。不要把 HTML 改写成另一个独立调研报告。
|
|
81
|
-
- 用户可见的 HTML 输出到本 Skill 的 `official-docs/output/`,中间产物(接口 JSON、答案文件)存 `official-docs/search-results/`。不要固定文件名,应让 `render_trace_html.py` 根据用户问题自动生成短文件名;不向 `/tmp` 写任何中间文件。
|
|
81
|
+
- 用户可见的 HTML 输出到本 Skill 的 `dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/output/`,中间产物(接口 JSON、答案文件)存 `dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/`。不要固定文件名,应让 `render_trace_html.py` 根据用户问题自动生成短文件名;不向 `/tmp` 写任何中间文件。
|
|
82
82
|
- 如果用户只是追问“你是否用了 skill”“你调用了几次”等元问题,不要再次调用本 skill;直接基于当前对话说明。
|
|
83
83
|
|
|
84
|
-
## 工作区约定(dsh
|
|
84
|
+
## 工作区约定(dsh)——会话隔离的产物目录
|
|
85
|
+
|
|
86
|
+
- **脚本调用一律用 skill 目录的绝对路径**(resourceBase 指引里给出的 "Base directory for this skill: <path>" 就是 skill 目录,以下称 `<skillDir>`)。不要用 `scripts/xxx.py` 相对路径调用脚本——bash 的相对路径基于会话工作区解析,脚本在 bundle 的 skill 目录里,相对路径找不到。
|
|
87
|
+
- **产物按会话隔离存放**:每个 dsh 会话在工作区下有独立产物目录,bash 中写作 ``dknowc-output/${DSH_SESSION_ID:0:8}``(DSH_SESSION_ID 由 dsh 注入;本地无此变量时为 `dknowc-output/_default`)。完整路径形如 `dknowc-output/<会话短ID>/official-docs/...`。同一工作区开多个会话时产物互不混杂、互不覆盖。
|
|
88
|
+
- **运行产物(接口 JSON、答案文件、溯源 HTML、干净 Markdown)**一律写入**本会话**目录,用全前缀相对路径:`dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/...`、`dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/output/...`。脚本对裸文件名也会自动路由到本会话对应子目录。
|
|
89
|
+
- 交付给用户的文件路径,以脚本实际打印的路径为准。
|
|
90
|
+
- 会话目录仍位于工作区内(dsh 沙箱/权限不受影响),用户可在访达中直接浏览 `dknowc-output/` 找到各会话产物。
|
|
85
91
|
|
|
86
|
-
- **脚本调用一律用 skill 目录的绝对路径**(resourceBase 指引里给出的 "Base directory for this skill: <path>" 就是 skill 目录,以下称 `<skillDir>`)。不要用 `scripts/xxx.py` 这种相对路径调用脚本——bash 命令的相对路径是基于当前工作区(session cwd)解析的,而脚本在 bundle 的 skill 目录里,相对路径会找不到。
|
|
87
|
-
- 因此所有脚本调用写成:`python3 <skillDir>/scripts/initialize.py`、`python3 <skillDir>/scripts/adapt_mcp_result.py`、`python3 <skillDir>/scripts/render_trace_html.py ...`。
|
|
88
|
-
- **运行产物(接口 JSON、答案文件、溯源 HTML)一律写入当前会话工作区**(即 bash 默认的当前工作目录),用相对路径 `official-docs/search-results/...`、`official-docs/output/...`。脚本已按 `WS_ROOT = 当前工作目录` 解析这些相对路径,产物会落到工作区,不会写进 bundle。
|
|
89
|
-
- 交付给用户的 HTML 路径,以 `render_trace_html.py` 实际打印的绝对路径为准。
|
|
90
92
|
|
|
91
93
|
## MCP 不可用处理(强制)
|
|
92
94
|
|
|
@@ -112,13 +114,13 @@ python3 <skillDir>/scripts/initialize.py
|
|
|
112
114
|
}
|
|
113
115
|
```
|
|
114
116
|
|
|
115
|
-
3. 把 MCP 工具返回的 JSON 保存到 `official-docs/search-results/dknowc_mcp_raw.json`。
|
|
117
|
+
3. 把 MCP 工具返回的 JSON 保存到 `dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_mcp_raw.json`。
|
|
116
118
|
|
|
117
119
|
4. 用适配脚本把 MCP 返回规范化成渲染脚本可消费的接口 JSON:
|
|
118
120
|
|
|
119
121
|
```bash
|
|
120
|
-
python3 <skillDir>/scripts/adapt_mcp_result.py official-docs/search-results/dknowc_mcp_raw.json \
|
|
121
|
-
--output official-docs/search-results/dknowc_consulting.json \
|
|
122
|
+
python3 <skillDir>/scripts/adapt_mcp_result.py dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_mcp_raw.json \
|
|
123
|
+
--output dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_consulting.json \
|
|
122
124
|
--mode chat
|
|
123
125
|
```
|
|
124
126
|
|
|
@@ -127,13 +129,13 @@ python3 <skillDir>/scripts/adapt_mcp_result.py official-docs/search-results/dkno
|
|
|
127
129
|
6. 形成面向用户的最终答案:
|
|
128
130
|
|
|
129
131
|
- 如果接口正文已经适合作为最终答案,且带有可用角标,可直接使用。
|
|
130
|
-
- 如果需要整理、压缩、表格化或补充咨询判断,把整理后的最终答案保存到 `official-docs/search-results/dknowc_consulting_answer.txt`。
|
|
132
|
+
- 如果需要整理、压缩、表格化或补充咨询判断,把整理后的最终答案保存到 `dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_consulting_answer.txt`。
|
|
131
133
|
- 整理后的答案仍必须保留真实角标;不要新增无法对应到材料的角标。
|
|
132
134
|
|
|
133
135
|
7. 生成 HTML 溯源报告:
|
|
134
136
|
|
|
135
137
|
```bash
|
|
136
|
-
python3 <skillDir>/scripts/render_trace_html.py official-docs/search-results/dknowc_consulting.json \
|
|
138
|
+
python3 <skillDir>/scripts/render_trace_html.py dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_consulting.json \
|
|
137
139
|
--title "深知可信咨询可信溯源" \
|
|
138
140
|
--question "用户原始问题"
|
|
139
141
|
```
|
|
@@ -141,17 +143,19 @@ python3 <skillDir>/scripts/render_trace_html.py official-docs/search-results/dkn
|
|
|
141
143
|
如果第 6 步生成了最终答案文件,必须传入:
|
|
142
144
|
|
|
143
145
|
```bash
|
|
144
|
-
python3 <skillDir>/scripts/render_trace_html.py official-docs/search-results/dknowc_consulting.json \
|
|
146
|
+
python3 <skillDir>/scripts/render_trace_html.py dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_consulting.json \
|
|
145
147
|
--title "深知可信咨询可信溯源" \
|
|
146
148
|
--question "用户原始问题" \
|
|
147
|
-
--answer-file official-docs/search-results/dknowc_consulting_answer.txt
|
|
149
|
+
--answer-file dknowc-output/${DSH_SESSION_ID:0:8}/official-docs/search-results/dknowc_consulting_answer.txt
|
|
148
150
|
```
|
|
149
151
|
|
|
150
|
-
8.
|
|
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
|
+
|
|
154
|
+
8. 回复用户(三件套交付:带角标答案 + 溯源 HTML + 干净 Markdown):
|
|
151
155
|
|
|
152
|
-
-
|
|
156
|
+
- 先给最终答案,保留角标;答案末尾附“来源”清单,逐行列出答案中实际用到的角标,格式:`[n]《材料标题》· 发布机构 · 日期`(按角标首次出现顺序;机构或日期缺失时可省略对应段)。只列被答案引用的角标,不要罗列全部返回材料。
|
|
153
157
|
- 不要再给用户输出接口返回的 `可信溯源报告` 链接;本地 HTML 已承载同一类溯源信息。
|
|
154
|
-
- 给出本地 HTML
|
|
158
|
+
- 给出本地 HTML 路径和干净 Markdown 路径,均使用 `render_trace_html.py` 实际打印的路径。
|
|
155
159
|
- 如接口材料不足,明确说明“当前接口返回材料不足以支撑某结论”,不要编造。
|
|
156
160
|
|
|
157
161
|
## 答案自检
|
|
@@ -162,6 +166,7 @@ python3 <skillDir>/scripts/render_trace_html.py official-docs/search-results/dkn
|
|
|
162
166
|
- 每个角标编号是否能在接口来源列表中找到。
|
|
163
167
|
- 每个被角标支撑的句子是否能从对应材料标题、摘要、段落摘录或原文链接中核验。
|
|
164
168
|
- 聊天答案和通过 `--answer-file` 传给 HTML 的答案是否一致。
|
|
169
|
+
- 答案末尾的“来源”清单是否覆盖答案中出现的全部角标,且每条来源信息与接口返回材料一致。
|
|
165
170
|
|
|
166
171
|
如果答案没有角标而接口返回了来源材料,先重写答案再生成 HTML;不要交付仅有“未识别到正文角标”提示的报告。
|
|
167
172
|
|
|
@@ -19,10 +19,15 @@ from typing import Any, Dict, Iterable, Optional
|
|
|
19
19
|
|
|
20
20
|
DEFAULT_ENDPOINT = "https://open.dknowc.cn/chat/trusted/unification"
|
|
21
21
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
22
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到
|
|
22
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
23
23
|
import os as _os
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
25
|
+
if not _ws:
|
|
26
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
27
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
28
|
+
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
29
|
+
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
30
|
+
WS_ROOT = Path(_ws).resolve()
|
|
26
31
|
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
27
32
|
DEFAULTS = {
|
|
28
33
|
"area": "",
|
|
@@ -42,6 +47,14 @@ DEFAULTS = {
|
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
|
|
50
|
+
def _rel_to_ws(path: Path) -> str:
|
|
51
|
+
"""把输出路径显示为相对工作区(WS_ROOT)的形式;不在工作区内则显示绝对路径。"""
|
|
52
|
+
try:
|
|
53
|
+
return str(path.relative_to(WS_ROOT))
|
|
54
|
+
except ValueError:
|
|
55
|
+
return str(path.resolve())
|
|
56
|
+
|
|
57
|
+
|
|
45
58
|
def resolve_output_json(output_path: str) -> Path:
|
|
46
59
|
"""把咨询结果 JSON 落到本 Skill 的 official-docs/search-results/ 工作区。
|
|
47
60
|
|
|
@@ -54,7 +67,7 @@ def resolve_output_json(output_path: str) -> Path:
|
|
|
54
67
|
elif raw.parent == Path("."):
|
|
55
68
|
resolved = (SEARCH_RESULTS_DIR / raw.name).resolve()
|
|
56
69
|
else:
|
|
57
|
-
resolved = (
|
|
70
|
+
resolved = (SKILL_ROOT / raw).resolve()
|
|
58
71
|
if resolved.suffix.lower() != ".json":
|
|
59
72
|
resolved = resolved.with_suffix(".json")
|
|
60
73
|
return resolved
|