dsh-lean-router 2.2.0 → 2.2.2

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/cordis.patch.yml CHANGED
@@ -276,6 +276,12 @@
276
276
  - id: tool-plugin-manager
277
277
  name: '@deepseek-ai/dsh-plugin-manager/tools'
278
278
  disabled: true
279
+ # live Usage 账本:订阅 session/event 采集带 usage 的 assistant/message,注册 /token-report 命令。
280
+ # 必须留在 preset 的 plugins 内(与 command-goal 同层)才拿得到 ctx.commands;实现 = lib/lean/usage-ledger.js。
281
+ - id: lean-usage-ledger
282
+ name: 'dsh-lean-router/lean/usage-ledger'
283
+ config:
284
+ enabled: true
279
285
 
280
286
  # ============ 新增行:preset-lean-router-balance(balance 档 3 条;上游双预设形态,flash-lean-ptc-v3-balance 同构)============
281
287
 
@@ -452,6 +458,11 @@
452
458
  - id: tool-plugin-manager
453
459
  name: '@deepseek-ai/dsh-plugin-manager/tools'
454
460
  disabled: true
461
+ # live Usage 账本(balance 档同挂):见 lean 档同名行说明。
462
+ - id: lean-usage-ledger
463
+ name: 'dsh-lean-router/lean/usage-ledger'
464
+ config:
465
+ enabled: true
455
466
 
456
467
  # ============ 新增行:交付门(加料件)============
457
468
  # 默认关闭(enabled: false):它会执行工作区里的验收脚本,要用户显式打开
@@ -477,17 +488,6 @@
477
488
  toolConcurrency:
478
489
  enabled: true
479
490
 
480
- # ============ 新增行:live Usage 账本挂载点(加料件)============
481
- # 默认开启:订阅 session/event,采集带 usage 的 assistant/message(lib/token-ledger/live.js)。
482
- # 斜杠命令 token-report([session|all])读账本,输出记录条数、prompt 总量、五项分项与最近一条 turn/step/seq;
483
- # 无记录时返回 success 并提示尚未采集。插件实现 = lib/lean/usage-ledger.js;
484
- # 插件行 name 为包内子路径,需 package.json exports 增加 ./lean/usage-ledger(master 集成)。
485
-
486
- - insert:
487
- - id: lean-usage-ledger
488
- name: 'dsh-lean-router/lean/usage-ledger'
489
- config:
490
- enabled: true
491
491
  # dsh-lean-router frag-toolface.patch.yml — 票 04 工具遮蔽层
492
492
  # 由 scripts/build-bundle.mjs 拼在 presets/base/lean-router.patch.yml 之后(顶层列表续项)。
493
493
  # 形态与上游 dsh-codemode 0.3.x 样本一致(cordis patch 顶层 "- <op>:" 列表;本分片为
@@ -803,6 +803,12 @@
803
803
  - id: tool-plugin-manager
804
804
  name: '@deepseek-ai/dsh-plugin-manager/tools'
805
805
  disabled: true
806
+ # live Usage 账本:订阅 session/event 采集带 usage 的 assistant/message,注册 /token-report 命令。
807
+ # 必须留在 preset 的 plugins 内(与 command-goal 同层)才拿得到 ctx.commands;实现 = lib/lean/usage-ledger.js。
808
+ - id: lean-usage-ledger
809
+ name: 'dsh-lean-router/lean/usage-ledger'
810
+ config:
811
+ enabled: true
806
812
 
807
813
  # ============ 新增行:preset-lean-router-balance(balance 档 3 条;上游双预设形态,flash-lean-ptc-v3-balance 同构)============
808
814
 
@@ -8,7 +8,21 @@
8
8
 
9
9
  复测的做法:从宿主类型定义或现有实现里确认真实结构,构造同样的形状跑一遍,对比前后长度、可解析性、关键字段是否保留。
10
10
 
11
- ## arch 图操作复核
11
+ ## PowerShell 会谎报退出码
12
+
13
+ 原生命令只要往 stderr 写任何东西(`npm` 的 notice/progress、Node 的 `DeprecationWarning`、`git push` 的进度行),PowerShell 就会把它包成 `NativeCommandError`,工具层看到的退出码变成 1——**即使命令实际完全成功**。
14
+
15
+ 判据:不要只信退出码,用能独立复核的状态判断。
16
+
17
+ - git 推送:看 `git status -sb` 还有没有 `ahead`,而不是看 `git push` 的退出码。
18
+ - npm 发布:看 `npm view <pkg>@<ver> version`,而不是看 `npm publish` 的退出码。
19
+ - 脚本内部:Windows 上避免 `execFileSync` + `shell:true` + args 数组(会触发 DEP0190 警告写 stderr),改用 `execSync` 的字符串形式。
20
+
21
+ ## 用结构验证,不要用 grep 验证
22
+
23
+ `grep` 到关键词只证明这段文字在文件里存在,不证明它生效:它可能整行被注释掉、可能在错误的缩进层级、可能被后面的定义覆盖。
24
+
25
+ 验证配置类文件时,解析它、取出**最终生效的那一份**、断言字段存在。补丁 YAML 的典型陷阱是同一个 `id` 有多个定义,最后写入的才生效。
12
26
 
13
27
  `.arch/` 是架构引擎自己的 shadow Git,不要 `git add` 进去;仓库已用 `.gitignore` 忽略,克隆后它不存在,需要时重新 `arch init`。
14
28
 
@@ -1,6 +1,19 @@
1
1
  # Changelog
2
2
 
3
- > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 2.2.0).
3
+ > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 2.2.1).
4
+
5
+ ## 2.2.2 (2026-11-29)
6
+
7
+ ### Fixed
8
+
9
+ - **Session creation failed outright (`agent-preset/invalid`)**: after 2.2.1 moved `lean-usage-ledger` into the presets' `plugins` array, the plugin read `ctx.commands` directly inside `apply`; cordis 4 requires a declared injection before that read, so it threw `cannot get property "commands" without inject` and both creating and restoring sessions failed. The plugin now declares `inject: ['commands']` (named export and default export alike): while `commands` is missing cordis waits instead of loading, and when the command seam never appears the plugin simply does not mount — neither path disturbs the host anymore, and `/token-report` behaves as before.
10
+ - **Regression test**: new `test/usage-ledger-inject.test.mjs` loads the plugin with real cordis in the "plugin first, `commands` later" order and asserts it does not throw and registers `/token-report` once the service appears.
11
+
12
+ ## 2.2.1 (2026-11-29)
13
+
14
+ ### Fixed
15
+
16
+ - **`/token-report` never appeared in a real session**: `lean-usage-ledger` was registered as a top-level add-on (the same layer as `lean-delivery-gate` and `lean-concurrency`), but the `ctx.commands` service is provided inside the preset scope, so the top-level row never received it and the plugin silently took its degraded path. It now lives in the `plugins` array of both the `lean` and `balance` presets, next to `command-goal`, so the command actually registers.
4
17
 
5
18
  ## 2.2.0 (2026-11-29)
6
19
 
package/docs/changelog.md CHANGED
@@ -1,6 +1,19 @@
1
1
  # 变更记录(changelog)
2
2
 
3
- > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 2.2.0)。
3
+ > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 2.2.1)。
4
+
5
+ ## 2.2.2 (2026-11-29)
6
+
7
+ ### 修复
8
+
9
+ - **创建会话直接失败(`agent-preset/invalid`)**:2.2.1 把 `lean-usage-ledger` 移进 preset 的 `plugins` 后,插件在 `apply` 里直接读 `ctx.commands`;cordis 4 要求先声明注入,未声明就读取会抛 `cannot get property "commands" without inject`,宿主新建与恢复会话都因此失败。插件现声明 `inject: ['commands']`(命名导出与默认导出同体):`commands` 未就绪时 cordis 等待而不是加载,命令缝始终缺席时插件静默不挂载,两种情况下都不再打断宿主;`/token-report` 行为不变。
10
+ - **回归测试**:新增 `test/usage-ledger-inject.test.mjs`,用真实 cordis 复现“先加载插件、后提供 `commands`”的顺序,断言不抛错、`commands` 出现后注册 `/token-report`。
11
+
12
+ ## 2.2.1 (2026-11-29)
13
+
14
+ ### 修复
15
+
16
+ - **`/token-report` 在真实环境不出现**:`lean-usage-ledger` 原先注册为顶层加料件(与 `lean-delivery-gate`、`lean-concurrency` 同层),但 `ctx.commands` 服务是在 preset scope 内提供的,顶层行拿不到,插件会按降级路径静默跳过。现已移入 `lean` 与 `balance` 两个 preset 的 `plugins` 数组(与 `command-goal` 同层),命令因此能真正注册。
4
17
 
5
18
  ## 2.2.0 (2026-11-29)
6
19
 
@@ -14,6 +14,12 @@ import { createLiveUsageAdapter } from '../token-ledger/live.js';
14
14
 
15
15
  export const name = 'lean-usage-ledger';
16
16
 
17
+ // cordis 4 的注入声明:未声明的服务属性在 apply 里读取会抛
18
+ // `cannot get property "commands" without inject`,宿主创建会话即失败
19
+ // (agent-preset/invalid)。声明后 cordis 会等 commands 就绪再加载本插件,
20
+ // 命令缝不存在时插件只是不挂载,绝不打断宿主启动。
21
+ export const inject = ['commands'];
22
+
17
23
  const TAG = '[lean-usage-ledger]';
18
24
  const COMMAND_NAME = 'token-report';
19
25
  const SCOPES = ['session', 'all'];
@@ -231,7 +237,7 @@ export function apply(ctx, config) {
231
237
  }
232
238
 
233
239
  /** 默认导出(插件行兼容形态,与命名导出同体)。 */
234
- export default { name, apply };
240
+ export default { name, inject, apply };
235
241
 
236
242
  /** 测试与集成内用的内部实现出口(不进公开契约文档)。 */
237
243
  export const __internals = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lean-router",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽的 DSH cordis 插件(单 bundle:预设)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -229,6 +229,12 @@
229
229
  - id: tool-plugin-manager
230
230
  name: '@deepseek-ai/dsh-plugin-manager/tools'
231
231
  disabled: true
232
+ # live Usage 账本:订阅 session/event 采集带 usage 的 assistant/message,注册 /token-report 命令。
233
+ # 必须留在 preset 的 plugins 内(与 command-goal 同层)才拿得到 ctx.commands;实现 = lib/lean/usage-ledger.js。
234
+ - id: lean-usage-ledger
235
+ name: 'dsh-lean-router/lean/usage-ledger'
236
+ config:
237
+ enabled: true
232
238
 
233
239
  # ============ 新增行:preset-lean-router-balance(balance 档 3 条;上游双预设形态,flash-lean-ptc-v3-balance 同构)============
234
240
 
@@ -405,6 +411,11 @@
405
411
  - id: tool-plugin-manager
406
412
  name: '@deepseek-ai/dsh-plugin-manager/tools'
407
413
  disabled: true
414
+ # live Usage 账本(balance 档同挂):见 lean 档同名行说明。
415
+ - id: lean-usage-ledger
416
+ name: 'dsh-lean-router/lean/usage-ledger'
417
+ config:
418
+ enabled: true
408
419
 
409
420
  # ============ 新增行:交付门(加料件)============
410
421
  # 默认关闭(enabled: false):它会执行工作区里的验收脚本,要用户显式打开
@@ -430,14 +441,3 @@
430
441
  toolConcurrency:
431
442
  enabled: true
432
443
 
433
- # ============ 新增行:live Usage 账本挂载点(加料件)============
434
- # 默认开启:订阅 session/event,采集带 usage 的 assistant/message(lib/token-ledger/live.js)。
435
- # 斜杠命令 token-report([session|all])读账本,输出记录条数、prompt 总量、五项分项与最近一条 turn/step/seq;
436
- # 无记录时返回 success 并提示尚未采集。插件实现 = lib/lean/usage-ledger.js;
437
- # 插件行 name 为包内子路径,需 package.json exports 增加 ./lean/usage-ledger(master 集成)。
438
-
439
- - insert:
440
- - id: lean-usage-ledger
441
- name: 'dsh-lean-router/lean/usage-ledger'
442
- config:
443
- enabled: true
@@ -223,6 +223,12 @@
223
223
  - id: tool-plugin-manager
224
224
  name: '@deepseek-ai/dsh-plugin-manager/tools'
225
225
  disabled: true
226
+ # live Usage 账本:订阅 session/event 采集带 usage 的 assistant/message,注册 /token-report 命令。
227
+ # 必须留在 preset 的 plugins 内(与 command-goal 同层)才拿得到 ctx.commands;实现 = lib/lean/usage-ledger.js。
228
+ - id: lean-usage-ledger
229
+ name: 'dsh-lean-router/lean/usage-ledger'
230
+ config:
231
+ enabled: true
226
232
 
227
233
  # ============ 新增行:preset-lean-router-balance(balance 档 3 条;上游双预设形态,flash-lean-ptc-v3-balance 同构)============
228
234
 
@@ -7,7 +7,7 @@
7
7
  // 本机陷阱(见 docs/agents/release.md):默认 registry 是 npmmirror,发布一律显式
8
8
  // --registry https://registry.npmjs.org;npm 的 notice 走 stderr,别据此判失败。
9
9
 
10
- import { execFileSync } from 'node:child_process';
10
+ import { execFileSync, execSync } from 'node:child_process';
11
11
  import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
12
12
  import { tmpdir } from 'node:os';
13
13
  import { join } from 'node:path';
@@ -35,13 +35,14 @@ function run(command, args, options = {}) {
35
35
  }
36
36
 
37
37
  function npm(args, options = {}) {
38
- // Windows 上 Node 不能直接 spawn .cmd(EINVAL),必须经 shell 执行;
39
- // 这里的参数都不含空格,所以 shell 拼接是安全的。
38
+ // Windows 上 Node 不能直接 spawn .cmd(EINVAL),必须经 shell 执行。
39
+ // 这里用 execSync 的字符串形式而不是 execFileSync + shell:true:后者会触发 DEP0190
40
+ // 警告写到 stderr,PowerShell 会把 stderr 当错误,让发布看起来失败。
41
+ // 传入的参数都不含空格,所以拼接是安全的。
40
42
  // npm 的 notice/progress 走 stderr,stdout 才是结果;统一只看退出码与 stdout。
41
- return execFileSync(NPM, args, {
43
+ return execSync([NPM, ...args].join(' '), {
42
44
  encoding: 'utf8',
43
45
  stdio: ['ignore', 'pipe', 'pipe'],
44
- shell: process.platform === 'win32',
45
46
  ...options,
46
47
  }).trim();
47
48
  }
@@ -26,9 +26,9 @@ function suffixBlock(text) {
26
26
  return out.join('\n');
27
27
  }
28
28
 
29
- test('frag-preset 是 preset 行唯一生效 owner:20 行并集、无重复、toolface 收尾', () => {
29
+ test('frag-preset 是 preset 行唯一生效 owner:21 行并集、无重复、toolface 收尾', () => {
30
30
  const ids = frag.split(/\r?\n/).filter(l => /^ - id: /.test(l)).map(l => /^ - id: (.+)$/.exec(l)[1].trim());
31
- assert.equal(ids.length, 20, '并集行数 = 覆写块 19 + toolface(2.0.0 移除 skill-lean-router;ptc-runtime 属宿主层,不进 preset)');
31
+ assert.equal(ids.length, 21, '并集行数 = 覆写块 20 + toolface(2.0.0 移除 skill-lean-router;2.2.0 加 lean-usage-ledger;ptc-runtime 属宿主层,不进 preset)');
32
32
  assert.equal(new Set(ids).size, ids.length, '无重复 id');
33
33
  assert.equal(ids[ids.length - 1], 'toolface', 'toolface 最后(遮蔽面与 preset 同行生效)');
34
34
  assert.ok(!ids.includes('ptc-runtime'), 'ptc-runtime 由宿主 dsh-base 挂载,放进 preset 会让整条 preset 激活失败(1.0.3 事故回归)');
@@ -14,8 +14,8 @@ test('分片存在且顶层为 YAML 块序列续项(首个非注释行为顶
14
14
  assert.ok(firstLine.startsWith('- '), '首个非注释行必须是顶层块序列项(- 开头),got: ' + firstLine);
15
15
  // 所有顶层项都在 0 列
16
16
  const topLevel = frag.split('\n').filter((l) => /^- /.test(l) || /^-insert/.test(l));
17
- assert.ok(topLevel.length >= 5, '至少 5 个顶层项(裸覆写行 + 4 个 insert 块)');
18
- assert.equal(frag.split('\n').filter((l) => l.startsWith('- ')).length, 5, '顶层项恰好 5 个:裸行 + balance + delivery-gate + concurrency + usage-ledger');
17
+ assert.ok(topLevel.length >= 4, '至少 4 个顶层项(裸覆写行 + 3 个 insert 块)');
18
+ assert.equal(frag.split('\n').filter((l) => l.startsWith('- ')).length, 4, '顶层项恰好 4 个:裸行 + balance + delivery-gate + concurrency(usage-ledger 已移入 preset plugins)');
19
19
  });
20
20
 
21
21
  test('裸覆写行重声明 preset-lean-router 完整 config(dsh-app-boot config 整键替换形态)', async () => {
@@ -20,7 +20,7 @@ function parseFile(path) {
20
20
  test("cordis.patch.yml 可被 dsh 等价解析器装载", () => {
21
21
  const doc = parseFile(join(root, "cordis.patch.yml"));
22
22
  assert.ok(Array.isArray(doc), "顶层必须是操作数组");
23
- assert.equal(doc.length, 9, "9 个顶层操作");
23
+ assert.equal(doc.length, 8, "8 个顶层操作");
24
24
  const rows = doc.flatMap((op) => op.insert ?? []);
25
25
  assert.ok(rows.some((row) => row.id === "preset-lean-router"), "含 preset-lean-router 行");
26
26
  });
@@ -0,0 +1,50 @@
1
+ // test/usage-ledger-inject.test.mjs —— 回归:未注入 commands 时读取属性会抛
2
+ // `cannot get property "commands" without inject`,宿主创建会话直接失败
3
+ // (agent-preset/invalid)。本测试用真实 cordis 加载插件,保证加载顺序不再致命。
4
+ import assert from 'node:assert/strict';
5
+ import test from 'node:test';
6
+ import { Context } from '@deepseek-ai/cordis';
7
+ import * as plugin from 'dsh-lean-router/lean/usage-ledger';
8
+
9
+ const tick = () => new Promise((resolve) => setTimeout(resolve, 20));
10
+
11
+ test('插件声明 commands 依赖(命名导出与默认导出同体)', () => {
12
+ assert.deepEqual(plugin.inject, ['commands'], 'inject 必须声明 commands');
13
+ assert.deepEqual(plugin.default.inject, ['commands'], '默认导出也要带 inject');
14
+ });
15
+
16
+ test('commands 尚未就绪时加载不抛错,服务出现后自动注册 /token-report', async () => {
17
+ const app = new Context();
18
+ const registered = [];
19
+ let thrown = null;
20
+
21
+ // 先加载插件、后提供 commands:正是 2.2.1 里让宿主报 agent-preset/invalid 的顺序。
22
+ try {
23
+ app.plugin(plugin, {});
24
+ } catch (error) {
25
+ thrown = error;
26
+ }
27
+ await tick();
28
+ assert.equal(thrown, null, '加载阶段不得抛错');
29
+ assert.deepEqual(registered, [], 'commands 缺席时不应注册任何命令');
30
+
31
+ app.provide('commands', {
32
+ register(command) {
33
+ registered.push(command.name);
34
+ },
35
+ });
36
+ await tick();
37
+ assert.deepEqual(registered, ['token-report'], 'commands 出现后应挂上 /token-report');
38
+ });
39
+
40
+ test('commands 始终缺席时保持静默:不抛错、不注册', async () => {
41
+ const app = new Context();
42
+ let thrown = null;
43
+ try {
44
+ app.plugin(plugin, {});
45
+ } catch (error) {
46
+ thrown = error;
47
+ }
48
+ await tick();
49
+ assert.equal(thrown, null, '没有命令缝也不能打断宿主');
50
+ });