dknowc-dsh 1.3.0 → 2.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.
Files changed (86) hide show
  1. package/README.md +20 -19
  2. package/package.json +4 -4
  3. package/skills/dknowc-official-doc-writer/README.md +18 -16
  4. package/skills/dknowc-official-doc-writer/SKILL.md +112 -123
  5. package/skills/dknowc-official-doc-writer/attribution.json +5 -0
  6. package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +5 -0
  7. package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +18 -8
  8. package/skills/dknowc-official-doc-writer/reference/output_guide.md +2 -2
  9. package/skills/dknowc-official-doc-writer/reference/research_notes.md +34 -0
  10. package/skills/dknowc-official-doc-writer/reference/review_checklist.md +2 -9
  11. package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +922 -270
  12. package/skills/dknowc-official-doc-writer/reference/search_guide.md +123 -28
  13. package/skills/dknowc-official-doc-writer/reference/search_intro.md +6 -6
  14. package/skills/dknowc-official-doc-writer/reference/search_policy.md +88 -53
  15. package/skills/dknowc-official-doc-writer/reference/task_router.md +6 -6
  16. package/skills/dknowc-official-doc-writer/scripts/adapt_mcp_result.py +52 -2
  17. package/skills/dknowc-official-doc-writer/scripts/api_key.py +41 -14
  18. package/skills/dknowc-official-doc-writer/scripts/attribution.py +60 -0
  19. package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +288 -0
  20. package/skills/dknowc-official-doc-writer/scripts/check_materials.py +265 -0
  21. package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +235 -0
  22. package/skills/dknowc-official-doc-writer/scripts/deep_query.py +333 -0
  23. package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +22 -5
  24. package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +245 -0
  25. package/skills/dknowc-official-doc-writer/scripts/format_document.py +106 -18
  26. package/skills/dknowc-official-doc-writer/scripts/initialize.py +15 -17
  27. package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +272 -0
  28. package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +257 -143
  29. package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +72 -8
  30. package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +14 -4
  31. package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +6 -1
  32. package/skills/dknowc-official-doc-writer/scripts/register.mjs +120 -48
  33. package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +1514 -660
  34. package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +151 -6
  35. package/skills/dknowc-official-doc-writer/scripts/template_generator.py +13 -0
  36. package/skills/dknowc-ppt-assistant/README.md +14 -10
  37. package/skills/dknowc-ppt-assistant/SKILL.md +33 -15
  38. package/skills/dknowc-ppt-assistant/attribution.json +5 -0
  39. package/skills/dknowc-ppt-assistant/references/material_usage.md +9 -5
  40. package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +14 -2
  41. package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +1343 -292
  42. package/skills/dknowc-ppt-assistant/references/search_intro.md +1 -1
  43. package/skills/dknowc-ppt-assistant/scripts/api_key.py +41 -14
  44. package/skills/dknowc-ppt-assistant/scripts/attribution.py +60 -0
  45. package/skills/dknowc-ppt-assistant/scripts/initialize.py +9 -17
  46. package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +188 -0
  47. package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +135 -6
  48. package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1539 -714
  49. package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +33 -3
  50. package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +17 -19
  51. package/skills/dknowc-trusted-search/README.md +27 -22
  52. package/skills/dknowc-trusted-search/SKILL.md +213 -140
  53. package/skills/dknowc-trusted-search/attribution.json +5 -0
  54. package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +17 -7
  55. package/skills/dknowc-trusted-search/reference/sample_trace_report.html +720 -253
  56. package/skills/dknowc-trusted-search/scripts/api_key.py +41 -14
  57. package/skills/dknowc-trusted-search/scripts/attribution.py +61 -0
  58. package/skills/dknowc-trusted-search/scripts/chart_embed.py +350 -0
  59. package/skills/dknowc-trusted-search/scripts/deep_query.py +26 -5
  60. package/skills/dknowc-trusted-search/scripts/initialize.py +20 -29
  61. package/skills/dknowc-trusted-search/scripts/mcp_convert.py +189 -0
  62. package/skills/dknowc-trusted-search/scripts/merge_search_results.py +272 -0
  63. package/skills/dknowc-trusted-search/scripts/register_key.mjs +149 -43
  64. package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1860 -751
  65. package/skills/dknowc-trusted-search/scripts/trusted_search.py +34 -31
  66. package/src/index.js +3 -8
  67. package/skills/dknowc-official-doc-writer/scripts/check_release.py +0 -93
  68. package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +0 -279
  69. package/skills/dknowc-ppt-assistant/scripts/check_release.py +0 -106
  70. package/skills/dknowc-trusted-consulting/README.md +0 -63
  71. package/skills/dknowc-trusted-consulting/SKILL.md +0 -236
  72. package/skills/dknowc-trusted-consulting/reference/consult_intro.md +0 -47
  73. package/skills/dknowc-trusted-consulting/reference/onboarding_scripts.md +0 -132
  74. package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +0 -31
  75. package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +0 -502
  76. package/skills/dknowc-trusted-consulting/scripts/adapt_mcp_result.py +0 -283
  77. package/skills/dknowc-trusted-consulting/scripts/api_key.py +0 -41
  78. package/skills/dknowc-trusted-consulting/scripts/check_release.py +0 -66
  79. package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +0 -508
  80. package/skills/dknowc-trusted-consulting/scripts/initialize.py +0 -133
  81. package/skills/dknowc-trusted-consulting/scripts/mcp_direct.py +0 -166
  82. package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +0 -279
  83. package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +0 -1616
  84. package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +0 -261
  85. package/skills/dknowc-trusted-search/scripts/check_release.py +0 -79
  86. package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +0 -894
@@ -2,27 +2,63 @@
2
2
  // 国内 MaaS headless 注册助手(供 skillhub skill 调用;纯 node,内置 fetch,无三方依赖)。
3
3
  // node register.mjs [--base URL] send --phone <p>
4
4
  // node register.mjs [--base URL] register --phone <p> --vcode <c> [--type 6] [--organ ..] [--name ..] [--channel ..] [--source ..] [--password ..] [--new-key]
5
+ // node register.mjs save-key # 3.7.7:把 MCP create_api_key 拿到的密钥落盘(stdin 优先,或 --api-key)
5
6
  // 无需 cookie / 加密 / 登录态。默认打生产,--base 可切测试环境。
6
7
 
7
8
  import fs from "fs";
8
9
  import os from "os";
9
10
  import path from "path";
11
+ import { fileURLToPath } from "url";
12
+
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = path.dirname(__filename);
10
15
 
11
16
  const DEFAULT_BASE = "https://platform.dknowc.cn/auth/home/userAuto";
12
17
  const DEFAULT_OPEN_BASE = "https://open.dknowc.cn";
13
18
  const DEFAULT_CHANNEL = "46A3BA1D-3E1A-4E8C-BD50-A6DCBEE1DB05";
14
19
  const DEFAULT_TYPE = "6";
15
- const DEFAULT_SOURCE = "agent";
20
+ // 2026-09-29 调整:与统一来源声明(X-Dknowc-Attribution)的 source 对齐,
21
+ // 不再用旧值 "agent"(与"来源统计最终方案 V1.0"的字段语义冲突)。
22
+ const DEFAULT_SOURCE = "dknowc-official-doc-writer";
16
23
  const API_KEY_ENV = "DKNOWC_API_KEY";
17
24
  const MAAS_PLATFORM_URL = "https://platform.dknowc.cn/auth/#/login";
18
25
  const FALLBACK_REGISTER_URL = MAAS_PLATFORM_URL;
26
+ // Key 持久化目标:本机专用配置文件(XDG 规范路径),不再写 ~/.zshrc。
27
+ // 3.7.5 迁移:写入新文件成功后,清理 ~/.zshrc 中的历史 Key 块。
28
+ const KEY_FILE_NAME = "api_key";
19
29
  const ZSHRC_START = "# >>> dknowc official doc writer api key >>>";
20
30
  const ZSHRC_END = "# <<< dknowc official doc writer api key <<<";
21
- // 早期版本遗留的标记块名(无 export 也一并清理,避免 ~/.zshrc 残留)
31
+ // 历史 ~/.zshrc 标记块(含旧名),迁移期统一清理
22
32
  const LEGACY_BLOCKS = [
33
+ [ZSHRC_START, ZSHRC_END],
23
34
  ["# >>> dknowc api key >>>", "# <<< dknowc api key <<<"],
24
35
  ];
25
36
 
37
+ function apiKeyFilePath() {
38
+ const home = os.homedir();
39
+ if (process.platform === "win32") {
40
+ const appdata = process.env.APPDATA || home;
41
+ return path.join(appdata, "dknowc", KEY_FILE_NAME);
42
+ }
43
+ const xdg = process.env.XDG_CONFIG_HOME || path.join(home, ".config");
44
+ return path.join(xdg, "dknowc", KEY_FILE_NAME);
45
+ }
46
+
47
+ function removeLegacyZshrcBlocks() {
48
+ // 迁移:从 ~/.zshrc 移除历史 Key 标记块(避免污染 shell 配置)
49
+ const zshrcPath = path.join(os.homedir(), ".zshrc");
50
+ try {
51
+ let existing = fs.existsSync(zshrcPath) ? fs.readFileSync(zshrcPath, "utf8") : "";
52
+ if (!existing) return;
53
+ let changed = false;
54
+ for (const [start, end] of LEGACY_BLOCKS) {
55
+ const re = new RegExp(`${escapeRegExp(start)}[\\s\\S]*?${escapeRegExp(end)}\\n?`, "m");
56
+ if (re.test(existing)) { existing = existing.replace(re, ""); changed = true; }
57
+ }
58
+ if (changed) fs.writeFileSync(zshrcPath, existing, { encoding: "utf8", mode: 0o600 });
59
+ } catch (e) { /* 清理失败不阻断写入流程 */ }
60
+ }
61
+
26
62
  function maskPhone(phone) {
27
63
  const p = String(phone || "");
28
64
  return p.length >= 7 ? `${p.slice(0, 3)}****${p.slice(-4)}` : p;
@@ -42,13 +78,35 @@ function parseArgs(argv) {
42
78
  return out;
43
79
  }
44
80
 
81
+ // —— 统一来源声明(X-Dknowc-Attribution,2026-09-29 与开发定稿《来源统计最终方案 V1.0》)——
82
+ // 读包根 attribution.json(kind/source/channel)+ SKILL.md 的 version;仅统计用、
83
+ // 不参与鉴权;读取失败返回 null(不加头、不阻断请求)。
84
+ function buildAttributionHeader() {
85
+ try {
86
+ const root = path.resolve(__dirname, "..");
87
+ const meta = JSON.parse(fs.readFileSync(path.join(root, "attribution.json"), "utf-8"));
88
+ if (!meta.source) return null;
89
+ const parts = [`kind=${meta.kind || "skill"}`, `source=${meta.source}`];
90
+ try {
91
+ const m = fs.readFileSync(path.join(root, "SKILL.md"), "utf-8").match(/^version:\s*"?([^"\n]+)"?/m);
92
+ if (m) parts.push(`version=${m[1].trim()}`);
93
+ } catch {}
94
+ if (meta.channel) parts.push(`channel=${meta.channel}`);
95
+ return parts.join(";");
96
+ } catch { return null; }
97
+ }
98
+ function withAttribution(headers) {
99
+ const attr = buildAttributionHeader();
100
+ return attr ? { ...headers, "X-Dknowc-Attribution": attr } : headers;
101
+ }
102
+
45
103
  async function post(url, payload) {
46
104
  const ctl = new AbortController();
47
105
  const timer = setTimeout(() => ctl.abort(), 30000);
48
106
  try {
49
107
  const r = await fetch(url, {
50
108
  method: "POST",
51
- headers: { "Content-Type": "application/json" },
109
+ headers: withAttribution({ "Content-Type": "application/json" }),
52
110
  body: JSON.stringify(payload),
53
111
  signal: ctl.signal,
54
112
  });
@@ -66,10 +124,10 @@ async function postWithBearer(url, apiKey, payload) {
66
124
  try {
67
125
  const r = await fetch(url, {
68
126
  method: "POST",
69
- headers: {
127
+ headers: withAttribution({
70
128
  "Authorization": `Bearer ${apiKey}`,
71
129
  "Content-Type": "application/json",
72
- },
130
+ }),
73
131
  body: JSON.stringify(payload),
74
132
  signal: ctl.signal,
75
133
  });
@@ -105,41 +163,16 @@ async function createNewApiKey(openBase, existingApiKey, name, remark) {
105
163
  return { result, apiKey };
106
164
  }
107
165
 
108
- function shellSingleQuote(value) {
109
- return `'${String(value).replace(/'/g, `'\\''`)}'`;
110
- }
111
-
112
- function writeApiKeyToZshrc(apiKey) {
113
- const zshrcPath = path.join(os.homedir(), ".zshrc");
114
- const block = [
115
- ZSHRC_START,
116
- `export ${API_KEY_ENV}=${shellSingleQuote(apiKey)}`,
117
- ZSHRC_END,
118
- "",
119
- ].join("\n");
120
- let existing = "";
121
- try {
122
- existing = fs.existsSync(zshrcPath) ? fs.readFileSync(zshrcPath, "utf8") : "";
123
- } catch (e) {
124
- return { written: false, path: zshrcPath, error: e && e.message ? e.message : String(e) };
125
- }
126
-
127
- // 清理早期版本遗留的标记块(含空块),再写入当前标准块
128
- for (const [start, end] of LEGACY_BLOCKS) {
129
- const legacy = new RegExp(`${escapeRegExp(start)}[\\s\\S]*?${escapeRegExp(end)}\\n?`, "m");
130
- existing = existing.replace(legacy, "");
131
- }
132
-
133
- const pattern = new RegExp(`${escapeRegExp(ZSHRC_START)}[\\s\\S]*?${escapeRegExp(ZSHRC_END)}\\n?`, "m");
134
- const next = pattern.test(existing)
135
- ? existing.replace(pattern, block)
136
- : `${existing}${existing && !existing.endsWith("\n") ? "\n" : ""}${block}`;
137
-
166
+ function writeApiKeyToConfigFile(apiKey) {
167
+ // 写本机专用配置文件(纯文本一行 Key,600 权限);成功后清理历史 ~/.zshrc 块
168
+ const filePath = apiKeyFilePath();
138
169
  try {
139
- fs.writeFileSync(zshrcPath, next, { encoding: "utf8", mode: 0o600 });
140
- return { written: true, path: zshrcPath, error: null };
170
+ fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
171
+ fs.writeFileSync(filePath, `${String(apiKey).trim()}\n`, { encoding: "utf8", mode: 0o600 });
172
+ removeLegacyZshrcBlocks();
173
+ return { written: true, path: filePath, error: null };
141
174
  } catch (e) {
142
- return { written: false, path: zshrcPath, error: e && e.message ? e.message : String(e) };
175
+ return { written: false, path: filePath, error: e && e.message ? e.message : String(e) };
143
176
  }
144
177
  }
145
178
 
@@ -152,6 +185,43 @@ async function main() {
152
185
  const base = a.base || DEFAULT_BASE;
153
186
  const cmd = a._[0];
154
187
 
188
+ if (cmd === "save-key") {
189
+ // 3.7.7:MCP 取 Key 路径的落盘子命令。宿主提供 dknowc-mcp 的 create_api_key 且调用
190
+ // 成功(返回顶层 JSON {"apiKey": "..."})后,用本命令落盘,用户无需手机号验证码。
191
+ // 密钥来源优先 stdin(printf '%s' "<密钥>" | node register.mjs save-key,避免出现在
192
+ // 命令行参数里),其次 --api-key;仅接受 sk- 开头。落盘复用 writeApiKeyToConfigFile
193
+ // (600 权限 + 清理历史 ~/.zshrc 块),与手机号注册路径同一份持久化逻辑。
194
+ let apiKey = "";
195
+ try {
196
+ if (!process.stdin.isTTY) {
197
+ const chunks = [];
198
+ for await (const c of process.stdin) chunks.push(c);
199
+ apiKey = Buffer.concat(chunks).toString("utf-8");
200
+ }
201
+ } catch { /* stdin 读取失败时回退 --api-key */ }
202
+ if (!apiKey.trim() && a["api-key"] && a["api-key"] !== true) apiKey = String(a["api-key"]);
203
+ apiKey = apiKey.trim();
204
+ if (!apiKey.startsWith("sk-") || apiKey.length < 20) {
205
+ console.log(JSON.stringify({
206
+ status: false,
207
+ msg: "密钥格式不符(应为 sk- 开头的 MaaS API Key),请确认调用的是 create_api_key 的返回值",
208
+ }));
209
+ process.exit(1);
210
+ }
211
+ const w = writeApiKeyToConfigFile(apiKey);
212
+ console.log(JSON.stringify({
213
+ status: w.written,
214
+ envWriteSucceeded: w.written,
215
+ envWriteTarget: w.path,
216
+ error: w.error || null,
217
+ // user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥
218
+ user_message: w.written
219
+ ? "已通过你的深知可信工作台授权直接开通搜索功能,无需手机号验证,马上开始检索。"
220
+ : "密钥保存到本机时出现问题,需要改用手机号验证码方式开通。",
221
+ }));
222
+ process.exit(w.written ? 0 : 1);
223
+ }
224
+
155
225
  if (cmd === "send") {
156
226
  if (!a.phone) { console.error("缺少 --phone"); process.exit(2); }
157
227
  // 渠道细分:sendMessage 与 register 请求体统一携带 SkillHub 渠道码。
@@ -210,16 +280,16 @@ async function main() {
210
280
  }
211
281
  }
212
282
  const zshrcWrite = ok && apiKeyToSave && !a["no-zshrc"]
213
- ? writeApiKeyToZshrc(apiKeyToSave)
214
- : { written: false, path: path.join(os.homedir(), ".zshrc"), error: null };
283
+ ? writeApiKeyToConfigFile(apiKeyToSave)
284
+ : { written: false, path: apiKeyFilePath(), error: null };
215
285
  // user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥。
216
- // 权益告知(300 次额度 + 实名认证赠金)已前移到开通引导(initialize.guide_message / onboarding_scripts S1),
217
- // 此处只做轻确认,避免成功节点信息过重导致转述截断。
286
+ // 权益告知(注册赠送 10 万积分 + 实名认证再送 10 万积分)已前移到开通引导
287
+ // (initialize.guide_message / onboarding_scripts S1),此处只做轻确认,避免成功节点信息过重导致转述截断。
218
288
  let userMessage;
219
289
  if (ok && apiKeyToSave) {
220
290
  userMessage = Boolean(data.existed)
221
- ? `这个手机号之前开通过,已直接找回原来的密钥和额度,不用重新注册。我马上开始检索。`
222
- : `开通成功,访问密钥已写入本机,300 次免费检索额度已生效。我马上开始检索。`;
291
+ ? `这个手机号之前开通过,已直接找回原来的密钥和积分,不用重新注册。我马上开始检索。`
292
+ : `开通成功,访问密钥已写入本机,注册赠送的 10 万积分已到账。我马上开始检索。`;
223
293
  if (newKeyError) {
224
294
  userMessage += ` 另外你要求的新密钥生成失败(${newKeyError}),已先沿用现有密钥继续,不影响使用;需要的话稍后再重新生成。`;
225
295
  }
@@ -238,15 +308,17 @@ async function main() {
238
308
  newKeyCreated,
239
309
  user_message: userMessage,
240
310
  envName: API_KEY_ENV,
241
- apiKey: apiKeyToSave,
311
+ // 明文 Key 只在"未写入本机配置文件、必须靠它临时注入环境变量"时才输出,其余情况
312
+ // 只给掩码——脚本输出可能被宿主 UI 回显或模型贴进对话(2026-09-21 修复)
313
+ apiKey: (apiKeyToSave && !zshrcWrite.written && !a["no-zshrc"]) ? apiKeyToSave : null,
242
314
  apiKeyMasked: apiKeyToSave ? `${apiKeyToSave.slice(0, 7)}...${apiKeyToSave.slice(-4)}` : null,
243
- envWriteRequired: false,
315
+ envWriteRequired: Boolean(apiKeyToSave) && !zshrcWrite.written,
244
316
  envWriteTarget: zshrcWrite.path,
245
317
  envWriteSucceeded: Boolean(zshrcWrite.written),
246
318
  envWriteError: zshrcWrite.error,
247
319
  envWriteInstruction: zshrcWrite.written
248
- ? `已写入 ${zshrcWrite.path};脚本直读该文件,无需重启宿主。当前任务可继续使用返回的 apiKey。`
249
- : `未能写入 ${zshrcWrite.path},请由 Agent 或平台密钥配置将返回的 apiKey 写入环境变量 ${API_KEY_ENV}。`,
320
+ ? `已写入 ${zshrcWrite.path};脚本直读该文件,无需重启宿主,本次不再返回明文密钥。`
321
+ : `未能写入 ${zshrcWrite.path},本次已在 apiKey 字段返回明文,请由 Agent 临时注入环境变量 ${API_KEY_ENV}(不得展示给用户、不得写入公开文件)。`,
250
322
  currentSessionInstruction: `当前任务继续执行初始化时,请用本次返回的 apiKey 临时注入环境变量 ${API_KEY_ENV},不得向用户展示完整 Key。`,
251
323
  newKeyError,
252
324
  fallbackRegisterUrl: FALLBACK_REGISTER_URL,