dsh-lean-router 2.2.1 → 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.
@@ -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
 
@@ -2,6 +2,13 @@
2
2
 
3
3
  > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 2.2.1).
4
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
+
5
12
  ## 2.2.1 (2026-11-29)
6
13
 
7
14
  ### Fixed
package/docs/changelog.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 2.2.1)。
4
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
+
5
12
  ## 2.2.1 (2026-11-29)
6
13
 
7
14
  ### 修复
@@ -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.1",
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",
@@ -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
+ });