dsh-lean-router 1.0.5 → 1.0.7

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.
@@ -1,6 +1,19 @@
1
1
  # Changelog
2
2
 
3
- > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 1.0.5).
3
+ > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 1.0.7).
4
+
5
+ ## 1.0.7 (2026-11-24)
6
+
7
+ - Fixed (critical, client side, on a real install): how `lib/client.js` obtains the slot service. In the client-side cordis, `slots` and `register` are **services**: reading `ctx.register` / `ctx.slots` directly throws `Error: cannot get property "register" without inject`. The old code performed that property access outside a `try`, so the whole `apply` failed and even the pure-DOM fallback never ran - which is exactly why the header "Skills" button never appeared (real 0.2.3 console text: `dsh-lean-router: failed: Error: cannot get property "register" without inject`). It now follows the `dsh-cost-meter` shape: `const slots = ctx.get("slots")`, then `slots.inject(slot, () => slots.register(spec, Component))`; the DOM fallback only runs when the service is missing.
8
+ - New regression: `test/client-plugin.test.mjs` loads the real `lib/client.js` behind a fake `window.__ModuleLoader__`, with a ctx whose `register` / `slots` properties throw on read; it asserts registration goes through `ctx.get("slots")` and returns a disposer, and that the missing-service path really appends `#lean-router-dom-fallback`. 220 tests green.
9
+
10
+ ## 1.0.6 (2026-11-23)
11
+
12
+ > 1.0.5 is already on npm, but the two defects below only surfaced the first time it was activated on a real 0.2.3 host. Use 1.0.6 instead.
13
+
14
+ - Fixed (critical, on a real install): the `inject` shape in `lib/index.js`. cordis accepts only two shapes - an array of service names, or a "service name to intercept config" map (`registry.ts: Inject<M> = (keyof M)[] | { [K in keyof M]?: M[K] }`). The `{ required: [], optional: ["skills"] }` written in 1.0.5 was parsed as two services named `required` and `optional`, so the host row `lean-router-client-host` stayed PENDING forever (real diagnostic: `pending (waiting for services: required, optional)`) and `apply` never ran: `dsh-client-modules` never scanned the client bundle (no header button) and the boot self-check `boot.log` was never written. Now `inject = []` with `ctx.inject(["skills"], cb)` inside `apply`: the host row activates immediately and the preset row registers the provider once `skills` is available.
15
+ - Fixed (critical, on a real install): `/panel` had an empty `input.hint`. On 0.2.3 `@deepseek-ai/dsh-commands` throws `TypeError: command "panel" input hint must not be empty` from `normalizeDefinition`, which kept the whole `lean-router-commands` entry from activating. It is now `[summary|skills|round|stats|never] [all]`, matching what `parsePanelArgs` actually accepts.
16
+ - New regressions: `test/plugin-entry.test.mjs` asserts the inject shape (no `required`/`optional` keys), that the host scope never touches `skills`, that the preset scope goes through `ctx.inject`, and the no-`ctx.inject` fallback; `test/router.test.mjs` asserts every command's input hint is non-empty. 218 tests green.
4
17
 
5
18
  ## 1.0.5 (2026-11-23)
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(当前 1.0.5)。
3
+ > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 1.0.7)。
4
+
5
+ ## 1.0.7 (2026-11-24)
6
+
7
+ - 修复(真机致命,客户端):`lib/client.js` 取 slot 服务的方式。客户端 cordis 里 `slots` / `register` 都是**服务**,直接读 `ctx.register` / `ctx.slots` 会抛 `Error: cannot get property "register" without inject`;旧代码把这个属性访问写在 `try` 之外,一抛就整个 `apply` 失败,连纯 DOM 兜底都跑不到 —— 这正是顶栏「技能」按钮一直不出现的真因(0.2.3 控制台原文:`dsh-lean-router: failed: Error: cannot get property "register" without inject`)。改为与 `dsh-cost-meter` 一致的写法:`const slots = ctx.get("slots")`,再 `slots.inject(slot, () => slots.register(spec, Component))`;服务缺失时才退回 DOM 兜底。
8
+ - 新增回归:`test/client-plugin.test.mjs` 用假 `window.__ModuleLoader__` 加载真实 `lib/client.js`,ctx 的 `register` / `slots` 属性被故意设成「一读就抛」,断言注册只走 `ctx.get("slots")` 且返回 disposer;另一条断言服务缺失时确实插入了 `#lean-router-dom-fallback` 按钮。220 测试全绿。
9
+
10
+ ## 1.0.6 (2026-11-23)
11
+
12
+ > 1.0.5 已发到 npm,但下面两处缺陷是它在 0.2.3 真机**首次激活**时才暴露的,请直接用 1.0.6。
13
+
14
+ - 修复(真机致命):`lib/index.js` 的 `inject` 形状。cordis 的 inject 只有两种形状 —— 服务名数组,或「服务名 → 拦截配置」映射(`registry.ts: Inject<M> = (keyof M)[] | { [K in keyof M]?: M[K] }`)。1.0.5 写的 `{ required: [], optional: ["skills"] }` 被解析成两个叫 `required` / `optional` 的服务,宿主层 `lean-router-client-host` 永远 PENDING(实机诊断:`pending (waiting for services: required, optional)`),`apply` 不执行 → 客户端 bundle 不被 `dsh-client-modules` 扫描(顶栏按钮不出现)、启动自检 `boot.log` 从不生成。改为 `inject = []` + `apply` 内 `ctx.inject(["skills"], cb)`:宿主层立即激活,预设层等 skills 就绪后再注册 provider。
15
+ - 修复(真机致命):`/panel` 的 `input.hint` 是空字符串。0.2.3 的 `@deepseek-ai/dsh-commands` 在 `normalizeDefinition` 里对空 hint 抛 `TypeError: command "panel" input hint must not be empty`,整条 `lean-router-commands` 因此不激活。改为 `[summary|skills|round|stats|never] [all]`(与 `parsePanelArgs` 实际接受的参数一致)。
16
+ - 新增回归:`test/plugin-entry.test.mjs` 断言 inject 形状(不得出现 required/optional 键)、宿主作用域不碰 skills、预设作用域走 `ctx.inject`、无 `ctx.inject` 时退化;`test/router.test.mjs` 增加「每个命令的 input hint 都非空」断言。218 测试全绿。
4
17
 
5
18
  ## 1.0.5 (2026-11-23)
6
19
 
@@ -20,7 +20,7 @@ After restarting DSH, pick the **Lean router** preset (lean tier) or **Lean rout
20
20
  ### Path B: npm install (recommended)
21
21
 
22
22
  ~~~powershell
23
- dsh plugin --profile desktop add npm:dsh-lean-router@1.0.5
23
+ dsh plugin --profile desktop add npm:dsh-lean-router@1.0.7
24
24
  ~~~
25
25
 
26
26
  (Both paths match the output of scripts/install.mjs; the real installer, claim boundaries and `--uninstall` rollback belong to ticket 09.)
@@ -20,7 +20,7 @@ dsh plugin --profile desktop add "link:D:\path\to\dsh-lean-router"
20
20
  ### 路径 B:npm 安装(推荐)
21
21
 
22
22
  ~~~powershell
23
- dsh plugin --profile desktop add npm:dsh-lean-router@1.0.5
23
+ dsh plugin --profile desktop add npm:dsh-lean-router@1.0.7
24
24
  ~~~
25
25
 
26
26
  (两条路径与 scripts/install.mjs 输出的说明一致;真安装器、认领边界与 `--uninstall` 回滚归票 09。)
package/lib/client.js CHANGED
@@ -149,45 +149,44 @@ window.__ModuleLoader__.load({
149
149
  document.body.appendChild(btn);
150
150
  }
151
151
 
152
+ // 0.2.3 真机事实(对照 dsh-cost-meter 的 lib/client.js):
153
+ // const slots = ctx.get("slots")
154
+ // slots.inject(slotName, () => slots.register({ name, id, order }, Component))
155
+ // `slots` / `register` 都是客户端 cordis 的服务;直接读 ctx.register / ctx.slots 会抛
156
+ // Error: cannot get property "register" without inject。取服务的唯一安全姿势是 ctx.get(name)。
157
+ //
158
+ // 1.0.7 修(真机):旧代码把 `typeof ctx.register === "function"` 写在 try 之外,属性访问
159
+ // 直接抛错 → 整个 apply 失败 → 连 DOM 兜底都跑不到(顶栏没按钮的真因,控制台原文:
160
+ // dsh-lean-router: failed: Error: cannot get property "register" without inject)。
152
161
  const SLOTS = ["conversation.session.header.actions", "conversation.session.header.utilities"];
153
162
 
154
- /**
155
- * 注册按钮。按参考实现的优先级依次尝试,每条路径独立 try,互不阻塞。
156
- * 1) ctx.inject(slot, () => ctx.register(spec, C)) —— dsh-cost-meter 的真实写法
157
- * 2) ctx.slots.inject(slot, () => ctx.slots.register(spec, C))
158
- * 3) ctx.slots.register(spec, C) —— 原实现
159
- */
160
163
  function apply(ctx) {
161
164
  const disposers = [];
162
- const tryRegister = (slot, fn) => {
165
+ let slots;
166
+ try {
167
+ slots = typeof ctx.get === "function" ? ctx.get("slots") : undefined;
168
+ } catch (err) {
163
169
  try {
164
- const d = fn();
165
- if (typeof d === "function") disposers.push(d);
166
- return true;
167
- } catch (err) {
170
+ console.warn("[lean-router] ctx.get('slots') failed", err);
171
+ } catch {}
172
+ }
173
+
174
+ if (slots !== undefined && typeof slots.inject === "function" && typeof slots.register === "function") {
175
+ for (const slot of SLOTS) {
176
+ const spec = { name: slot, id: "lean-router.skills", order: 60 };
168
177
  try {
169
- console.warn("[lean-router] register failed on", slot, err);
170
- } catch {}
171
- return false;
178
+ const dispose = slots.inject(slot, () => slots.register(spec, SkillsButton));
179
+ if (typeof dispose === "function") disposers.push(dispose);
180
+ break;
181
+ } catch (err) {
182
+ try {
183
+ console.warn("[lean-router] register failed on", slot, err);
184
+ } catch {}
185
+ }
172
186
  }
173
- };
174
-
175
- for (const slot of SLOTS) {
176
- const spec = { name: slot, id: "lean-router.skills", order: 60 };
177
- const ok =
178
- (typeof ctx.inject === "function" &&
179
- typeof ctx.register === "function" &&
180
- tryRegister(slot, () => ctx.inject(slot, () => ctx.register(spec, SkillsButton)))) ||
181
- (ctx.slots &&
182
- typeof ctx.slots.inject === "function" &&
183
- tryRegister(slot, () => ctx.slots.inject(slot, () => ctx.slots.register(spec, SkillsButton)))) ||
184
- (ctx.slots &&
185
- typeof ctx.slots.register === "function" &&
186
- tryRegister(slot, () => ctx.slots.register(spec, SkillsButton)));
187
- if (ok) break;
188
187
  }
189
188
 
190
- // 诊断兜底:所有 slot 路径都失败时,用纯 DOM 在右上角插一个悬浮按钮。
189
+ // 诊断兜底:slots 服务缺失或所有 slot 路径都失败时,用纯 DOM 在右上角插一个悬浮按钮。
191
190
  // 目的不是最终形态,而是区分「bundle 没加载」与「slot API 不对」这两类失败。
192
191
  if (disposers.length === 0) {
193
192
  try {
package/lib/index.js CHANGED
@@ -3,9 +3,16 @@
3
3
  // 1.0.5 修:宿主层需要以裸包名 dsh-lean-router 挂一行,否则 dsh-client-modules 扫不到本包
4
4
  // 的 dsh.client 声明,客户端 bundle 不会加载(顶栏按钮因此不出现)。
5
5
  //
6
- // 但原来的 inject = ["skills"] 会让宿主层那一行永远停在“等待依赖”——skills 服务由预设里的
6
+ // 但 inject = ["skills"] 会让宿主层那一行永远停在“等待依赖”——skills 服务由预设里的
7
7
  // @deepseek-ai/dsh-skill-filesystem 提供,宿主作用域没有它。插件不 apply,扫描就看不到活跃
8
- // 条目。改为可选依赖:宿主层照常 apply(只写自检),预设层照常注册 provider。
8
+ // 条目。
9
+ //
10
+ // 1.0.6 修:cordis 的 inject 只有两种形状——服务名数组,或「服务名 → 拦截配置」映射
11
+ // (registry.ts: Inject<M> = (keyof M)[] | { [K in keyof M]?: M[K] })。写成
12
+ // { required: [], optional: ["skills"] } 会被当成两个叫 required / optional 的服务,
13
+ // 宿主层那行永远 PENDING(0.2.3 实机诊断:pending (waiting for services: required, optional))。
14
+ // 改为「无必需依赖」+ apply 内 ctx.inject(["skills"], …):宿主层立刻激活(客户端 bundle 才会
15
+ // 被 dsh-client-modules 扫到),预设层等 skills 就绪后再注册 provider。
9
16
  import { appendFileSync, mkdirSync } from "node:fs";
10
17
  import { homedir } from "node:os";
11
18
  import { join } from "node:path";
@@ -13,7 +20,7 @@ import { makeProvider } from "./skill-provider.js";
13
20
  import { getAuditChannel } from "./skillgate.js";
14
21
 
15
22
  export const name = "skill-lean-router";
16
- export const inject = { required: [], optional: ["skills"] };
23
+ export const inject = [];
17
24
 
18
25
  /** 启动自检:把宿主层是否 apply、ctx 上有哪些能力,写进 ~/.dsh/lean-router/boot.log。 */
19
26
  function probe(line) {
@@ -39,10 +46,19 @@ export function apply(ctx, options) {
39
46
  } catch {}
40
47
 
41
48
  if (cfg.provider === false) return;
42
- if (!ctx.skills || typeof ctx.skills.registerProvider !== "function") {
43
- probe("skip provider: ctx.skills 不可用(宿主作用域属正常)");
44
- return;
49
+ const register = (scope) => {
50
+ if (!scope.skills || typeof scope.skills.registerProvider !== "function") {
51
+ probe("skip provider: ctx.skills 不可用(宿主作用域属正常)");
52
+ return;
53
+ }
54
+ const rank = typeof cfg.rank === "number" ? cfg.rank : 350;
55
+ scope.skills.registerProvider(() => makeProvider({ rank, audit: getAuditChannel() }));
56
+ };
57
+ // ctx.inject(deps, cb):服务可用后运行 cb,服务变化时自动重跑(cordis 官方语义)。
58
+ // 返回值是子 fiber,apply 必须继续返回 undefined,别把 fiber 当 effect 交回去。
59
+ if (typeof ctx.inject === "function") {
60
+ ctx.inject(["skills"], register);
61
+ } else {
62
+ register(ctx);
45
63
  }
46
- const rank = typeof cfg.rank === "number" ? cfg.rank : 350;
47
- ctx.skills.registerProvider(() => makeProvider({ rank, audit: getAuditChannel() }));
48
64
  }
package/lib/router.js CHANGED
@@ -397,7 +397,7 @@ export function apply(ctx, options) {
397
397
  ctx.commands.register({
398
398
  name: "panel",
399
399
  description: "Skill panel: 31 skills with switches, current round hit scores and history stats",
400
- input: { hint: "" },
400
+ input: { hint: "[summary|skills|round|stats|never] [all]" },
401
401
  handler: (invocation) =>
402
402
  executeSkillsPanelCommand(invocation, {
403
403
  auditPath: cfg.auditPath ?? defaultAuditPath(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lean-router",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽 × mattpocock 技能自动调用的 DSH cordis 插件(单 bundle:预设+配套技能)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -0,0 +1,70 @@
1
+ // dsh-lean-router 1.0.7 —— 客户端插件(lib/client.js)的服务获取回归。
2
+ // 背景(0.2.3 真机,控制台原文):
3
+ // dsh-lean-router: failed: Error: cannot get property "register" without inject
4
+ // 客户端 cordis 里 slots / register 都是服务,直接读 ctx.register 会抛错;正确姿势是
5
+ // ctx.get("slots"),再 slots.inject(slot, () => slots.register(spec, Component))。
6
+ // 旧代码把 typeof ctx.register 写在 try 之外,一抛就整个 apply 失败,连 DOM 兜底都跑不到。
7
+ import test from "node:test";
8
+ import assert from "node:assert/strict";
9
+
10
+ let registration;
11
+ globalThis.window = { __ModuleLoader__: { load(reg) { registration = reg; } } };
12
+ await import("../lib/client.js");
13
+
14
+ const React = {
15
+ createElement: (type, props, ...children) => ({ type, props, children }),
16
+ Fragment: "Fragment",
17
+ useState: (value) => [value, () => {}],
18
+ useCallback: (fn) => fn,
19
+ };
20
+
21
+ function makePlugin() {
22
+ return registration.factory((id) => {
23
+ if (id === "react") return React;
24
+ throw new Error("unexpected require: " + id);
25
+ });
26
+ }
27
+
28
+ /** 一个访问 slots / register 属性就会抛错的 ctx,复刻客户端 cordis 的行为。 */
29
+ function makeCtx(slots) {
30
+ return {
31
+ get(name) { return name === "slots" ? slots : undefined; },
32
+ get register() { throw new Error('cannot get property "register" without inject'); },
33
+ get slots() { throw new Error('cannot get property "slots" without inject'); },
34
+ };
35
+ }
36
+
37
+ test("apply 只通过 ctx.get('slots') 取服务,注册到头栏 slot 并返回 disposer", () => {
38
+ const registered = [];
39
+ const slots = {
40
+ inject(name, cb) { cb(); return () => {}; },
41
+ register(spec, component) { registered.push({ spec, component }); return () => {}; },
42
+ };
43
+ const dispose = makePlugin().apply(makeCtx(slots));
44
+ assert.equal(typeof dispose, "function");
45
+ assert.equal(registered.length, 1);
46
+ assert.equal(registered[0].spec.name, "conversation.session.header.actions");
47
+ assert.equal(registered[0].spec.id, "lean-router.skills");
48
+ assert.equal(typeof registered[0].component, "function");
49
+ });
50
+
51
+ test("slots 服务缺失时退回纯 DOM 兜底,而不是抛错", () => {
52
+ const appended = [];
53
+ const fakeDocument = {
54
+ body: { appendChild(node) { appended.push(node); } },
55
+ getElementById() { return undefined; },
56
+ createElement(tag) {
57
+ return { tag, style: {}, addEventListener() {}, remove() {} };
58
+ },
59
+ };
60
+ globalThis.document = fakeDocument;
61
+ try {
62
+ const dispose = makePlugin().apply(makeCtx(undefined));
63
+ assert.equal(typeof dispose, "function");
64
+ assert.equal(appended.length, 1, "兜底按钮必须被插进 body");
65
+ assert.equal(appended[0].tag, "button");
66
+ assert.equal(appended[0].id, "lean-router-dom-fallback");
67
+ } finally {
68
+ delete globalThis.document;
69
+ }
70
+ });
@@ -0,0 +1,61 @@
1
+ // dsh-lean-router 1.0.6 —— 包入口(lib/index.js)的 cordis 契约回归。
2
+ // 背景(0.2.3 真机):inject 写成 { required: [], optional: ["skills"] } 会被 cordis 当成
3
+ // 两个叫 required / optional 的服务,宿主层那行永远 PENDING,apply 不跑,客户端 bundle
4
+ // 不被扫描,顶栏按钮不出现。cordis 的 inject 只有两种形状:
5
+ // Inject<M> = (keyof M)[] | { [K in keyof M]?: M[K] } (registry.ts L19)
6
+ import test from "node:test";
7
+ import assert from "node:assert/strict";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+
11
+ import * as entry from "../lib/index.js";
12
+
13
+ /** 把 homedir() 指向临时目录,避免自检日志写进真实用户目录。 */
14
+ function withTempHome(fn) {
15
+ const saved = process.env.USERPROFILE;
16
+ process.env.USERPROFILE = join(tmpdir(), "dsh-lean-router-test-home");
17
+ try {
18
+ return fn();
19
+ } finally {
20
+ if (saved === undefined) delete process.env.USERPROFILE;
21
+ else process.env.USERPROFILE = saved;
22
+ }
23
+ }
24
+
25
+ test("inject 是 cordis 认的形状,不能出现 required/optional 键", () => {
26
+ if (Array.isArray(entry.inject)) return;
27
+ assert.equal(typeof entry.inject, "object", "inject 必须是数组或服务名映射");
28
+ const keys = Object.keys(entry.inject);
29
+ assert.ok(
30
+ !keys.includes("required") && !keys.includes("optional"),
31
+ "inject 被当成服务名映射后出现了 required/optional 键:" + keys.join(","),
32
+ );
33
+ });
34
+
35
+ test("宿主作用域:provider:false 时不碰 skills,apply 返回 undefined", () => {
36
+ withTempHome(() => {
37
+ const ctx = { inject() { throw new Error("provider:false 不该调用 ctx.inject"); } };
38
+ assert.equal(entry.apply(ctx, { provider: false }), undefined);
39
+ });
40
+ });
41
+
42
+ test("预设作用域:用 ctx.inject 等 skills 就绪,而不是把它写进必需依赖", () => {
43
+ withTempHome(() => {
44
+ const calls = [];
45
+ const ctx = { inject(deps, cb) { calls.push({ deps, cb }); } };
46
+ assert.equal(entry.apply(ctx, {}), undefined, "apply 不能把 ctx.inject 的 fiber 当 effect 交回去");
47
+ assert.equal(calls.length, 1);
48
+ assert.deepEqual(calls[0].deps, ["skills"]);
49
+ let registered = null;
50
+ calls[0].cb({ skills: { registerProvider(factory) { registered = factory; } } });
51
+ assert.equal(typeof registered, "function", "skills 就绪后必须注册 provider");
52
+ });
53
+ });
54
+
55
+ test("没有 ctx.inject 时退化为直接注册(老宿主兼容)", () => {
56
+ withTempHome(() => {
57
+ let registered = null;
58
+ entry.apply({ skills: { registerProvider(factory) { registered = factory; } } }, {});
59
+ assert.equal(typeof registered, "function");
60
+ });
61
+ });
@@ -79,6 +79,18 @@ test("apply 默认注册 hooks 与 commands", async () => {
79
79
  assert.ok(commands.has("skill"));
80
80
  });
81
81
 
82
+ test("每个命令的 input hint 都非空(宿主 normalizeDefinition 会抛 TypeError)", async () => {
83
+ // 1.0.6 回归:/panel 曾用 input:{hint:""},0.2.3 真机报
84
+ // TypeError: command "panel" input hint must not be empty,整条 lean-router-commands 不激活。
85
+ const { commands } = await routedSetup({});
86
+ assert.ok(commands.size >= 4, "band / skill / panel / lean-audit 都应注册");
87
+ for (const [name, def] of commands) {
88
+ if (def.input === undefined) continue;
89
+ assert.equal(typeof def.input.hint, "string", name + " 的 input.hint 必须是字符串");
90
+ assert.ok(def.input.hint.trim().length > 0, "命令 " + name + " 的 input hint 不能为空");
91
+ }
92
+ });
93
+
82
94
  test("options 分流:hooks:false 只留命令;commands:false 只留钩子", async () => {
83
95
  const a = await routedSetup({ hooks: false });
84
96
  assert.ok(!a.handlers.has("agent/inbox/claimed"));