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,202 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""调用公文范文大纲接口,生成写作结构参考。"""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Optional
|
|
11
|
+
|
|
12
|
+
import requests
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
16
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 skill 目录(SkillHub 兼容)
|
|
17
|
+
import os as _os
|
|
18
|
+
WS_ROOT = Path(_os.environ.get("DKNWOC_WS_ROOT") or _os.getcwd()).resolve()
|
|
19
|
+
|
|
20
|
+
API_KEY_ENV = "DKNOWC_API_KEY"
|
|
21
|
+
OUTLINE_RESULTS_DIR = WS_ROOT / "official-docs" / "outline-results"
|
|
22
|
+
OUTLINE_API_URL = "https://open.dknowc.cn/llm-api/proxy-builtin/official-doc-outline/v1"
|
|
23
|
+
MIN_QUERY_LENGTH = 2
|
|
24
|
+
MAX_QUERY_LENGTH = 1200
|
|
25
|
+
DEFAULT_TIMEOUT = 180
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_relative_to(path: Path, parent: Path) -> bool:
|
|
29
|
+
try:
|
|
30
|
+
path.relative_to(parent)
|
|
31
|
+
return True
|
|
32
|
+
except ValueError:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def safe_filename(text: str, max_length: int = 60) -> str:
|
|
37
|
+
name = "".join(ch if ch.isalnum() or ch in "-_" else "_" for ch in text.strip())
|
|
38
|
+
name = "_".join(part for part in name.split("_") if part)
|
|
39
|
+
return (name or "outline")[:max_length]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _rel_to_ws(path: Path) -> str:
|
|
43
|
+
"""把输出路径显示为相对工作区(WS_ROOT)的形式;不在工作区内则显示绝对路径。"""
|
|
44
|
+
try:
|
|
45
|
+
return str(path.relative_to(WS_ROOT))
|
|
46
|
+
except ValueError:
|
|
47
|
+
return str(path.resolve())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def resolve_output_json(output_path: Optional[str], query: str) -> Path:
|
|
51
|
+
if output_path:
|
|
52
|
+
raw_path = Path(output_path).expanduser()
|
|
53
|
+
else:
|
|
54
|
+
raw_path = Path(f"{safe_filename(query)}_范文大纲.json")
|
|
55
|
+
|
|
56
|
+
if raw_path.is_absolute():
|
|
57
|
+
resolved = raw_path.resolve()
|
|
58
|
+
elif raw_path.parent == Path("."):
|
|
59
|
+
resolved = (OUTLINE_RESULTS_DIR / raw_path.name).resolve()
|
|
60
|
+
else:
|
|
61
|
+
resolved = (WS_ROOT / raw_path).resolve()
|
|
62
|
+
|
|
63
|
+
if resolved.suffix.lower() != ".json":
|
|
64
|
+
resolved = resolved.with_suffix(".json")
|
|
65
|
+
if not is_relative_to(resolved, OUTLINE_RESULTS_DIR.resolve()):
|
|
66
|
+
raise ValueError(f"输出文件必须位于范文大纲结果目录内: {OUTLINE_RESULTS_DIR}")
|
|
67
|
+
return resolved
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def load_api_key(config_path: Optional[Path] = None) -> str:
|
|
71
|
+
if config_path is not None:
|
|
72
|
+
raise ValueError(f"当前版本不再读取 config.ini,请通过环境变量 {API_KEY_ENV} 配置 API Key。")
|
|
73
|
+
|
|
74
|
+
# dsh 场景:dsh 会清理名字含 KEY 的隐式环境变量,bundle 插件会把主进程的
|
|
75
|
+
# DKNOWC_API_KEY 经 shell-env 显式注入为 DSH_DKNOWC_API_KEY,优先读取。
|
|
76
|
+
api_key = os.environ.get("DSH_DKNOWC_API_KEY", "").strip() or os.environ.get(API_KEY_ENV, "").strip()
|
|
77
|
+
if not api_key or api_key in {"your_api_key_here", "你的深知搜索 API Key"}:
|
|
78
|
+
raise ValueError(f"API Key 为空,请通过环境变量 {API_KEY_ENV} 配置有效 API Key。")
|
|
79
|
+
return api_key
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def validate_query(query: str) -> str:
|
|
83
|
+
value = query.strip()
|
|
84
|
+
if len(value) < MIN_QUERY_LENGTH:
|
|
85
|
+
raise ValueError(f"写作需求过短,最少需要 {MIN_QUERY_LENGTH} 个字符")
|
|
86
|
+
if len(value) > MAX_QUERY_LENGTH:
|
|
87
|
+
raise ValueError(f"写作需求过长,超过限制(最大 {MAX_QUERY_LENGTH} 字符)")
|
|
88
|
+
return value
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def call_outline_api(query: str, api_key: str, timeout: int) -> tuple[int, dict | str, float]:
|
|
92
|
+
start = time.time()
|
|
93
|
+
response = requests.post(
|
|
94
|
+
OUTLINE_API_URL,
|
|
95
|
+
headers={
|
|
96
|
+
"api-key": api_key,
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
},
|
|
99
|
+
json={"query": query},
|
|
100
|
+
timeout=timeout,
|
|
101
|
+
)
|
|
102
|
+
elapsed = round(time.time() - start, 2)
|
|
103
|
+
try:
|
|
104
|
+
body: dict | str = response.json()
|
|
105
|
+
except ValueError:
|
|
106
|
+
body = response.text
|
|
107
|
+
return response.status_code, body, elapsed
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def build_output(query: str, status_code: int, body: dict | str, elapsed: float) -> dict:
|
|
111
|
+
result = {
|
|
112
|
+
"request_meta": {
|
|
113
|
+
"query": query,
|
|
114
|
+
"url": OUTLINE_API_URL,
|
|
115
|
+
"elapsed_seconds": elapsed,
|
|
116
|
+
"status_code": status_code,
|
|
117
|
+
"auth": f"api-key from {API_KEY_ENV}",
|
|
118
|
+
},
|
|
119
|
+
"raw_response": body,
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if not isinstance(body, dict):
|
|
123
|
+
result.update({
|
|
124
|
+
"success": False,
|
|
125
|
+
"reason": "接口未返回 JSON",
|
|
126
|
+
"outline_available": False,
|
|
127
|
+
})
|
|
128
|
+
return result
|
|
129
|
+
|
|
130
|
+
data = body.get("data")
|
|
131
|
+
outline_available = (
|
|
132
|
+
status_code == 200
|
|
133
|
+
and body.get("code") == 200
|
|
134
|
+
and isinstance(data, dict)
|
|
135
|
+
and data.get("success") is True
|
|
136
|
+
and isinstance(data.get("outline"), list)
|
|
137
|
+
and len(data.get("outline")) > 0
|
|
138
|
+
)
|
|
139
|
+
result.update({
|
|
140
|
+
"success": status_code == 200 and body.get("code") == 200,
|
|
141
|
+
"outline_available": outline_available,
|
|
142
|
+
"response_id": body.get("id"),
|
|
143
|
+
"message": body.get("msg"),
|
|
144
|
+
})
|
|
145
|
+
if isinstance(data, dict):
|
|
146
|
+
result["outline_title"] = data.get("outline_title")
|
|
147
|
+
result["doc_type"] = data.get("doc_type")
|
|
148
|
+
result["structure_summary"] = data.get("structure_summary")
|
|
149
|
+
result["outline"] = data.get("outline")
|
|
150
|
+
result["style_notes"] = data.get("style_notes")
|
|
151
|
+
result["risk_notes"] = data.get("risk_notes")
|
|
152
|
+
result["reason"] = data.get("reason") if data.get("success") is False else None
|
|
153
|
+
else:
|
|
154
|
+
result["reason"] = body.get("msg") or "接口未返回 data 对象"
|
|
155
|
+
return result
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def main():
|
|
159
|
+
parser = argparse.ArgumentParser(description="公文范文大纲接口调用工具")
|
|
160
|
+
parser.add_argument("query", help="用户写作需求,包含文种、主题、用途和写作重点")
|
|
161
|
+
parser.add_argument("--output", help="输出 JSON 文件名或 official-docs/outline-results/ 下的路径")
|
|
162
|
+
parser.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT, help="请求超时时间,默认 180 秒")
|
|
163
|
+
args = parser.parse_args()
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
query = validate_query(args.query)
|
|
167
|
+
api_key = load_api_key()
|
|
168
|
+
output_path = resolve_output_json(args.output, query)
|
|
169
|
+
status_code, body, elapsed = call_outline_api(query, api_key, args.timeout)
|
|
170
|
+
result = build_output(query, status_code, body, elapsed)
|
|
171
|
+
|
|
172
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
173
|
+
with output_path.open("w", encoding="utf-8") as f:
|
|
174
|
+
json.dump(result, f, ensure_ascii=False, indent=2)
|
|
175
|
+
|
|
176
|
+
summary = {
|
|
177
|
+
"output": str(_rel_to_ws(output_path)),
|
|
178
|
+
"status_code": status_code,
|
|
179
|
+
"elapsed_seconds": elapsed,
|
|
180
|
+
"request_success": result.get("success"),
|
|
181
|
+
"outline_available": result.get("outline_available"),
|
|
182
|
+
"outline_title": result.get("outline_title"),
|
|
183
|
+
"doc_type": result.get("doc_type"),
|
|
184
|
+
"outline_count": len(result.get("outline") or []),
|
|
185
|
+
"reason": result.get("reason"),
|
|
186
|
+
"next_action": "confirm_outline_and_search_suggestions" if result.get("outline_available") else "ignore_outline_and_continue_314_flow",
|
|
187
|
+
}
|
|
188
|
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
|
189
|
+
if status_code != 200:
|
|
190
|
+
return 1
|
|
191
|
+
return 0
|
|
192
|
+
except Exception as exc:
|
|
193
|
+
print(json.dumps({
|
|
194
|
+
"success": False,
|
|
195
|
+
"outline_available": False,
|
|
196
|
+
"error": str(exc),
|
|
197
|
+
}, ensure_ascii=False, indent=2), file=sys.stderr)
|
|
198
|
+
return 1
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
if __name__ == "__main__":
|
|
202
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""深知公文写作 - 中文正式文稿语言质检脚本。
|
|
3
|
+
|
|
4
|
+
扫描 .txt / .md / .docx 草稿,提示 AI 味、旁白、口语、占位符和格式风险。
|
|
5
|
+
只报风险,不自动改写正文。本脚本是可选质检能力,不参与主写作流程。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
import zipfile
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from xml.etree import ElementTree
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Finding:
|
|
20
|
+
"""一条质检发现。"""
|
|
21
|
+
|
|
22
|
+
__slots__ = ("path", "line", "severity", "label", "match", "advice")
|
|
23
|
+
|
|
24
|
+
def __init__(self, path: str, line: int, severity: str, label: str, match: str, advice: str):
|
|
25
|
+
self.path = path
|
|
26
|
+
self.line = line
|
|
27
|
+
self.severity = severity
|
|
28
|
+
self.label = label
|
|
29
|
+
self.match = match
|
|
30
|
+
self.advice = advice
|
|
31
|
+
|
|
32
|
+
def as_dict(self) -> dict:
|
|
33
|
+
return {
|
|
34
|
+
"path": self.path,
|
|
35
|
+
"line": self.line,
|
|
36
|
+
"severity": self.severity,
|
|
37
|
+
"label": self.label,
|
|
38
|
+
"match": self.match,
|
|
39
|
+
"advice": self.advice,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
SEVERITY_RANK = {"low": 1, "medium": 2, "high": 3}
|
|
44
|
+
|
|
45
|
+
# (severity, label, pattern, advice)
|
|
46
|
+
PATTERNS = [
|
|
47
|
+
# --- 思考泄露与起草过程(硬边界,high)---
|
|
48
|
+
("high", "thought-leak", r"作为(?:一个)?\s*AI|我是(?:一个)?\s*AI|由\s*AI\s*(?:起草|生成|辅助生成)", "删除模型身份或生成过程表述,改为正文判断。"),
|
|
49
|
+
("high", "thought-leak", r"我的(?:思路|推理|分析)|(?:思考|推理)过程(?:如下|是|:|:)|内部推理", "删除思考过程或内部推理表述。"),
|
|
50
|
+
("high", "thought-leak", r"我将根据|接下来我会|按你的要求|这版文章|这段文字|根据用户要求(?:修改|改写|调整)", "删除外部修改过程表述,改为定稿正文。"),
|
|
51
|
+
("medium", "thought-leak", r"本(?:文|稿|报告|方案|材料|说明)[^。\n]{0,8}(?:是|为)?\s*AI\s*(?:辅助)?生成", "删除 AI 生成声明,正式正文不出现该表述。"),
|
|
52
|
+
|
|
53
|
+
# --- 旁白句(写作说明混入正文)---
|
|
54
|
+
("high", "side-commentary", r"本方案重点说明|本文将从|本节主要(?:介绍|说明)", "删除写作说明,改成正文判断。"),
|
|
55
|
+
("medium", "side-commentary", r"以下(?:直接)?列出|相关情况如下|需要指出的是|值得注意的是", "删除提示语,直接进入事项。"),
|
|
56
|
+
("medium", "side-commentary", r"根据有关资料显示|有关方面认为|业内专家指出", "避免模糊背书,补充明确来源或改为材料已给事实。"),
|
|
57
|
+
("medium", "side-commentary", r"为了便于理解|简单来说|通俗地说|可以理解为|综上所述[,,]", "正式文稿中删除解释腔或过渡套话。"),
|
|
58
|
+
|
|
59
|
+
# --- 二元包装句(成簇判断,单次可保留)---
|
|
60
|
+
("medium", "paired-summary", r"不是[^。;;\n]{0,80}而是", "检查是否为虚假对比;必要否定对比可保留。"),
|
|
61
|
+
("medium", "paired-summary", r"不仅[^。;;\n]{0,80}(?:还|更是)", "检查是否拆成具体事实;成簇出现时提示。"),
|
|
62
|
+
("medium", "paired-summary", r"不但[^。;;\n]{0,80}而且", "检查是否拆成具体事实;成簇出现时提示。"),
|
|
63
|
+
("medium", "paired-summary", r"既[^。;;\n]{0,80}又", "改为具体并列事项,避免套话。"),
|
|
64
|
+
("medium", "paired-summary", r"一方面[^。;;\n]{0,100}另一方面", "检查是否为真实并列;否则按业务自然分段。"),
|
|
65
|
+
|
|
66
|
+
# --- 未完成占位符 ---
|
|
67
|
+
("medium", "placeholder", r"\[[^\]\n]{0,30}(?:具体|待|填写|补充|确认|项目名称|单位名称|金额|日期)[^\]\n]{0,30}\]", "交付正文不应保留方括号占位;缺项改为正文外提示。"),
|
|
68
|
+
("medium", "placeholder", r"(?<![A-Za-z一-鿿])X{2,}(?:万元|亿元|项|%|%|卡|套|人|次|个|年|月|日|张|台)", "交付正文不应保留 X/XXXX 类占位。"),
|
|
69
|
+
("medium", "placeholder", r"Y{4}年M{1,2}月D{1,2}日", "交付正文不应保留 YYYY年MM月DD日 类占位。"),
|
|
70
|
+
("medium", "placeholder", r"[((][^))\n]{0,30}(?:待(?:确认|补充|填写|签发)|签发日期|会议时间|成文日期)[^))\n]{0,30}[))]", "交付正文不应保留括号占位。"),
|
|
71
|
+
("medium", "placeholder", r"〔(?:签发日期|会议时间|待补充)〕", "交付正文不应保留未完成占位。"),
|
|
72
|
+
|
|
73
|
+
# --- 口语化与弱判断 ---
|
|
74
|
+
("medium", "casual", r"这个钱花得值|用不完|AI味|老板关心|马上要|搞清楚", "改为正式表达,且不升级强度(见 anti_ai_patterns.md)。"),
|
|
75
|
+
|
|
76
|
+
# --- 空泛套话(low,需有实质支撑)---
|
|
77
|
+
("low", "empty-filler", r"全面赋能|提供有力支撑|奠定坚实基础|未来可期|高度重视|充分发挥|不断提升|持续推进", "确认是否有具体对象、机制或结果支撑;无则改为具体工作。"),
|
|
78
|
+
("low", "template-phrase", r"形成一批|重点任务包括|保障措施包括|总体看|再上新台阶", "避免总括句承接长清单或口号式收尾。"),
|
|
79
|
+
|
|
80
|
+
# --- 高频抽象词 ---
|
|
81
|
+
("low", "abstract-term", r"赋能|闭环|底座|抓手|矩阵", "抽象词需落到具体对象、机制或验收标准;同一词过多时替换。"),
|
|
82
|
+
|
|
83
|
+
# --- 格式噪点 ---
|
|
84
|
+
("medium", "format", r"[一-鿿][,;:!?][一-鿿]", "中文正文中改用全角标点。"),
|
|
85
|
+
("low", "format", r"\d{1,3}(?:,\d{3})+(?:\.\d+)?", "确认正式中文材料中是否应取消千位分隔符。"),
|
|
86
|
+
("low", "format", r"\*\*[^*\n]{1,80}\*\*|^\s*#{1,6}\s+|^\s*---\s*$", "正式公文正文不要用 Markdown 加粗/标题/横线。"),
|
|
87
|
+
("low", "format", r"[\U0001F300-\U0001FAFF]", "正式公文正文避免使用 Emoji。"),
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
# 术语过度集中阈值
|
|
91
|
+
REPEAT_TERMS = {
|
|
92
|
+
"赋能": 3, "闭环": 4, "抓手": 3, "底座": 6, "矩阵": 3,
|
|
93
|
+
"生态": 4, "口径": 4, "边界": 4,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def read_docx(path: Path) -> str:
|
|
98
|
+
"""提取 .docx 中的正文文本。"""
|
|
99
|
+
pieces = []
|
|
100
|
+
xml_names = (
|
|
101
|
+
"word/document.xml",
|
|
102
|
+
"word/header1.xml", "word/header2.xml", "word/header3.xml",
|
|
103
|
+
"word/footer1.xml", "word/footer2.xml", "word/footer3.xml",
|
|
104
|
+
)
|
|
105
|
+
try:
|
|
106
|
+
with zipfile.ZipFile(path) as zf:
|
|
107
|
+
for name in xml_names:
|
|
108
|
+
if name not in zf.namelist():
|
|
109
|
+
continue
|
|
110
|
+
root = ElementTree.fromstring(zf.read(name))
|
|
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 read_text(arg: str) -> tuple[str, str]:
|
|
123
|
+
"""读取 .txt / .md / .docx / stdin。"""
|
|
124
|
+
if arg == "-":
|
|
125
|
+
return "<stdin>", sys.stdin.read()
|
|
126
|
+
path = Path(arg)
|
|
127
|
+
if path.suffix.lower() == ".docx":
|
|
128
|
+
return str(path), read_docx(path)
|
|
129
|
+
try:
|
|
130
|
+
raw = path.read_bytes()
|
|
131
|
+
except OSError as exc:
|
|
132
|
+
raise SystemExit(f"无法读取文件 {path}: {exc}")
|
|
133
|
+
for enc in ("utf-8-sig", "utf-8", "gb18030"):
|
|
134
|
+
try:
|
|
135
|
+
return str(path), raw.decode(enc)
|
|
136
|
+
except UnicodeDecodeError:
|
|
137
|
+
continue
|
|
138
|
+
return str(path), raw.decode("gb18030", errors="replace")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def scan_file(path: str, text: str, include_format: bool, include_structure: bool) -> list[Finding]:
|
|
142
|
+
findings = []
|
|
143
|
+
lines = text.splitlines() or [text]
|
|
144
|
+
seen_pairs = set()
|
|
145
|
+
|
|
146
|
+
for idx, line in enumerate(lines, start=1):
|
|
147
|
+
for severity, label, pattern, advice in PATTERNS:
|
|
148
|
+
if label == "format" and not include_format:
|
|
149
|
+
continue
|
|
150
|
+
for match in re.finditer(pattern, line):
|
|
151
|
+
key = (label, match.group(0), idx)
|
|
152
|
+
if key in seen_pairs:
|
|
153
|
+
continue
|
|
154
|
+
seen_pairs.add(key)
|
|
155
|
+
findings.append(Finding(path, idx, severity, label, match.group(0), advice))
|
|
156
|
+
|
|
157
|
+
if include_structure:
|
|
158
|
+
findings.extend(repeat_term_findings(path, text))
|
|
159
|
+
findings.extend(duplicate_paragraph_findings(path, lines))
|
|
160
|
+
return findings
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def repeat_term_findings(path: str, text: str) -> list[Finding]:
|
|
164
|
+
findings = []
|
|
165
|
+
for term, threshold in REPEAT_TERMS.items():
|
|
166
|
+
count = text.count(term)
|
|
167
|
+
if count >= threshold:
|
|
168
|
+
findings.append(Finding(
|
|
169
|
+
path, 1, "low", "term-overuse", term,
|
|
170
|
+
f"`{term}` 出现 {count} 次;建议将部分表述替换为更具体的事项、主体或办理要素。",
|
|
171
|
+
))
|
|
172
|
+
return findings
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def duplicate_paragraph_findings(path: str, lines: list[str]) -> list[Finding]:
|
|
176
|
+
"""相邻段落事项重叠检测。"""
|
|
177
|
+
findings = []
|
|
178
|
+
prev_text = ""
|
|
179
|
+
prev_line = 0
|
|
180
|
+
for idx, line in enumerate(lines, start=1):
|
|
181
|
+
text = re.sub(r"\s+", "", line)
|
|
182
|
+
if len(text) < 60:
|
|
183
|
+
prev_text = ""
|
|
184
|
+
continue
|
|
185
|
+
if prev_text and text and _similarity(prev_text, text) >= 0.42:
|
|
186
|
+
findings.append(Finding(
|
|
187
|
+
path, idx, "medium", "adjacent-duplicate",
|
|
188
|
+
text[:40] + "...",
|
|
189
|
+
f"与第 {prev_line} 行段落事项重叠较高;检查是否为胶水式重复连接。",
|
|
190
|
+
))
|
|
191
|
+
prev_text = text
|
|
192
|
+
prev_line = idx
|
|
193
|
+
return findings
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _similarity(a: str, b: str) -> float:
|
|
197
|
+
a_set, b_set = set(a), set(b)
|
|
198
|
+
if not a_set or not b_set:
|
|
199
|
+
return 0.0
|
|
200
|
+
return len(a_set & b_set) / len(a_set | b_set)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def main(argv: list[str] | None = None) -> int:
|
|
204
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
205
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
206
|
+
parser = argparse.ArgumentParser(description="深知公文写作草稿语言质检")
|
|
207
|
+
parser.add_argument("files", nargs="+", help="要扫描的 .txt/.md/.docx 文件,或 '-' 表示 stdin")
|
|
208
|
+
parser.add_argument("--encoding", help="纯文本文件编码(可选)")
|
|
209
|
+
parser.add_argument("--json", action="store_true", help="输出 JSON 结果")
|
|
210
|
+
parser.add_argument("--format", action="store_true", help="同时检查标点、数字、Markdown、Emoji 格式风险")
|
|
211
|
+
parser.add_argument("--structure", action="store_true", help="同时检查相邻段落重复与术语过度集中")
|
|
212
|
+
parser.add_argument("--strict", action="store_true", help="存在中高等级发现时返回退出码 1")
|
|
213
|
+
args = parser.parse_args(argv)
|
|
214
|
+
|
|
215
|
+
all_findings = []
|
|
216
|
+
had_error = False
|
|
217
|
+
for arg in args.files:
|
|
218
|
+
try:
|
|
219
|
+
path, text = read_text(arg)
|
|
220
|
+
except SystemExit as exc:
|
|
221
|
+
print(f"ERROR: {exc}", file=sys.stderr)
|
|
222
|
+
had_error = True
|
|
223
|
+
continue
|
|
224
|
+
all_findings.extend(scan_file(path, text, args.format, args.structure))
|
|
225
|
+
|
|
226
|
+
if args.json:
|
|
227
|
+
print(json.dumps([f.as_dict() for f in all_findings], ensure_ascii=False, indent=2))
|
|
228
|
+
elif all_findings:
|
|
229
|
+
for f in all_findings:
|
|
230
|
+
print(f"{f.path}:{f.line}: {f.severity}: {f.label}: {f.match}")
|
|
231
|
+
print(f" {f.advice}")
|
|
232
|
+
elif not had_error:
|
|
233
|
+
print("未发现明显语言风险。")
|
|
234
|
+
|
|
235
|
+
if args.strict and not had_error:
|
|
236
|
+
high_medium = [f for f in all_findings if SEVERITY_RANK[f.severity] >= 2]
|
|
237
|
+
return 1 if high_medium else 0
|
|
238
|
+
return 1 if had_error else 0
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
if __name__ == "__main__":
|
|
242
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 国内 MaaS headless 注册助手(供 skillhub skill 调用;纯 node,内置 fetch,无三方依赖)。
|
|
3
|
+
// node register.mjs [--base URL] send --phone <p>
|
|
4
|
+
// node register.mjs [--base URL] register --phone <p> --vcode <c> [--type 6] [--organ ..] [--name ..] [--channel ..] [--source ..] [--password ..] [--new-key]
|
|
5
|
+
// 无需 cookie / 加密 / 登录态。默认打生产,--base 可切测试环境。
|
|
6
|
+
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import os from "os";
|
|
9
|
+
import path from "path";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_BASE = "https://platform.dknowc.cn/auth/home/userAuto";
|
|
12
|
+
const DEFAULT_OPEN_BASE = "https://open.dknowc.cn";
|
|
13
|
+
const DEFAULT_CHANNEL = "46A3BA1D-3E1A-4E8C-BD50-A6DCBEE1DB05";
|
|
14
|
+
const DEFAULT_TYPE = "6";
|
|
15
|
+
const DEFAULT_SOURCE = "agent";
|
|
16
|
+
const API_KEY_ENV = "DKNOWC_API_KEY";
|
|
17
|
+
const MAAS_PLATFORM_URL = "https://platform.dknowc.cn/";
|
|
18
|
+
const FALLBACK_REGISTER_URL = MAAS_PLATFORM_URL;
|
|
19
|
+
const ZSHRC_START = "# >>> dknowc official doc writer api key >>>";
|
|
20
|
+
const ZSHRC_END = "# <<< dknowc official doc writer api key <<<";
|
|
21
|
+
|
|
22
|
+
function parseArgs(argv) {
|
|
23
|
+
const out = { _: [] };
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const a = argv[i];
|
|
26
|
+
if (a.startsWith("--")) {
|
|
27
|
+
const key = a.slice(2);
|
|
28
|
+
const next = argv[i + 1];
|
|
29
|
+
if (next === undefined || next.startsWith("--")) { out[key] = true; }
|
|
30
|
+
else { out[key] = next; i++; }
|
|
31
|
+
} else { out._.push(a); }
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function post(url, payload) {
|
|
37
|
+
const ctl = new AbortController();
|
|
38
|
+
const timer = setTimeout(() => ctl.abort(), 30000);
|
|
39
|
+
try {
|
|
40
|
+
const r = await fetch(url, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
43
|
+
body: JSON.stringify(payload),
|
|
44
|
+
signal: ctl.signal,
|
|
45
|
+
});
|
|
46
|
+
const text = await r.text();
|
|
47
|
+
try { return JSON.parse(text); }
|
|
48
|
+
catch { return { status: false, msg: "非JSON响应(前200字符): " + text.slice(0, 200) }; }
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return { status: false, msg: "请求异常: " + (e && e.message ? e.message : String(e)) };
|
|
51
|
+
} finally { clearTimeout(timer); }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function postWithBearer(url, apiKey, payload) {
|
|
55
|
+
const ctl = new AbortController();
|
|
56
|
+
const timer = setTimeout(() => ctl.abort(), 30000);
|
|
57
|
+
try {
|
|
58
|
+
const r = await fetch(url, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify(payload),
|
|
65
|
+
signal: ctl.signal,
|
|
66
|
+
});
|
|
67
|
+
const text = await r.text();
|
|
68
|
+
try { return JSON.parse(text); }
|
|
69
|
+
catch { return { code: r.status, errmsg: "非JSON响应(前200字符): " + text.slice(0, 200) }; }
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return { code: 0, errmsg: "请求异常: " + (e && e.message ? e.message : String(e)) };
|
|
72
|
+
} finally { clearTimeout(timer); }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function genPassword() {
|
|
76
|
+
// 8-32 位,含大写/小写/数字/特殊至少 3 类
|
|
77
|
+
const pools = ["ABCDEFGHJKLMNPQRSTUVWXYZ", "abcdefghijkmnpqrstuvwxyz", "23456789", "!@#$%^&*"];
|
|
78
|
+
const pick = (s) => s[Math.floor(Math.random() * s.length)];
|
|
79
|
+
let chars = pools.map(pick); // 每类至少一个
|
|
80
|
+
const all = pools.join("");
|
|
81
|
+
for (let i = 0; i < 8; i++) chars.push(pick(all)); // 补到 12 位
|
|
82
|
+
for (let i = chars.length - 1; i > 0; i--) { // 洗牌
|
|
83
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
84
|
+
[chars[i], chars[j]] = [chars[j], chars[i]];
|
|
85
|
+
}
|
|
86
|
+
return chars.join("");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function createNewApiKey(openBase, existingApiKey, name, remark) {
|
|
90
|
+
const result = await postWithBearer(
|
|
91
|
+
openBase.replace(/\/$/, "") + "/open-api/maas/api-key/create",
|
|
92
|
+
existingApiKey,
|
|
93
|
+
{ name, remark },
|
|
94
|
+
);
|
|
95
|
+
const apiKey = result && result.data ? result.data.appKey : "";
|
|
96
|
+
return { result, apiKey };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function shellSingleQuote(value) {
|
|
100
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function writeApiKeyToZshrc(apiKey) {
|
|
104
|
+
const zshrcPath = path.join(os.homedir(), ".zshrc");
|
|
105
|
+
const block = [
|
|
106
|
+
ZSHRC_START,
|
|
107
|
+
`export ${API_KEY_ENV}=${shellSingleQuote(apiKey)}`,
|
|
108
|
+
ZSHRC_END,
|
|
109
|
+
"",
|
|
110
|
+
].join("\n");
|
|
111
|
+
let existing = "";
|
|
112
|
+
try {
|
|
113
|
+
existing = fs.existsSync(zshrcPath) ? fs.readFileSync(zshrcPath, "utf8") : "";
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return { written: false, path: zshrcPath, error: e && e.message ? e.message : String(e) };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const pattern = new RegExp(`${escapeRegExp(ZSHRC_START)}[\\s\\S]*?${escapeRegExp(ZSHRC_END)}\\n?`, "m");
|
|
119
|
+
const next = pattern.test(existing)
|
|
120
|
+
? existing.replace(pattern, block)
|
|
121
|
+
: `${existing}${existing && !existing.endsWith("\n") ? "\n" : ""}${block}`;
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
fs.writeFileSync(zshrcPath, next, { encoding: "utf8", mode: 0o600 });
|
|
125
|
+
return { written: true, path: zshrcPath, error: null };
|
|
126
|
+
} catch (e) {
|
|
127
|
+
return { written: false, path: zshrcPath, error: e && e.message ? e.message : String(e) };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function escapeRegExp(value) {
|
|
132
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function main() {
|
|
136
|
+
const a = parseArgs(process.argv.slice(2));
|
|
137
|
+
const base = a.base || DEFAULT_BASE;
|
|
138
|
+
const cmd = a._[0];
|
|
139
|
+
|
|
140
|
+
if (cmd === "send") {
|
|
141
|
+
if (!a.phone) { console.error("缺少 --phone"); process.exit(2); }
|
|
142
|
+
const r = await post(base + "/sendMessage", { phone: a.phone, type: "register" });
|
|
143
|
+
console.log(JSON.stringify(r));
|
|
144
|
+
if (r.status) console.error("验证码已发送,请向用户索取收到的 6 位验证码后再执行 register。");
|
|
145
|
+
process.exit(r.status ? 0 : 1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (cmd === "register") {
|
|
149
|
+
if (!a.phone || !a.vcode) { console.error("缺少 --phone 或 --vcode"); process.exit(2); }
|
|
150
|
+
const payload = {
|
|
151
|
+
phone: a.phone,
|
|
152
|
+
vcode: a.vcode,
|
|
153
|
+
password: a.password && a.password !== true ? a.password : genPassword(),
|
|
154
|
+
type: a.type && a.type !== true ? a.type : DEFAULT_TYPE,
|
|
155
|
+
organ: a.organ && a.organ !== true ? a.organ : "个人",
|
|
156
|
+
name: a.name && a.name !== true ? a.name : "用户",
|
|
157
|
+
apiKeyName: a["apikey-name"] && a["apikey-name"] !== true ? a["apikey-name"] : "agent-key",
|
|
158
|
+
};
|
|
159
|
+
payload.channel = a.channel && a.channel !== true ? a.channel : DEFAULT_CHANNEL;
|
|
160
|
+
payload.source = a.source && a.source !== true ? a.source : DEFAULT_SOURCE;
|
|
161
|
+
const r = await post(base + "/register", payload);
|
|
162
|
+
const data = r.data || {};
|
|
163
|
+
const ok = Boolean(r.status) && Boolean(data.apiKey);
|
|
164
|
+
let apiKeyToSave = ok ? data.apiKey : "";
|
|
165
|
+
let newKeyCreated = false;
|
|
166
|
+
let newKeyError = null;
|
|
167
|
+
if (ok && a["new-key"]) {
|
|
168
|
+
const keyName = a["new-key-name"] && a["new-key-name"] !== true ? a["new-key-name"] : payload.apiKeyName;
|
|
169
|
+
const keyRemark = a["new-key-remark"] && a["new-key-remark"] !== true
|
|
170
|
+
? a["new-key-remark"]
|
|
171
|
+
: "由 SkillHub 深知公文写作按用户要求重新生成";
|
|
172
|
+
const { result, apiKey } = await createNewApiKey(
|
|
173
|
+
a["open-base"] && a["open-base"] !== true ? a["open-base"] : DEFAULT_OPEN_BASE,
|
|
174
|
+
data.apiKey,
|
|
175
|
+
keyName,
|
|
176
|
+
keyRemark,
|
|
177
|
+
);
|
|
178
|
+
if (apiKey) {
|
|
179
|
+
apiKeyToSave = apiKey;
|
|
180
|
+
newKeyCreated = true;
|
|
181
|
+
} else {
|
|
182
|
+
newKeyError = result.errmsg || result.msg || "新 API Key 创建失败";
|
|
183
|
+
apiKeyToSave = "";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const zshrcWrite = ok && apiKeyToSave && !newKeyError && !a["no-zshrc"]
|
|
187
|
+
? writeApiKeyToZshrc(apiKeyToSave)
|
|
188
|
+
: { written: false, path: path.join(os.homedir(), ".zshrc"), error: null };
|
|
189
|
+
console.log(JSON.stringify({
|
|
190
|
+
status: ok && Boolean(apiKeyToSave) && !newKeyError,
|
|
191
|
+
msg: r.msg,
|
|
192
|
+
url: data.url || null,
|
|
193
|
+
existed: Boolean(data.existed),
|
|
194
|
+
keyCreatedByRegister: Boolean(data.keyCreated),
|
|
195
|
+
newKeyRequested: Boolean(a["new-key"]),
|
|
196
|
+
newKeyCreated,
|
|
197
|
+
envName: API_KEY_ENV,
|
|
198
|
+
apiKey: apiKeyToSave,
|
|
199
|
+
apiKeyMasked: apiKeyToSave ? `${apiKeyToSave.slice(0, 7)}...${apiKeyToSave.slice(-4)}` : null,
|
|
200
|
+
envWriteRequired: false,
|
|
201
|
+
envWriteTarget: zshrcWrite.path,
|
|
202
|
+
envWriteSucceeded: Boolean(zshrcWrite.written),
|
|
203
|
+
envWriteError: zshrcWrite.error,
|
|
204
|
+
envWriteInstruction: zshrcWrite.written
|
|
205
|
+
? `已写入 ${zshrcWrite.path}。当前任务可继续使用返回的 apiKey;后续新对话如仍检测不到 ${API_KEY_ENV},请重启 WorkBuddy 后再试。`
|
|
206
|
+
: `未能写入 ${zshrcWrite.path},请由 Agent 或平台密钥配置将返回的 apiKey 写入环境变量 ${API_KEY_ENV}。`,
|
|
207
|
+
currentSessionInstruction: `当前任务继续执行初始化时,请用本次返回的 apiKey 临时注入环境变量 ${API_KEY_ENV},不得向用户展示完整 Key。`,
|
|
208
|
+
newKeyError,
|
|
209
|
+
fallbackRegisterUrl: FALLBACK_REGISTER_URL,
|
|
210
|
+
}));
|
|
211
|
+
process.exit(ok && Boolean(apiKeyToSave) && !newKeyError ? 0 : 1);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
console.error("用法: node register.mjs <send|register> ...");
|
|
215
|
+
process.exit(2);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
main();
|