dsh-lean-router 1.0.4 → 1.0.6

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/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,64 @@
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
+ // 条目。
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。
16
+ import { appendFileSync, mkdirSync } from "node:fs";
17
+ import { homedir } from "node:os";
18
+ import { join } from "node:path";
3
19
  import { makeProvider } from "./skill-provider.js";
4
20
  import { getAuditChannel } from "./skillgate.js";
5
21
 
6
22
  export const name = "skill-lean-router";
7
- export const inject = ["skills"];
23
+ export const inject = [];
24
+
25
+ /** 启动自检:把宿主层是否 apply、ctx 上有哪些能力,写进 ~/.dsh/lean-router/boot.log。 */
26
+ function probe(line) {
27
+ try {
28
+ const dir = join(homedir(), ".dsh", "lean-router");
29
+ mkdirSync(dir, { recursive: true });
30
+ appendFileSync(join(dir, "boot.log"), new Date().toISOString() + " " + line + "\n", "utf8");
31
+ } catch {
32
+ // 自检失败绝不影响插件本身
33
+ }
34
+ }
8
35
 
9
36
  export function apply(ctx, options) {
10
37
  const cfg = options ?? {};
11
- const rank = typeof cfg.rank === "number" ? cfg.rank : 350;
12
- // master 集成(票 07 §9.2):provider 挂共享审计通道(skillgate 决策流单例)。
13
- ctx.skills.registerProvider(() => makeProvider({ rank, audit: getAuditChannel() }));
38
+ try {
39
+ probe(
40
+ "apply: options=" + JSON.stringify(cfg) +
41
+ " hasSkills=" + Boolean(ctx.skills) +
42
+ " slots=" + typeof ctx.slots +
43
+ " register=" + typeof ctx.register +
44
+ " inject=" + typeof ctx.inject
45
+ );
46
+ } catch {}
47
+
48
+ if (cfg.provider === false) 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);
63
+ }
14
64
  }
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: "[summary|skills|round|stats|never] [all]" },
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.6",
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
  });