dknowc-dsh 2.3.1 → 2.4.1
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 +11 -3
- package/cordis.patch.yml +1 -1
- package/package.json +7 -4
- package/skills/dk-trace-report/SKILL.md +288 -0
- package/skills/dk-trace-report/config/examples/doc.json +56 -0
- package/skills/dk-trace-report/config/examples/legal.json +51 -0
- package/skills/dk-trace-report/config/examples/ppt.json +47 -0
- package/skills/dk-trace-report/config/examples/tax.json +46 -0
- package/skills/dk-trace-report/config/examples/trusted.json +122 -0
- package/skills/dk-trace-report/reference/sample_input.json +60 -0
- package/skills/dk-trace-report/resources/ECHARTS-NOTICE.txt +10 -0
- package/skills/dk-trace-report/resources/echarts.custom.min.js +48 -0
- package/skills/dk-trace-report/scripts/build_report_input.py +333 -0
- package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/chart_embed.py +4 -1
- package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/render_trace_html.py +1071 -536
- package/skills/dk-trace-report/scripts/run_paths.py +95 -0
- package/skills/dk-trace-report/scripts/trust_digest.py +77 -0
- package/skills/dknowc-legal-assistant/README.md +95 -0
- package/skills/dknowc-legal-assistant/SKILL.md +122 -0
- package/skills/dknowc-legal-assistant/attribution.json +5 -0
- package/skills/dknowc-legal-assistant/reference/answer-and-report.md +221 -0
- package/skills/dknowc-legal-assistant/reference/capability-layer.md +143 -0
- package/skills/dknowc-legal-assistant/reference/legal_claims.example.json +96 -0
- package/skills/dknowc-legal-assistant/reference/onboarding_scripts.md +198 -0
- package/skills/dknowc-legal-assistant/reference/policy_tags.json +2002 -0
- package/skills/dknowc-legal-assistant/reference/retrieval-statute.md +81 -0
- package/skills/dknowc-legal-assistant/reference/retrieval-v2.md +133 -0
- package/skills/dknowc-legal-assistant/reference/sample_search_result.md +33 -0
- package/skills/dknowc-legal-assistant/reference/sample_trace_report.html +940 -0
- package/skills/dknowc-legal-assistant/reference/tags.md +53 -0
- package/skills/dknowc-legal-assistant/reference/troubleshooting.md +50 -0
- package/skills/dknowc-legal-assistant/reference/verification-pass.md +59 -0
- package/skills/dknowc-legal-assistant/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-legal-assistant/scripts/api_key.py +68 -0
- package/skills/dknowc-legal-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-legal-assistant/scripts/calc_legal.py +375 -0
- package/skills/dknowc-legal-assistant/scripts/calc_period.py +155 -0
- package/skills/dknowc-legal-assistant/scripts/check_answer.py +664 -0
- package/skills/dknowc-legal-assistant/scripts/initialize.py +188 -0
- package/skills/dknowc-legal-assistant/scripts/legal_client.py +208 -0
- package/skills/dknowc-legal-assistant/scripts/legal_search.py +1059 -0
- package/skills/dknowc-legal-assistant/scripts/merge_search_results.py +630 -0
- package/skills/dknowc-legal-assistant/scripts/path_guard.py +92 -0
- package/skills/dknowc-legal-assistant/scripts/question_profile.py +215 -0
- package/skills/dknowc-legal-assistant/scripts/register_key.mjs +1152 -0
- package/skills/dknowc-legal-assistant/scripts/run_eval.py +109 -0
- package/skills/dknowc-legal-assistant/scripts/source_cards.py +321 -0
- package/skills/dknowc-legal-assistant/scripts/tag_catalog.py +162 -0
- package/skills/dknowc-legal-assistant/scripts/trace_report.config.json +66 -0
- package/skills/dknowc-legal-assistant/scripts/verify_claims.py +448 -0
- package/skills/dknowc-legal-assistant/scripts/websearch_convert.py +396 -0
- package/skills/dknowc-official-doc-writer/README.md +32 -21
- package/skills/dknowc-official-doc-writer/SKILL.md +28 -15
- package/skills/dknowc-official-doc-writer/config/trace_report.config.json +56 -0
- package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +14 -2
- package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +4 -0
- package/skills/dknowc-official-doc-writer/reference/genre_writing_notes.md +4 -0
- package/skills/dknowc-official-doc-writer/reference/initialization.md +13 -8
- package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +21 -0
- package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +64 -7
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/outline_rules.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +13 -13
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +5 -3
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +6 -2
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +44 -32
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +63 -36
- package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +6 -3
- package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +12 -3
- package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +8 -2
- package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/25_plan.md +2 -1
- package/skills/dknowc-official-doc-writer/reference/standards/26_summary.md +7 -1
- package/skills/dknowc-official-doc-writer/reference/standards/27_speech.md +4 -1
- package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/working_principles.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/writing_method.md +166 -0
- package/skills/dknowc-official-doc-writer/reference/writing_rules.md +10 -4
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +24 -25
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +205 -13
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +367 -22
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +5 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +2 -1
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +20 -7
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +88 -30
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +232 -6
- package/skills/dknowc-official-doc-writer/scripts/local_memory.py +2 -6
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +100 -7
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +2 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +265 -32
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +117 -10
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/update_skill.py +339 -0
- package/skills/dknowc-official-doc-writer/scripts/websearch_convert.py +326 -0
- package/skills/dknowc-ppt-assistant/README.md +7 -9
- package/skills/dknowc-ppt-assistant/SKILL.md +28 -19
- package/skills/dknowc-ppt-assistant/config/trace_report.config.json +65 -0
- package/skills/dknowc-ppt-assistant/references/initialization.md +20 -8
- package/skills/dknowc-ppt-assistant/references/material_usage.md +46 -9
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +7 -5
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +372 -920
- package/skills/dknowc-ppt-assistant/references/search_intro.md +2 -2
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +2 -2
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +5 -28
- package/skills/dknowc-ppt-assistant/scripts/build_trace_input.py +188 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +238 -3
- package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +1 -10
- package/skills/dknowc-ppt-assistant/scripts/merge_search_results.py +604 -0
- package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +4 -11
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +224 -63
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +29 -12
- package/skills/dknowc-ppt-assistant/scripts/update_skill.py +314 -0
- package/skills/dknowc-ppt-assistant/scripts/websearch_convert.py +326 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +92 -29
- package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
- package/skills/dknowc-tax-assistant/README.md +54 -0
- package/skills/dknowc-tax-assistant/SKILL.md +99 -0
- package/skills/dknowc-tax-assistant/attribution.json +5 -0
- package/skills/dknowc-tax-assistant/reference/answer-and-report.md +100 -0
- package/skills/dknowc-tax-assistant/reference/capability-layer.md +205 -0
- package/skills/dknowc-tax-assistant/reference/onboarding_scripts.md +68 -0
- package/skills/dknowc-tax-assistant/reference/policy_tags.json +2002 -0
- package/skills/dknowc-tax-assistant/reference/retrieval-policy.md +43 -0
- package/skills/dknowc-tax-assistant/reference/retrieval-v2.md +58 -0
- package/skills/dknowc-tax-assistant/reference/tags.md +53 -0
- package/skills/dknowc-tax-assistant/reference/tax_claims.example.json +76 -0
- package/skills/dknowc-tax-assistant/reference/trace_report.config.json +46 -0
- package/skills/dknowc-tax-assistant/reference/troubleshooting.md +70 -0
- package/skills/dknowc-tax-assistant/reference/websearch-fallback.md +59 -0
- package/skills/dknowc-tax-assistant/resources/THIRD_PARTY_NOTICES.md +9 -0
- package/skills/dknowc-tax-assistant/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-tax-assistant/scripts/api_key.py +60 -0
- package/skills/dknowc-tax-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-tax-assistant/scripts/calc_period.py +156 -0
- package/skills/dknowc-tax-assistant/scripts/calc_tax.py +179 -0
- package/skills/dknowc-tax-assistant/scripts/check_answer.py +210 -0
- package/skills/dknowc-tax-assistant/scripts/initialize.py +208 -0
- package/skills/dknowc-tax-assistant/scripts/merge_search_results.py +631 -0
- package/skills/dknowc-tax-assistant/scripts/path_guard.py +23 -0
- package/skills/dknowc-tax-assistant/scripts/question_profile.py +444 -0
- package/skills/dknowc-tax-assistant/scripts/register_key.mjs +1173 -0
- package/skills/dknowc-tax-assistant/scripts/run_dir.py +149 -0
- package/skills/dknowc-tax-assistant/scripts/source_cards.py +372 -0
- package/skills/dknowc-tax-assistant/scripts/tag_catalog.py +164 -0
- package/skills/dknowc-tax-assistant/scripts/tax_client.py +218 -0
- package/skills/dknowc-tax-assistant/scripts/tax_search.py +403 -0
- package/skills/dknowc-tax-assistant/scripts/verify_claims.py +587 -0
- package/skills/dknowc-tax-assistant/scripts/websearch_convert.py +352 -0
- package/skills/dknowc-trusted-search/README.md +25 -19
- package/skills/dknowc-trusted-search/SKILL.md +205 -73
- package/skills/dknowc-trusted-search/config/trace_report.config.json +119 -0
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +3 -3
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +286 -191
- package/skills/dknowc-trusted-search/resources/ECHARTS-NOTICE.txt +10 -0
- package/skills/dknowc-trusted-search/scripts/api_key.py +0 -1
- package/skills/dknowc-trusted-search/scripts/attribution.py +1 -1
- package/skills/dknowc-trusted-search/scripts/build_trace_input.py +173 -0
- package/skills/dknowc-trusted-search/scripts/deep_convert.py +79 -30
- package/skills/dknowc-trusted-search/scripts/deep_query.py +22 -33
- package/skills/dknowc-trusted-search/scripts/initialize.py +343 -2
- package/skills/dknowc-trusted-search/scripts/merge_search_results.py +222 -35
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +241 -29
- package/skills/dknowc-trusted-search/scripts/source_display.py +59 -0
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +67 -34
- package/skills/dknowc-trusted-search/scripts/update_skill.py +300 -0
- package/skills/dknowc-trusted-search/scripts/websearch_convert.py +328 -0
- package/src/index.js +18 -2
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +0 -2574
- package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +0 -2642
- package/skills/dknowc-trusted-search/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-trusted-search/official-docs/search-results/.gitkeep +0 -0
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// 国内 MaaS 注册助手(供 skill 调用;纯 node,内置 fetch,无三方依赖)。
|
|
3
|
-
// node register_key.mjs [--guide URL] challenge --phone <p> [--channel <c>]
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// node register_key.mjs [--guide URL] challenge --phone <p> [--channel <c>] [--legacy]
|
|
4
|
+
// 默认走固定注册通行码通道:一次请求即发码,无需领题作答(退出 0=已发码、
|
|
5
|
+
// 1=停点,输出 flow="key")。通行码失效/停用或无法识别业务码时自动回落原领题流程;
|
|
6
|
+
// --legacy 显式跳过通行码通道。回落领题时:退出 0 返回题目,
|
|
6
7
|
// 退出 2 表示平台要求人工图片验证(返回 verificationUrl),退出 1 为失败。
|
|
8
|
+
// 本脚本不读取、不写入、不改写任何 shell 配置文件(~/.zshrc 等)。
|
|
7
9
|
// node register_key.mjs answer --phone <p> --answer <非负整数>
|
|
8
10
|
// 提交答案;答对即申请发码。退出 0=已发短信;3=答错换题(JSON 带新 question,需再答);
|
|
9
11
|
// 2=转人工接手;4=发送结果未确认(不重发);1=失败。
|
|
10
|
-
// node register_key.mjs register --phone <p> --vcode <c> [--
|
|
12
|
+
// node register_key.mjs register --phone <p> --vcode <c> [--organ ..] [--name ..] [--channel ..] [--source ..] [--password ..] [--new-key]
|
|
11
13
|
// 可能返回 pending:true(账号已创建、密钥资源准备中)——非错误,稍后同参数重试一次。
|
|
12
14
|
// node register_key.mjs save-key # 把 MCP create_api_key 拿到的密钥落盘(stdin 优先,或 --api-key)
|
|
13
15
|
// 说明:文字题由调用方(Agent)直接计算,本脚本只负责会话、题目状态与提交,不求解。
|
|
16
|
+
// 2026-11-25:对齐深知公文写作 3.9.9 / 深知可信搜索 1.8.2,注册发码默认走固定注册通行码通道
|
|
17
|
+
// (请求头 X-MaaS-Registration-Key,一次请求即发码);原领题(agent-text)与旧短信直发(legacy)
|
|
18
|
+
// 两条路径完整保留,通行码失效/停用才回落,限频/号码被拒/供应商失败/结果未确认一律停点不回落。
|
|
14
19
|
// 2026-10-29 注册链路改造:平台新增 Agent 注册文字题(先解题再发码,图片验证只作为人工兜底)。
|
|
15
20
|
// 旧 /sendMessage 发码入口对 Agent 一律要求图片验证,已由 challenge + answer 取代。
|
|
16
21
|
// 2026-10-09 改造仍保留于 register 一步:X-MaaS 客户端观测请求头、错误码族映射、验证链接安全校验。
|
|
@@ -18,6 +23,7 @@
|
|
|
18
23
|
import fs from "fs";
|
|
19
24
|
import os from "os";
|
|
20
25
|
import path from "path";
|
|
26
|
+
import { randomInt } from "node:crypto";
|
|
21
27
|
import { fileURLToPath } from "url";
|
|
22
28
|
|
|
23
29
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -26,7 +32,6 @@ const __dirname = path.dirname(__filename);
|
|
|
26
32
|
const DEFAULT_BASE = "https://platform.dknowc.cn/auth/home/userAuto";
|
|
27
33
|
const DEFAULT_OPEN_BASE = "https://open.dknowc.cn";
|
|
28
34
|
const DEFAULT_CHANNEL = "46A3BA1D-3E1A-4E8C-BD50-A6DCBEE1DB05";
|
|
29
|
-
const DEFAULT_TYPE = "11";
|
|
30
35
|
// body 的 source 是注册 API 的合同标记:服务端按 source="agent" 放行"老用户直接返 Key"
|
|
31
36
|
// 路径(生产环境可能出现:source=dknowc-ppt-assistant 时返回"用户已存在!"错误,
|
|
32
37
|
// source=agent 时正常返回 Key)。它与 X-Dknowc-Attribution 统计声明里的 skill 标识是两个
|
|
@@ -69,18 +74,19 @@ function assertEndpointAllowed(rawUrl, flagName) {
|
|
|
69
74
|
// 挑战状态(Cookie / token / attempt / 题目)落盘,供 challenge 与 answer 两次调用之间传递。
|
|
70
75
|
// attempt 必须始终使用服务端返回值,刷新题目不增加机会,故本机只做保存、不改写。
|
|
71
76
|
const CHALLENGE_STATE_FILE = "maas_agent_challenge.json";
|
|
72
|
-
//
|
|
73
|
-
//
|
|
77
|
+
// 2026-11-25 起(对齐深知公文写作 3.9.9 / 深知可信搜索 1.8.2):固定注册通行码发码通道。
|
|
78
|
+
// 平台按注册渠道分配一条固定通行值,一次请求即申请验证码,不再需要「先领题再作答」。
|
|
79
|
+
// 原领题路径整体保留,通行码失效/停用即自动回落;--legacy 可显式跳过本通道(平台旧路径回归用)。
|
|
80
|
+
// 注册通行码是发码通行值,不是用户检索凭证:只放请求头,不进对话/日志/工作区。
|
|
81
|
+
const REGISTRATION_PASSCODE_SEND_URL =
|
|
82
|
+
"https://platform.dknowc.cn/auth/open-api/maas/identity/v1/agent-registration-key-send";
|
|
83
|
+
const PASSCODE_HEADER_NAME = "X-MaaS-Registration-Key"; // 协议约定请求头(平台契约,名称不可改)
|
|
84
|
+
const REGISTRATION_PASSCODE = "So3EdPDJMf7z0MmH1zfvm6VDEQpR2EIRRsqqtnl866MrpVPl-Sj--g";
|
|
85
|
+
// 发码返回的会话(SESSION / sl-session)在发码与注册之间复用,按手机号落盘。
|
|
86
|
+
const REG_SESSION_STATE_FILE = "maas_registration_session.json";
|
|
87
|
+
// Key 持久化目标:本机专用配置文件(XDG 规范路径)。
|
|
88
|
+
// 2026-11-25 审核整改:本脚本**不读取、不写入、不改写任何 shell 配置文件**(~/.zshrc 等)。
|
|
74
89
|
const KEY_FILE_NAME = "api_key";
|
|
75
|
-
const ZSHRC_START = "# >>> dknowc ppt assistant api key >>>";
|
|
76
|
-
const ZSHRC_END = "# <<< dknowc ppt assistant api key <<<";
|
|
77
|
-
// 历史 ~/.zshrc 标记块(历史版本与历史产品名)。注意:脚本默认**不修改** ~/.zshrc;
|
|
78
|
-
// 仅当用户显式传 --clean-zshrc 时才清理这些块(历史块只作读取兜底,见 api_key.py)。
|
|
79
|
-
const LEGACY_BLOCKS = [
|
|
80
|
-
[ZSHRC_START, ZSHRC_END],
|
|
81
|
-
["# >>> dknowc official doc writer api key >>>", "# <<< dknowc official doc writer api key <<<"],
|
|
82
|
-
["# >>> dknowc api key >>>", "# <<< dknowc api key <<<"],
|
|
83
|
-
];
|
|
84
90
|
|
|
85
91
|
// 配置目录:默认 ~/.config/dknowc(Windows 为 %APPDATA%\dknowc),可用 DKNOWC_CONFIG_DIR 覆盖。
|
|
86
92
|
function configDir() {
|
|
@@ -98,21 +104,6 @@ function apiKeyFilePath() {
|
|
|
98
104
|
return path.join(configDir(), KEY_FILE_NAME);
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
function removeLegacyZshrcBlocks() {
|
|
102
|
-
// 迁移:从 ~/.zshrc 移除历史 Key 标记块(避免污染 shell 配置)
|
|
103
|
-
const zshrcPath = path.join(os.homedir(), ".zshrc");
|
|
104
|
-
try {
|
|
105
|
-
let existing = fs.existsSync(zshrcPath) ? fs.readFileSync(zshrcPath, "utf8") : "";
|
|
106
|
-
if (!existing) return;
|
|
107
|
-
let changed = false;
|
|
108
|
-
for (const [start, end] of LEGACY_BLOCKS) {
|
|
109
|
-
const re = new RegExp(`${escapeRegExp(start)}[\\s\\S]*?${escapeRegExp(end)}\\n?`, "m");
|
|
110
|
-
if (re.test(existing)) { existing = existing.replace(re, ""); changed = true; }
|
|
111
|
-
}
|
|
112
|
-
if (changed) fs.writeFileSync(zshrcPath, existing, { encoding: "utf8", mode: 0o600 });
|
|
113
|
-
} catch (e) { /* 清理失败不阻断写入流程 */ }
|
|
114
|
-
}
|
|
115
|
-
|
|
116
107
|
function maskPhone(phone) {
|
|
117
108
|
const p = String(phone || "");
|
|
118
109
|
return p.length >= 7 ? `${p.slice(0, 3)}****${p.slice(-4)}` : p;
|
|
@@ -164,7 +155,9 @@ function readChallengeState() {
|
|
|
164
155
|
try {
|
|
165
156
|
const raw = fs.readFileSync(stateFilePath(), "utf-8");
|
|
166
157
|
const st = JSON.parse(raw);
|
|
167
|
-
|
|
158
|
+
// 已清除的占位状态(见 clearChallengeState)等同"没有进行中的题目"
|
|
159
|
+
if (st && typeof st === "object" && !st.cleared) return st;
|
|
160
|
+
return null;
|
|
168
161
|
} catch { return null; }
|
|
169
162
|
}
|
|
170
163
|
function writeChallengeState(st) {
|
|
@@ -175,7 +168,53 @@ function writeChallengeState(st) {
|
|
|
175
168
|
} catch { return false; }
|
|
176
169
|
}
|
|
177
170
|
function clearChallengeState() {
|
|
178
|
-
|
|
171
|
+
// 2026-11-25 整改:不再删除状态文件(宿主把删除判成"删除文件"并逐次弹确认,
|
|
172
|
+
// 注册成功收尾时弹框会吓到用户)。改为写入"已清除且已过期"的空状态:
|
|
173
|
+
// 题目/答案/token 等敏感字段随覆盖消失;expiresAt 设为过去时间,读取端按"过期"处理,
|
|
174
|
+
// 不会误复用。
|
|
175
|
+
try {
|
|
176
|
+
fs.writeFileSync(stateFilePath(), '{"cleared": true, "expiresAt": 1}\n',
|
|
177
|
+
{ encoding: "utf-8", mode: 0o600 });
|
|
178
|
+
} catch { /* 写入失败不影响主流程:旧状态到期后自然失效 */ }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// —— 固定注册通行码发码通道的会话状态(对齐公文写作 3.9.9)——
|
|
182
|
+
// 只存 {phone, cookies, at};读取时校验手机号与 10 分钟时效,避免串号与陈旧会话。
|
|
183
|
+
// 清除时写入"已清除"占位而不是删文件(宿主会把删除判成"删除文件"并要求确认)。
|
|
184
|
+
function regSessionStatePath() {
|
|
185
|
+
return path.join(configDir(), REG_SESSION_STATE_FILE);
|
|
186
|
+
}
|
|
187
|
+
function readRegSessionState() {
|
|
188
|
+
try {
|
|
189
|
+
const st = JSON.parse(fs.readFileSync(regSessionStatePath(), "utf-8"));
|
|
190
|
+
if (st && typeof st === "object" && !st.cleared) return st;
|
|
191
|
+
return null;
|
|
192
|
+
} catch { return null; }
|
|
193
|
+
}
|
|
194
|
+
function writeRegSessionState(phone, cookies) {
|
|
195
|
+
try {
|
|
196
|
+
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
197
|
+
fs.writeFileSync(regSessionStatePath(),
|
|
198
|
+
JSON.stringify({ phone, cookies: cookies || {}, at: new Date().toISOString() }, null, 2) + "\n",
|
|
199
|
+
{ encoding: "utf-8", mode: 0o600 });
|
|
200
|
+
return true;
|
|
201
|
+
} catch { return false; }
|
|
202
|
+
}
|
|
203
|
+
function clearRegSessionState() {
|
|
204
|
+
try {
|
|
205
|
+
fs.writeFileSync(regSessionStatePath(), '{"cleared": true}\n', { encoding: "utf-8", mode: 0o600 });
|
|
206
|
+
} catch { /* 写入失败不影响主流程:旧会话 10 分钟后自然失效 */ }
|
|
207
|
+
}
|
|
208
|
+
const REG_KEY_STATE_TTL_MS = 10 * 60 * 1000;
|
|
209
|
+
function regSessionFor(phone) {
|
|
210
|
+
const st = readRegSessionState();
|
|
211
|
+
if (!st || st.phone !== phone) return null;
|
|
212
|
+
const at = Date.parse(String(st.at || ""));
|
|
213
|
+
if (!Number.isFinite(at) || Date.now() - at > REG_KEY_STATE_TTL_MS) {
|
|
214
|
+
clearRegSessionState();
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return st.cookies && Object.keys(st.cookies).length ? st.cookies : null;
|
|
179
218
|
}
|
|
180
219
|
function challengeExpired(st) {
|
|
181
220
|
const exp = Number(st && st.expiresAt);
|
|
@@ -309,9 +348,10 @@ async function httpJson(method, url, { body, cookies, headers, timeoutMs = 30000
|
|
|
309
348
|
// 首次不带(服务端响应头签发后落盘,后续请求回传,不自行生成);
|
|
310
349
|
// - 返回 { body, requestUnknown }:requestUnknown=true 表示超时/断网等"结果未确认"情形
|
|
311
350
|
// (发送结果未知时不得立即补发,由调用方按专用话术处理)。
|
|
312
|
-
async function post(url, payload) {
|
|
351
|
+
async function post(url, payload, { cookies } = {}) {
|
|
313
352
|
const { json, setCookies, requestUnknown } = await httpJson("POST", url, {
|
|
314
353
|
body: payload,
|
|
354
|
+
cookies,
|
|
315
355
|
headers: withAttribution({
|
|
316
356
|
"X-MaaS-Entry-Surface": "DIRECT_API",
|
|
317
357
|
"X-MaaS-Client-Name": MAAS_CLIENT_NAME,
|
|
@@ -334,15 +374,72 @@ async function postWithBearer(url, apiKey, payload) {
|
|
|
334
374
|
return json;
|
|
335
375
|
}
|
|
336
376
|
|
|
377
|
+
// —— 固定注册通行码发码通道(对齐公文写作 3.9.9)——
|
|
378
|
+
// 通行码通道地址:生产固定地址;显式传 --key-send-url 或 --base(本机 mock/测试)时随参数派生。
|
|
379
|
+
// 地址可被参数改写,必须校验主机,否则注册通行码会随请求发往任意地址。
|
|
380
|
+
// 注意:本白名单独立于 DKNOWC_ALLOW_ANY_ENDPOINT——通行码是平台凭据,任何情况下不出官方域名与本机回环。
|
|
381
|
+
function regKeySendUrl(a) {
|
|
382
|
+
const allowedHosts = new Set(["platform.dknowc.cn", "127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
383
|
+
const check = (url) => {
|
|
384
|
+
let host = "";
|
|
385
|
+
try { host = new URL(url).hostname; } catch { host = ""; }
|
|
386
|
+
if (!allowedHosts.has(host)) {
|
|
387
|
+
emit(errorPayload(
|
|
388
|
+
"PASSCODE_URL_REJECTED",
|
|
389
|
+
null,
|
|
390
|
+
`通行码通道地址只允许 platform.dknowc.cn 或本机回环(测试),当前被拒:${url}`,
|
|
391
|
+
), 1);
|
|
392
|
+
}
|
|
393
|
+
return url;
|
|
394
|
+
};
|
|
395
|
+
const explicit = a["key-send-url"];
|
|
396
|
+
if (explicit && explicit !== true) return check(String(explicit));
|
|
397
|
+
if (a.base && a.base !== true) return check(String(a.base).replace(/\/+$/, "") + "/key-send");
|
|
398
|
+
return REGISTRATION_PASSCODE_SEND_URL;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// 申请发码:成功 {ok};通行码不可用 {fallback}(回落领题);限频/被拒/供应商失败/结果未确认
|
|
402
|
+
// 一律停点,不回落(回落等于再发一次,可能绕过频控或重复发送)。
|
|
403
|
+
async function sendCodeByPasscode(url, phone, channel) {
|
|
404
|
+
const headers = withAttribution({
|
|
405
|
+
[PASSCODE_HEADER_NAME]: REGISTRATION_PASSCODE,
|
|
406
|
+
"X-MaaS-Entry-Surface": "DIRECT_API",
|
|
407
|
+
"X-MaaS-Client-Name": MAAS_CLIENT_NAME,
|
|
408
|
+
"X-MaaS-Client-Version": readSkillVersion(),
|
|
409
|
+
...(readInstanceId() ? { "X-MaaS-Client-Instance-Id": readInstanceId() } : {}),
|
|
410
|
+
});
|
|
411
|
+
const r = await httpJson("POST", url, { body: { phone, channel }, headers });
|
|
412
|
+
const issued = r.respHeaders ? r.respHeaders.get("x-maas-client-instance-id") : null;
|
|
413
|
+
if (issued) writeInstanceId(issued);
|
|
414
|
+
const j = r.json || {};
|
|
415
|
+
const code = String(j.code || "");
|
|
416
|
+
if (r.requestUnknown) return { unknown: true, detail: j.msg || null };
|
|
417
|
+
if (j.status === true && (j.deliveryStatus === "SENT" || j.nextAction === "SUBMIT_SMS_CODE")) {
|
|
418
|
+
writeRegSessionState(phone, mergeCookies({}, r.setCookies));
|
|
419
|
+
return { ok: true, retryAfterSeconds: Number(j.retryAfterSeconds) || 0, detail: j.msg || null };
|
|
420
|
+
}
|
|
421
|
+
if (code === "REGISTRATION_KEY_INVALID" || code === "REGISTRATION_KEY_UNAVAILABLE") {
|
|
422
|
+
return { fallback: true, reason: code };
|
|
423
|
+
}
|
|
424
|
+
if (code === "SMS_RATE_LIMIT_PHONE" || code === "SMS_RATE_LIMIT") {
|
|
425
|
+
return { rateLimited: true, retryAfterSeconds: Number(j.retryAfterSeconds) || 0 };
|
|
426
|
+
}
|
|
427
|
+
if (code === "SMS_REQUEST_REJECTED") return { rejected: true, detail: j.msg || null };
|
|
428
|
+
if (code.startsWith("SMS_PROVIDER_")) return { providerFailed: true, detail: j.msg || null };
|
|
429
|
+
if (r.httpStatus >= 400) return { unknown: true, detail: `${r.httpStatus} ${j.msg || ""}`.trim() };
|
|
430
|
+
return { fallback: true, reason: code || "UNRECOGNIZED" };
|
|
431
|
+
}
|
|
432
|
+
|
|
337
433
|
function genPassword() {
|
|
338
|
-
// 8-32 位,含大写/小写/数字/特殊至少 3
|
|
434
|
+
// 8-32 位,含大写/小写/数字/特殊至少 3 类。
|
|
435
|
+
// 口令与洗牌一律使用加密安全随机源(node:crypto randomInt),不用 Math.random。
|
|
339
436
|
const pools = ["ABCDEFGHJKLMNPQRSTUVWXYZ", "abcdefghijkmnpqrstuvwxyz", "23456789", "!@#$%^&*"];
|
|
340
|
-
const pick = (s) => s[
|
|
437
|
+
const pick = (s) => s[randomInt(s.length)];
|
|
341
438
|
let chars = pools.map(pick); // 每类至少一个
|
|
342
439
|
const all = pools.join("");
|
|
343
440
|
for (let i = 0; i < 8; i++) chars.push(pick(all)); // 补到 12 位
|
|
344
441
|
for (let i = chars.length - 1; i > 0; i--) { // 洗牌
|
|
345
|
-
const j =
|
|
442
|
+
const j = randomInt(i + 1);
|
|
346
443
|
[chars[i], chars[j]] = [chars[j], chars[i]];
|
|
347
444
|
}
|
|
348
445
|
return chars.join("");
|
|
@@ -359,22 +456,20 @@ async function createNewApiKey(openBase, existingApiKey, name, remark) {
|
|
|
359
456
|
}
|
|
360
457
|
|
|
361
458
|
function writeApiKeyToConfigFile(apiKey) {
|
|
362
|
-
// 写本机专用配置文件(纯文本一行 Key,600
|
|
459
|
+
// 写本机专用配置文件(纯文本一行 Key,600 权限),不触碰任何 shell 配置文件。
|
|
460
|
+
// 2026-11-25 整改:直接覆盖写,不用临时文件 + rename(宿主把 rename 判成"删除文件"会弹确认);
|
|
461
|
+
// 覆写前先 chmod 0600 收紧已存在文件的权限。
|
|
363
462
|
const filePath = apiKeyFilePath();
|
|
364
463
|
try {
|
|
365
464
|
fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
465
|
+
try { fs.chmodSync(filePath, 0o600); } catch { /* 文件不存在时忽略,创建时按 mode 生效 */ }
|
|
366
466
|
fs.writeFileSync(filePath, `${String(apiKey).trim()}\n`, { encoding: "utf8", mode: 0o600 });
|
|
367
|
-
// 不自动修改 ~/.zshrc:历史块只作读取兜底;清理需用户显式 --clean-zshrc
|
|
368
467
|
return { written: true, path: filePath, error: null };
|
|
369
468
|
} catch (e) {
|
|
370
469
|
return { written: false, path: filePath, error: e && e.message ? e.message : String(e) };
|
|
371
470
|
}
|
|
372
471
|
}
|
|
373
472
|
|
|
374
|
-
function escapeRegExp(value) {
|
|
375
|
-
return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
376
|
-
}
|
|
377
|
-
|
|
378
473
|
// —— Agent 注册:响应归类 ——
|
|
379
474
|
// 平台返回 status:true 只代表"本步成功":领题成功≠已发码,发码成功≠注册完成。
|
|
380
475
|
function emit(obj, code) {
|
|
@@ -439,7 +534,7 @@ async function main() {
|
|
|
439
534
|
// 成功(返回顶层 JSON {"apiKey": "..."})后,用本命令落盘,用户无需手机号验证码。
|
|
440
535
|
// 密钥来源优先 stdin(printf '%s' "<密钥>" | node register_key.mjs save-key,避免出现在
|
|
441
536
|
// 命令行参数里),其次 --api-key;仅接受 sk- 开头。落盘复用 writeApiKeyToConfigFile
|
|
442
|
-
// (600
|
|
537
|
+
// (600 权限),与手机号注册路径同一份持久化逻辑。
|
|
443
538
|
let apiKey = "";
|
|
444
539
|
try {
|
|
445
540
|
if (!process.stdin.isTTY) {
|
|
@@ -458,9 +553,7 @@ async function main() {
|
|
|
458
553
|
process.exit(1);
|
|
459
554
|
}
|
|
460
555
|
const w = writeApiKeyToConfigFile(apiKey);
|
|
461
|
-
const zshrcCleaned = (w.written && a["clean-zshrc"]) ? (removeLegacyZshrcBlocks(), true) : false;
|
|
462
556
|
console.log(JSON.stringify({
|
|
463
|
-
zshrcCleaned,
|
|
464
557
|
status: w.written,
|
|
465
558
|
envWriteSucceeded: w.written,
|
|
466
559
|
envWriteTarget: w.path,
|
|
@@ -486,10 +579,78 @@ async function main() {
|
|
|
486
579
|
const guideUrl = assertEndpointAllowed(a.guide && a.guide !== true ? String(a.guide) : DEFAULT_GUIDE, "--guide");
|
|
487
580
|
const channel = a.channel && a.channel !== true ? String(a.channel) : DEFAULT_CHANNEL;
|
|
488
581
|
|
|
582
|
+
// 先走固定注册通行码发码通道:一次请求即发码,不需要领题与作答(对齐公文写作 3.9.9)。
|
|
583
|
+
// 通行码失效/停用或返回无法识别的业务码时回落原领题流程;--legacy 显式跳过本通道。
|
|
584
|
+
const useKeyChannel = !(a.legacy === true || a.legacy === "true");
|
|
585
|
+
let keyFallbackReason = null;
|
|
586
|
+
if (useKeyChannel) {
|
|
587
|
+
const k = await sendCodeByPasscode(regKeySendUrl(a), phone, channel);
|
|
588
|
+
if (k.ok) {
|
|
589
|
+
emit({
|
|
590
|
+
status: true,
|
|
591
|
+
code: "SMS_SENT",
|
|
592
|
+
flow: "key",
|
|
593
|
+
retryAfterSeconds: k.retryAfterSeconds || 0,
|
|
594
|
+
user_message: `验证码已发送到 ${maskPhone(phone)},请把最新一条短信里的 6 位验证码发我。`,
|
|
595
|
+
instruction: "已发码:转述 user_message 后暂停,等用户回复 6 位验证码,再调用 register。不得重复发码,也不需要调用 answer。",
|
|
596
|
+
}, 0);
|
|
597
|
+
}
|
|
598
|
+
if (k.rateLimited) {
|
|
599
|
+
const secs = k.retryAfterSeconds > 0 ? k.retryAfterSeconds : 0;
|
|
600
|
+
emit({
|
|
601
|
+
...errorPayload(
|
|
602
|
+
"SMS_RATE_LIMIT",
|
|
603
|
+
secs > 0
|
|
604
|
+
? `验证码发送太频繁了,短信通道要求约 ${secs} 秒后再试。你先忙别的,想重发时跟我说一声。`
|
|
605
|
+
: "验证码发送太频繁了,稍等一会儿再试;想重发时跟我说一声。",
|
|
606
|
+
"限频停点:等用户明确要求且冷却过后再发起,不自动重试。",
|
|
607
|
+
),
|
|
608
|
+
flow: "key",
|
|
609
|
+
retryAfterSeconds: secs,
|
|
610
|
+
}, 1);
|
|
611
|
+
}
|
|
612
|
+
if (k.providerFailed) {
|
|
613
|
+
emit({
|
|
614
|
+
...errorPayload(
|
|
615
|
+
"SMS_PROVIDER_FAILED",
|
|
616
|
+
`短信服务暂时出了点问题,发不出验证码。可以稍后再试,或用网页方式开通:${FALLBACK_REGISTER_URL}`,
|
|
617
|
+
"供应商失败停点:不自动重试、不回落旧路径。",
|
|
618
|
+
),
|
|
619
|
+
flow: "key",
|
|
620
|
+
detail: k.detail || null,
|
|
621
|
+
}, 1);
|
|
622
|
+
}
|
|
623
|
+
if (k.rejected) {
|
|
624
|
+
emit({
|
|
625
|
+
...errorPayload(
|
|
626
|
+
"SMS_REQUEST_REJECTED",
|
|
627
|
+
"这个手机号这次没能通过开通校验,麻烦核对一下号码再发我。",
|
|
628
|
+
"不重复提交同一号码,等用户核对后再发起。",
|
|
629
|
+
),
|
|
630
|
+
flow: "key",
|
|
631
|
+
detail: k.detail || null,
|
|
632
|
+
}, 1);
|
|
633
|
+
}
|
|
634
|
+
if (k.unknown) {
|
|
635
|
+
emit({
|
|
636
|
+
...errorPayload(
|
|
637
|
+
"RESULT_UNKNOWN",
|
|
638
|
+
"刚才发送请求的结果没有确认(网络波动)。先看一下手机有没有收到验证码短信:收到了直接把 6 位验证码发我;没收到再跟我说,我重新发。",
|
|
639
|
+
"结果未确认停点:先等用户确认是否收到短信,未确认前不重新发送。",
|
|
640
|
+
),
|
|
641
|
+
flow: "key",
|
|
642
|
+
resultUnknown: true,
|
|
643
|
+
detail: k.detail || null,
|
|
644
|
+
}, 1);
|
|
645
|
+
}
|
|
646
|
+
keyFallbackReason = k.reason || null;
|
|
647
|
+
if (keyFallbackReason) console.error(`注册通行码通道未生效(${keyFallbackReason}),改走原领题流程。`);
|
|
648
|
+
}
|
|
649
|
+
|
|
489
650
|
// 同号未过期的题直接复用:刷新题目不增加机会、不延长到期时间,也不该重复请求服务端
|
|
490
651
|
const cached = readChallengeState();
|
|
491
652
|
if (cached && cached.phone === phone && cached.question && !challengeExpired(cached)) {
|
|
492
|
-
emit(questionPayload(cached, { reused: true }), 0);
|
|
653
|
+
emit(questionPayload(cached, keyFallbackReason ? { reused: true, keyFallback: keyFallbackReason } : { reused: true }), 0);
|
|
493
654
|
}
|
|
494
655
|
|
|
495
656
|
const g = await httpJson("GET", guideUrl, { headers: withAttribution({}) });
|
|
@@ -627,7 +788,7 @@ async function main() {
|
|
|
627
788
|
createdAt: new Date().toISOString(),
|
|
628
789
|
};
|
|
629
790
|
writeChallengeState(st);
|
|
630
|
-
emit(questionPayload(st), 0);
|
|
791
|
+
emit(questionPayload(st, keyFallbackReason ? { keyFallback: keyFallbackReason } : {}), 0);
|
|
631
792
|
}
|
|
632
793
|
if (j.fallbackRequired === true || j.code === "AGENT_TEXT_FAILED") {
|
|
633
794
|
const h = handoffPayload(j.verificationUrl, guideFinal, phone);
|
|
@@ -799,14 +960,15 @@ async function main() {
|
|
|
799
960
|
phone: a.phone,
|
|
800
961
|
vcode: a.vcode,
|
|
801
962
|
password: a.password && a.password !== true ? a.password : genPassword(),
|
|
802
|
-
type: a.type && a.type !== true ? a.type : DEFAULT_TYPE,
|
|
803
963
|
organ: a.organ && a.organ !== true ? a.organ : "个人",
|
|
804
964
|
name: a.name && a.name !== true ? a.name : "用户",
|
|
805
965
|
apiKeyName: a["apikey-name"] && a["apikey-name"] !== true ? a["apikey-name"] : "agent-key",
|
|
806
966
|
};
|
|
807
967
|
payload.channel = a.channel && a.channel !== true ? a.channel : DEFAULT_CHANNEL;
|
|
808
968
|
payload.source = a.source && a.source !== true ? a.source : DEFAULT_SOURCE;
|
|
809
|
-
|
|
969
|
+
// 注册通行码通道发码时下发的会话按手机号复用(同一会话完成发码与注册);旧领题路径无此会话
|
|
970
|
+
const regCookies = regSessionFor(String(payload.phone));
|
|
971
|
+
const { body: r } = await post(base + "/register", payload, regCookies ? { cookies: regCookies } : {});
|
|
810
972
|
const data = r.data || {};
|
|
811
973
|
// 2026-10-09(user-auth maas-1.1.6):registered:true + deliveryStatus:"PENDING"——
|
|
812
974
|
// 账号已创建、Key 资源尚在准备。非错误:不盲目重注册,等用户示意后在短信码有效期内
|
|
@@ -823,6 +985,7 @@ async function main() {
|
|
|
823
985
|
process.exit(0);
|
|
824
986
|
}
|
|
825
987
|
const ok = Boolean(r.status) && Boolean(data.apiKey);
|
|
988
|
+
if (ok) clearRegSessionState();
|
|
826
989
|
let apiKeyToSave = ok ? data.apiKey : "";
|
|
827
990
|
let newKeyCreated = false;
|
|
828
991
|
let newKeyError = null;
|
|
@@ -845,14 +1008,13 @@ async function main() {
|
|
|
845
1008
|
newKeyError = result.errmsg || result.msg || "新 API Key 创建失败";
|
|
846
1009
|
}
|
|
847
1010
|
}
|
|
848
|
-
const
|
|
1011
|
+
const cfgWrite = ok && apiKeyToSave
|
|
849
1012
|
? writeApiKeyToConfigFile(apiKeyToSave)
|
|
850
1013
|
: { written: false, path: apiKeyFilePath(), error: null };
|
|
851
1014
|
// 落盘失败时:把明文 Key 写入仅当前用户可读的待用文件(600),stdout 只给路径与掩码,
|
|
852
1015
|
// 避免完整密钥出现在对话框/宿主 UI 回显里。Agent 从该文件读取注入环境变量后即可删除。
|
|
853
|
-
const zshrcCleaned = (zshrcWrite.written && a["clean-zshrc"]) ? (removeLegacyZshrcBlocks(), true) : false;
|
|
854
1016
|
let pendingKeyFile = null;
|
|
855
|
-
if (ok && apiKeyToSave && !
|
|
1017
|
+
if (ok && apiKeyToSave && !cfgWrite.written) {
|
|
856
1018
|
try {
|
|
857
1019
|
const pendingPath = path.join(configDir(), "api_key.pending");
|
|
858
1020
|
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
@@ -892,19 +1054,18 @@ async function main() {
|
|
|
892
1054
|
envName: API_KEY_ENV,
|
|
893
1055
|
// 明文 Key 只在"未写入本机配置文件、必须靠它临时注入环境变量"时才输出,其余情况
|
|
894
1056
|
// 只给掩码——脚本输出可能被宿主 UI 回显或模型贴进对话
|
|
895
|
-
apiKey: (apiKeyToSave && !
|
|
1057
|
+
apiKey: (apiKeyToSave && !cfgWrite.written && !pendingKeyFile) ? apiKeyToSave : null,
|
|
896
1058
|
pendingKeyFile,
|
|
897
1059
|
apiKeyMasked: apiKeyToSave ? `${apiKeyToSave.slice(0, 7)}...${apiKeyToSave.slice(-4)}` : null,
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
? `已写入 ${zshrcWrite.path};脚本直读该文件,无需重启宿主,本次不再返回明文密钥。`
|
|
1060
|
+
envWriteRequired: Boolean(apiKeyToSave) && !cfgWrite.written,
|
|
1061
|
+
envWriteTarget: cfgWrite.path,
|
|
1062
|
+
envWriteSucceeded: Boolean(cfgWrite.written),
|
|
1063
|
+
envWriteError: cfgWrite.error,
|
|
1064
|
+
envWriteInstruction: cfgWrite.written
|
|
1065
|
+
? `已写入 ${cfgWrite.path};脚本直读该文件,无需重启宿主,本次不再返回明文密钥。`
|
|
905
1066
|
: (pendingKeyFile
|
|
906
|
-
? `未能写入 ${
|
|
907
|
-
: `未能写入 ${
|
|
1067
|
+
? `未能写入 ${cfgWrite.path};明文 Key 已写入仅本用户可读的 ${pendingKeyFile}(600 权限),请由 Agent 读取该文件临时注入环境变量 ${API_KEY_ENV},用完删除该文件;不得展示给用户、不得写入公开文件。`
|
|
1068
|
+
: `未能写入 ${cfgWrite.path},本次已在 apiKey 字段返回明文,请由 Agent 临时注入环境变量 ${API_KEY_ENV}(不得展示给用户、不得写入公开文件)。`),
|
|
908
1069
|
currentSessionInstruction: `当前任务继续执行初始化时,请用本次返回的 apiKey 临时注入环境变量 ${API_KEY_ENV},不得向用户展示完整 Key。`,
|
|
909
1070
|
newKeyError,
|
|
910
1071
|
fallbackRegisterUrl: FALLBACK_REGISTER_URL,
|
|
@@ -48,19 +48,10 @@ DEFAULT_SEARCH_TYPE = "policy"
|
|
|
48
48
|
DEFAULT_SEGMENT_COUNT = 4
|
|
49
49
|
DEFAULT_MATERIAL_LENGTH = 18000
|
|
50
50
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
51
|
-
|
|
52
|
-
import os as _os
|
|
53
|
-
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
54
|
-
if not _ws:
|
|
55
|
-
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/,
|
|
56
|
-
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
57
|
-
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
58
|
-
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
59
|
-
WS_ROOT = Path(_ws).resolve()
|
|
60
|
-
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
51
|
+
SEARCH_RESULTS_DIR = SKILL_ROOT / "official-docs" / "search-results"
|
|
61
52
|
|
|
62
53
|
def _resolve_key():
|
|
63
|
-
"""环境变量优先,缺失时读本机专用配置文件 ~/.config/dknowc/api_key
|
|
54
|
+
"""环境变量优先,缺失时读本机专用配置文件 ~/.config/dknowc/api_key(不读写 shell 配置文件)。"""
|
|
64
55
|
try:
|
|
65
56
|
from api_key import resolve_api_key
|
|
66
57
|
key, _ = resolve_api_key()
|
|
@@ -77,7 +68,7 @@ def resolve_output_json(output_path: str) -> Path:
|
|
|
77
68
|
elif raw_path.parent == Path("."):
|
|
78
69
|
resolved = (SEARCH_RESULTS_DIR / raw_path.name).resolve()
|
|
79
70
|
else:
|
|
80
|
-
resolved = raw_path.resolve()
|
|
71
|
+
resolved = (SKILL_ROOT / raw_path).resolve()
|
|
81
72
|
|
|
82
73
|
if resolved.suffix.lower() != ".json":
|
|
83
74
|
resolved = resolved.with_suffix(".json")
|
|
@@ -141,6 +132,10 @@ def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
|
141
132
|
raise SystemExit("错误:--material-length 必须为正整数")
|
|
142
133
|
payload: Dict[str, Any] = {
|
|
143
134
|
"query": args.query,
|
|
135
|
+
# 联网搜索模式:searchChannel 单值传 webSearch,
|
|
136
|
+
# 返回真实互联网内容(网页正文段落+源网址,可溯源到原段);dataAuthority 随联网路自动开——
|
|
137
|
+
# 返回文章级 数据权威性 标注(联网结果为"非权威"),供渲染层打"非官方来源"徽标。
|
|
138
|
+
"dataAuthority": bool(getattr(args, "data_authority", False) or getattr(args, "search_channel", "") == "webSearch"),
|
|
144
139
|
"searchType": [search_type],
|
|
145
140
|
"policy": False if args.no_policy else True,
|
|
146
141
|
"item": False if args.no_item else True,
|
|
@@ -164,6 +159,10 @@ def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
|
164
159
|
if eff_time:
|
|
165
160
|
payload["eff_time"] = _list_arg(_validate_eff_time(eff_time))
|
|
166
161
|
|
|
162
|
+
search_channel = getattr(args, "search_channel", "") or ""
|
|
163
|
+
if search_channel:
|
|
164
|
+
# 单值(与 searchType 同理):govSearch/webSearch/wxSearch 一次只传一个
|
|
165
|
+
payload["searchChannel"] = [search_channel]
|
|
167
166
|
return payload
|
|
168
167
|
|
|
169
168
|
|
|
@@ -413,6 +412,14 @@ def main() -> None:
|
|
|
413
412
|
parser.add_argument("--segment-count", type=int, help="每篇材料最多返回段落数(默认 4,V2 定档)")
|
|
414
413
|
parser.add_argument("--search-type", help="V2 必填单值:policy / govSite / affair / qa / private(默认 policy;"
|
|
415
414
|
"多值报错——多类来源分路调用后合并)")
|
|
415
|
+
parser.add_argument("--search-channel", default="",
|
|
416
|
+
choices=["webSearch", "govSearch", "wxSearch"],
|
|
417
|
+
help="动态搜索渠道(单值,三阶段降级链阶段二):webSearch=自动联网搜索模式"
|
|
418
|
+
"(返回互联网网页正文段落+源网址,可溯源到原段;dataAuthority 自动开启,"
|
|
419
|
+
"联网路材料统一标「非官方来源」);govSearch=政府站定向;wxSearch=微信生态。"
|
|
420
|
+
"默认不传=只查深知库内")
|
|
421
|
+
parser.add_argument("--data-authority", action="store_true",
|
|
422
|
+
help="请求返回文章级 数据权威性 标注(联网路自动开启,无需显式传)")
|
|
416
423
|
parser.add_argument("--material-length", type=int, help="返回材料总字符上限(默认 18000,V2 定档)")
|
|
417
424
|
parser.add_argument("--simplified", action="store_true", help="精炼输出(会丢存档快照 screenShotPath,默认关闭)")
|
|
418
425
|
parser.add_argument("--no-simplified", action="store_true", help="兼容保留:默认已不精炼,无需传此参数")
|
|
@@ -452,6 +459,16 @@ def main() -> None:
|
|
|
452
459
|
if args.json_only:
|
|
453
460
|
# 落盘前校验业务码:错误响应不落盘、不报"已保存"
|
|
454
461
|
_bail_if_biz_error(body)
|
|
462
|
+
# 联网路(searchChannel=webSearch)打标:每篇材料注入 检索通道 与 非官方来源
|
|
463
|
+
# (渲染层按 非官方来源=True + 数据权威性=非权威 双口径打"非官方来源"徽标)
|
|
464
|
+
if getattr(args, "search_channel", "") == "webSearch":
|
|
465
|
+
_content = body.get("content") if isinstance(body.get("content"), dict) else {}
|
|
466
|
+
_data = _content.get("data") if isinstance(_content.get("data"), dict) else {}
|
|
467
|
+
for _a in (_data.get("检索文章") or []):
|
|
468
|
+
if isinstance(_a, dict):
|
|
469
|
+
if not _a.get("检索通道"):
|
|
470
|
+
_a["检索通道"] = "深知可信搜索·联网"
|
|
471
|
+
_a["非官方来源"] = True
|
|
455
472
|
raw_json = json.dumps(body, ensure_ascii=False, indent=2)
|
|
456
473
|
if args.output:
|
|
457
474
|
output_path = resolve_output_json(args.output)
|