dsh-deepseek-web-login 0.5.3 → 0.6.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/CHANGELOG.md CHANGED
@@ -2,6 +2,98 @@
2
2
 
3
3
  本项目遵循大致语义化版本;日期为本地时间。
4
4
 
5
+ ## 0.6.1 — 2026-09-27
6
+
7
+ > 工具目录按「用不用得上」分级:常用的给完整说明,长尾的只留一句话。**能力一个不少。**
8
+
9
+ ### 改进
10
+
11
+ - **工具描述分两级下发**。0.6.0 把参数从 JSON 换成签名之后,目录里最大的一块变成了
12
+ **工具级描述**(13 个真实工具实测:描述 10,369 字符 vs 参数段 7,588)。现在:
13
+ - **核心工具** —— `pwsh` / `bash` / `run_code` / `read` / `write` / `edit` / `grep` / `glob` /
14
+ `ls` / `todo_write` / `skill` / `present` / `ask_user_question`:描述按 3200 字符完整保留,参数说明也在;
15
+ - **长尾工具** —— 描述压到 240 字符,且**不输出参数说明**。
16
+ - ⚠️ **两级都保留工具名与参数签名** ⇒ 模型照样能调用长尾工具,只是看不到长篇说明。
17
+ **这不是「禁用工具」**,不会出现「要用的工具看不见」。
18
+
19
+ ### 为什么这么分(实测依据)
20
+
21
+ 扫最近 8 个会话的 **826 次真实工具调用**:
22
+
23
+ | 工具 | 次数 | 占比 |
24
+ |---|---|---|
25
+ | pwsh | 230 | 27.8% |
26
+ | run_code | 206 | 24.9% |
27
+ | edit | 140 | 16.9% |
28
+ | read | 80 | 9.7% |
29
+ | write | 66 | 8.0% |
30
+ | bash | 46 | 5.6% |
31
+ | 其余(grep/glob/present/skill/todo_write…) | 58 | 7.1% |
32
+
33
+ **覆盖 90% 的调用只需要 6 个工具**,而 DSH 每轮下发 **61 个**。剩下的那些
34
+ (jobs / goal / ralph / workflow / web / subagent 系列…)在这 8 个会话里**一次都没被调用过**,
35
+ 却每个都在每一轮的上下文里占几百字符。
36
+
37
+ ### 实测收益(13 个真实 DSH 工具定义)
38
+
39
+ | 版本 | 目录长度 | 累计省 |
40
+ |---|---|---|
41
+ | 0.5.3(JSON + 完整描述) | 18,217 | — |
42
+ | 0.6.0(签名 + 完整描述) | 14,815 | 19% |
43
+ | **0.6.1(分级)** | **10,544** | **42%** |
44
+
45
+ 按 61 个工具(50,942 字符)外推,约 **省 2.1 万字符 ≈ 5,000 token / 每轮上下文**,
46
+ 而且**零额外请求**。
47
+
48
+ ### 说明
49
+
50
+ - ⚠️ **这是 head 的变化**:重启 DSH 后**第一个任务会全量重发一次**,之后照常。
51
+ - 长尾工具丢的是「遇错怎么办」那类长指引;**真正常用的工具一个字没动**。
52
+ - 想调整名单:改 `src/protocol.ts` 里的 `CORE_TOOLS` 集合 —— 那是唯一的开关。
53
+ 哪天真觉得某个工具"看不懂了",把它加进去重新构建即可。
54
+
55
+ ## 0.6.0 — 2026-09-27
56
+
57
+ > 工具目录改用**紧凑类型签名**下发,不再给模型贴原始 JSON。
58
+
59
+ ### 改进
60
+
61
+ - **每个工具的参数不再原样贴 JSON**。原先那行是
62
+ `Parameters (JSON Schema): {"type":"object","properties":{…}}`,现在渲染成类型签名:
63
+
64
+ ```
65
+ ### read_file
66
+ Read a file.
67
+ read_file(file_path: string, offset?: number, limit?: number)
68
+ file_path: Path to read, resolved by the filesystem backend.
69
+ offset: 1-based first line to return. Defaults to 1.
70
+ ```
71
+
72
+ 模型要写出 `arguments`,真正需要的只是**参数名、类型、必填性**;那串 JSON 里
73
+ `"type":"…"`、键名的引号、每个参数各套一层对象,全是结构性样板。
74
+ - **两种参数形态都认**。DSH 自家工具是**扁平**写法(顶层键直接是参数名、`required: true`
75
+ 挂在参数自己身上),而 `@deepseek-ai/dsh-tools` 的 `schemaOf()` 把它**原样透传**、不做规范化;
76
+ 标准 JSON Schema 包裹形态(`{type:'object',properties:{…}}`)一并支持。
77
+ - 嵌套对象/数组/枚举/`anyOf` 都能渲染:`{content: string, status: string}[]`、
78
+ `"view" | "create" | "str_replace" | "insert"`。
79
+
80
+ ### 实测(2026-09-27,取自 13 个真实 DSH 工具定义)
81
+
82
+ - 参数段 **7,588 → 4,186 字符(省 45%)**,`required` 与参数描述全部保留、零回退。
83
+ - 折算到**整个工具目录约省 18%** —— 目录里更大的一块是工具级描述(同批样本 10,369 字符),
84
+ 那块**没动**:它藏的是"遇错怎么办"的指引,不许砍。
85
+ - 按 61 个工具 / 50,942 字符的目录估,约 **省 9,500 字符 ≈ 2,400 token**,占单轮输入 **3%** 左右。
86
+ ⇒ 别指望它解决"提示词太长":真正的大头是消息历史与环境注入,不在工具目录。
87
+
88
+ ### 说明 / 风险
89
+
90
+ - ⚠️ **这是 head 的变化**:升级后**第一个任务会全量重发一次**(投喂链断),之后照常。
91
+ - ⚠️ 模型看到的参数形态变了(JSON → 类型签名)。签名是模型最熟的形态,预期更好读;
92
+ 但**首次实测若发现参数写错,请立刻反馈** —— 回退只改一处:`buildToolSection` 里不用
93
+ `buildToolSignature` 即退回原始 JSON(回退分支与"认不出就不许发空参数"由
94
+ `tests/check-tool-signature.mjs` 守着)。
95
+ - 参数描述超过 160 字符会被截断;**工具级描述仍是 3200 上限,不受影响**。
96
+
5
97
  ## 0.5.3 — 2026-09-27
6
98
 
7
99
  > 修掉一个"重启后前 3 分钟里限流不换号"的窗口 —— 0.5.2 的漏洞。
package/lib/index.js CHANGED
@@ -3325,6 +3325,43 @@ function staleAuthMessage(auth) {
3325
3325
  */
3326
3326
  const MAX_DESCRIPTION_CHARS = 3200;
3327
3327
  /**
3328
+ * 「核心工具」白名单 —— 只有它们值得在**每轮上下文**里都带上完整描述。
3329
+ *
3330
+ * 依据(2026-09-27 实测):扫最近 8 个会话的 **826 次真实工具调用**,
3331
+ * pwsh 27.8% / run_code 24.9% / edit 16.9% / read 9.7% / write 8.0% / bash 5.6%
3332
+ * ⇒ **覆盖 90% 的调用只需要这几个**。
3333
+ * 其余 50 多个工具(jobs / goal / ralph / workflow / web / subagent / cordis_*…)
3334
+ * 在那 8 个会话里**一次都没被调用过**,却每个都在每轮上下文里占几百字符。
3335
+ *
3336
+ * ⚠️ 分级只压**说明文字**:工具名与参数签名字字不少 ⇒ 模型照样能调用它们,
3337
+ * 只是看不到长篇说明("遇错怎么办"那类指引只对常用工具才值得每轮都带着)。
3338
+ * 要调整就把名字增删进这个集合 —— 这是唯一的开关。
3339
+ */
3340
+ const CORE_TOOLS = /* @__PURE__ */ new Set([
3341
+ "pwsh",
3342
+ "bash",
3343
+ "run_code",
3344
+ "read",
3345
+ "write",
3346
+ "edit",
3347
+ "grep",
3348
+ "glob",
3349
+ "ls",
3350
+ "todo_write",
3351
+ "skill",
3352
+ "present",
3353
+ "ask_user_question"
3354
+ ]);
3355
+ /**
3356
+ * 长尾工具的描述上限。240 字符 ≈ 首句 + 一句补充,够模型判断"这工具干什么"。
3357
+ * ⚠️ 长尾工具**也不输出参数描述**(参数名/类型/必填性仍在签名里)—— 那是它们体积的另一半。
3358
+ */
3359
+ const MAX_LONGTAIL_DESCRIPTION_CHARS = 240;
3360
+ /** 工具是否属于核心组(决定描述给多长、要不要带参数说明)。 */
3361
+ function isCoreTool(name) {
3362
+ return CORE_TOOLS.has(String(name ?? ""));
3363
+ }
3364
+ /**
3328
3365
  * 工具目录(一节)的总预算。
3329
3366
  *
3330
3367
  * 2026-09-12 从 24_000 提到 56_000。理由:实测 DSH 下发 61 个工具、不截描述时共需
@@ -3443,24 +3480,171 @@ function truncate(text, max) {
3443
3480
  if (text.length <= max) return text;
3444
3481
  return `${text.slice(0, max - 3)}...`;
3445
3482
  }
3446
- /** 渲染工具目录(含 JSON Schema)。 */
3483
+ /**
3484
+ * 参数级描述的截断长度。
3485
+ *
3486
+ * 紧凑签名保留的是「参数名 + 类型 + 必填性」—— 那是模型写出正确 arguments 的**最小信息集**。
3487
+ * 参数描述是锦上添花:第 160 字符之后通常是举例或边角说明(`path` 这类参数压根没有),
3488
+ * 砍掉它比砍掉工具级描述划算得多 —— 工具级描述里藏的是「遇错怎么办」。
3489
+ */
3490
+ const MAX_PARAM_DESC_CHARS = 160;
3491
+ /** 嵌套展开的深度上限:异常 schema(自引用、深层嵌套)不该把工具目录撑爆。 */
3492
+ const MAX_SIGNATURE_DEPTH = 4;
3493
+ /** `parameters` 是对象时才当映射用(`parameters: []` 这类异常值直接忽略)。 */
3494
+ function asRecord(value) {
3495
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
3496
+ }
3497
+ /**
3498
+ * 「标准 JSON Schema 包裹」形态的顶层关键字。顶层**只**出现这些键 ⇒ 是
3499
+ * `{type:'object',properties:{…},required:[…]}` 包裹;出现别的键 ⇒ 那些键就是参数名。
3500
+ */
3501
+ const SCHEMA_TOP_KEYS = /* @__PURE__ */ new Set([
3502
+ "type",
3503
+ "properties",
3504
+ "required",
3505
+ "additionalProperties",
3506
+ "description",
3507
+ "title",
3508
+ "default",
3509
+ "examples",
3510
+ "$schema",
3511
+ "definitions",
3512
+ "$defs"
3513
+ ]);
3514
+ /**
3515
+ * `parameters` 是「标准包裹」还是「DSH 扁平写法」。
3516
+ *
3517
+ * ⚠️ 两种都得认(2026-09-27 读 `@deepseek-ai/dsh-tools/lib/index.js` 的 `schemaOf()` 确认):
3518
+ * 它把工具定义里的 `parameters` **原样透传**给 provider,不做任何规范化。而 DSH 自家工具
3519
+ * 清一色写**扁平**形态 —— 顶层键直接是参数名、`required: true` 写在参数自己身上:
3520
+ *
3521
+ * parameters: { command: { type: 'string', required: true, description: '…' },
3522
+ * description: { type: 'string', required: true, description: '…' } }
3523
+ *
3524
+ * 常见的标准包裹形态仍要支持(第三方工具可能按 OpenAI 惯例写)。
3525
+ */
3526
+ function isWrappedSchema(node) {
3527
+ const properties = asRecord(node.properties);
3528
+ if (!properties || Object.keys(properties).length === 0) return false;
3529
+ if (!Object.values(properties).every((value) => asRecord(value) !== null)) return false;
3530
+ return Object.keys(node).every((key) => SCHEMA_TOP_KEYS.has(key));
3531
+ }
3532
+ /** 参数自己身上的必填标记(DSH 扁平写法)。 */
3533
+ function isRequiredParam(def) {
3534
+ return asRecord(def)?.required === true;
3535
+ }
3536
+ /** 读参数描述并压平空白。 */
3537
+ function paramDescription(schema) {
3538
+ const description = asRecord(schema)?.description;
3539
+ return typeof description === "string" ? description.replace(/\s+/g, " ").trim() : "";
3540
+ }
3541
+ /**
3542
+ * 渲染**一层参数映射**(`{参数名: 定义}`)→ `['a: string', 'b?: number']`。
3543
+ *
3544
+ * ⚠️ `depth` 必须**由调用方透传**。第一版在这里硬编码了 `1`,于是每下沉一层深度就重置,
3545
+ * `MAX_SIGNATURE_DEPTH` 完全失效 —— 深层嵌套(甚至自引用 schema)会一路展开到栈溢出,
3546
+ * 再被 catch 吞掉,表现为"莫名其妙回退到原始 JSON"。
3547
+ */
3548
+ function renderParamMap(map, requiredList, depth) {
3549
+ const fromList = new Set(requiredList);
3550
+ return Object.entries(map).map(([name, def]) => {
3551
+ return `${name}${fromList.has(name) || isRequiredParam(def) ? "" : "?"}: ${renderParamType(def, depth)}`;
3552
+ });
3553
+ }
3554
+ /**
3555
+ * 渲染一个参数的类型表达式:`string` / `T[]` / `{a: T, b?: U}` / `"x" | "y"`。
3556
+ *
3557
+ * 认不出来的形态一律退化成 `any` —— 签名本身永远合法。只有整份 parameters
3558
+ * 都不敢降级时,才由 `buildToolSignature` 返回 null 让调用方回退到原始 JSON。
3559
+ */
3560
+ function renderParamType(schema, depth) {
3561
+ const node = asRecord(schema);
3562
+ if (!node) return "any";
3563
+ if (depth > MAX_SIGNATURE_DEPTH) return "any";
3564
+ if (Array.isArray(node.enum) && node.enum.length > 0) return node.enum.map((value) => JSON.stringify(value)).join(" | ");
3565
+ const variants = Array.isArray(node.anyOf) ? node.anyOf : Array.isArray(node.oneOf) ? node.oneOf : null;
3566
+ if (variants && variants.length > 0) {
3567
+ const rendered = variants.map((item) => renderParamType(item, depth + 1));
3568
+ return [...new Set(rendered)].join(" | ");
3569
+ }
3570
+ const declared = typeof node.type === "string" ? node.type : "";
3571
+ if (declared === "array" || !declared && node.items !== void 0) {
3572
+ const item = renderParamType(node.items, depth + 1);
3573
+ return item.includes("|") ? `(${item})[]` : `${item}[]`;
3574
+ }
3575
+ const properties = asRecord(node.properties);
3576
+ if (declared === "object" || properties) {
3577
+ const inner = properties ? renderParamMap(properties, [], depth + 1) : [];
3578
+ const extra = asRecord(node.additionalProperties);
3579
+ if (extra) inner.push(`[key: string]: ${renderParamType(extra, depth + 1)}`);
3580
+ if (inner.length === 0) return "object";
3581
+ return `{${inner.join(", ")}}`;
3582
+ }
3583
+ return declared || "any";
3584
+ }
3585
+ /**
3586
+ * 把工具参数渲染成紧凑签名(0.6.0):
3587
+ *
3588
+ * read_file(file_path: string, offset?: number, limit?: number)
3589
+ * file_path: Path to read, resolved by the filesystem backend.
3590
+ *
3591
+ * 为什么值得做:原先直接贴 `JSON.stringify(parameters)`。那串文本里**结构性样板**占了大头
3592
+ * —— 每个参数都要套一层 `{"type":"…","description":"…"}`、键名与类型值全带引号,
3593
+ * 而模型写出 arguments 真正需要的只是**参数名、类型、必填性**。
3594
+ *
3595
+ * ⚠️ 返回 `null` = "这份 parameters 不敢降级",调用方必须回退到原始 JSON:
3596
+ * 宁可多花字符,也不能让模型看不见参数。
3597
+ *
3598
+ * @param withParamDocs 是否附上每个参数的说明。核心工具传 `true`,长尾工具传 `false`
3599
+ * —— 签名里已经有参数名、类型、必填性,那是模型写出正确 arguments 的**最小信息集**。
3600
+ */
3601
+ function buildToolSignature(tool, withParamDocs = true) {
3602
+ try {
3603
+ const node = asRecord(tool.parameters);
3604
+ if (!node) return `${tool.name}()`;
3605
+ const wrapped = isWrappedSchema(node);
3606
+ const map = wrapped ? asRecord(node.properties) : node;
3607
+ const args = renderParamMap(map, wrapped && Array.isArray(node.required) ? node.required.filter((key) => typeof key === "string") : [], 1);
3608
+ if (args.length === 0) return Object.keys(node).length === 0 ? `${tool.name}()` : null;
3609
+ const lines = [`${tool.name}(${args.join(", ")})`];
3610
+ if (withParamDocs) for (const [name, def] of Object.entries(map)) {
3611
+ const description = paramDescription(def);
3612
+ if (description) lines.push(` ${name}: ${truncate(description, MAX_PARAM_DESC_CHARS)}`);
3613
+ }
3614
+ return lines.join("\n");
3615
+ } catch {
3616
+ return null;
3617
+ }
3618
+ }
3619
+ /**
3620
+ * 渲染工具目录。
3621
+ *
3622
+ * 每个工具占一段:`### 名字` / 工具描述(≤3200 字符,不轻易砍)/ **参数紧凑签名**。
3623
+ * 签名由 `buildToolSignature` 产出;它只在 schema 不敢降级时返回 null,那时才贴原始 JSON Schema。
3624
+ */
3447
3625
  function buildToolSection(tools, maxChars = MAX_TOOLS_SECTION_CHARS) {
3448
3626
  if (!tools || tools.length === 0) return "";
3449
3627
  const parts = ["", "## Available tools"];
3450
3628
  let budget = Math.max(0, Math.min(MAX_TOOLS_SECTION_CHARS, maxChars));
3451
3629
  for (let index = 0; index < tools.length; index += 1) {
3452
3630
  const tool = tools[index];
3453
- let schemaText = "";
3454
- try {
3455
- schemaText = JSON.stringify(tool.parameters ?? {});
3456
- } catch {
3457
- schemaText = "{}";
3631
+ const core = isCoreTool(tool.name);
3632
+ const signature = buildToolSignature(tool, core);
3633
+ let parametersText = signature ?? "";
3634
+ if (signature === null) {
3635
+ let schemaText = "";
3636
+ try {
3637
+ schemaText = JSON.stringify(tool.parameters ?? {});
3638
+ } catch {
3639
+ schemaText = "{}";
3640
+ }
3641
+ parametersText = `Parameters (JSON Schema): ${schemaText}`;
3458
3642
  }
3459
3643
  const block = [
3460
3644
  "",
3461
3645
  `### ${tool.name}`,
3462
- truncate(String(tool.description ?? "").replace(/\s+/g, " ").trim(), MAX_DESCRIPTION_CHARS),
3463
- `Parameters (JSON Schema): ${schemaText}`
3646
+ truncate(String(tool.description ?? "").replace(/\s+/g, " ").trim(), core ? MAX_DESCRIPTION_CHARS : MAX_LONGTAIL_DESCRIPTION_CHARS),
3647
+ parametersText
3464
3648
  ].join("\n");
3465
3649
  if (budget - block.length < 0) {
3466
3650
  const rest = tools.slice(index).map((item) => String(item?.name ?? "")).filter(Boolean);
@@ -8648,7 +8832,7 @@ async function checkForUpdate(current, fetchImpl) {
8648
8832
  * 兜底常量与 package.json 的一致性由 `tests/check-smoke.mjs` 守着,不会漂。
8649
8833
  */
8650
8834
  /** 与 package.json 保持一致的兜底版本(由测试保证不会漂)。 */
8651
- const FALLBACK_VERSION = "0.5.3";
8835
+ const FALLBACK_VERSION = "0.6.1";
8652
8836
  let cached;
8653
8837
  /** 本插件版本(如 `0.1.26`)。 */
8654
8838
  function pluginVersion() {