dknowc-dsh 1.3.0 → 1.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 +4 -2
- package/package.json +3 -3
- package/skills/dknowc-official-doc-writer/README.md +1 -1
- package/skills/dknowc-official-doc-writer/SKILL.md +26 -6
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +901 -269
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +31 -3
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +14 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +1 -1
- package/skills/dknowc-official-doc-writer/scripts/adapt_mcp_result.py +52 -2
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +9 -1
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +6 -14
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +2 -2
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +1317 -607
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +140 -4
- package/skills/dknowc-ppt-assistant/SKILL.md +3 -3
- package/skills/dknowc-ppt-assistant/references/material_usage.md +2 -2
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +1335 -292
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +1 -1
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +7 -17
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +99 -60
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1458 -653
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +2 -2
- package/skills/dknowc-trusted-consulting/README.md +1 -1
- package/skills/dknowc-trusted-consulting/SKILL.md +9 -4
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +672 -307
- package/skills/dknowc-trusted-consulting/scripts/initialize.py +24 -34
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +5 -3
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +1647 -729
- package/skills/dknowc-trusted-search/README.md +2 -1
- package/skills/dknowc-trusted-search/SKILL.md +3 -2
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +1110 -251
- package/skills/dknowc-trusted-search/scripts/initialize.py +2 -3
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +2 -2
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1590 -692
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +6 -3
- package/src/index.js +1 -1
- package/skills/dknowc-official-doc-writer/scripts/check_release.py +0 -93
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +0 -106
- package/skills/dknowc-trusted-consulting/scripts/check_release.py +0 -66
- package/skills/dknowc-trusted-search/scripts/check_release.py +0 -79
|
@@ -152,7 +152,10 @@ def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
|
152
152
|
"item": False if args.no_item else True,
|
|
153
153
|
"knowBase": False if args.no_know_base else True,
|
|
154
154
|
"return_full_content": args.return_full_content,
|
|
155
|
-
|
|
155
|
+
# simplified 默认 False(对齐公文写作 dkag_search FIXED_SIMPLIFIED=False):
|
|
156
|
+
# 实测同一 query 下 simplified=true 返回精简集(材料更少且无存档快照 screenShotPath),
|
|
157
|
+
# simplified=false 返回完整集(含快照字段,供核验报告原文失效时兜底回看)。
|
|
158
|
+
"simplified": bool(args.simplified),
|
|
156
159
|
}
|
|
157
160
|
|
|
158
161
|
segment_count = args.segment_count if args.segment_count is not None else 2
|
|
@@ -341,8 +344,8 @@ def main() -> None:
|
|
|
341
344
|
parser.add_argument("--no-know-base", action="store_true", help="不返回知识专库链接")
|
|
342
345
|
parser.add_argument("--return-full-content", action="store_true", help="返回资料全文")
|
|
343
346
|
parser.add_argument("--segment-count", type=int, help="每篇材料最多返回段落数")
|
|
344
|
-
parser.add_argument("--simplified", action="store_true",
|
|
345
|
-
|
|
347
|
+
parser.add_argument("--simplified", action="store_true",
|
|
348
|
+
help="精炼输出(剔除部分材料;将丢失存档快照 screenShotPath 与部分候选材料,不建议在需要生成核验报告时使用)")
|
|
346
349
|
parser.add_argument("--max-articles", type=int, default=3, help="摘要最多展示材料数")
|
|
347
350
|
parser.add_argument("--max-paragraphs", type=int, default=1, help="每篇材料最多展示段落数")
|
|
348
351
|
parser.add_argument("--paragraph-chars", type=int, default=1200, help="每段最多展示字符数")
|
package/src/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const SKILLS = [
|
|
|
35
35
|
{
|
|
36
36
|
name: 'dknowc-official-doc-writer',
|
|
37
37
|
description:
|
|
38
|
-
'当用户要求写一份正式文稿、成稿或报告——如"帮我写一份××分析报告"、"写一份××调研报告"、"写一份××政策分析报告"、"写一份××工作报告/总结/方案/汇报材料",或要求起草通知、请示、报告、函、复函、批复、会议纪要、通报、通告、公告、意见、管理办法、发言稿、讲话稿、经验材料等正式文种时,使用深知公文写作。正式交付支持生成 Word 文档,用户明确需要时可生成红头文件;涉及政策依据时可内部通过深知可信搜索(MCP
|
|
38
|
+
'当用户要求写一份正式文稿、成稿或报告——如"帮我写一份××分析报告"、"写一份××调研报告"、"写一份××政策分析报告"、"写一份××工作报告/总结/方案/汇报材料",或要求起草通知、请示、报告、函、复函、批复、会议纪要、通报、通告、公告、意见、管理办法、发言稿、讲话稿、经验材料等正式文种时,使用深知公文写作。正式交付支持生成 Word 文档,用户明确需要时可生成红头文件;涉及政策依据时可内部通过深知可信搜索(MCP)获取素材并生成溯源核验报告,正式写作前经 MCP doc_outline 获取范文大纲参考。若用户只是要求检索/查证政策原文或做深度搜索核验而不是把素材写成成稿,应改用深知可信搜索。',
|
|
39
39
|
},
|
|
40
40
|
]
|
|
41
41
|
|
|
@@ -1,93 +0,0 @@
|
|
|
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", "writing_preferences.json"}
|
|
13
|
-
BANNED_DIRS = {"knowledge-base"}
|
|
14
|
-
BANNED_ARTIFACT_NAMES = {".gitignore", ".gitkeep", ".DS_Store"}
|
|
15
|
-
BANNED_ARTIFACT_SUFFIXES = {".pyc", ".pyo"}
|
|
16
|
-
# 二进制产物:skill 只有文本规则与脚本,任何 Office/PDF/图片/压缩包都不该出现,
|
|
17
|
-
# 平台上传也会因"禁止上传二进制文件"被跳过。
|
|
18
|
-
BANNED_BINARY_SUFFIXES = {
|
|
19
|
-
".doc", ".docx", ".docm", ".xls", ".xlsx", ".xlsm", ".ppt", ".pptx",
|
|
20
|
-
".pdf", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico",
|
|
21
|
-
".zip", ".tar", ".gz", ".dmg", ".exe",
|
|
22
|
-
}
|
|
23
|
-
ALLOWED_API_KEY_VALUES = {"", "your_api_key_here", "你的深知搜索 API Key"}
|
|
24
|
-
API_KEY_PATTERN = re.compile(r"(?im)^\s*api_key\s*=\s*([^\s#;]+)\s*$")
|
|
25
|
-
SECRET_TOKEN_PATTERN = re.compile(r"\bsk-[A-Za-z0-9_-]{16,}\b")
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def load_local_blocklist():
|
|
29
|
-
if not LOCAL_BLOCKLIST_PATH.exists():
|
|
30
|
-
return []
|
|
31
|
-
terms = []
|
|
32
|
-
for line in LOCAL_BLOCKLIST_PATH.read_text(encoding="utf-8").splitlines():
|
|
33
|
-
clean = line.strip()
|
|
34
|
-
if clean and not clean.startswith("#"):
|
|
35
|
-
terms.append(clean)
|
|
36
|
-
return terms
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def should_flag_api_key_value(value):
|
|
40
|
-
clean = value.strip().strip('"').strip("'")
|
|
41
|
-
if clean in ALLOWED_API_KEY_VALUES:
|
|
42
|
-
return False
|
|
43
|
-
# 代码变量、函数调用和对象属性不是明文 Key;真实配置值通常是单个 token。
|
|
44
|
-
if any(mark in clean for mark in ("(", ")", "[", "]", "{", "}", ".", ",")):
|
|
45
|
-
return False
|
|
46
|
-
return True
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def main():
|
|
50
|
-
banned_terms = load_local_blocklist()
|
|
51
|
-
findings = []
|
|
52
|
-
for path in SKILL_ROOT.rglob("*"):
|
|
53
|
-
if path.name in BANNED_ARTIFACT_NAMES or path.suffix in BANNED_ARTIFACT_SUFFIXES:
|
|
54
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含本地产物或平台不允许的文件")
|
|
55
|
-
continue
|
|
56
|
-
if path.suffix.lower() in BANNED_BINARY_SUFFIXES:
|
|
57
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含二进制产物(平台禁止上传二进制文件)")
|
|
58
|
-
continue
|
|
59
|
-
if any(part == "__pycache__" for part in path.parts):
|
|
60
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含 __pycache__")
|
|
61
|
-
continue
|
|
62
|
-
# 个人素材库与写作偏好是本机私有状态,绝不进入公开包。
|
|
63
|
-
if any(part in BANNED_DIRS for part in path.relative_to(SKILL_ROOT).parts):
|
|
64
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含个人素材库等本机私有数据")
|
|
65
|
-
continue
|
|
66
|
-
if path.is_file() and path.name in BANNED_FILES:
|
|
67
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含真实配置文件或本机私有状态")
|
|
68
|
-
continue
|
|
69
|
-
if not path.is_file() or path.name in SKIP_FILES or any(part in SKIP_PARTS for part in path.parts):
|
|
70
|
-
continue
|
|
71
|
-
try:
|
|
72
|
-
text = path.read_text(encoding="utf-8")
|
|
73
|
-
except (UnicodeDecodeError, OSError):
|
|
74
|
-
continue
|
|
75
|
-
for line_number, line in enumerate(text.splitlines(), 1):
|
|
76
|
-
for term in banned_terms:
|
|
77
|
-
if term in line:
|
|
78
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: {term}")
|
|
79
|
-
for match in API_KEY_PATTERN.finditer(line):
|
|
80
|
-
if should_flag_api_key_value(match.group(1)):
|
|
81
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: 发现非占位符 api_key")
|
|
82
|
-
if SECRET_TOKEN_PATTERN.search(line):
|
|
83
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: 发现疑似 API Key")
|
|
84
|
-
|
|
85
|
-
if findings:
|
|
86
|
-
print("发布检查失败:发现客户强相关内容")
|
|
87
|
-
print("\n".join(findings))
|
|
88
|
-
raise SystemExit(1)
|
|
89
|
-
print("发布检查通过:未发现已登记的客户强相关内容")
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if __name__ == "__main__":
|
|
93
|
-
main()
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""深知可信PPT发布前检查。
|
|
3
|
-
|
|
4
|
-
阻止 API Key、真实配置和本地生成物进入 SkillHub 公开包。
|
|
5
|
-
针对本 Skill 的抽取结构适配:允许第三方声明文件(THIRD_PARTY_NOTICES.md、
|
|
6
|
-
LICENSE*.txt、NOTICE.md)与编译器数据文件;projects/ 与 official-docs/
|
|
7
|
-
工作区内只允许 .gitkeep 占位。
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import re
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _is_within(path: Path, parent: Path) -> bool:
|
|
15
|
-
try:
|
|
16
|
-
path.relative_to(parent)
|
|
17
|
-
return True
|
|
18
|
-
except ValueError:
|
|
19
|
-
return False
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
23
|
-
SKIP_PARTS = {".git", "__pycache__"}
|
|
24
|
-
WORKSPACE_DIR_NAMES = {"official-docs", "projects"}
|
|
25
|
-
ALLOWED_WORKSPACE_FILES = {".gitkeep"}
|
|
26
|
-
SKIP_FILES = {"CHANGE_log.md", "release_blocklist.txt", "THIRD_PARTY_NOTICES.md"}
|
|
27
|
-
BANNED_FILES = {
|
|
28
|
-
"config.ini",
|
|
29
|
-
"config.ini.example",
|
|
30
|
-
"_meta.json",
|
|
31
|
-
"environment_state.json",
|
|
32
|
-
}
|
|
33
|
-
# 第三方许可文件随包分发(MIT 合规要求),不视为违禁。
|
|
34
|
-
ALLOWED_LICENSE_NAMES = {"THIRD_PARTY_NOTICES.md", "NOTICE.md"}
|
|
35
|
-
ALLOWED_LICENSE_PREFIXES = ("LICENSE-",)
|
|
36
|
-
ALLOWED_DATA_SUFFIXES = {".json", ".xml", ".txt"}
|
|
37
|
-
BANNED_ARTIFACT_NAMES = {".DS_Store"}
|
|
38
|
-
BANNED_ARTIFACT_SUFFIXES = {".pyc", ".pyo"}
|
|
39
|
-
ALLOWED_API_KEY_VALUES = {
|
|
40
|
-
"",
|
|
41
|
-
"your_api_key_here",
|
|
42
|
-
"你的深知可信搜索 API Key",
|
|
43
|
-
"你的深知搜索 API Key",
|
|
44
|
-
}
|
|
45
|
-
API_KEY_PATTERN = re.compile(r"(?im)^\s*api_key[^\S\r\n]*=[^\S\r\n]*([^\s#;]+)[^\S\r\n]*$")
|
|
46
|
-
SECRET_TOKEN_PATTERN = re.compile(r"\bsk-[A-Za-z0-9_-]{16,}\b")
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def should_flag_api_key_value(value):
|
|
50
|
-
clean = value.strip().strip('"').strip("'")
|
|
51
|
-
if clean in ALLOWED_API_KEY_VALUES:
|
|
52
|
-
return False
|
|
53
|
-
if any(mark in clean for mark in ("(", ")", "[", "]", "{", "}", ".", ",")):
|
|
54
|
-
return False
|
|
55
|
-
return True
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _is_allowed_license_file(path: Path) -> bool:
|
|
59
|
-
if path.name in ALLOWED_LICENSE_NAMES:
|
|
60
|
-
return True
|
|
61
|
-
return any(path.name.startswith(p) for p in ALLOWED_LICENSE_PREFIXES)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def main():
|
|
65
|
-
findings = []
|
|
66
|
-
for path in SKILL_ROOT.rglob("*"):
|
|
67
|
-
rel = path.relative_to(SKILL_ROOT)
|
|
68
|
-
parts = rel.parts
|
|
69
|
-
if path.name in BANNED_ARTIFACT_NAMES or path.suffix in BANNED_ARTIFACT_SUFFIXES:
|
|
70
|
-
findings.append(f"{rel}: 公开包不得包含本地产物")
|
|
71
|
-
continue
|
|
72
|
-
if any(part in SKIP_PARTS for part in parts):
|
|
73
|
-
continue
|
|
74
|
-
if path.is_file() and path.name in BANNED_FILES:
|
|
75
|
-
findings.append(f"{rel}: 公开包不得包含真实配置文件")
|
|
76
|
-
continue
|
|
77
|
-
# 工作区目录只允许 .gitkeep(第三方许可文件除外)
|
|
78
|
-
if path.is_file() and WORKSPACE_DIR_NAMES.intersection(parts):
|
|
79
|
-
if path.name not in ALLOWED_WORKSPACE_FILES and not _is_allowed_license_file(path):
|
|
80
|
-
findings.append(f"{rel}: 工作区目录内只允许 .gitkeep 占位,公开包不得包含工作区产物")
|
|
81
|
-
continue
|
|
82
|
-
if not path.is_file() or path.name in SKIP_FILES:
|
|
83
|
-
continue
|
|
84
|
-
try:
|
|
85
|
-
text = path.read_text(encoding="utf-8")
|
|
86
|
-
except (UnicodeDecodeError, OSError):
|
|
87
|
-
# 二进制数据文件(json/xml/txt 之外的图片等)跳过文本扫描
|
|
88
|
-
if path.suffix.lower() not in ALLOWED_DATA_SUFFIXES:
|
|
89
|
-
continue
|
|
90
|
-
continue
|
|
91
|
-
for line_number, line in enumerate(text.splitlines(), 1):
|
|
92
|
-
for match in API_KEY_PATTERN.finditer(line):
|
|
93
|
-
if should_flag_api_key_value(match.group(1)):
|
|
94
|
-
findings.append(f"{rel}:{line_number}: 发现非占位符 api_key")
|
|
95
|
-
if SECRET_TOKEN_PATTERN.search(line):
|
|
96
|
-
findings.append(f"{rel}:{line_number}: 发现疑似 API Key")
|
|
97
|
-
|
|
98
|
-
if findings:
|
|
99
|
-
print("发布检查失败:发现不应进入 SkillHub 公开包的内容")
|
|
100
|
-
print("\n".join(findings))
|
|
101
|
-
raise SystemExit(1)
|
|
102
|
-
print("发布检查通过:未发现真实配置、API Key 或本地生成物")
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if __name__ == "__main__":
|
|
106
|
-
main()
|
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
SKIP_PARTS = {".git"}
|
|
10
|
-
BANNED_DIRS = {"outputs"}
|
|
11
|
-
SKIP_FILES = {"CHANGE_log.md"}
|
|
12
|
-
BANNED_FILES = {"config.ini", "_meta.json", "config.ini.example", "register.mjs"}
|
|
13
|
-
BANNED_ARTIFACT_NAMES = {".DS_Store"}
|
|
14
|
-
BANNED_ARTIFACT_SUFFIXES = {".pyc", ".pyo"}
|
|
15
|
-
BANNED_TERMS = (
|
|
16
|
-
"广东省政务服务和数据管理" + "局",
|
|
17
|
-
"广东省政数" + "局",
|
|
18
|
-
"粤政" + "数",
|
|
19
|
-
"粤政" + "易",
|
|
20
|
-
)
|
|
21
|
-
ALLOWED_API_KEY_VALUES = {"", "your_api_key_here", "你的深知可信统一接口 API Key"}
|
|
22
|
-
API_KEY_PATTERN = re.compile(r"(?im)^\s*api_key[^\S\r\n]*=[^\S\r\n]*([^\s#;]+)[^\S\r\n]*$")
|
|
23
|
-
SECRET_TOKEN_PATTERN = re.compile(r"\bsk-[A-Za-z0-9_-]{16,}\b")
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def main():
|
|
27
|
-
findings = []
|
|
28
|
-
for path in SKILL_ROOT.rglob("*"):
|
|
29
|
-
if path.name in BANNED_ARTIFACT_NAMES or path.suffix in BANNED_ARTIFACT_SUFFIXES:
|
|
30
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含本地产物或平台不允许的文件")
|
|
31
|
-
continue
|
|
32
|
-
if any(part in BANNED_DIRS for part in path.relative_to(SKILL_ROOT).parts):
|
|
33
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含本地生成输出目录")
|
|
34
|
-
continue
|
|
35
|
-
if any(part == "__pycache__" for part in path.parts):
|
|
36
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含 __pycache__")
|
|
37
|
-
continue
|
|
38
|
-
if path.is_file() and path.name in BANNED_FILES:
|
|
39
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含真实配置文件")
|
|
40
|
-
continue
|
|
41
|
-
if not path.is_file() or path.name in SKIP_FILES or any(part in SKIP_PARTS for part in path.parts):
|
|
42
|
-
continue
|
|
43
|
-
try:
|
|
44
|
-
text = path.read_text(encoding="utf-8")
|
|
45
|
-
except (UnicodeDecodeError, OSError):
|
|
46
|
-
continue
|
|
47
|
-
for line_number, line in enumerate(text.splitlines(), 1):
|
|
48
|
-
for term in BANNED_TERMS:
|
|
49
|
-
if term in line:
|
|
50
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}:{line_number}: {term}")
|
|
51
|
-
if path.suffix != ".py":
|
|
52
|
-
for match in API_KEY_PATTERN.finditer(text):
|
|
53
|
-
if match.group(1) not in ALLOWED_API_KEY_VALUES:
|
|
54
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 发现非占位符 api_key")
|
|
55
|
-
if SECRET_TOKEN_PATTERN.search(text):
|
|
56
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 发现疑似 API Key")
|
|
57
|
-
|
|
58
|
-
if findings:
|
|
59
|
-
print("发布检查失败:发现不应进入 SkillHub 公开包的内容")
|
|
60
|
-
print("\n".join(findings))
|
|
61
|
-
raise SystemExit(1)
|
|
62
|
-
print("发布检查通过:未发现真实配置、API Key 或本地生成物")
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if __name__ == "__main__":
|
|
66
|
-
main()
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""阻止 API Key、真实配置和本地生成物进入 SkillHub 公开包。"""
|
|
3
|
-
|
|
4
|
-
import re
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def _is_within(path: Path, parent: Path) -> bool:
|
|
9
|
-
try:
|
|
10
|
-
path.relative_to(parent)
|
|
11
|
-
return True
|
|
12
|
-
except ValueError:
|
|
13
|
-
return False
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
17
|
-
SKIP_PARTS = {".git"}
|
|
18
|
-
BANNED_DIRS = {"outputs"}
|
|
19
|
-
WORKSPACE_DIR = SKILL_ROOT / "official-docs"
|
|
20
|
-
ALLOWED_WORKSPACE_FILES = {".gitkeep"}
|
|
21
|
-
SKIP_FILES = {"CHANGE_log.md"}
|
|
22
|
-
BANNED_FILES = {"config.ini", "_meta.json", "config.ini.example", "register.mjs"}
|
|
23
|
-
BANNED_ARTIFACT_NAMES = {".DS_Store"}
|
|
24
|
-
BANNED_ARTIFACT_SUFFIXES = {".pyc", ".pyo"}
|
|
25
|
-
BANNED_TERMS = (
|
|
26
|
-
"广东省政务服务和数据管理" + "局",
|
|
27
|
-
"广东省政数" + "局",
|
|
28
|
-
"粤政" + "数",
|
|
29
|
-
"粤政" + "易",
|
|
30
|
-
)
|
|
31
|
-
ALLOWED_API_KEY_VALUES = {"", "your_api_key_here", "你的深知可信搜索 API Key", "你的深知搜索 API Key"}
|
|
32
|
-
API_KEY_PATTERN = re.compile(r"(?im)^\s*api_key[^\S\r\n]*=[^\S\r\n]*([^\s#;]+)[^\S\r\n]*$")
|
|
33
|
-
SECRET_TOKEN_PATTERN = re.compile(r"\bsk-[A-Za-z0-9_-]{16,}\b")
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def main():
|
|
37
|
-
findings = []
|
|
38
|
-
for path in SKILL_ROOT.rglob("*"):
|
|
39
|
-
if path.name in BANNED_ARTIFACT_NAMES or path.suffix in BANNED_ARTIFACT_SUFFIXES:
|
|
40
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含本地产物或平台不允许的文件")
|
|
41
|
-
continue
|
|
42
|
-
if any(part in BANNED_DIRS for part in path.relative_to(SKILL_ROOT).parts):
|
|
43
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含本地生成输出目录")
|
|
44
|
-
continue
|
|
45
|
-
if any(part == "__pycache__" for part in path.parts):
|
|
46
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含 __pycache__")
|
|
47
|
-
continue
|
|
48
|
-
if path.is_file() and path.name in BANNED_FILES:
|
|
49
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 公开包不得包含真实配置文件")
|
|
50
|
-
continue
|
|
51
|
-
if path.is_file() and _is_within(path, WORKSPACE_DIR) and path.name not in ALLOWED_WORKSPACE_FILES:
|
|
52
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: official-docs/ 工作区内只允许 .gitkeep 占位,公开包不得包含工作区产物")
|
|
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
|
-
if path.suffix != ".py":
|
|
65
|
-
for match in API_KEY_PATTERN.finditer(text):
|
|
66
|
-
if match.group(1) not in ALLOWED_API_KEY_VALUES:
|
|
67
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 发现非占位符 api_key")
|
|
68
|
-
if SECRET_TOKEN_PATTERN.search(text):
|
|
69
|
-
findings.append(f"{path.relative_to(SKILL_ROOT)}: 发现疑似 API Key")
|
|
70
|
-
|
|
71
|
-
if findings:
|
|
72
|
-
print("发布检查失败:发现不应进入 SkillHub 公开包的内容")
|
|
73
|
-
print("\n".join(findings))
|
|
74
|
-
raise SystemExit(1)
|
|
75
|
-
print("发布检查通过:未发现真实配置、API Key 或本地生成物")
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if __name__ == "__main__":
|
|
79
|
-
main()
|