dsh-lean-router 1.0.4 → 1.0.5

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.en.md CHANGED
@@ -21,7 +21,7 @@ A DeepSeek Harness (DSH) cordis plugin tuned for DeepSeek V4.1 Flash: **one plug
21
21
 
22
22
  ## Target DSH
23
23
 
24
- engines: `>=0.2.1-rc.5 <0.2.3-0` (measured baseline 0.2.2-rc.5). DSH is in developer preview; breaking changes are handled by the engines gate + the doctor self-check + a warn banner, never by silent degradation.
24
+ engines: `>=0.2.1-rc.5 <0.2.4-0` (measured baseline 0.2.3-alpha.2, still compatible back to 0.2.1-rc.5). DSH is in developer preview; breaking changes are handled by the engines gate + the doctor self-check + a warn banner, never by silent degradation.
25
25
 
26
26
  ## Install
27
27
 
package/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  ## 目标 DSH
23
23
 
24
- engines:`>=0.2.1-rc.5 <0.2.3-0`(实测基线 0.2.2-rc.5)。DSH 处于 developer preview,破坏性变更将以 engines 闸 + doctor 自检 + warn 黄条应对,不做静默降级。
24
+ engines:`>=0.2.1-rc.5 <0.2.4-0`(实测基线 0.2.3-alpha.2,兼容回 0.2.1-rc.5)。DSH 处于 developer preview,破坏性变更将以 engines 闸 + doctor 自检 + warn 黄条应对,不做静默降级。
25
25
 
26
26
  ## 安装
27
27
 
package/cordis.patch.yml CHANGED
@@ -569,12 +569,20 @@
569
569
  # 入口子路径 dsh-lean-router/router 需要 package.json exports 增补 "./router": "./lib/router.js"
570
570
  # (package.json 为共享文件,由 master 统一集成;见 lib/router.js ROUTER_INJECTION_NOTES.patchEntry)
571
571
  - insert:
572
+ # 1.0.5 修:宿主层裸包名行(对照 dsh-cost-meter 的 "one host row")。
573
+ # 没有这一行,客户端模块扫描看不到 dsh.client -> 客户端 bundle 不加载 -> 无顶栏按钮。
574
+ # config.provider=false:不重复注册 skill provider(预设层已注册)。
575
+ - id: lean-router-client-host
576
+ name: dsh-lean-router
572
577
  - id: lean-router-router
573
578
  name: dsh-lean-router/router
574
579
  config:
575
580
  hooks: true
576
581
  commands: false
577
582
  diligenceEvery: 10
583
+ # 1.0.5 修:每轮门控必须开,否则 skillgate 不跑 -> 审计零条目、审计文件从不生成。
584
+ # 依据 lib/router.js:345(cfg.hooks && cfg.gate 才建 runner)与 lib/router.js:194。
585
+ gate: true
578
586
  - id: lean-router-commands
579
587
  name: dsh-lean-router/router
580
588
  config:
@@ -0,0 +1,155 @@
1
+ # 交接:dsh-lean-router(技能面板 B 路进行中)
2
+
3
+ 日期:2026-11-22 | 仓库:`D:\Agent Workspace\dsh-lean-router`(branch main)
4
+
5
+ ## 一句话现状
6
+
7
+ 1.0.4 **已发布到 npm 并装进用户 dsh**(`/band` 可视化改造 + 技能面板阶段 1 客户端骨架);**正等用户重启验证顶栏「技能」按钮**。
8
+
9
+ ## 立即要做的(下个会话第一件事)
10
+
11
+ **问用户:重启 dsh 后,顶栏右侧有没有出现「技能」按钮,点了会不会弹出「技能面板 · 骨架」。**
12
+
13
+ - 出现 → 阶段 1 成功,直接进阶段 2(接 31 技能真实数据)
14
+ - 没出现 → 查客户端加载日志;重点怀疑 `dsh.client` 扫描是否覆盖到本包
15
+ - 白屏/报错 → **立刻回滚**(见文末「回滚」),再用更小的步子重试
16
+
17
+ ## 已完成
18
+
19
+ ### A. /band 可视化改造(1.0.4,已发布 npm)
20
+
21
+ 按用户三选定的样式改完,实机预览已确认:
22
+
23
+ ```
24
+ ▲ react · 已按首条消息分类,关键词不再改带 · 可选 spec / react / weak
25
+
26
+ | 档位 | 定位 | 工具面 |
27
+ |---|---|---|
28
+ | auto | 按首条用户消息自动分类 | — |
29
+ | spec | 先查后改(读优先) | 窄 |
30
+ | **▲ react** | 直接产出(写优先) | 宽 |
31
+ | weak | 交给模型自判 | 窄 |
32
+
33
+ 最近一次自动分类:react(build 词 6 · fix 词 0;命中 写一个、游戏、从零)
34
+ 用法:/band spec | react | weak | auto · /band react task=发布 MVP · /band help
35
+ ```
36
+
37
+ 改动点:
38
+ - `lib/bands.js`:新增 `explainClassification(text)` → `{band, reactHits, specHits, signals}`;`classifyTask` 变成它的薄封装(分类结果与 1.0.3 逐字符一致)
39
+ - `lib/router.js`:state 增加 `manual`(手动指定 vs 自动分类)与 `last`(最近一次关键词分类结果);`/band` 无参 = `/band help` 输出状态面板;改档确认 = `▲ x · 已切换`
40
+ - `test/router.test.mjs`:断言升级为「第一行是状态 / 有三带表格 / 当前档位粗体 ▲ / 无消息时明确说明」
41
+ - 版本与文档 bump 到 1.0.4(package.json、README 双语、changelog 双语、quickstart 双语)
42
+ - `npm run verify` PASS,`npm test` 203/202 pass/0 fail/1 skip
43
+
44
+ ### B. 技能面板:阶段 1 客户端骨架(提交 `0b1fc3e`)
45
+
46
+ - 新增 `lib/client.js`(约 4.3KB):顶栏「技能」按钮 + 用 `ReactDOM.createPortal` 挂到 body 的全屏浮层
47
+ - `package.json`:加 `dsh.client = { platform: "web" }` 与 `exports["./client"] = { default: "./lib/client.js" }`
48
+ - 离线验证全过:`node --check` 通过;用假 `__ModuleLoader__` + fake react 跑通「load 被调用 → factory 返回 apply → 注册到 `conversation.session.header.utilities` → 组件可渲染」
49
+ - **通过 npm 正式安装**:`dsh plugin --profile desktop add npm:dsh-lean-router@1.0.4`(exit 0,1.0.3 → 1.0.4);已安装副本核对:`dsh.client` ✓、`exports['./client']` ✓、`lib/client.js` 4295B ✓、patch 无 `ptc-runtime` ✓
50
+ - ⚠️ 早期手工部署时的备份 `package.json.orig-1.0.3` **已被 npm 安装清掉**,别再指望它
51
+
52
+ ## 阻塞项
53
+
54
+ ### ~~1. npm 发布 403~~(已解决)
55
+
56
+ 旧的 granular token 能 `whoami` 但无发布所需的 2FA bypass 权限 → `npm publish` 403。用户提供了一个新的 granular token 后**发布成功**(exit 0,75 秒后 registry 可下载)。注意:那个 token 已出现在对话记录里,**用户被建议去 npmjs.com 撤销**;下次发布若再 403,须在生成 token 时勾上「Bypass two-factor authentication」。
57
+
58
+ ### 2. 阶段 1 真机验证(等用户重启)
59
+
60
+ ## 技能面板方案(已与用户拍板)
61
+
62
+ 用户明确要求:**不要侧边栏、不要命令输出,要独立面板** → 选 B 路「dsh 内置 tab/浮层面板」,接受 2–3 天成本。
63
+
64
+ 阶段划分(每阶段单独验收):
65
+
66
+ | 阶段 | 内容 | 验收 | 状态 |
67
+ |---|---|---|---|
68
+ | 1 | 客户端插件骨架(按钮 + 空面板) | 重启后能看到按钮与面板 | 代码完成,**等用户重启验证** |
69
+ | 2 | 数据通道:31 技能 + 审计统计 | 面板里看到 31 个技能名 | 未开始 |
70
+ | 3 | 面板 UI:分组表 + 开关 + 命中分 + 历史统计 + 6 条工作流 | 可日常使用 | 未开始 |
71
+
72
+ 面板必须显示的四类信息(用户点名):31 技能清单+功能说明、每个技能开关(model/user/关闭)、本轮/最近命中分与依据、历史命中统计(哪些从没用过)。
73
+
74
+ ### 已确认的 6 套一键工作流
75
+
76
+ | 名字 | 技能序列 |
77
+ |---|---|
78
+ | 审查 review | code-review → grilling |
79
+ | 提质 harden | improve-codebase-architecture → codebase-design → domain-modeling |
80
+ | 修 bug fix | diagnosing-bugs → tdd → code-review |
81
+ | 计划 plan | grilling → to-spec → to-tickets |
82
+ | 开工 build | implement → tdd → code-review → pr |
83
+ | 复盘 retro | retro(会话级) |
84
+
85
+ ## 客户端插件技术契约(本次逆向所得,别重新踩)
86
+
87
+ - 入口文件 `lib/client.js`,形式:`window.__ModuleLoader__.load({ id: "包名", factory: (require) => { ... return { apply } } })`
88
+ - `factory(require)` 里的 `require` 取**宿主提供的模块**:`react`、`react-dom`、`react/jsx-runtime`、`@deepseek-ai/dsh-client-ui-primitives` 等;插件自身依赖不打包
89
+ - 插件导出 `{ apply, inject }`(cordis 形);`apply` 可为 generator,`yield` 的 effect 卸载时自动回收
90
+ - UI 注册:`ctx.slots.register({ name, id, order }, Component)`;另有 `ctx.inject(slotName, () => ctx.register({...}, C))` 写法(dsh-cost-meter 用后者)
91
+ - 正文视图 API 另有一条:`ctx.uiConversation.views.register({ target, ... })`(dsh-client-ui-trajectory 用),但它是会话事件流视图,静态面板不建议走
92
+ - 加载条件:`dsh-client-modules` 扫描**宿主 Loader entries** 中声明了 `dsh.client` 的包,且要求 `exports["./client"]` 存在,否则抛「client bundle not found; run `pnpm run build` before launch」
93
+ - 参考实现(npm 安装目录里可反编译看):`dsh-cost-meter`、`dsh-ops`、`dsh-smooth-stream`
94
+
95
+ ### 可用的非侧边栏 slot(已枚举 614 个中的关键几个)
96
+
97
+ - `conversation.session.header.utilities` ← 顶栏工具区(当前阶段 1 用它)
98
+ - `conversation.input.overlay` ← 输入框上方浮层(官方 `/` 命令面板同位置)
99
+ - `shell.overlay` ← 全屏遮罩层
100
+ - `conversation.chat.turnTail` ← 每条回答下方
101
+ - `settings.section` ← 设置页分区
102
+ - `conversation.session.header.views.actions` ← 正文 tab 切换区
103
+
104
+ ## 数据通路(阶段 2 直接用)
105
+
106
+ - 技能目录:`ctx.skills.list({ scope: agent })`(宿主侧)→ 含 name/description/invocation
107
+ - 技能开关与中文分类:`assets/skills.matrix.json`(`_meta` + `skills[]`,每项有 `model`/`user`/`scenario`/`scenarioZh`/`note`;计数 13 both / 10 modelOnly / 8 userOnly)
108
+ - 最近一轮命中:`getAuditChannel().entries()`(内存环形 256 条,每条形如 `{seq, kind:"skillgate-round", scores, decision, band, complex}`)
109
+ - 历史统计:审计 JSONL 落盘,读法见 `lib/audit-sink.js` 的 `readAuditEntries`,`lib/audit-commands.js` 已用它做 `/lean-audit stats`
110
+ - **审计已开启**:`cordis.patch.yml:585` 是 `audit: true`,所以面板一开始就有真实数据(用户特意要求确认这点)
111
+
112
+ ## 关键文件
113
+
114
+ - `lib/router.js`:`/band` `/skill` `/lean-audit` 注册与实现;`capture`(状态机)、`guideTextFor`(近场文本)
115
+ - `lib/bands.js`:三带配置表、关键词词表、`classifyTask`/`explainClassification`、`parseRouterDirective`
116
+ - `lib/skillgate.js`:打分/分档/裁决/软降/审计通道(`createAuditChannel`、`getAuditChannel`、`round`)
117
+ - `lib/gate-runner.js`:每轮门控接线(`gate: true` 才创建)
118
+ - `lib/client.js`:**新增**,客户端插件
119
+ - `cordis.patch.yml`:装配产物(`presets/base/*.yml` + `scripts/integrate-preset.mjs` 生成,勿手改)
120
+ - `assets/skills.matrix.json`:31 技能开关与场景
121
+ - `assets/skills/`:31 个技能目录(frontmatter 里有英文 description)
122
+
123
+ ## 陷阱与教训(都是这轮真实踩过的)
124
+
125
+ 1. **preset 的 plugins 里绝不能挂宿主层服务插件**(如 `ptc-runtime`)——preset 在独立 scope 激活,重复挂载会让整条 preset 注册失败、从预设列表消失(1.0.3 事故)
126
+ 2. **cordis 插件的 apply 不能返回普通对象**——返回值必须是 dispose 函数 / null / undefined / thenable,否则真宿主报 `Invalid effect`(1.0.2 事故)
127
+ 3. **`dsh plugin add` 会做 overlay 校验**,YAML 缩进错会让整个安装回滚
128
+ 4. **别信 CI 全绿**:模块测试与真机装配是两件事,上述两次事故 CI 都绿
129
+ 5. **`ui/go.json` 不是 dsh 原生机制**——它是给第三方 dsh-Go 用的,而用户环境**没装 dsh-Go**(`@stardustlc` 是空目录),别指望它渲染面板
130
+ 6. **`propose_action`(个性化页面)在本会话工具面里不存在**——虽然 `dsh-personalized-recommendations` 已装且工具真实存在,但没暴露出来,所以官方「页面卡片」通道走不通
131
+ 7. **npm 发布**:默认 registry 是 npmmirror(只读),必须 `--registry=https://registry.npmjs.org`
132
+ 8. 在 PowerShell 里重定向 YAML 用 `Out-File -Encoding utf8`(`*>` 会写 UTF-16,js-yaml 报 null byte)
133
+
134
+ ## 回滚(客户端插件出问题时)
135
+
136
+ ```powershell
137
+ # 装回上一个可用版本(现在是唯一可靠的回滚路径)
138
+ & "D:\Deepseek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add npm:dsh-lean-router@1.0.3
139
+ ```
140
+ 仓库侧:`git revert 0b1fc3e`(客户端骨架)或 `git revert 2aad876`(/band 改造)。改完重启 dsh。
141
+
142
+ ## 用户偏好(务必遵守)
143
+
144
+ - **先说结果,再解释**;中文;称呼「主人」
145
+ - **不确定就问**,每次提问用 `ask_user_question`(可批量、timeoutMs 给足)——用户明确说「试错的成本远远比问问题大」
146
+ - 讨厌「要展开才看得清」的 UI,喜欢一眼看清、可视化优先
147
+ - 系统侧操作(启动项、安装等)由助手代劳,不让用户手抄命令;但**涉及密码/2FA 必须用户本人**
148
+ - 长任务要分阶段通报,不要攒到最后
149
+
150
+ ## 建议下个会话加载的技能
151
+
152
+ - `/handoff` — 再次交接时用
153
+ - `/ds-plan-loop` — 阶段 2/3 是多文件改造,先出带验收的编号计划
154
+ - `/ds-verify-loop` — 每次改客户端插件后跑最窄的真检查(离线 harness + 重启验证)
155
+ - `/ds-blast-radius` — 改 `lib/router.js` / `package.json` 前评估影响面
@@ -0,0 +1,38 @@
1
+ # 领域文档
2
+
3
+ 工程技能探索本仓库领域文档的方式。**布局:单上下文(single-context)。**
4
+
5
+ ## 探索前先读
6
+
7
+ - 根目录 **`GLOSSARY.md`**(若存在)
8
+ - **`docs/adr/`** 下与你要动的区域相关的 ADR
9
+ - `docs/` 下已有的设计说明(架构、配置、路由、工具遮蔽、技能门控等),与当前课题相关时读
10
+
11
+ 以上任一不存在就**静默继续**:不要提它们的缺失,也不要主动建议先建。`/domain-modeling`(经 `/grilling --docs` 与 `/improve-codebase-architecture` 到达)在术语或决策真正定案时才惰性创建。
12
+
13
+ ## 文件结构
14
+
15
+ 单上下文(本仓库):
16
+
17
+ ```
18
+ /
19
+ ├── GLOSSARY.md
20
+ ├── docs/adr/
21
+ │ ├── 0001-<决定>.md
22
+ │ └── 0002-<决定>.md
23
+ └── lib/ ← 实现
24
+ ```
25
+
26
+ 只有本仓库变成多包仓库(`pnpm-workspace.yaml` / `workspaces` / `packages/*`)时才改多上下文:根 `GLOSSARY-MAP.md` 指向各上下文的 `GLOSSARY.md`,`docs/adr/` 存系统级决策,`src/<context>/docs/adr/` 存局部决策。
27
+
28
+ ## 用词表里的词汇
29
+
30
+ 输出产物(issue 标题、重构提案、假设、测试名)里出现领域概念时,用 `GLOSSARY.md` 定义的那个词,不要漂移到它明确避开的同义词。
31
+
32
+ 需要的概念词表里没有,这本身是信号:要么你在发明项目不用的语言(重新考虑),要么真有缺口(留给 `/domain-modeling`)。
33
+
34
+ ## 撞 ADR 要显式指出
35
+
36
+ 输出与既有 ADR 冲突时,明说,不要静默覆盖:
37
+
38
+ > _与 ADR-0007(<决定>)冲突,但值得重开,因为……_
@@ -0,0 +1,44 @@
1
+ # Issue tracker: GitHub
2
+
3
+ 本仓库的 issue 与 spec 都放在 GitHub Issues。所有操作走 `gh` CLI。
4
+
5
+ ## 约定
6
+
7
+ - **新建**:`gh issue create --title "..." --body "..."`(多行正文用 heredoc)
8
+ - **读取**:`gh issue view <n> --json number,title,body,labels,comments`
9
+ - **列出**:`gh issue list --state open --json number,title,body,labels,comments --jq '[.[] | {number, title, body, labels: [.labels[].name], comments: [.comments[].body]}]'`
10
+ - **评论**:`gh issue comment <n> --body "..."`
11
+ - **加/删标签**:`gh issue edit <n> --add-label "..."` / `--remove-label "..."`
12
+ - **关闭**:先 `gh issue comment <n> --body "..."` 写说明,再 `gh issue close <n>`
13
+
14
+ ### 子 issue 与阻塞
15
+
16
+ - **子 issue**:`gh issue create --parent <parent> ...`,或 `gh issue edit <parent> --add-sub-issue <child>`(gh 2.94+)。旧版:`gh api --method POST repos/<owner>/<repo>/issues/<parent>/sub_issues -F sub_issue_id=<child-db-id>`。用不了子 issue 时,子 issue 正文开头写 `Part of #<parent>`。
17
+ - **阻塞**:用 GitHub 原生 issue dependency(UI 可见)。`gh issue create --blocked-by <n>,<n> ...` 或 `gh issue edit <child> --add-blocked-by <blocker>`(gh 2.94+)。旧版:`gh api --method POST repos/<owner>/<repo>/issues/<child>/dependencies/blocked_by -F issue_id=<blocker-db-id>`,db-id 取 `gh api repos/<owner>/<repo>/issues/<n> --jq .id`。功能不可用时退化为正文开头写 `Blocked by: #<n>, #<n>`;所有阻塞者关闭才算解锁。
18
+ - **数未关闭阻塞者**:`gh api repos/<owner>/<repo>/issues/<n> --jq .issue_dependencies_summary.blocked_by`(0 即可开工)。用 `gh issue view <n> --json blockedBy` 时要过滤 `select(.state == "OPEN")`,否则会把已关闭的算进去。
19
+
20
+ ## 安全边界
21
+
22
+ - 仓库由 `git remote -v` 推断;在克隆目录内运行 `gh` 会自动取。
23
+ - issue 只写进用户自己的仓库,不要写进 `mattpocock/skills`。
24
+ - fork 里 `gh` 可能默认指向 upstream,首次 `gh issue create` 前先 `gh repo view --json nameWithOwner` 核对。
25
+
26
+ ## PR 作为分诊入口
27
+
28
+ **PR 作为请求入口:否。**(`/triage` 读这个开关;把外部 PR 当功能请求处理时改成 `yes`。)
29
+
30
+ 设为 `yes` 时 PR 走同一套标签与状态机:`gh pr view <n> --comments`、`gh pr diff <n>`、`gh pr comment`、`gh pr edit --add-label`、`gh pr close`。GitHub 的 issue 与 PR 共用编号空间,裸 `#42` 先用 `gh pr view 42`、回落 `gh issue view 42`。
31
+
32
+ ## 技能措辞对照
33
+
34
+ - "publish to the issue tracker" → 建一个 GitHub issue。
35
+ - "fetch the relevant ticket" → 按上面 **读取** 取。
36
+
37
+ ## 寻路(wayfinder)操作
38
+
39
+ **地图**:单个 issue,带 `wayfinder:map` 标签,正文存 Notes / Decisions-so-far / Fog。
40
+ **子票**:作为地图的子 issue 挂上,带 `wayfinder:<type>` 标签(`research` / `prototype` / `grilling` / `task`);认领时 assign 给开工人。
41
+
42
+ - **前沿查询**:列出地图下未关闭的子票,丢掉有未关闭阻塞者或已有 assignee 的,按地图顺序取第一个。
43
+ - **认领**:`gh issue edit <n> --add-assignee @me`(会话的第一次写操作)。
44
+ - **解决**:`gh issue comment <n> --body "<答案>"` → `gh issue close <n>` → 把上下文指针(gist + 链接)追加到地图的 Decisions-so-far。
@@ -0,0 +1,13 @@
1
+ # 分诊标签
2
+
3
+ 技能用五个规范角色说话;本文件把角色映射到本仓库实际使用的标签串。
4
+
5
+ | 规范角色 | 本仓库标签 | 含义 |
6
+ | --- | --- | --- |
7
+ | `needs-triage` | `needs-triage` | 维护者需要评估 |
8
+ | `needs-info` | `needs-info` | 等报告者补充信息 |
9
+ | `ready-for-agent` | `ready-for-agent` | 规格已完整,可交给 AFK 代理 |
10
+ | `ready-for-human` | `ready-for-human` | 需要人来实现 |
11
+ | `wontfix` | `wontfix` | 不处理 |
12
+
13
+ 技能提到某个角色(如 "apply the AFK-ready triage label")时,用上表对应的标签串。要改词表就改「本仓库标签」列。`wontfix` 此前已存在,其余四个由本次 setup 创建。
@@ -6,7 +6,7 @@
6
6
 
7
7
  ~~~text
8
8
  ┌──────────────────────────────────────────────────────────────────────┐
9
- │ DSH host (engines >=0.2.1-rc.5 <0.2.3-0) │
9
+ │ DSH host (engines >=0.2.1-rc.5 <0.2.4-0) │
10
10
  ├──────────────────────────────────────────────────────────────────────┤
11
11
  │ preset preset-lean-router (frag-preset.patch.yml snapshot = sole owner)│
12
12
  │ │
@@ -6,7 +6,7 @@
6
6
 
7
7
  ~~~text
8
8
  ┌─────────────────────────────────────────────────────────────────────┐
9
- │ DSH 宿主(engines >=0.2.1-rc.5 <0.2.3-0) │
9
+ │ DSH 宿主(engines >=0.2.1-rc.5 <0.2.4-0) │
10
10
  ├─────────────────────────────────────────────────────────────────────┤
11
11
  │ 预设 preset-lean-router(frag-preset.patch.yml 并集快照 = 唯一生效行) │
12
12
  │ │
@@ -1,6 +1,21 @@
1
1
  # Changelog
2
2
 
3
- > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 1.0.4).
3
+ > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 1.0.5).
4
+
5
+ ## 1.0.5 (2026-11-23)
6
+
7
+ ### Adapt to the DSH 0.2.3 kernel (measured baseline 0.2.3-alpha.2)
8
+
9
+ - Fixed (critical): the `engines.dsh` upper bound goes from `<0.2.3-0` to `<0.2.4-0`. DSH's compatibility check (`evaluatePluginCompatibility` in `@deepseek-ai/dsh-app-boot`) calls `semver.satisfies(runtime, range, { includePrerelease: true })`; by semver prerelease precedence `0.2.3-0 < 0.2.3-alpha.2`, so the old range judged 0.2.3-alpha.2 incompatible and blocked both installation and activation. The widened range covers the whole 0.2.1-rc.5 through 0.2.3 line.
10
+ - Change: the `@deepseek-ai/dsh-tool-executor-native` dependency goes from `^0.2.2-alpha.3` to `>=0.2.2-alpha.3 <0.2.4-0`. Measured: 0.2.3-alpha.2 and 0.2.2-rc.5 are byte-identical in implementation (SHA256 over every file; only `package.json` differs), so the vendored executor needs no change.
11
+ - Change: the `@deepseek-ai/cordis` peer goes from `~4.1.0` to `>=4.1.0-0 <4.3.0-0`. The 0.2.3-alpha.2 host ships cordis 4.2.0-alpha.1, which the old range excluded (prerelease). cordis 4.2 only renames internal symbols (`symbols.config` to `symbols.metadata`) and reworks `ValidationError` issue paths; the **effect contract is unchanged**, and this package never imports cordis at runtime - it only uses its plugin shape - so no code change was needed.
12
+ - Re-checked, nothing broken: the client loading contract (`dsh-client-modules` scanning `dsh.client` plus `exports["./client"]`) is identical to 0.2.2, and all 26 `@deepseek-ai/dsh-*` plugins referenced by the patches still exist in 0.2.3.
13
+
14
+ ### Skills panel, stage 1 (1.0.5 content that had only lived in commits, never published)
15
+
16
+ - New: the `/panel` command as the usable form of the skills panel (server-rendered, so it does not depend on a client slot); the client overlay now groups by scenario, adds sub-views, hides skills that are off everywhere and fixes column alignment.
17
+ - Fixed (on a real install): the package now loads at host scope so `dsh-client-modules` actually scans its client bundle; `react-dom` was dropped in favour of `ctx.inject`/`ctx.register`; a pure-DOM fallback tells "bundle never loaded" apart from "slot never mounted".
18
+ - Fixed: skill injection is now optional, so the host's patch row really applies; the per-turn skill gate is enabled.
4
19
 
5
20
  ## 1.0.4 (2026-11-22)
6
21
 
package/docs/changelog.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # 变更记录(changelog)
2
2
 
3
- > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 1.0.4)。
3
+ > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 1.0.5)。
4
+
5
+ ## 1.0.5 (2026-11-23)
6
+
7
+ ### 适配 DSH 0.2.3 内核(实测基线 0.2.3-alpha.2)
8
+
9
+ - 修复(致命):`engines.dsh` 上限 `<0.2.3-0` → `<0.2.4-0`。DSH 的兼容性校验(`@deepseek-ai/dsh-app-boot` 的 `evaluatePluginCompatibility`)用 `semver.satisfies(runtime, range, { includePrerelease: true })`;按 semver 预发布优先级 `0.2.3-0 < 0.2.3-alpha.2`,旧范围把 0.2.3-alpha.2 判为不兼容,安装与激活都会被拦。放宽后 0.2.1-rc.5 至 0.2.3 全系列都满足。
10
+ - 变更:`dependencies` 的 `@deepseek-ai/dsh-tool-executor-native` 从 `^0.2.2-alpha.3` 放宽为 `>=0.2.2-alpha.3 <0.2.4-0`。实测 0.2.3-alpha.2 与 0.2.2-rc.5 的实现逐字节相同(全文件 SHA256 对比,仅 `package.json` 变),vendored executor 无需改动。
11
+ - 变更:`peerDependencies` 的 `@deepseek-ai/cordis` 从 `~4.1.0` 放宽为 `>=4.1.0-0 <4.3.0-0`。宿主 0.2.3-alpha.2 装的是 cordis 4.2.0-alpha.1,旧区间不含 4.2 的预发布。cordis 4.2 只改内部符号(`symbols.config` → `symbols.metadata`)与 `ValidationError` 的 issue 路径处理,**effect 契约未变**;本包运行时不 import cordis,仅用其插件形状,故无需改代码。
12
+ - 复核无破坏:客户端加载契约(`dsh-client-modules` 扫描 `dsh.client` + `exports["./client"]`)与 0.2.2 一致;补丁里引用的 26 个 `@deepseek-ai/dsh-*` 插件在 0.2.3 全部仍存在。
13
+
14
+ ### 技能面板阶段 1(1.0.5 内容,此前只在提交里、未发布)
15
+
16
+ - 新增:`/panel` 命令作为技能面板的可用形态(服务端渲染,不依赖客户端 slot),并在客户端浮层上按场景分组、加子视图、隐藏全关技能、修列对齐。
17
+ - 修复(真机):包改在宿主作用域加载,客户端 bundle 才会被 `dsh-client-modules` 扫到;去掉 `react-dom` 依赖,改走 `ctx.inject`/`ctx.register`;补纯 DOM 兜底,用于区分「bundle 没加载」与「slot 没挂上」两种失败。
18
+ - 修复:技能注入改为可选,宿主那一行 patch 才真正 apply 成功;逐轮技能门控已启用。
4
19
 
5
20
  ## 1.0.4 (2026-11-22)
6
21
 
@@ -48,7 +48,7 @@ dsh --dump-config | Select-String "skill-lean-router" # expect no output
48
48
  | Item | Value |
49
49
  |---|---|
50
50
  | Node.js | 24 (CI baseline; 22.12+ locally for `require` of ESM packages) |
51
- | DSH | `>=0.2.1-rc.5 <0.2.3-0` (`package.json#engines.dsh`) |
51
+ | DSH | `>=0.2.1-rc.5 <0.2.4-0` (`package.json#engines.dsh`) |
52
52
  | Platform | Windows / macOS / Linux (CI verifies ubuntu-latest) |
53
53
 
54
54
  ## Troubleshooting
package/docs/install.md CHANGED
@@ -48,7 +48,7 @@ dsh --dump-config | Select-String "skill-lean-router" # 期望无输出
48
48
  | 项 | 值 |
49
49
  |---|---|
50
50
  | Node.js | 24(CI 口径;本地 22.12+ 起支持 `require` ESM 包) |
51
- | DSH | `>=0.2.1-rc.5 <0.2.3-0`(`package.json#engines.dsh`) |
51
+ | DSH | `>=0.2.1-rc.5 <0.2.4-0`(`package.json#engines.dsh`) |
52
52
  | 平台 | Windows / macOS / Linux(CI 在 ubuntu-latest 验证) |
53
53
 
54
54
  ## 排错
@@ -4,12 +4,12 @@
4
4
 
5
5
  ## Prerequisites
6
6
 
7
- - DSH `>=0.2.1-rc.5 <0.2.3-0` (measured baseline 0.2.2-rc.5; see the engines field in package.json).
8
- - The package is not published to npm yet, so install via a local link (below). DSH is in developer preview; engine drift is handled by the engines gate + doctor self-check + a warn banner, never by silent degradation.
7
+ - DSH `>=0.2.1-rc.5 <0.2.4-0` (measured baseline 0.2.3-alpha.2; see the engines field in package.json).
8
+ - The package is published on npm (`dsh-lean-router`), so Path B is recommended; use Path A when you edit the code. DSH is in developer preview; engine drift is handled by the engines gate + doctor self-check + a warn banner, never by silent degradation.
9
9
 
10
10
  ## Install
11
11
 
12
- ### Path A: local link (recommended today)
12
+ ### Path A: local link (for development)
13
13
 
14
14
  ~~~powershell
15
15
  dsh plugin --profile desktop add "link:D:\path\to\dsh-lean-router"
@@ -17,10 +17,10 @@ dsh plugin --profile desktop add "link:D:\path\to\dsh-lean-router"
17
17
 
18
18
  After restarting DSH, pick the **Lean router** preset (lean tier) or **Lean router (balance)** (weaker-constraint tier) for new sessions.
19
19
 
20
- ### Path B: npm install (once published)
20
+ ### Path B: npm install (recommended)
21
21
 
22
22
  ~~~powershell
23
- dsh plugin --profile desktop add npm:dsh-lean-router@1.0.4
23
+ dsh plugin --profile desktop add npm:dsh-lean-router@1.0.5
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.)
@@ -4,12 +4,12 @@
4
4
 
5
5
  ## 前置条件
6
6
 
7
- - DSH `>=0.2.1-rc.5 <0.2.3-0`(实测基线 0.2.2-rc.5;见 package.json engines 字段)。
8
- - 本包未发布到 npm,先走本地 link 安装(下文)。DSH 处于 developer preview,版本越界将以 engines 闸 + doctor 自检 + warn 黄条应对,不做静默降级。
7
+ - DSH `>=0.2.1-rc.5 <0.2.4-0`(实测基线 0.2.3-alpha.2;见 package.json engines 字段)。
8
+ - 本包已发布到 npm(`dsh-lean-router`),推荐路径 B;改代码调试走路径 A。DSH 处于 developer preview,版本越界将以 engines 闸 + doctor 自检 + warn 黄条应对,不做静默降级。
9
9
 
10
10
  ## 安装
11
11
 
12
- ### 路径 A:本地 link(当前推荐)
12
+ ### 路径 A:本地 link(开发调试)
13
13
 
14
14
  ~~~powershell
15
15
  dsh plugin --profile desktop add "link:D:\path\to\dsh-lean-router"
@@ -17,10 +17,10 @@ dsh plugin --profile desktop add "link:D:\path\to\dsh-lean-router"
17
17
 
18
18
  重启 DSH 后,新会话在预设列表选择 **Lean router**(lean 档)或 **Lean router (balance)**(弱约束精简档)。
19
19
 
20
- ### 路径 B:npm 安装(发布后可用)
20
+ ### 路径 B:npm 安装(推荐)
21
21
 
22
22
  ~~~powershell
23
- dsh plugin --profile desktop add npm:dsh-lean-router@1.0.4
23
+ dsh plugin --profile desktop add npm:dsh-lean-router@1.0.5
24
24
  ~~~
25
25
 
26
26
  (两条路径与 scripts/install.mjs 输出的说明一致;真安装器、认领边界与 `--uninstall` 回滚归票 09。)
@@ -69,10 +69,10 @@ scripts/build-bundle.mjs 生成,master 已合入并通过 build --check 反向
69
69
 
70
70
  ## 6. package.json 需 master 新增(本票禁改共享文件,由 master 统一加)
71
71
 
72
- - dependencies: "@deepseek-ai/dsh-tool-executor-native": "^0.2.2-alpha.3"
73
- (上游区间;覆盖宿主现装 0.2.2-rc.5)
74
- - peerDependencies(建议): "@deepseek-ai/cordis": "~4.1.0"(宿主现装 4.1.0;
75
- native 包自身 peer 亦要求 ~4.1.0)
72
+ - dependencies: "@deepseek-ai/dsh-tool-executor-native": ">=0.2.2-alpha.3 <0.2.4-0"
73
+ (1.0.5 起放宽到 0.2.3 线;0.2.3-alpha.2 与 0.2.2-rc.5 的实现逐字节相同,仅 package.json 变)
74
+ - peerDependencies(建议): "@deepseek-ai/cordis": ">=4.1.0-0 <4.3.0-0"
75
+ (宿主 0.2.3-alpha.2 装 cordis 4.2.0-alpha.1;旧 ~4.1.0 不含 4.2 预发布)
76
76
  - exports 增加: "./toolface": "./lib/toolface/index.js"
77
77
  (frag 行 name 'dsh-lean-router/toolface' 依赖 exports 子路径,
78
78
  同形先例:@deepseek-ai/dsh-plugin-manager 的 './tools')
package/lib/client.js CHANGED
@@ -1,22 +1,20 @@
1
1
  // dsh-lean-router - 客户端 UI 层(技能面板)
2
2
  //
3
- // 加载契约(逆向自 dsh-cost-meter / dsh-ops 的产物,dsh 客户端模块系统 dsh-client-modules):
4
- // 1. 入口文件是 lib/client.js,package.json 用 dsh.client.platform = "web" 声明;
5
- // 2. 文件形如 window.__ModuleLoader__.load({ id, factory }),factory(require) 内
6
- // require 宿主提供的模块(react / react-dom / @deepseek-ai/dsh-client-ui-*),
7
- // 插件自身的依赖不打包,全部走宿主;
8
- // 3. factory 返回插件模块,导出 apply(cordis 插件形;generator 形式 = effect 生命周期)。
3
+ // 1.0.5 修(真机两轮验证后):
4
+ // 1. 原实现 require("react-dom") + ReactDOM.createPortal —— 参考实现 dsh-cost-meter 只
5
+ // require("react"),从不 require react-dom。宿主若不提供 react-dom,factory 立刻抛错,
6
+ // 整个客户端模块加载失败,按钮不出现且无任何可见症状。改为不依赖 react-dom,
7
+ // 面板用 position:fixed 直接渲染在按钮旁边。
8
+ // 2. 原实现用 ctx.slots.register(...);cost-meter 用的是
9
+ // ctx.inject(slotName, () => ctx.register(spec, Component))。改为优先走后者,保留回退。
10
+ // 3. apply 不再是 generator:1.0.2 曾因 apply 返回值不符合 cordis effect 契约而整条预设失效。
9
11
  //
10
- // 阶段 1(骨架):顶栏工具区一个「技能」按钮,点开全屏门户面板,面板内容暂为占位;
11
- // 面板与按钮同组件、用 ReactDOM.createPortal 挂到 body,不依赖第二个 slot,
12
- // 也不受任何 slot 容器的布局/裁剪影响。
13
- //
14
- // 阶段 2:接宿主数据(31 技能 + 审计统计);阶段 3:分组表 + 开关 + 一键工作流。
12
+ // 加载契约:package.json 的 dsh.client.platform="web" + exports["./client"],
13
+ // 入口形如 window.__ModuleLoader__.load({ id, factory }),factory(require) 取宿主模块。
15
14
  window.__ModuleLoader__.load({
16
15
  id: "dsh-lean-router",
17
16
  factory: (require) => {
18
17
  const React = require("react");
19
- const ReactDOM = require("react-dom");
20
18
  const h = React.createElement;
21
19
 
22
20
  const btnStyle = {
@@ -38,7 +36,7 @@ window.__ModuleLoader__.load({
38
36
  const overlayStyle = {
39
37
  position: "fixed",
40
38
  inset: 0,
41
- zIndex: 1000,
39
+ zIndex: 9999,
42
40
  display: "flex",
43
41
  alignItems: "center",
44
42
  justifyContent: "center",
@@ -72,7 +70,7 @@ window.__ModuleLoader__.load({
72
70
  opacity: 0.7,
73
71
  };
74
72
 
75
- /** 技能面板(阶段 1 占位;阶段 2/3 接真实数据)。 */
73
+ /** 技能面板(骨架;阶段 2/3 接真实数据)。 */
76
74
  function SkillsPanel(props) {
77
75
  return h(
78
76
  "div",
@@ -93,7 +91,7 @@ window.__ModuleLoader__.load({
93
91
  );
94
92
  }
95
93
 
96
- /** 顶栏「技能」按钮:点开/关闭门户面板。 */
94
+ /** 顶栏「技能」按钮:点开/关闭面板。 */
97
95
  function SkillsButton() {
98
96
  const [open, setOpen] = React.useState(false);
99
97
  const close = React.useCallback(() => setOpen(false), []);
@@ -110,16 +108,104 @@ window.__ModuleLoader__.load({
110
108
  },
111
109
  "技能"
112
110
  ),
113
- open ? ReactDOM.createPortal(h(SkillsPanel, { onClose: close }), document.body) : null
111
+ open ? h(SkillsPanel, { onClose: close }) : null
114
112
  );
115
113
  }
116
114
 
117
- /** cordis 插件入口:注册顶栏按钮(generator = effect,卸载时自动注销)。 */
118
- function* apply(ctx) {
119
- yield ctx.slots.register(
120
- { name: "conversation.session.header.utilities", id: "lean-router.skills", order: 60 },
121
- SkillsButton
122
- );
115
+ /**
116
+ * 纯 DOM 兜底(零 React 依赖):右上角一个固定定位的「技能」按钮。
117
+ * 只在 slot 注册全部失败时使用,用来区分失败类型。
118
+ */
119
+ function domFallback() {
120
+ if (typeof document === "undefined" || !document.body) return;
121
+ if (document.getElementById("lean-router-dom-fallback")) return;
122
+ const btn = document.createElement("button");
123
+ btn.id = "lean-router-dom-fallback";
124
+ btn.type = "button";
125
+ btn.textContent = "技能";
126
+ btn.title = "lean-router 兜底按钮(slot 注册失败)";
127
+ btn.style.cssText =
128
+ "position:fixed;top:8px;right:12px;z-index:2147483647;height:26px;padding:0 10px;" +
129
+ "border-radius:6px;border:1px solid rgba(128,128,128,.45);background:rgba(30,30,36,.92);" +
130
+ "color:#fff;font-size:12px;line-height:24px;cursor:pointer;box-shadow:0 4px 16px rgba(0,0,0,.35)";
131
+ let panel = null;
132
+ btn.addEventListener("click", () => {
133
+ if (panel) {
134
+ panel.remove();
135
+ panel = null;
136
+ return;
137
+ }
138
+ panel = document.createElement("div");
139
+ panel.style.cssText =
140
+ "position:fixed;top:44px;right:12px;z-index:2147483647;width:min(420px,92vw);" +
141
+ "padding:16px 18px;border-radius:10px;background:rgba(30,30,36,.97);color:#fff;" +
142
+ "font:13px/1.6 system-ui,sans-serif;box-shadow:0 18px 60px rgba(0,0,0,.5)";
143
+ panel.innerHTML =
144
+ "<div style='font-weight:600;margin-bottom:6px'>技能面板 · 兜底渲染</div>" +
145
+ "<div style='opacity:.75'>客户端 bundle 已加载,但 slot 注册没成功。" +
146
+ "这说明问题在 slot API,不在加载链路。</div>";
147
+ document.body.appendChild(panel);
148
+ });
149
+ document.body.appendChild(btn);
150
+ }
151
+
152
+ const SLOTS = ["conversation.session.header.actions", "conversation.session.header.utilities"];
153
+
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
+ function apply(ctx) {
161
+ const disposers = [];
162
+ const tryRegister = (slot, fn) => {
163
+ try {
164
+ const d = fn();
165
+ if (typeof d === "function") disposers.push(d);
166
+ return true;
167
+ } catch (err) {
168
+ try {
169
+ console.warn("[lean-router] register failed on", slot, err);
170
+ } catch {}
171
+ return false;
172
+ }
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
+ }
189
+
190
+ // 诊断兜底:所有 slot 路径都失败时,用纯 DOM 在右上角插一个悬浮按钮。
191
+ // 目的不是最终形态,而是区分「bundle 没加载」与「slot API 不对」这两类失败。
192
+ if (disposers.length === 0) {
193
+ try {
194
+ domFallback();
195
+ } catch (err) {
196
+ try {
197
+ console.warn("[lean-router] dom fallback failed", err);
198
+ } catch {}
199
+ }
200
+ }
201
+
202
+ return () => {
203
+ for (const d of disposers) {
204
+ try {
205
+ d();
206
+ } catch {}
207
+ }
208
+ };
123
209
  }
124
210
 
125
211
  return { apply };
package/lib/index.js CHANGED
@@ -1,14 +1,48 @@
1
- // dsh-lean-router - cordis 插件入口(骨架,票 02)
2
- // 票 04/05/06 将在此追加:executor 遮蔽、路由钩子(inbox/pre-step)、技能评分门控、审计。
1
+ // dsh-lean-router - cordis 插件入口
2
+ //
3
+ // 1.0.5 修:宿主层需要以裸包名 dsh-lean-router 挂一行,否则 dsh-client-modules 扫不到本包
4
+ // 的 dsh.client 声明,客户端 bundle 不会加载(顶栏按钮因此不出现)。
5
+ //
6
+ // 但原来的 inject = ["skills"] 会让宿主层那一行永远停在“等待依赖”——skills 服务由预设里的
7
+ // @deepseek-ai/dsh-skill-filesystem 提供,宿主作用域没有它。插件不 apply,扫描就看不到活跃
8
+ // 条目。改为可选依赖:宿主层照常 apply(只写自检),预设层照常注册 provider。
9
+ import { appendFileSync, mkdirSync } from "node:fs";
10
+ import { homedir } from "node:os";
11
+ import { join } from "node:path";
3
12
  import { makeProvider } from "./skill-provider.js";
4
13
  import { getAuditChannel } from "./skillgate.js";
5
14
 
6
15
  export const name = "skill-lean-router";
7
- export const inject = ["skills"];
16
+ export const inject = { required: [], optional: ["skills"] };
17
+
18
+ /** 启动自检:把宿主层是否 apply、ctx 上有哪些能力,写进 ~/.dsh/lean-router/boot.log。 */
19
+ function probe(line) {
20
+ try {
21
+ const dir = join(homedir(), ".dsh", "lean-router");
22
+ mkdirSync(dir, { recursive: true });
23
+ appendFileSync(join(dir, "boot.log"), new Date().toISOString() + " " + line + "\n", "utf8");
24
+ } catch {
25
+ // 自检失败绝不影响插件本身
26
+ }
27
+ }
8
28
 
9
29
  export function apply(ctx, options) {
10
30
  const cfg = options ?? {};
31
+ try {
32
+ probe(
33
+ "apply: options=" + JSON.stringify(cfg) +
34
+ " hasSkills=" + Boolean(ctx.skills) +
35
+ " slots=" + typeof ctx.slots +
36
+ " register=" + typeof ctx.register +
37
+ " inject=" + typeof ctx.inject
38
+ );
39
+ } catch {}
40
+
41
+ if (cfg.provider === false) return;
42
+ if (!ctx.skills || typeof ctx.skills.registerProvider !== "function") {
43
+ probe("skip provider: ctx.skills 不可用(宿主作用域属正常)");
44
+ return;
45
+ }
11
46
  const rank = typeof cfg.rank === "number" ? cfg.rank : 350;
12
- // master 集成(票 07 §9.2):provider 挂共享审计通道(skillgate 决策流单例)。
13
47
  ctx.skills.registerProvider(() => makeProvider({ rank, audit: getAuditChannel() }));
14
48
  }
package/lib/router.js CHANGED
@@ -33,6 +33,7 @@ import { defaultAuditPath, wireAuditSink } from "./audit-sink.js";
33
33
  import { executeAuditCommand } from "./audit-commands.js";
34
34
  import { getAuditChannel } from "./skillgate.js";
35
35
  import { createGateRunner } from "./gate-runner.js";
36
+ import { executeSkillsPanelCommand } from "./skills-panel.js";
36
37
 
37
38
  /** 三带配置表(re-export,满足单入口消费)。 */
38
39
  export { BANDS, BAND_IDS, DIRECTIVE_BAND_IDS, classifyTask, isComplexTask, parseRouterDirective, diligenceReminder } from "./bands.js";
@@ -392,6 +393,16 @@ export function apply(ctx, options) {
392
393
  });
393
394
  // 票 07 加法接线:/lean-audit 双入口之一(命令;实现放 lib/audit-commands.js,
394
395
  // 数据源 = 审计 JSONL 回放,不新增内存态)。ui/go.json 面板按钮是另一入口。
396
+ // 1.0.5:技能面板的命令输出形态(客户端插件未修好前的可用形态)。
397
+ ctx.commands.register({
398
+ name: "panel",
399
+ description: "Skill panel: 31 skills with switches, current round hit scores and history stats",
400
+ input: { hint: "" },
401
+ handler: (invocation) =>
402
+ executeSkillsPanelCommand(invocation, {
403
+ auditPath: cfg.auditPath ?? defaultAuditPath(),
404
+ }),
405
+ });
395
406
  ctx.commands.register({
396
407
  name: "lean-audit",
397
408
  description: "Show recent skill-gate audit decisions, hit statistics and manual weights",
@@ -0,0 +1,322 @@
1
+ // dsh-lean-router - 技能面板(宿主侧命令输出形态)
2
+ //
3
+ // 背景:客户端插件(真面板)在真机上始终加载不了,见 issue #2 的排除链。本模块先把面板的
4
+ // 信息价值用命令输出交付;客户端修好后,这里的数据组装逻辑可直接复用到 UI。
5
+ //
6
+ // 用法:
7
+ // /panel 总览(本轮 + 分组技能表 + 从未命中摘要)
8
+ // /panel skills 完整技能表(含全关)
9
+ // /panel round 本轮门控明细
10
+ // /panel stats 历史命中统计(按活跃度排序)
11
+ // /panel never 从未命中的完整清单
12
+ // /panel all 总览,但不隐藏全关技能
13
+ //
14
+ // 数据源:
15
+ // - 31 技能与开关 = assets/skills.matrix.json(包内矩阵,唯一事实源)
16
+ // - 本轮命中 = getAuditChannel().entries()(skillgate 内存环形缓冲)
17
+ // - 历史统计 = readAuditEntries(auditPath)(审计 JSONL 回放)
18
+ import { readFileSync } from "node:fs";
19
+ import { dirname, join } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ import { defaultAuditPath, readAuditEntries } from "./audit-sink.js";
22
+ import { aggregateStats } from "./audit-commands.js";
23
+ import { getAuditChannel } from "./skillgate.js";
24
+
25
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
26
+ const REPLAY_MAX = 2000;
27
+ const NEVER_PREVIEW = 10;
28
+
29
+ /** 场景顺序与中文名:分组表的展示顺序。 */
30
+ const SCENES = [
31
+ ["engineering", "工程"],
32
+ ["process", "流程"],
33
+ ["research", "研究"],
34
+ ["meta", "元交互"],
35
+ ];
36
+
37
+ export const VIEWS = ["summary", "skills", "round", "stats", "never"];
38
+
39
+ /** 读包内技能矩阵;读不到返回 null(面板降级而不是报错)。 */
40
+ export function loadMatrix(root) {
41
+ try {
42
+ return JSON.parse(readFileSync(join(root ?? ROOT, "assets", "skills.matrix.json"), "utf8"));
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+
48
+ /** 显示宽度:中日韩与全角字符算两列。 */
49
+ export function displayWidth(text) {
50
+ const s = String(text ?? "");
51
+ let w = 0;
52
+ for (const ch of s) w += /[\u3000-\u9fff\uff00-\uffef]/.test(ch) ? 2 : 1;
53
+ return w;
54
+ }
55
+
56
+ /** 按显示宽度补齐,保证表格在等宽字体下不错位。 */
57
+ function pad(text, width) {
58
+ const s = String(text ?? "");
59
+ return s + " ".repeat(Math.max(0, width - displayWidth(s)));
60
+ }
61
+
62
+ function countSwitches(skills) {
63
+ let model = 0;
64
+ let user = 0;
65
+ let off = 0;
66
+ for (const s of skills) {
67
+ if (s.model) model += 1;
68
+ if (s.user) user += 1;
69
+ if (!s.model && !s.user) off += 1;
70
+ }
71
+ return { model, user, off, total: skills.length };
72
+ }
73
+
74
+ /** 本轮摘要:最后一条 skillgate-round。 */
75
+ function renderCurrentRound(entries, detailed) {
76
+ const last = [...entries].reverse().find((e) => e && e.kind === "skillgate-round");
77
+ if (!last) return ["--- 本轮 ---", "(尚无门控记录:gate 未启用,或本轮还没走到门控)"];
78
+
79
+ const d = last.decision ?? {};
80
+ const auto = Array.isArray(d.auto) ? d.auto : [];
81
+ const hint = Array.isArray(d.hint) ? d.hint : [];
82
+ const deg = Array.isArray(d.degradations) ? d.degradations : [];
83
+ const budget = last.config?.tokenBudget;
84
+ const est = last.estTokens ?? d.estTokens;
85
+
86
+ const lines = [
87
+ "--- 本轮 ---",
88
+ "turn " + String(last.turn ?? "?") +
89
+ " · band " + String(last.band ?? "?") +
90
+ (last.complex ? " · 复杂任务" : "") +
91
+ (budget !== undefined ? " · token " + String(est ?? "?") + "/" + String(budget) : ""),
92
+ "自动入选:" + (auto.length ? auto.join(", ") : "(无)"),
93
+ "近场提示:" + (hint.length ? hint.join(", ") : "(无)"),
94
+ ];
95
+ if (deg.length) {
96
+ lines.push("软降级:" + deg.map((x) => (typeof x === "string" ? x : x?.name ?? "?")).join(", "));
97
+ }
98
+
99
+ const scored = (Array.isArray(last.scores) ? last.scores : [])
100
+ .filter((s) => typeof s?.score === "number" && s.score > 0)
101
+ .sort((a, b) => b.score - a.score);
102
+
103
+ if (scored.length) {
104
+ if (detailed) {
105
+ lines.push("得分构成:");
106
+ for (const s of scored.slice(0, 10)) {
107
+ const sig = s.signals ?? {};
108
+ const cat = sig.category ?? {};
109
+ const kws = Array.isArray(sig.keywords) ? sig.keywords : [];
110
+ lines.push(
111
+ " " + pad(s.name, 24) +
112
+ "总分 " + String(s.score) +
113
+ " · 类别 " + String(cat.points ?? 0) +
114
+ (cat.scene ? "(" + String(cat.scene) + ")" : "") +
115
+ " · 关键词 " + (kws.length ? kws.join("/") : "无") +
116
+ (cat.complex ? " · 复杂加成" : "")
117
+ );
118
+ }
119
+ } else {
120
+ lines.push("得分:" + scored.slice(0, 5).map((s) => s.name + "(" + s.score + ")").join(" "));
121
+ }
122
+ }
123
+ return lines;
124
+ }
125
+
126
+ /** 单行技能。 */
127
+ function skillRow(s, st) {
128
+ return (
129
+ pad(s.name, 30) +
130
+ pad(s.model ? "开" : "关", 7) +
131
+ pad(s.user ? "开" : "关", 6) +
132
+ pad(String(st ? st.hits : 0), 5) +
133
+ pad(String(st ? st.auto : 0), 6) +
134
+ String(st ? st.hint : 0)
135
+ );
136
+ }
137
+
138
+ const TABLE_HEAD =
139
+ pad("技能", 30) + pad("model", 7) + pad("user", 6) + pad("词", 5) + pad("自动", 6) + "提示";
140
+ const TABLE_RULE = "-".repeat(displayWidth(TABLE_HEAD));
141
+
142
+ /** 按场景分组的技能表;hideOff=true 时隐藏 model 与 user 全关的技能。 */
143
+ function renderGroupedSkills(skills, statsByName, hideOff) {
144
+ const lines = [];
145
+ let hidden = 0;
146
+ const known = new Set(SCENES.map((s) => s[0]));
147
+ const groups = [...SCENES];
148
+ const extras = [...new Set(skills.map((s) => s.scenario).filter((x) => x && !known.has(x)))];
149
+ for (const e of extras) groups.push([e, e]);
150
+
151
+ for (const [scene, label] of groups) {
152
+ const inGroup = skills.filter((s) => (s.scenario ?? "other") === scene);
153
+ if (!inGroup.length) continue;
154
+ const shown = [];
155
+ for (const s of inGroup) {
156
+ if (hideOff && !s.model && !s.user) {
157
+ hidden += 1;
158
+ continue;
159
+ }
160
+ shown.push(s);
161
+ }
162
+ if (!shown.length) continue;
163
+ lines.push("--- " + label + "(" + shown.length + " 个)---");
164
+ lines.push(TABLE_HEAD);
165
+ lines.push(TABLE_RULE);
166
+ for (const s of shown) lines.push(skillRow(s, statsByName.get(s.name)));
167
+ lines.push("");
168
+ }
169
+ if (hidden > 0) {
170
+ lines.push("(另有 " + hidden + " 个 model 与 user 全关的技能已隐藏:/panel skills 查看全部)");
171
+ }
172
+ return lines;
173
+ }
174
+
175
+ /** 历史统计:按活跃度(自动+提示+关键词)排序。 */
176
+ function renderStats(stats, rounds) {
177
+ if (!stats.length) return ["--- 历史统计 ---", "(还没有门控记录)"];
178
+ const sorted = [...stats].sort(
179
+ (a, b) => b.hits + b.auto + b.hint - (a.hits + a.auto + a.hint) || a.name.localeCompare(b.name)
180
+ );
181
+ const lines = [
182
+ "--- 历史统计(" + rounds + " 轮)---",
183
+ pad("技能", 30) + pad("轮次", 7) + pad("词", 5) + pad("自动", 6) + pad("提示", 6) + "降级",
184
+ "-".repeat(30 + 7 + 5 + 6 + 6 + 4),
185
+ ];
186
+ for (const r of sorted) {
187
+ lines.push(
188
+ pad(r.name, 30) +
189
+ pad(String(r.rounds), 7) +
190
+ pad(String(r.hits), 5) +
191
+ pad(String(r.auto), 6) +
192
+ pad(String(r.hint), 6) +
193
+ String(r.degraded)
194
+ );
195
+ }
196
+ return lines;
197
+ }
198
+
199
+ /** 从未命中(关键词/自动/提示都为 0)。 */
200
+ function neverHit(skills, statsByName) {
201
+ return skills.filter((s) => {
202
+ const st = statsByName.get(s.name);
203
+ return !st || st.hits + st.auto + st.hint === 0;
204
+ });
205
+ }
206
+
207
+ function renderNever(skills, statsByName, full) {
208
+ const never = neverHit(skills, statsByName);
209
+ if (!never.length) return ["--- 从未命中 ---", "(无:每个技能都至少命中过一次)"];
210
+ if (full) {
211
+ const lines = ["--- 从未命中(" + never.length + " 个)---"];
212
+ for (const s of never) lines.push(" " + pad(s.name, 30) + (s.scenarioZh ?? s.scenario ?? ""));
213
+ return lines;
214
+ }
215
+ const preview = never.slice(0, NEVER_PREVIEW).map((s) => s.name).join(", ");
216
+ const more = never.length > NEVER_PREVIEW ? " …(共 " + never.length + " 个,/panel never 看全部)" : "";
217
+ return ["--- 从未命中(" + never.length + " 个)---", preview + more];
218
+ }
219
+
220
+ /** 解析命令参数:第一个词是视图,出现 all 则不隐藏全关。 */
221
+ export function parsePanelArgs(raw) {
222
+ const tokens = String(raw ?? "").trim().split(/\s+/).filter(Boolean);
223
+ let view = "summary";
224
+ let all = false;
225
+ for (const t of tokens) {
226
+ const low = t.toLowerCase();
227
+ if (low === "all") {
228
+ all = true;
229
+ continue;
230
+ }
231
+ if (VIEWS.includes(low)) view = low;
232
+ }
233
+ return { view, all };
234
+ }
235
+
236
+ /**
237
+ * 渲染面板文本。
238
+ * options: { root?, auditPath?, view?, all? }
239
+ */
240
+ export function renderSkillsPanel(options) {
241
+ const matrix = loadMatrix(options?.root);
242
+ const auditPath = options?.auditPath ?? defaultAuditPathSafe();
243
+ const view = options?.view ?? "summary";
244
+ const all = options?.all === true;
245
+
246
+ if (!matrix || !Array.isArray(matrix.skills)) {
247
+ return "技能面板:读不到 assets/skills.matrix.json,无法渲染。";
248
+ }
249
+ const skills = matrix.skills;
250
+ const c = countSwitches(skills);
251
+
252
+ const replay = readAuditEntries(auditPath, { limit: REPLAY_MAX });
253
+ const history = replay.entries.filter((e) => e && e.kind === "skillgate-round");
254
+ const stats = aggregateStats(history);
255
+ const statsByName = new Map(stats.map((r) => [r.name, r]));
256
+
257
+ let live = [];
258
+ try {
259
+ live = getAuditChannel().entries() ?? [];
260
+ } catch {
261
+ live = [];
262
+ }
263
+
264
+ const auditState = replay.missing ? "未生成(gate 未启用或还没跑过一轮)" : history.length + " 轮";
265
+
266
+ const header = [
267
+ "=== 技能面板(lean-router)===",
268
+ "技能 " + c.total + " · model 开 " + c.model + " · user 开 " + c.user + " · 全关 " + c.off,
269
+ "门控:已启用 · 历史审计 " + auditState,
270
+ "审计文件:" + auditPath,
271
+ "",
272
+ ];
273
+
274
+ let body;
275
+ if (view === "round") {
276
+ body = renderCurrentRound(live, true);
277
+ } else if (view === "skills") {
278
+ body = renderGroupedSkills(skills, statsByName, false);
279
+ } else if (view === "stats") {
280
+ body = renderStats(stats, history.length);
281
+ } else if (view === "never") {
282
+ body = renderNever(skills, statsByName, true);
283
+ } else {
284
+ body = [
285
+ ...renderCurrentRound(live, false),
286
+ "",
287
+ ...renderGroupedSkills(skills, statsByName, !all),
288
+ ...renderNever(skills, statsByName, false),
289
+ ];
290
+ }
291
+
292
+ return [...header, ...body].join("\n").replace(/\n+$/, "");
293
+ }
294
+
295
+ function defaultAuditPathSafe() {
296
+ try {
297
+ return defaultAuditPath();
298
+ } catch {
299
+ return "(未知路径)";
300
+ }
301
+ }
302
+
303
+ /** 命令入口:/panel [summary|skills|round|stats|never] [all] */
304
+ export async function executeSkillsPanelCommand(invocation, context) {
305
+ try {
306
+ const { view, all } = parsePanelArgs(invocation?.rawInput ?? "");
307
+ return {
308
+ kind: "success",
309
+ text: renderSkillsPanel({
310
+ root: context?.root,
311
+ auditPath: context?.auditPath ?? defaultAuditPathSafe(),
312
+ view,
313
+ all,
314
+ }),
315
+ };
316
+ } catch (error) {
317
+ return {
318
+ kind: "error",
319
+ text: "技能面板渲染失败:" + (error instanceof Error ? error.message : String(error)),
320
+ };
321
+ }
322
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lean-router",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽 × mattpocock 技能自动调用的 DSH cordis 插件(单 bundle:预设+配套技能)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -37,7 +37,7 @@
37
37
  "url": "git+https://github.com/ShawnSun-Debug/dsh-lean-router.git"
38
38
  },
39
39
  "engines": {
40
- "dsh": ">=0.2.1-rc.5 <0.2.3-0"
40
+ "dsh": ">=0.2.1-rc.5 <0.2.4-0"
41
41
  },
42
42
  "scripts": {
43
43
  "test": "node --test \"test/*.test.mjs\"",
@@ -63,10 +63,10 @@
63
63
  "skills"
64
64
  ],
65
65
  "dependencies": {
66
- "@deepseek-ai/dsh-tool-executor-native": "^0.2.2-alpha.3"
66
+ "@deepseek-ai/dsh-tool-executor-native": ">=0.2.2-alpha.3 <0.2.4-0"
67
67
  },
68
68
  "peerDependencies": {
69
- "@deepseek-ai/cordis": "~4.1.0"
69
+ "@deepseek-ai/cordis": ">=4.1.0-0 <4.3.0-0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "js-yaml": "^4.1.0"
@@ -4,12 +4,20 @@
4
4
  # 入口子路径 dsh-lean-router/router 需要 package.json exports 增补 "./router": "./lib/router.js"
5
5
  # (package.json 为共享文件,由 master 统一集成;见 lib/router.js ROUTER_INJECTION_NOTES.patchEntry)
6
6
  - insert:
7
+ # 1.0.5 修:宿主层裸包名行(对照 dsh-cost-meter 的 "one host row")。
8
+ # 没有这一行,客户端模块扫描看不到 dsh.client -> 客户端 bundle 不加载 -> 无顶栏按钮。
9
+ # config.provider=false:不重复注册 skill provider(预设层已注册)。
10
+ - id: lean-router-client-host
11
+ name: dsh-lean-router
7
12
  - id: lean-router-router
8
13
  name: dsh-lean-router/router
9
14
  config:
10
15
  hooks: true
11
16
  commands: false
12
17
  diligenceEvery: 10
18
+ # 1.0.5 修:每轮门控必须开,否则 skillgate 不跑 -> 审计零条目、审计文件从不生成。
19
+ # 依据 lib/router.js:345(cfg.hooks && cfg.gate 才建 runner)与 lib/router.js:194。
20
+ gate: true
13
21
  - id: lean-router-commands
14
22
  name: dsh-lean-router/router
15
23
  config:
@@ -13,6 +13,8 @@ test("package.json 骨架字段", async () => {
13
13
  assert.equal(pkg.license, "MIT");
14
14
  assert.equal(pkg.type, "module");
15
15
  assert.equal(pkg.main, "lib/index.js");
16
- assert.equal(pkg.engines.dsh, ">=0.2.1-rc.5 <0.2.3-0");
16
+ // 上限 <0.2.4-0:DSH 用 semver.satisfies(..., { includePrerelease: true }) 校验,
17
+ // 旧的 <0.2.3-0 会把 0.2.3-alpha.2 判为不兼容并拦截激活。
18
+ assert.equal(pkg.engines.dsh, ">=0.2.1-rc.5 <0.2.4-0");
17
19
  assert.equal(pkg.dsh.bundle.patch, "./cordis.patch.yml");
18
20
  });
@@ -0,0 +1,114 @@
1
+ // 技能面板(命令输出形态)的单元测试:断言结构与关键事实,不锁死排版细节。
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { mkdtempSync, writeFileSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import {
8
+ renderSkillsPanel,
9
+ loadMatrix,
10
+ parsePanelArgs,
11
+ executeSkillsPanelCommand,
12
+ displayWidth,
13
+ } from "../lib/skills-panel.js";
14
+
15
+ function tmpAudit(lines) {
16
+ const dir = mkdtempSync(join(tmpdir(), "lean-router-panel-"));
17
+ const p = join(dir, "audit.jsonl");
18
+ writeFileSync(p, lines.map((l) => JSON.stringify(l)).join("\n") + "\n", "utf8");
19
+ return p;
20
+ }
21
+
22
+ const MISSING = () => join(tmpdir(), "missing-" + Date.now() + "-" + Math.random() + ".jsonl");
23
+
24
+ function roundEntry(over) {
25
+ return {
26
+ seq: 1,
27
+ v: 1,
28
+ kind: "skillgate-round",
29
+ turn: 1,
30
+ band: "react",
31
+ scores: [
32
+ { name: "code-review", score: 3, signals: { category: { scene: "engineering", points: 2 }, keywords: [] } },
33
+ { name: "tdd", score: 1, signals: { category: { scene: "engineering", points: 1 }, keywords: [] } },
34
+ ],
35
+ decision: { auto: ["code-review"], hint: [], degradations: [] },
36
+ config: { tokenBudget: 8000, charsPerToken: 4 },
37
+ ...over,
38
+ };
39
+ }
40
+
41
+ test("loadMatrix 读到 31 个技能", () => {
42
+ const m = loadMatrix();
43
+ assert.ok(m && Array.isArray(m.skills));
44
+ assert.equal(m.skills.length, 31);
45
+ });
46
+
47
+ test("总览包含四类信息", () => {
48
+ const text = renderSkillsPanel({ auditPath: MISSING() });
49
+ assert.match(text, /=== 技能面板/);
50
+ assert.match(text, /技能 31/);
51
+ assert.match(text, /--- 本轮 ---/);
52
+ assert.match(text, /--- 工程(/);
53
+ assert.match(text, /--- 从未命中/);
54
+ });
55
+
56
+ test("按场景分组:工程与流程两组都在", () => {
57
+ const text = renderSkillsPanel({ auditPath: MISSING(), view: "skills" });
58
+ assert.match(text, /--- 工程(/);
59
+ assert.match(text, /--- 流程(/);
60
+ assert.match(text, /--- 元交互(/);
61
+ });
62
+
63
+ test("技能名列不被最长名字撑破(表头与分隔线对齐)", () => {
64
+ const text = renderSkillsPanel({ auditPath: MISSING(), view: "skills" });
65
+ const lines = text.split("\n");
66
+ const i = lines.findIndex((l) => l.includes("自动") && l.includes("提示") && l.startsWith("技能"));
67
+ assert.ok(i >= 0, "应有表头行");
68
+ const rule = lines[i + 1];
69
+ assert.equal(displayWidth(lines[i]), displayWidth(rule), "表头与分隔线显示宽度应一致");
70
+ const row = lines.find((l) => l.startsWith("improve-codebase-architecture"));
71
+ assert.ok(row, "最长技能名应有行");
72
+ assert.ok(
73
+ displayWidth(row) <= displayWidth(rule),
74
+ "最长技能名那一行不应超出分隔线(名字列宽度够用)"
75
+ );
76
+ assert.ok(displayWidth(row) >= displayWidth(rule) - 4, "该行也不应明显短于分隔线");
77
+ });
78
+
79
+ test("审计缺失时降级而不抛错", () => {
80
+ const text = renderSkillsPanel({ auditPath: MISSING() });
81
+ assert.match(text, /未生成/);
82
+ });
83
+
84
+ test("历史统计按技能聚合", () => {
85
+ const text = renderSkillsPanel({ auditPath: tmpAudit([roundEntry({})]) });
86
+ assert.match(text, /1 轮/);
87
+ const row = text.split("\n").find((l) => l.startsWith("code-review"));
88
+ assert.ok(row);
89
+ });
90
+
91
+ test("stats 视图含轮次/自动/提示列", () => {
92
+ const text = renderSkillsPanel({ auditPath: tmpAudit([roundEntry({})]), view: "stats" });
93
+ assert.match(text, /--- 历史统计(1 轮)---/);
94
+ assert.match(text, /轮次/);
95
+ });
96
+
97
+ test("round 视图给得分构成", () => {
98
+ const text = renderSkillsPanel({ auditPath: MISSING(), view: "round" });
99
+ assert.match(text, /尚无门控记录/);
100
+ });
101
+
102
+ test("parsePanelArgs 解析视图与 all", () => {
103
+ assert.deepEqual(parsePanelArgs(""), { view: "summary", all: false });
104
+ assert.deepEqual(parsePanelArgs("skills"), { view: "skills", all: false });
105
+ assert.deepEqual(parsePanelArgs("all"), { view: "summary", all: true });
106
+ assert.deepEqual(parsePanelArgs(" stats ALL "), { view: "stats", all: true });
107
+ assert.deepEqual(parsePanelArgs("bogus"), { view: "summary", all: false });
108
+ });
109
+
110
+ test("命令入口返回 success", async () => {
111
+ const out = await executeSkillsPanelCommand({ rawInput: "" }, { auditPath: MISSING() });
112
+ assert.equal(out.kind, "success");
113
+ assert.match(out.text, /技能面板/);
114
+ });