dsh-rolegroup 0.12.0 → 0.12.1
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/CHANGELOG.md +50 -0
- package/README.en.md +4 -1
- package/README.md +4 -1
- package/lib/client.js +79 -74
- package/lib/index.js +4 -4
- package/lib/roles.js +2 -2
- package/package.json +1 -1
- package/src/client/index.js +21 -4
- package/src/client/settings-nav-icon.js +62 -80
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,56 @@
|
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
+
## [0.12.1] — 2026-11-19
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **实例配置不再携带已退役键 `modelSelectionSettings`**(dsh 0.2.2-rc.5 核对,2026-11-19)。该键在
|
|
17
|
+
0.2.1-rc.1 起被上游改名为 `modelSelection`(升级指南
|
|
18
|
+
`docs/upgrade-guide/v0.2.1-rc.1/subagent-control-tools/guide.md:12`),
|
|
19
|
+
rc.5 的 schema 对旧键名**不消费也不报错**——传 `true` 也不会开启调用期路由字段。此前它一直躺在
|
|
20
|
+
`buildInstanceConfig` 里,靠 schemastery「未知键原样保留」侥幸无害;现删除,行为不变(缺省即 false)。
|
|
21
|
+
- 注释与文档同步:`lib/index.js` / `lib/roles.js` 头注中关于 `install(ctx, undefined)` 站立式组合、
|
|
22
|
+
`assertAllowedModelSelection` 白名单的说法改为按 rc.5 契约措辞(`modelSelection` 缺省 false → 不暴露
|
|
23
|
+
调用期路由字段)。
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- README 中英「本机实测」版本改为 0.2.2-rc.5(`engines.dsh` 保持 `>=0.2.1-rc.1`)。
|
|
28
|
+
- **设置页导航图标改用官方 `settings.section.icon` 槽位注册**(rc.5 新增,contract/slots.d.ts:85),
|
|
29
|
+
替换旧的「data 属性 + scoped CSS mask」装饰 hack;registration id = section id(`rolegroup`)。
|
|
30
|
+
组件是 settings-nav-icon.js 导出的真 React 组件(顶层 `import * as React from 'react'`——client
|
|
31
|
+
环境不存在全局 React 注入点,第一版那么取导致图标渲染为空,2026-11-19 截图实证后修复);
|
|
32
|
+
`index.js` 经动态 import 取 NavGlyph 并 catch 兜底。**低版本 dsh(< rc.5)上该注册无消费方 =
|
|
33
|
+
静默 no-op**,其余功能不受影响,故 engines.dsh 维持 `>=0.2.1-rc.1`;README 中英头部各加一行说明。
|
|
34
|
+
浏览器验收通过(2026-11-19 用户确认图标出现)。
|
|
35
|
+
- 新增两条部署树断言(`tests/smoke.mjs`):① `buildInstanceConfig` 的输出经 rc.5 真实 Config schema
|
|
36
|
+
逐字段解析通过且不含退役键;② 旧键名即使传 `true` 也不改变 `modelSelection` 缺省语义(no-op 锁定)。
|
|
37
|
+
证伪:把 `modelSelectionSettings: false` 塞回实现 → 第 ① 条红。
|
|
38
|
+
- 图标迁移的断言:svg 描述 + size 回落、createElement 展开计数、退役字符串卫生检查、
|
|
39
|
+
gating 用例改按槽位名分流 + __dshRgStubImport 桩通道(node 不加载 react 依赖模块)。AGENTS.md 坑清单同步改写。
|
|
40
|
+
|
|
41
|
+
### 验证(0.2.2-rc.5 真机)
|
|
42
|
+
|
|
43
|
+
- 启动报告 8/8 注册,`failed` / `invalid` / `problems` 全空(`~/.dsh/plugins/dsh-rolegroup/last-startup.json`,2026-11-19T02:37:33Z);
|
|
44
|
+
- schemastery 软链指向部署树 3.19.0,`npm run link:deps` 输出「无需改动」;
|
|
45
|
+
- `npm test` 158 passed;`npm run build:client` 重建产物含 `require("react")` 与 icon 槽位注册;
|
|
46
|
+
浏览器实测图标出现(2026-11-19)。
|
|
47
|
+
|
|
48
|
+
### 核对过的升级项(均不适用)
|
|
49
|
+
|
|
50
|
+
`v0.2.2-rc.4/web-search-deepseek-model-default`(只改 web 搜索默认提供方)、
|
|
51
|
+
`v0.2.2-rc.3/deepseek-refusal-code`(错误码改名,插件不消费)。委派、Agent Preset、settings、
|
|
52
|
+
manifest、schemastery 五个依赖面逐项对照 rc.5 安装版源码核验,契约全部存活。
|
|
53
|
+
|
|
54
|
+
Removes the retired `modelSelectionSettings` key from instance configs (renamed to `modelSelection`
|
|
55
|
+
upstream since 0.2.1-rc.1; rc.5's schema ignores it silently). Behavior unchanged — the default is
|
|
56
|
+
already false. Adds two deployment-tree assertions that parse our instance config through the real
|
|
57
|
+
rc.5 Config schema and pin the retired key as a no-op. Updates the verified-on version in both READMEs
|
|
58
|
+
to 0.2.2-rc.5.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
12
62
|
## [0.12.0] — 2026-11-16
|
|
13
63
|
|
|
14
64
|
### Added
|
package/README.en.md
CHANGED
|
@@ -7,7 +7,10 @@ instance, so the tool name is the role name.
|
|
|
7
7
|
The role/category binding is inspired by
|
|
8
8
|
[oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent) ("omo"); see §9.
|
|
9
9
|
|
|
10
|
-
> Version **0.12.
|
|
10
|
+
> Version **0.12.1** | dsh **≥ 0.2.1-rc.1** (verified on 0.2.2-rc.5) | MIT
|
|
11
|
+
>
|
|
12
|
+
> The settings-page nav icon only shows on dsh ≥ 0.2.2-rc.5 (the official `settings.section.icon`
|
|
13
|
+
> slot exists from that version); everything else works on older releases.
|
|
11
14
|
|
|
12
15
|
---
|
|
13
16
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,10 @@ dsh 的角色化委派插件。先定义角色(名字、绑定模型、persona
|
|
|
6
6
|
角色/类别绑定的思路参考了 [oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent)(omo),
|
|
7
7
|
详见 §9。
|
|
8
8
|
|
|
9
|
-
> 版本 **0.12.
|
|
9
|
+
> 版本 **0.12.1** | 要求 dsh **≥ 0.2.1-rc.1**(本机实测 0.2.2-rc.5)| MIT
|
|
10
|
+
>
|
|
11
|
+
> 设置页导航图标只在 dsh ≥ 0.2.2-rc.5 上显示(官方 `settings.section.icon` 槽位从该版本起提供);
|
|
12
|
+
> 低版本其余功能不受影响。
|
|
10
13
|
|
|
11
14
|
---
|
|
12
15
|
|
package/lib/client.js
CHANGED
|
@@ -3,9 +3,11 @@ window.__ModuleLoader__.load({
|
|
|
3
3
|
factory: (require) => {
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
|
+
var __create = Object.create;
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
12
|
var __esm = (fn, res, err) => function __init() {
|
|
11
13
|
if (err) throw err[0];
|
|
@@ -27,13 +29,80 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
27
29
|
}
|
|
28
30
|
return to;
|
|
29
31
|
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
30
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
41
|
|
|
42
|
+
// src/client/settings-nav-icon.js
|
|
43
|
+
var settings_nav_icon_exports = {};
|
|
44
|
+
__export(settings_nav_icon_exports, {
|
|
45
|
+
NAV_GLYPH_CIRCLE: () => NAV_GLYPH_CIRCLE,
|
|
46
|
+
NAV_GLYPH_PATHS: () => NAV_GLYPH_PATHS,
|
|
47
|
+
NavGlyph: () => NavGlyph,
|
|
48
|
+
buildNavGlyph: () => buildNavGlyph,
|
|
49
|
+
renderNavGlyph: () => renderNavGlyph
|
|
50
|
+
});
|
|
51
|
+
function buildNavGlyph(props = {}) {
|
|
52
|
+
const size = typeof props.size === "number" && props.size > 0 ? props.size : 16;
|
|
53
|
+
return {
|
|
54
|
+
tag: "svg",
|
|
55
|
+
props: {
|
|
56
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
57
|
+
viewBox: "0 0 16 16",
|
|
58
|
+
width: size,
|
|
59
|
+
height: size,
|
|
60
|
+
fill: "none",
|
|
61
|
+
stroke: "currentColor",
|
|
62
|
+
strokeWidth: 1.2,
|
|
63
|
+
strokeLinejoin: "round",
|
|
64
|
+
strokeLinecap: "round",
|
|
65
|
+
"aria-hidden": "true"
|
|
66
|
+
},
|
|
67
|
+
children: [
|
|
68
|
+
{ tag: "path", props: { d: NAV_GLYPH_PATHS[0] } },
|
|
69
|
+
{ tag: "circle", props: { ...NAV_GLYPH_CIRCLE, fill: "currentColor", stroke: "none" } },
|
|
70
|
+
{ tag: "path", props: { d: NAV_GLYPH_PATHS[1] } }
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function NavGlyph(props) {
|
|
75
|
+
const g = buildNavGlyph(props);
|
|
76
|
+
return React.createElement(
|
|
77
|
+
g.tag,
|
|
78
|
+
g.props,
|
|
79
|
+
...g.children.map((c) => React.createElement(c.tag, c.props))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
function renderNavGlyph(React2, glyph) {
|
|
83
|
+
return React2.createElement(
|
|
84
|
+
glyph.tag,
|
|
85
|
+
glyph.props,
|
|
86
|
+
...glyph.children.map((c) => React2.createElement(c.tag, c.props))
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
var React, NAV_GLYPH_PATHS, NAV_GLYPH_CIRCLE;
|
|
90
|
+
var init_settings_nav_icon = __esm({
|
|
91
|
+
"src/client/settings-nav-icon.js"() {
|
|
92
|
+
React = __toESM(require("react"), 1);
|
|
93
|
+
NAV_GLYPH_PATHS = [
|
|
94
|
+
"M8 1.7 13.4 4.8v6.4L8 14.3 2.6 11.2V4.8Z",
|
|
95
|
+
"M8 6.4V4.7M6.7 8.7 5.3 9.5M9.3 8.7 10.7 9.5"
|
|
96
|
+
];
|
|
97
|
+
NAV_GLYPH_CIRCLE = { cx: 8, cy: 8, r: 1.35 };
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
32
101
|
// src/client/meta.js
|
|
33
102
|
var PLUGIN_VERSION, PLUGIN_REPO_URL;
|
|
34
103
|
var init_meta = __esm({
|
|
35
104
|
"src/client/meta.js"() {
|
|
36
|
-
PLUGIN_VERSION = true ? "0.12.
|
|
105
|
+
PLUGIN_VERSION = true ? "0.12.1" : "dev";
|
|
37
106
|
PLUGIN_REPO_URL = "https://github.com/zhouxnsz/dsh-rolegroup";
|
|
38
107
|
}
|
|
39
108
|
});
|
|
@@ -835,78 +904,6 @@ var RolegroupCardController = class {
|
|
|
835
904
|
}
|
|
836
905
|
};
|
|
837
906
|
|
|
838
|
-
// src/client/settings-nav-icon.js
|
|
839
|
-
var NAV_GLYPH = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8 1.7 13.4 4.8v6.4L8 14.3 2.6 11.2V4.8Z" fill="none" stroke="#000" stroke-width="1.2" stroke-linejoin="round"/><circle cx="8" cy="8" r="1.35" fill="#000"/><path d="M8 6.4V4.7M6.7 8.7 5.3 9.5M9.3 8.7 10.7 9.5" stroke="#000" stroke-width="1.2" stroke-linecap="round"/></svg>';
|
|
840
|
-
var NAV_GLYPH_URI = `data:image/svg+xml,${encodeURIComponent(NAV_GLYPH)}`;
|
|
841
|
-
var NAV_ICON_CSS = `@supports ((mask-image: linear-gradient(#000, #000)) or (-webkit-mask-image: linear-gradient(#000, #000))) {
|
|
842
|
-
button[data-dsh-rg-nav] > svg { display: none !important; }
|
|
843
|
-
button[data-dsh-rg-nav]::before { content: ""; width: 16px; height: 16px; flex: none; display: inline-block; background-color: currentColor; -webkit-mask: url("${NAV_GLYPH_URI}") center / 16px 16px no-repeat; mask: url("${NAV_GLYPH_URI}") center / 16px 16px no-repeat; }
|
|
844
|
-
}`;
|
|
845
|
-
function markSettingsNavButton(buttons, label) {
|
|
846
|
-
const wanted = String(label ?? "").trim();
|
|
847
|
-
if (wanted === "") return void 0;
|
|
848
|
-
for (const button of buttons ?? []) {
|
|
849
|
-
if (button?.dataset?.dshRgNav !== void 0) return button;
|
|
850
|
-
if (String(button?.textContent ?? "").trim() !== wanted) continue;
|
|
851
|
-
if (String(button?.firstElementChild?.tagName ?? "").toLowerCase() !== "svg") continue;
|
|
852
|
-
if (button.dataset !== void 0) button.dataset.dshRgNav = "";
|
|
853
|
-
else button.setAttribute?.("data-dsh-rg-nav", "");
|
|
854
|
-
return button;
|
|
855
|
-
}
|
|
856
|
-
return void 0;
|
|
857
|
-
}
|
|
858
|
-
function installSettingsNavIcon(labelOf, options = {}) {
|
|
859
|
-
const doc = options.document ?? (typeof document === "undefined" ? void 0 : document);
|
|
860
|
-
if (doc === void 0 || doc === null || doc.body === void 0 || doc.body === null) return () => {
|
|
861
|
-
};
|
|
862
|
-
const root = doc.head ?? doc.documentElement;
|
|
863
|
-
if (typeof root?.append !== "function") return () => {
|
|
864
|
-
};
|
|
865
|
-
const style = doc.createElement("style");
|
|
866
|
-
style.setAttribute("data-dsh-rg-nav-style", "");
|
|
867
|
-
style.textContent = NAV_ICON_CSS;
|
|
868
|
-
try {
|
|
869
|
-
root.append(style);
|
|
870
|
-
} catch {
|
|
871
|
-
return () => {
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
const Observer = options.MutationObserver ?? globalThis.MutationObserver;
|
|
875
|
-
const raf = options.requestAnimationFrame ?? globalThis.requestAnimationFrame;
|
|
876
|
-
let scheduled = false;
|
|
877
|
-
let disposed = false;
|
|
878
|
-
const apply2 = () => {
|
|
879
|
-
scheduled = false;
|
|
880
|
-
if (disposed) return;
|
|
881
|
-
try {
|
|
882
|
-
markSettingsNavButton(doc.querySelectorAll?.("button") ?? [], labelOf?.());
|
|
883
|
-
} catch {
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
const schedule = () => {
|
|
887
|
-
if (scheduled || disposed) return;
|
|
888
|
-
scheduled = true;
|
|
889
|
-
if (typeof raf === "function") raf(apply2);
|
|
890
|
-
else Promise.resolve().then(apply2);
|
|
891
|
-
};
|
|
892
|
-
let observer;
|
|
893
|
-
if (typeof Observer === "function") {
|
|
894
|
-
try {
|
|
895
|
-
observer = new Observer(schedule);
|
|
896
|
-
observer.observe(doc.body, { childList: true, subtree: true });
|
|
897
|
-
} catch {
|
|
898
|
-
observer = void 0;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
apply2();
|
|
902
|
-
return () => {
|
|
903
|
-
disposed = true;
|
|
904
|
-
observer?.disconnect?.();
|
|
905
|
-
style.remove?.();
|
|
906
|
-
for (const button of doc.querySelectorAll?.("[data-dsh-rg-nav]") ?? []) button.removeAttribute?.("data-dsh-rg-nav");
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
|
|
910
907
|
// src/client/locales.js
|
|
911
908
|
var zh = {
|
|
912
909
|
title: "\u89D2\u8272\u914D\u7F6E",
|
|
@@ -1003,7 +1000,15 @@ var inject = ["slots", "locale", "remote", "remote.session", "configForms"];
|
|
|
1003
1000
|
function apply(ctx) {
|
|
1004
1001
|
ctx.effect(() => ctx.locale.register("rolegroup", { zh, en }), "dsh-rolegroup: dictionaries");
|
|
1005
1002
|
const t = ctx.locale.bind("rolegroup");
|
|
1006
|
-
ctx.effect(() =>
|
|
1003
|
+
ctx.effect(() => {
|
|
1004
|
+
const loadNavGlyph = globalThis.__dshRgStubImport ?? (() => Promise.resolve().then(() => (init_settings_nav_icon(), settings_nav_icon_exports)));
|
|
1005
|
+
return loadNavGlyph().catch(() => void 0).then((mod) => mod === void 0 ? void 0 : ctx.slots.register({
|
|
1006
|
+
name: "settings.section.icon",
|
|
1007
|
+
id: "rolegroup",
|
|
1008
|
+
order: 30,
|
|
1009
|
+
label: () => t("title")
|
|
1010
|
+
}, mod.NavGlyph));
|
|
1011
|
+
}, "dsh-rolegroup: settings nav icon");
|
|
1007
1012
|
const controller = new RolegroupCardController(ctx.configForms.get(ROLEGROUP_CLIENT_NS), ctx);
|
|
1008
1013
|
ctx.effect(() => ctx.configForms.whileServed([ROLEGROUP_CLIENT_NS], () => ctx.slots.inject("settings.section", async () => {
|
|
1009
1014
|
try {
|
package/lib/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 设计依据见仓库 docs/proposal.md(§2 F1-F6 / §3 D-Rev1..4 / §7 R1-R2):
|
|
4
4
|
// - 每角色一个 dsh-tool-subagent 实例:固定 agentOptions{provider,model}
|
|
5
|
-
// +
|
|
6
|
-
// -
|
|
7
|
-
// 工具直接注册在 host 平面,无需 preset scope
|
|
5
|
+
// + maxDepth:1 + persona(F1;persona 住 Agent Preset,见 lib/presets.js)
|
|
6
|
+
// - modelSelection 缺省 false(0.2.1-rc.1 起取代 modelSelectionSettings),不暴露调用期路由字段,
|
|
7
|
+
// 工具直接注册在 host 平面,无需 preset scope
|
|
8
8
|
// - 统一 maxDepth:1(主会话可委派、角色子代理不可再委派,D-Rev2;
|
|
9
9
|
// 0 会把顶层调用也挡掉,见 2e5ffd6 与 lib/roles.js buildInstanceConfig 注释)
|
|
10
10
|
// - readonly 已移除(v0.5):工具面白名单表达不了权限边界,在配置面提供它易被误读成安全开关
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// 没有配置文件层——rolegroup.jsonc 不再被读取。
|
|
16
16
|
//
|
|
17
17
|
// 启动校验(proposal §4「已知坑」修订版):
|
|
18
|
-
// 源码审计(L1):
|
|
18
|
+
// 源码审计(L1):modelSelection 缺省 false 时白名单 assertAllowedModelSelection
|
|
19
19
|
// 不被调用(policy 为 undefined 直接返回);真正的运行时防线是委派时的
|
|
20
20
|
// preflightChildLlmRoute(llm.resolveCallConfig)。因此启动校验改为:
|
|
21
21
|
// - 硬校验:provider 必须在 llm 注册表中(不可用时降级为跳过)
|
package/lib/roles.js
CHANGED
|
@@ -333,7 +333,8 @@ export function resolveRoleRoute(role, availability = {}) {
|
|
|
333
333
|
* - **拒绝** `persona` / `toolFilter` / `backgroundMode`(出现即 throw)→ persona 只能由 Agent Preset 承载
|
|
334
334
|
* - `agentPreset` 必须被 `allowedAgentPresets` 包含(:209 显式 throw);显式 preset 会**替换**父组合,
|
|
335
335
|
* 故调用方传入的 preset 是「克隆默认 preset 完整 rows + 替换 persona + 剔除 delegation」的产物
|
|
336
|
-
* - `
|
|
336
|
+
* - `modelSelection` 缺省 false(0.2.1-rc.1 起该字段取代 modelSelectionSettings)→ 不暴露调用期路由字段,
|
|
337
|
+
* host 平面直接可用;旧键名已不被 schema 消费,不要再写进实例配置
|
|
337
338
|
* - `maxDepth: 1` → 主会话可委派、角色子会话不可再委派(防套娃;0 会连顶层也挡掉)
|
|
338
339
|
* - 固定 `agentOptions` → 委派时 preflightChildLlmRoute 校验路由真实存在
|
|
339
340
|
* - 只读边界仍由**会话级 permission preset** 承担(随委派继承),不在工具面表达
|
|
@@ -345,7 +346,6 @@ export function buildInstanceConfig(role, presetId) {
|
|
|
345
346
|
return {
|
|
346
347
|
provider: SUBAGENT_PROVIDER,
|
|
347
348
|
toolName: role.toolName,
|
|
348
|
-
modelSelectionSettings: false,
|
|
349
349
|
agentOptions: {
|
|
350
350
|
provider: role.provider,
|
|
351
351
|
model: role.model,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-rolegroup",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "角色化委派插件:把「这类活该用哪个模型」固化为角色(名字 + 绑定模型 + persona),按角色名委派 · Role-based delegation: bind each kind of work to a model once and delegate by role name",
|
|
5
5
|
"icon": "assets/icon.svg",
|
|
6
6
|
"license": "MIT",
|
package/src/client/index.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
// 值必须与 host 侧条目 id / 命名空间逐字一致。
|
|
15
15
|
|
|
16
16
|
import { RolegroupCardController } from './controller.js'
|
|
17
|
-
import { installSettingsNavIcon } from './settings-nav-icon.js'
|
|
18
17
|
import { zh, en } from './locales.js'
|
|
19
18
|
|
|
20
19
|
/** settings 命名空间 === host Loader 条目 id(`lib/config.js` 的 ROLEGROUP_ENTRY_ID)。 */
|
|
@@ -29,9 +28,27 @@ export function apply(ctx) {
|
|
|
29
28
|
ctx.effect(() => ctx.locale.register('rolegroup', { zh, en }), 'dsh-rolegroup: dictionaries')
|
|
30
29
|
// 导航条目名与节内标题都取自词典(注册项的 `label` 是设置页左侧导航显示的名字)。
|
|
31
30
|
const t = ctx.locale.bind('rolegroup')
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
31
|
+
// 设置页导航图标:0.2.2-rc.5 起走官方 `settings.section.icon` 槽位(registration id 必须
|
|
32
|
+
// 等于目标 section 的 id;缺席时 shell 保留默认齿轮)。旧版是 CSS mask 装饰 hack,已退役。
|
|
33
|
+
// 第二参必须是 **React 组件**(shell renderSlot 按 element 语义消费,官方样例同款);
|
|
34
|
+
// React 经模块系统 import(react 在 bundle 里 external、由 shell seed 解析)——
|
|
35
|
+
// 浏览器侧不存在全局 React 注入点,上一版靠它取 React 导致渲染为空(2026-11-19 实证)。
|
|
36
|
+
// node 可导入性红线同 card.jsx:settings-nav-icon.js 顶层 import react,只能经动态 import
|
|
37
|
+
// 藏在回调内加载(node 测试不触发该回调)。
|
|
38
|
+
ctx.effect(() => {
|
|
39
|
+
// 测试桩通道:node 环境裸导入 react 必失败(link: 形态),smoke 用例注入 __dshRgStubImport
|
|
40
|
+
// 让本 effect 走失败分支。两条兜底缺一不可:
|
|
41
|
+
// ① catch——防 unhandledRejection 掀翻 node 进程;
|
|
42
|
+
// ② .then(register) 而非 await——async effect 的 Promise 若先 reject、cordis 同步期又没
|
|
43
|
+
// 挂上 disposer,调用方会撞 "disposer is not a function"(2026-11-19 套件实证)。
|
|
44
|
+
const loadNavGlyph = globalThis.__dshRgStubImport ?? (() => import('./settings-nav-icon.js'))
|
|
45
|
+
return loadNavGlyph().catch(() => undefined).then((mod) => mod === undefined ? undefined : ctx.slots.register({
|
|
46
|
+
name: 'settings.section.icon',
|
|
47
|
+
id: 'rolegroup',
|
|
48
|
+
order: 30,
|
|
49
|
+
label: () => t('title'),
|
|
50
|
+
}, mod.NavGlyph))
|
|
51
|
+
}, 'dsh-rolegroup: settings nav icon')
|
|
35
52
|
// scope 面与旧 settings 作用域同形(getSnapshot/subscribe/mutate/unset),controller 逻辑零改动。
|
|
36
53
|
const controller = new RolegroupCardController(ctx.configForms.get(ROLEGROUP_CLIENT_NS), ctx)
|
|
37
54
|
// 注册为**设置页的一个 section**(`settings.section`;官方 models / agent-presets、第三方皮肤中心 / PET 同款),
|
|
@@ -1,92 +1,74 @@
|
|
|
1
|
-
//
|
|
1
|
+
// dsh-rolegroup: 设置页导航图标(官方 `settings.section.icon` 槽位版)。
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// `settings.section`
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
3
|
+
// 历史:0.2.2-rc.5 之前 shell 只按 section id 硬编码 navIcon、未知 id 一律齿轮,本模块曾是
|
|
4
|
+
// 「给按钮打自定义 data 属性 + scoped CSS mask」的装饰 hack(旧版见 git 历史)。
|
|
5
|
+
// rc.5 起上游提供 `settings.section.icon` 槽位(contract/slots.d.ts:85;registration id 必须
|
|
6
|
+
// 等于目标 section 的 id,不匹配则永不渲染;缺席时 shell 保留默认齿轮),故改为正式注册。
|
|
7
|
+
//
|
|
8
|
+
// ⚠️ 浏览器侧依赖 React:NavGlyph 必须是真 React 组件且经模块系统 import react——
|
|
9
|
+
// globalThis.React / ctx.react 在 client 环境不存在(上一版那么取导致图标渲染为空,
|
|
10
|
+
// 2026-11-19 用户截图实证)。react 在 bundle 里 external、由 shell seed 解析(build-client.mjs)。
|
|
11
|
+
// node 测试**不得**直接 import 本模块(link: 形态下裸导入 react 必失败);纯函数部分
|
|
12
|
+
// (buildNavGlyph/NAV_GLYPH_*)经源码文本断言覆盖即可。
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
const NAV_GLYPH_URI = `data:image/svg+xml,${encodeURIComponent(NAV_GLYPH)}`
|
|
14
|
+
import * as React from 'react'
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
/** rolegroup 线稿(与插件 icon.svg 同款六边形+委派点),16×16 viewBox。 */
|
|
17
|
+
export const NAV_GLYPH_PATHS = [
|
|
18
|
+
'M8 1.7 13.4 4.8v6.4L8 14.3 2.6 11.2V4.8Z',
|
|
19
|
+
'M8 6.4V4.7M6.7 8.7 5.3 9.5M9.3 8.7 10.7 9.5',
|
|
20
|
+
]
|
|
21
|
+
export const NAV_GLYPH_CIRCLE = { cx: 8, cy: 8, r: 1.35 }
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param {
|
|
21
|
-
* @
|
|
22
|
-
* @returns {object | undefined} the tagged button
|
|
24
|
+
* 构建导航图标节点(喂给 slots.register 的组件)。
|
|
25
|
+
* @param {{ size?: number }} [props] shell 传入的 owner props(size = 请求的方形边长 px)
|
|
26
|
+
* @returns {{ tag: string, props: object, children: object[] }} 可序列化的图标描述(JSX-free,node 可测)
|
|
23
27
|
*/
|
|
24
|
-
export function
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
export function buildNavGlyph(props = {}) {
|
|
29
|
+
const size = typeof props.size === 'number' && props.size > 0 ? props.size : 16
|
|
30
|
+
return {
|
|
31
|
+
tag: 'svg',
|
|
32
|
+
props: {
|
|
33
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
34
|
+
viewBox: '0 0 16 16',
|
|
35
|
+
width: size,
|
|
36
|
+
height: size,
|
|
37
|
+
fill: 'none',
|
|
38
|
+
stroke: 'currentColor',
|
|
39
|
+
strokeWidth: 1.2,
|
|
40
|
+
strokeLinejoin: 'round',
|
|
41
|
+
strokeLinecap: 'round',
|
|
42
|
+
'aria-hidden': 'true',
|
|
43
|
+
},
|
|
44
|
+
children: [
|
|
45
|
+
{ tag: 'path', props: { d: NAV_GLYPH_PATHS[0] } },
|
|
46
|
+
{ tag: 'circle', props: { ...NAV_GLYPH_CIRCLE, fill: 'currentColor', stroke: 'none' } },
|
|
47
|
+
{ tag: 'path', props: { d: NAV_GLYPH_PATHS[1] } },
|
|
48
|
+
],
|
|
34
49
|
}
|
|
35
|
-
return undefined
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
53
|
+
* 导航图标组件(React function component)。
|
|
54
|
+
* ⚠️ React **必须经模块系统 import**:client bundle 里 react 是 external,由 shell seed 解析
|
|
55
|
+
* (与 card.jsx 同款通道);globalThis.React / ctx.react 在浏览器侧不存在——上一版这么取导致
|
|
56
|
+
* 图标渲染为空(2026-11-19 用户截图实证)。本文件因此不是零 DOM 依赖模块;node 测试只 import
|
|
57
|
+
* buildNavGlyph/NAV_GLYPH_* 纯函数部分即可(import 'react' 在 link:deps 软链下可解析)。
|
|
58
|
+
* @param {{ size?: number, active?: boolean }} props shell 传入的 owner props
|
|
43
59
|
*/
|
|
44
|
-
export function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const raf = options.requestAnimationFrame ?? globalThis.requestAnimationFrame
|
|
59
|
-
let scheduled = false
|
|
60
|
-
let disposed = false
|
|
61
|
-
const apply = () => {
|
|
62
|
-
scheduled = false
|
|
63
|
-
if (disposed) return
|
|
64
|
-
try {
|
|
65
|
-
markSettingsNavButton(doc.querySelectorAll?.('button') ?? [], labelOf?.())
|
|
66
|
-
} catch {
|
|
67
|
-
// Decoration only; never let it affect the settings page.
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const schedule = () => {
|
|
71
|
-
if (scheduled || disposed) return
|
|
72
|
-
scheduled = true
|
|
73
|
-
if (typeof raf === 'function') raf(apply)
|
|
74
|
-
else Promise.resolve().then(apply)
|
|
75
|
-
}
|
|
76
|
-
let observer
|
|
77
|
-
if (typeof Observer === 'function') {
|
|
78
|
-
try {
|
|
79
|
-
observer = new Observer(schedule)
|
|
80
|
-
observer.observe(doc.body, { childList: true, subtree: true })
|
|
81
|
-
} catch {
|
|
82
|
-
observer = undefined
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
apply()
|
|
86
|
-
return () => {
|
|
87
|
-
disposed = true
|
|
88
|
-
observer?.disconnect?.()
|
|
89
|
-
style.remove?.()
|
|
90
|
-
for (const button of doc.querySelectorAll?.('[data-dsh-rg-nav]') ?? []) button.removeAttribute?.('data-dsh-rg-nav')
|
|
91
|
-
}
|
|
60
|
+
export function NavGlyph(props) {
|
|
61
|
+
const g = buildNavGlyph(props)
|
|
62
|
+
return React.createElement(g.tag, g.props,
|
|
63
|
+
...g.children.map((c) => React.createElement(c.tag, c.props)))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 把图标描述渲染成真 React element(供 NavGlyph 与测试共用)。
|
|
68
|
+
* @param {object} React React 命名空间
|
|
69
|
+
* @param {ReturnType<typeof buildNavGlyph>} glyph
|
|
70
|
+
*/
|
|
71
|
+
export function renderNavGlyph(React, glyph) {
|
|
72
|
+
return React.createElement(glyph.tag, glyph.props,
|
|
73
|
+
...glyph.children.map((c) => React.createElement(c.tag, c.props)))
|
|
92
74
|
}
|