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.
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/cordis.patch.yml +17 -0
- package/package.json +33 -0
- package/skills/dknowc-official-doc-writer/README.md +156 -0
- package/skills/dknowc-official-doc-writer/SKILL.md +462 -0
- package/skills/dknowc-official-doc-writer/config/format.json +101 -0
- package/skills/dknowc-official-doc-writer/config/user_profile.json.example +6 -0
- package/skills/dknowc-official-doc-writer/official-docs/input/mcp_intro_content.md +61 -0
- package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +113 -0
- package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +62 -0
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +138 -0
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +288 -0
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +156 -0
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +317 -0
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +15 -0
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +284 -0
- package/skills/dknowc-official-doc-writer/reference/standards/00_index.md +151 -0
- package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +51 -0
- package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +53 -0
- package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +48 -0
- package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +51 -0
- package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +55 -0
- package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +81 -0
- package/skills/dknowc-official-doc-writer/reference/standards/07_minutes.md +46 -0
- package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +53 -0
- package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +45 -0
- package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +44 -0
- package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +46 -0
- package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +46 -0
- package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +46 -0
- package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +41 -0
- package/skills/dknowc-official-doc-writer/reference/standards/15_business_docs.md +47 -0
- package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +47 -0
- package/skills/dknowc-official-doc-writer/reference/standards/17_resolution.md +45 -0
- package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +44 -0
- package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +45 -0
- package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +45 -0
- package/skills/dknowc-official-doc-writer/reference/standards/21_explanation.md +40 -0
- package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +47 -0
- package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +46 -0
- package/skills/dknowc-official-doc-writer/reference/standards/24_procurement.md +40 -0
- package/skills/dknowc-official-doc-writer/reference/standards/25_plan.md +42 -0
- package/skills/dknowc-official-doc-writer/reference/standards/26_summary.md +42 -0
- package/skills/dknowc-official-doc-writer/reference/standards/27_speech.md +43 -0
- package/skills/dknowc-official-doc-writer/reference/standards/28_rules.md +40 -0
- package/skills/dknowc-official-doc-writer/reference/standards/29_research.md +42 -0
- package/skills/dknowc-official-doc-writer/reference/standards/30_feasibility.md +42 -0
- package/skills/dknowc-official-doc-writer/reference/standards/31_review_material.md +40 -0
- package/skills/dknowc-official-doc-writer/reference/standards/32_ai_compute.md +41 -0
- package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +569 -0
- package/skills/dknowc-official-doc-writer/reference/task_router.md +119 -0
- package/skills/dknowc-official-doc-writer/scripts/adapt_mcp_result.py +241 -0
- package/skills/dknowc-official-doc-writer/scripts/check_release.py +78 -0
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +575 -0
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +1756 -0
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +178 -0
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +223 -0
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +202 -0
- package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +242 -0
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +218 -0
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +966 -0
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +127 -0
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +180 -0
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +975 -0
- package/skills/dknowc-trusted-consulting/README.md +63 -0
- package/skills/dknowc-trusted-consulting/SKILL.md +172 -0
- package/skills/dknowc-trusted-consulting/scripts/adapt_mcp_result.py +241 -0
- package/skills/dknowc-trusted-consulting/scripts/check_release.py +66 -0
- package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +475 -0
- package/skills/dknowc-trusted-consulting/scripts/initialize.py +89 -0
- package/skills/dknowc-trusted-consulting/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +181 -0
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +990 -0
- package/skills/dknowc-trusted-search/README.md +63 -0
- package/skills/dknowc-trusted-search/SKILL.md +232 -0
- package/skills/dknowc-trusted-search/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-trusted-search/official-docs/search-results/.gitkeep +0 -0
- package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +241 -0
- package/skills/dknowc-trusted-search/scripts/check_release.py +79 -0
- package/skills/dknowc-trusted-search/scripts/deep_query.py +266 -0
- package/skills/dknowc-trusted-search/scripts/initialize.py +89 -0
- package/skills/dknowc-trusted-search/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +181 -0
- package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +889 -0
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1011 -0
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +325 -0
- package/src/index.js +103 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""深知 dsh —— MCP 工具返回 → 渲染脚本输入 适配器。
|
|
3
|
+
|
|
4
|
+
dsh 场景下,skill 不再直连深知接口,而是通过 MCP 工具
|
|
5
|
+
(mcp__dknowc__credible_chat / _trusted_search / _deep_query)拿数据。
|
|
6
|
+
MCP 工具返回的是 MCP 协议结构({content:[{type:"text",text:"..."}]}),
|
|
7
|
+
而 render_trace_html.py 等渲染脚本期望的是深知接口 JSON 结构。
|
|
8
|
+
|
|
9
|
+
本脚本把 MCP 返回规范化成渲染脚本可消费的接口 JSON,保证溯源 HTML
|
|
10
|
+
等交付物与直连版一致。
|
|
11
|
+
|
|
12
|
+
用法:
|
|
13
|
+
python3 scripts/adapt_mcp_result.py <mcp返回.json> --output <规范化.json> [--mode chat|search|deep]
|
|
14
|
+
|
|
15
|
+
- 输入:模型保存的 MCP 工具返回 JSON(content 数组形式,或已含接口 JSON)
|
|
16
|
+
- 输出:可直接传给 render_trace_html.py 的接口 JSON 结构
|
|
17
|
+
- --mode:chat=可信咨询 / search=可信搜索 / deep=深度搜索;缺省自动识别
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import argparse
|
|
21
|
+
import json
|
|
22
|
+
import sys
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from typing import Any, Dict, List, Optional
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _deep_find(o: Any, keys, depth=0, max_depth=8):
|
|
28
|
+
"""在任意嵌套结构里查找第一个命中任一 key 的值。"""
|
|
29
|
+
if depth > max_depth:
|
|
30
|
+
return None
|
|
31
|
+
if isinstance(o, dict):
|
|
32
|
+
for k, v in o.items():
|
|
33
|
+
if k in keys:
|
|
34
|
+
return v
|
|
35
|
+
r = _deep_find(v, keys, depth + 1, max_depth)
|
|
36
|
+
if r is not None:
|
|
37
|
+
return r
|
|
38
|
+
elif isinstance(o, list):
|
|
39
|
+
for item in o:
|
|
40
|
+
r = _deep_find(item, keys, depth + 1, max_depth)
|
|
41
|
+
if r is not None:
|
|
42
|
+
return r
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _extract_mcp_text(o: Any) -> Optional[str]:
|
|
47
|
+
"""从 MCP 协议返回中提取文本内容。
|
|
48
|
+
|
|
49
|
+
支持形态:
|
|
50
|
+
- {content: [{type:"text", text:"..."}]}(MCP 标准,text 常为 JSON 字符串)
|
|
51
|
+
- {structuredContent: {...}}
|
|
52
|
+
- 直接就是接口 JSON
|
|
53
|
+
返回:解析出的 dict payload;无法解析时返回 None。
|
|
54
|
+
"""
|
|
55
|
+
if isinstance(o, dict):
|
|
56
|
+
# structuredContent 优先
|
|
57
|
+
sc = o.get("structuredContent")
|
|
58
|
+
if isinstance(sc, dict):
|
|
59
|
+
return json.dumps(sc, ensure_ascii=False)
|
|
60
|
+
content = o.get("content")
|
|
61
|
+
if isinstance(content, list):
|
|
62
|
+
parts = []
|
|
63
|
+
for block in content:
|
|
64
|
+
if isinstance(block, dict) and isinstance(block.get("text"), str):
|
|
65
|
+
parts.append(block["text"])
|
|
66
|
+
elif isinstance(block, str):
|
|
67
|
+
parts.append(block)
|
|
68
|
+
if parts:
|
|
69
|
+
return "\n".join(parts)
|
|
70
|
+
# 已经是接口 JSON?
|
|
71
|
+
if any(k in o for k in ("resp", "data", "referenceMaterials", "检索文章", "success")):
|
|
72
|
+
return json.dumps(o, ensure_ascii=False)
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _try_json(text: str) -> Any:
|
|
77
|
+
"""尝试把文本解析为 JSON。"""
|
|
78
|
+
if not isinstance(text, str):
|
|
79
|
+
return None
|
|
80
|
+
try:
|
|
81
|
+
return json.loads(text)
|
|
82
|
+
except json.JSONDecodeError:
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _unwrap_payload(o: Any) -> Dict[str, Any]:
|
|
87
|
+
"""递归展开嵌套的接口 JSON,找到最内层含业务字段的对象。
|
|
88
|
+
|
|
89
|
+
接口返回常见 {data: {resp: {...}, referenceMaterials:[...]}},
|
|
90
|
+
也偶见 {content: {data: {...}}} 等包装。这里尽量展开到业务层。
|
|
91
|
+
"""
|
|
92
|
+
cur = o
|
|
93
|
+
seen = set()
|
|
94
|
+
while isinstance(cur, dict) and id(cur) not in seen:
|
|
95
|
+
seen.add(id(cur))
|
|
96
|
+
# 展开 {content:{...}} / {data:{...}} 包装,但保留 data 本身
|
|
97
|
+
if len(cur) == 1:
|
|
98
|
+
only = next(iter(cur.values()))
|
|
99
|
+
if isinstance(only, dict):
|
|
100
|
+
cur = only
|
|
101
|
+
continue
|
|
102
|
+
if isinstance(cur.get("data"), dict) and (
|
|
103
|
+
"resp" in cur["data"] or "检索文章" in cur["data"] or "referenceMaterials" in cur["data"]
|
|
104
|
+
):
|
|
105
|
+
# 保留外层 data 键,同时业务字段也升到顶层
|
|
106
|
+
merged = dict(cur)
|
|
107
|
+
merged.update({k: v for k, v in cur["data"].items() if k not in merged})
|
|
108
|
+
merged["data"] = cur["data"]
|
|
109
|
+
return merged
|
|
110
|
+
break
|
|
111
|
+
return cur if isinstance(cur, dict) else {"raw": cur}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _normalize_chat(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
115
|
+
"""规范化可信咨询(credible_chat)返回。"""
|
|
116
|
+
out = dict(payload)
|
|
117
|
+
data = payload.get("data") if isinstance(payload.get("data"), dict) else {}
|
|
118
|
+
# 确保 resp.content 可被提取
|
|
119
|
+
if "resp" not in out:
|
|
120
|
+
resp = data.get("resp") if isinstance(data, dict) else None
|
|
121
|
+
if isinstance(resp, dict):
|
|
122
|
+
out["resp"] = resp
|
|
123
|
+
else:
|
|
124
|
+
# 从任意位置找正文
|
|
125
|
+
answer = _deep_find(payload, ("content", "answer", "text", "resp"), depth=0)
|
|
126
|
+
if isinstance(answer, str):
|
|
127
|
+
out["resp"] = {"content": answer}
|
|
128
|
+
# 确保 referenceMaterials
|
|
129
|
+
if "referenceMaterials" not in out:
|
|
130
|
+
rm = data.get("referenceMaterials") if isinstance(data, dict) else None
|
|
131
|
+
if isinstance(rm, list):
|
|
132
|
+
out["referenceMaterials"] = rm
|
|
133
|
+
# knowledgeBase / question
|
|
134
|
+
for key in ("knowledgeBase", "question"):
|
|
135
|
+
if key not in out and isinstance(data, dict) and key in data:
|
|
136
|
+
out[key] = data[key]
|
|
137
|
+
return out
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _normalize_search(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
141
|
+
"""规范化可信搜索(trusted_search)返回。"""
|
|
142
|
+
out = dict(payload)
|
|
143
|
+
# 检索文章:优先顶层 data.检索文章,其次 content.data.检索文章
|
|
144
|
+
articles = _deep_find(payload, ("检索文章",))
|
|
145
|
+
if articles is None:
|
|
146
|
+
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
147
|
+
data = content.get("data") if isinstance(content.get("data"), dict) else {}
|
|
148
|
+
articles = data.get("检索文章")
|
|
149
|
+
if isinstance(articles, list):
|
|
150
|
+
if "data" not in out or not isinstance(out["data"], dict):
|
|
151
|
+
out["data"] = {}
|
|
152
|
+
out["data"]["检索文章"] = articles
|
|
153
|
+
# 确保 referenceMaterials
|
|
154
|
+
if "referenceMaterials" not in out:
|
|
155
|
+
rm = _deep_find(payload, ("referenceMaterials",))
|
|
156
|
+
if isinstance(rm, list):
|
|
157
|
+
out["referenceMaterials"] = rm
|
|
158
|
+
# knowledgeBase
|
|
159
|
+
if "knowledgeBase" not in out:
|
|
160
|
+
kb = _deep_find(payload, ("knowledgeBase", "knowledgeBaseUrl"))
|
|
161
|
+
if isinstance(kb, str):
|
|
162
|
+
out["knowledgeBase"] = kb
|
|
163
|
+
return out
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _normalize_deep(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
167
|
+
"""规范化深度搜索(deep_query)返回。"""
|
|
168
|
+
out = dict(payload)
|
|
169
|
+
events = payload.get("events")
|
|
170
|
+
if not isinstance(events, list):
|
|
171
|
+
events = _deep_find(payload, ("events",))
|
|
172
|
+
if isinstance(events, list):
|
|
173
|
+
out["events"] = events
|
|
174
|
+
# data.list 兜底
|
|
175
|
+
data = payload.get("data") if isinstance(payload.get("data"), dict) else {}
|
|
176
|
+
if isinstance(data.get("list"), list):
|
|
177
|
+
out["data"] = data
|
|
178
|
+
if "referenceMaterials" not in out:
|
|
179
|
+
rm = _deep_find(payload, ("referenceMaterials",))
|
|
180
|
+
if isinstance(rm, list):
|
|
181
|
+
out["referenceMaterials"] = rm
|
|
182
|
+
return out
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def detect_mode(payload: Dict[str, Any]) -> str:
|
|
186
|
+
"""自动识别返回属于哪种接口。"""
|
|
187
|
+
if _deep_find(payload, ("检索文章",)) is not None:
|
|
188
|
+
return "search"
|
|
189
|
+
if isinstance(payload.get("events"), list) or _deep_find(payload, ("events",)) is not None:
|
|
190
|
+
return "deep"
|
|
191
|
+
if _deep_find(payload, ("resp",)) is not None:
|
|
192
|
+
return "chat"
|
|
193
|
+
return "chat"
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def main() -> int:
|
|
197
|
+
parser = argparse.ArgumentParser(description="MCP 返回 → 渲染脚本输入 适配器")
|
|
198
|
+
parser.add_argument("input_json", help="MCP 工具返回 JSON 文件路径")
|
|
199
|
+
parser.add_argument("--output", "-o", required=True, help="规范化 JSON 输出路径")
|
|
200
|
+
parser.add_argument("--mode", choices=["chat", "search", "deep"], default=None, help="接口类型;缺省自动识别")
|
|
201
|
+
args = parser.parse_args()
|
|
202
|
+
|
|
203
|
+
src = Path(args.input_json).expanduser()
|
|
204
|
+
if not src.exists():
|
|
205
|
+
print(f"错误:输入文件不存在:{src}", file=sys.stderr)
|
|
206
|
+
return 2
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
raw = json.loads(src.read_text(encoding="utf-8"))
|
|
210
|
+
except json.JSONDecodeError as e:
|
|
211
|
+
print(f"错误:输入不是合法 JSON:{e}", file=sys.stderr)
|
|
212
|
+
return 2
|
|
213
|
+
|
|
214
|
+
# 1) 提取 MCP 文本 → 尝试解析成接口 JSON
|
|
215
|
+
text = _extract_mcp_text(raw)
|
|
216
|
+
payload = _try_json(text) if text else None
|
|
217
|
+
if not isinstance(payload, dict):
|
|
218
|
+
# 纯文本回答(无 JSON)→ 包成 resp.content
|
|
219
|
+
payload = {"resp": {"content": text or json.dumps(raw, ensure_ascii=False)}}
|
|
220
|
+
|
|
221
|
+
# 2) 展开包装层
|
|
222
|
+
payload = _unwrap_payload(payload)
|
|
223
|
+
|
|
224
|
+
# 3) 按模式规范化
|
|
225
|
+
mode = args.mode or detect_mode(payload)
|
|
226
|
+
if mode == "search":
|
|
227
|
+
out = _normalize_search(payload)
|
|
228
|
+
elif mode == "deep":
|
|
229
|
+
out = _normalize_deep(payload)
|
|
230
|
+
else:
|
|
231
|
+
out = _normalize_chat(payload)
|
|
232
|
+
|
|
233
|
+
out_path = Path(args.output).expanduser()
|
|
234
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
235
|
+
out_path.write_text(json.dumps(out, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
236
|
+
print(f"已规范化(mode={mode}):{out_path}")
|
|
237
|
+
return 0
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
if __name__ == "__main__":
|
|
241
|
+
sys.exit(main())
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""阻止客户信息、API Key 和本地生成物进入 SkillHub 公开包。"""
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
9
|
+
LOCAL_BLOCKLIST_PATH = SKILL_ROOT / "config" / "release_blocklist.txt"
|
|
10
|
+
SKIP_PARTS = {".git"}
|
|
11
|
+
SKIP_FILES = {"CHANGE_log.md", "release_blocklist.txt"}
|
|
12
|
+
BANNED_FILES = {"_meta.json", "config.ini", "config.ini.example", "environment_state.json", "user_profile.json"}
|
|
13
|
+
BANNED_ARTIFACT_NAMES = {".gitignore", ".gitkeep", ".DS_Store"}
|
|
14
|
+
BANNED_ARTIFACT_SUFFIXES = {".pyc", ".pyo"}
|
|
15
|
+
ALLOWED_API_KEY_VALUES = {"", "your_api_key_here", "你的深知搜索 API Key"}
|
|
16
|
+
API_KEY_PATTERN = re.compile(r"(?im)^\s*api_key\s*=\s*([^\s#;]+)\s*$")
|
|
17
|
+
SECRET_TOKEN_PATTERN = re.compile(r"\bsk-[A-Za-z0-9_-]{16,}\b")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def load_local_blocklist():
|
|
21
|
+
if not LOCAL_BLOCKLIST_PATH.exists():
|
|
22
|
+
return []
|
|
23
|
+
terms = []
|
|
24
|
+
for line in LOCAL_BLOCKLIST_PATH.read_text(encoding="utf-8").splitlines():
|
|
25
|
+
clean = line.strip()
|
|
26
|
+
if clean and not clean.startswith("#"):
|
|
27
|
+
terms.append(clean)
|
|
28
|
+
return terms
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def should_flag_api_key_value(value):
|
|
32
|
+
clean = value.strip().strip('"').strip("'")
|
|
33
|
+
if clean in ALLOWED_API_KEY_VALUES:
|
|
34
|
+
return False
|
|
35
|
+
# 代码变量、函数调用和对象属性不是明文 Key;真实配置值通常是单个 token。
|
|
36
|
+
if any(mark in clean for mark in ("(", ")", "[", "]", "{", "}", ".", ",")):
|
|
37
|
+
return False
|
|
38
|
+
return True
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main():
|
|
42
|
+
banned_terms = load_local_blocklist()
|
|
43
|
+
findings = []
|
|
44
|
+
for path in SKILL_ROOT.rglob("*"):
|
|
45
|
+
if path.name in BANNED_ARTIFACT_NAMES or path.suffix in BANNED_ARTIFACT_SUFFIXES:
|
|
46
|
+
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含本地产物或平台不允许的文件")
|
|
47
|
+
continue
|
|
48
|
+
if any(part == "__pycache__" for part in path.parts):
|
|
49
|
+
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含 __pycache__")
|
|
50
|
+
continue
|
|
51
|
+
if path.is_file() and path.name in BANNED_FILES:
|
|
52
|
+
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含真实配置文件")
|
|
53
|
+
continue
|
|
54
|
+
if not path.is_file() or path.name in SKIP_FILES or any(part in SKIP_PARTS for part in path.parts):
|
|
55
|
+
continue
|
|
56
|
+
try:
|
|
57
|
+
text = path.read_text(encoding="utf-8")
|
|
58
|
+
except (UnicodeDecodeError, OSError):
|
|
59
|
+
continue
|
|
60
|
+
for line_number, line in enumerate(text.splitlines(), 1):
|
|
61
|
+
for term in banned_terms:
|
|
62
|
+
if term in line:
|
|
63
|
+
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: {term}")
|
|
64
|
+
for match in API_KEY_PATTERN.finditer(line):
|
|
65
|
+
if should_flag_api_key_value(match.group(1)):
|
|
66
|
+
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: 发现非占位符 api_key")
|
|
67
|
+
if SECRET_TOKEN_PATTERN.search(line):
|
|
68
|
+
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: 发现疑似 API Key")
|
|
69
|
+
|
|
70
|
+
if findings:
|
|
71
|
+
print("发布检查失败:发现客户强相关内容")
|
|
72
|
+
print("\n".join(findings))
|
|
73
|
+
raise SystemExit(1)
|
|
74
|
+
print("发布检查通过:未发现已登记的客户强相关内容")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
main()
|