@dotdance/dsh-skill-scope 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/client.js +62 -62
- package/lib/index.js +186 -27
- package/package.json +9 -9
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
7
7
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
8
8
|
[](https://github.com/dotdance/dsh-skill-scope)
|
|
9
|
-
[](#installation)
|
|
10
10
|

|
|
11
11
|
|
|
12
12
|
**Lighten the load on your agent: one-click toggles for skills and MCP, so the context holds only what this turn actually needs. Skills and MCP servers you switch off are no longer injected into the model context — cleaner, and lighter on tokens.**
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
7
7
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
8
8
|
[](https://github.com/dotdance/dsh-skill-scope)
|
|
9
|
-
[](#安装)
|
|
10
10
|

|
|
11
11
|
|
|
12
12
|
**给你的 Agent 减负:Skill 与 MCP 一键启停,让上下文只装这一轮真正要用的能力。关掉的 skill / MCP 不再进入模型上下文,更干净,更省 token。**
|
package/lib/client.js
CHANGED
|
@@ -137,8 +137,8 @@ window.__ModuleLoader__.load({
|
|
|
137
137
|
return `网络请求失败:${String(error)}`;
|
|
138
138
|
}
|
|
139
139
|
//#endregion
|
|
140
|
-
//#region \0dsh-css-module:/
|
|
141
|
-
const css = ".
|
|
140
|
+
//#region \0dsh-css-module:/home/runner/work/dsh-skill-scope/dsh-skill-scope/src/client/styles.module.css?dsh-css-module
|
|
141
|
+
const css = ".Jg-IJa_panel{box-sizing:border-box;flex-direction:column;gap:16px;height:100%;padding:20px 24px 32px;display:flex;overflow-y:auto}.Jg-IJa_overlay{pointer-events:auto;background:var(--dsw-alias-bg-mask-1,#00000073);z-index:60;justify-content:center;align-items:center;display:flex;position:fixed;inset:0}.Jg-IJa_modal{z-index:1;background:var(--dsw-alias-bg-layer-1,Canvas);width:min(760px,100vw - 48px);max-width:calc(100vw - 48px);height:min(680px,100vh - 48px);color:var(--dsw-alias-label-primary,CanvasText);border-radius:24px;flex-direction:column;display:flex;position:relative;overflow:hidden;box-shadow:0 24px 64px #00000052}.Jg-IJa_panelHead{flex-direction:column;gap:16px;padding:24px 24px 16px;display:flex}.Jg-IJa_header{justify-content:space-between;align-items:center;gap:12px;display:flex}.Jg-IJa_title{margin:0;font-size:17px;font-weight:600;line-height:1.3}.Jg-IJa_intro{color:var(--dsw-alias-label-secondary,currentColor);margin:0;font-size:13px;line-height:1.55}.Jg-IJa_introWarn{color:var(--dsw-alias-state-warn-primary,currentColor);font-weight:600}.Jg-IJa_closeButton{width:28px;height:28px;color:var(--dsw-alias-label-secondary,currentColor);cursor:pointer;background:0 0;border:0;border-radius:8px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.Jg-IJa_closeButton:hover{background:var(--dsw-alias-interactive-bg-hover,transparent);color:var(--dsw-alias-label-primary,currentColor)}.Jg-IJa_searchRow{align-items:center;display:flex;position:relative}.Jg-IJa_searchIcon{color:var(--dsw-alias-label-tertiary,currentColor);pointer-events:none;display:inline-flex;position:absolute;left:12px}.Jg-IJa_search{border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-3,transparent);width:100%;color:var(--dsw-alias-label-primary,currentColor);font:inherit;border-radius:10px;padding:9px 12px 9px 36px;font-size:13px}.Jg-IJa_search::placeholder{color:var(--dsw-alias-label-tertiary,currentColor)}.Jg-IJa_search:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}.Jg-IJa_panelBody{flex:1;min-height:0;padding:4px 24px 24px;overflow-y:auto}.Jg-IJa_body{flex-direction:column;gap:14px;width:100%;display:flex}.Jg-IJa_section{flex-direction:column;gap:10px;min-width:0;display:flex}.Jg-IJa_sectionHead{align-items:center;gap:8px;min-width:0;display:flex}.Jg-IJa_sectionToggle{min-width:0;color:var(--dsw-alias-label-primary,currentColor);font:inherit;cursor:pointer;text-align:left;background:0 0;border:0;flex:1;align-items:center;gap:8px;padding:2px 0;display:flex}.Jg-IJa_sectionTitle{margin:0;font-size:14px;font-weight:600}.Jg-IJa_sectionCount{color:var(--dsw-alias-label-secondary,currentColor);font-size:13px}.Jg-IJa_sectionChevron{color:var(--dsw-alias-label-secondary,currentColor);margin-left:auto;transition:transform .14s;display:inline-flex}.Jg-IJa_sectionChevronOpen{transform:rotate(180deg)}.Jg-IJa_cards{grid-template-columns:repeat(2,minmax(0,1fr));align-items:start;gap:12px;margin:0;padding:0;list-style:none;display:grid}.Jg-IJa_groups{flex-direction:column;gap:14px;display:flex}.Jg-IJa_group{border-left:2px solid var(--dsw-alias-border-1,#00000014);flex-direction:column;gap:8px;min-width:0;padding-left:10px;display:flex}.Jg-IJa_groupToggle{min-width:0;color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;text-align:left;background:0 0;border:0;align-items:center;gap:6px;padding:2px 0;font-size:13px;font-weight:600;display:flex}.Jg-IJa_groupToggle:hover{color:var(--dsw-alias-label-primary,currentColor)}.Jg-IJa_groupChevron{flex:none;transition:transform .14s;display:inline-flex}.Jg-IJa_groupChevron[data-open=true]{transform:rotate(180deg)}.Jg-IJa_groupTitle{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.Jg-IJa_groupCount{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary,currentColor));font-variant-numeric:tabular-nums;flex:none;font-weight:400}@media (width<=640px){.Jg-IJa_cards{grid-template-columns:minmax(0,1fr)}}.Jg-IJa_card{border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-3,transparent);border-radius:10px;min-width:0;overflow:hidden}.Jg-IJa_cardHead{align-items:center;gap:10px;min-width:0;padding:11px 12px;display:flex}.Jg-IJa_cardMain{flex:1;align-items:center;gap:10px;min-width:0;display:flex}.Jg-IJa_cardName{text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;font-size:13px;font-weight:600;overflow:hidden}.Jg-IJa_overridden{align-items:center;display:inline-flex}.Jg-IJa_cardDisabled .Jg-IJa_cardName{color:var(--dsw-alias-label-secondary,currentColor)}.Jg-IJa_cardTail{flex:0 3 auto;align-items:center;gap:6px;min-width:0;display:inline-flex}.Jg-IJa_expandButton{width:20px;height:20px;color:var(--dsw-alias-label-secondary,currentColor);cursor:pointer;background:0 0;border:0;border-radius:6px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.Jg-IJa_expandButton:hover{background:var(--dsw-alias-interactive-bg-hover,transparent)}.Jg-IJa_expandChevron{transition:transform .14s;display:inline-flex}.Jg-IJa_expandChevronOpen{transform:rotate(180deg)}.Jg-IJa_cardBody{border-top:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);padding:10px;font-size:12px;line-height:1.55}.Jg-IJa_cardDescription{overflow-wrap:anywhere;margin:0}.Jg-IJa_detailRow{gap:10px;margin-top:8px;display:flex}.Jg-IJa_detailKey{width:56px;color:var(--dsw-alias-label-secondary,currentColor);flex:none}.Jg-IJa_detailValue{min-width:0;color:var(--dsw-alias-label-primary,currentColor);overflow-wrap:anywhere}.Jg-IJa_detailOrigin{min-width:0;color:var(--dsw-alias-label-primary,currentColor);overflow-wrap:anywhere;word-break:break-all;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:1.5}.Jg-IJa_toolList{min-width:0;max-height:120px;margin:0;padding:0;list-style:none;overflow-y:auto}.Jg-IJa_toolName{color:var(--dsw-alias-label-primary,currentColor);overflow-wrap:anywhere;word-break:break-all;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}.Jg-IJa_switch{cursor:pointer;background:0 0;border:0;border-radius:999px;flex:none;align-items:center;padding:0;display:inline-flex}.Jg-IJa_switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,currentColor);outline-offset:2px}.Jg-IJa_switchTrack{background:var(--dsw-alias-border-l2,currentColor);border-radius:999px;width:28px;height:16px;transition:background-color .12s ease-in-out;display:inline-block;position:relative}.Jg-IJa_switchOn .Jg-IJa_switchTrack{background:var(--dsw-alias-state-business-primary,currentColor)}.Jg-IJa_switchThumb{background:var(--dsw-alias-bg-layer-1,currentColor);border-radius:50%;width:12px;height:12px;transition:transform .12s ease-in-out;position:absolute;top:2px;left:2px}.Jg-IJa_switchOn .Jg-IJa_switchThumb{transform:translate(12px)}.Jg-IJa_switch:disabled{cursor:not-allowed;opacity:.5}.Jg-IJa_alert{border:1px solid var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-primary,currentColor);border-radius:8px;justify-content:space-between;align-items:center;gap:8px;padding:8px 10px;font-size:12px;display:flex}.Jg-IJa_modeRow{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.Jg-IJa_modeButton{border:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;background:0 0;border-radius:999px;padding:4px 12px;font-size:12px}.Jg-IJa_modeButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,transparent)}.Jg-IJa_modeButtonActive{border-color:var(--dsw-alias-brand-primary,currentColor);background:var(--dsw-alias-interactive-bg-active,transparent);color:var(--dsw-alias-brand-primary,currentColor)}.Jg-IJa_modeButton:disabled{cursor:not-allowed;opacity:.5}.Jg-IJa_modeRowTrailing{align-items:center;margin-left:auto;display:flex}.Jg-IJa_toggleRow{color:var(--dsw-alias-label-secondary,currentColor);align-items:center;gap:8px;font-size:12px;display:flex}.Jg-IJa_toggleLabel{cursor:default;user-select:none}.Jg-IJa_button{border:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;background:0 0;border-radius:8px;padding:4px 10px;font-size:12px}.Jg-IJa_button:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,transparent)}.Jg-IJa_button:disabled{cursor:not-allowed;opacity:.5}.Jg-IJa_empty{color:var(--dsw-alias-label-secondary,currentColor);padding:4px 2px;font-size:12px}.Jg-IJa_chip{border:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;background:0 0;border-radius:999px;align-items:center;gap:5px;padding:3px 9px;font-size:12px;display:inline-flex}.Jg-IJa_chip:hover{background:var(--dsw-alias-interactive-bg-hover,transparent)}";
|
|
142
142
|
const tagId = "@dotdance/dsh-skill-scope/styles.module.css";
|
|
143
143
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
144
144
|
const tag = document.createElement("style");
|
|
@@ -148,66 +148,66 @@ window.__ModuleLoader__.load({
|
|
|
148
148
|
document.head.appendChild(tag);
|
|
149
149
|
}
|
|
150
150
|
var styles_module_default = {
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
"
|
|
173
|
-
"
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
-
"
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"
|
|
190
|
-
"
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"
|
|
205
|
-
"
|
|
206
|
-
"
|
|
207
|
-
"
|
|
208
|
-
"
|
|
209
|
-
"
|
|
210
|
-
"
|
|
151
|
+
"cardMain": "Jg-IJa_cardMain",
|
|
152
|
+
"cardDisabled": "Jg-IJa_cardDisabled",
|
|
153
|
+
"chip": "Jg-IJa_chip",
|
|
154
|
+
"switchThumb": "Jg-IJa_switchThumb",
|
|
155
|
+
"intro": "Jg-IJa_intro",
|
|
156
|
+
"sectionHead": "Jg-IJa_sectionHead",
|
|
157
|
+
"cards": "Jg-IJa_cards",
|
|
158
|
+
"cardName": "Jg-IJa_cardName",
|
|
159
|
+
"searchRow": "Jg-IJa_searchRow",
|
|
160
|
+
"modeRowTrailing": "Jg-IJa_modeRowTrailing",
|
|
161
|
+
"detailValue": "Jg-IJa_detailValue",
|
|
162
|
+
"section": "Jg-IJa_section",
|
|
163
|
+
"sectionChevron": "Jg-IJa_sectionChevron",
|
|
164
|
+
"search": "Jg-IJa_search",
|
|
165
|
+
"cardDescription": "Jg-IJa_cardDescription",
|
|
166
|
+
"modeRow": "Jg-IJa_modeRow",
|
|
167
|
+
"expandChevronOpen": "Jg-IJa_expandChevronOpen",
|
|
168
|
+
"sectionChevronOpen": "Jg-IJa_sectionChevronOpen",
|
|
169
|
+
"sectionTitle": "Jg-IJa_sectionTitle",
|
|
170
|
+
"group": "Jg-IJa_group",
|
|
171
|
+
"switchOn": "Jg-IJa_switchOn",
|
|
172
|
+
"toggleRow": "Jg-IJa_toggleRow",
|
|
173
|
+
"panel": "Jg-IJa_panel",
|
|
174
|
+
"switchTrack": "Jg-IJa_switchTrack",
|
|
175
|
+
"panelBody": "Jg-IJa_panelBody",
|
|
176
|
+
"closeButton": "Jg-IJa_closeButton",
|
|
177
|
+
"groups": "Jg-IJa_groups",
|
|
178
|
+
"groupTitle": "Jg-IJa_groupTitle",
|
|
179
|
+
"detailRow": "Jg-IJa_detailRow",
|
|
180
|
+
"expandChevron": "Jg-IJa_expandChevron",
|
|
181
|
+
"header": "Jg-IJa_header",
|
|
182
|
+
"searchIcon": "Jg-IJa_searchIcon",
|
|
183
|
+
"cardBody": "Jg-IJa_cardBody",
|
|
184
|
+
"overridden": "Jg-IJa_overridden",
|
|
185
|
+
"alert": "Jg-IJa_alert",
|
|
186
|
+
"empty": "Jg-IJa_empty",
|
|
187
|
+
"panelHead": "Jg-IJa_panelHead",
|
|
188
|
+
"body": "Jg-IJa_body",
|
|
189
|
+
"overlay": "Jg-IJa_overlay",
|
|
190
|
+
"sectionCount": "Jg-IJa_sectionCount",
|
|
191
|
+
"sectionToggle": "Jg-IJa_sectionToggle",
|
|
192
|
+
"detailKey": "Jg-IJa_detailKey",
|
|
193
|
+
"toggleLabel": "Jg-IJa_toggleLabel",
|
|
194
|
+
"toolName": "Jg-IJa_toolName",
|
|
195
|
+
"cardTail": "Jg-IJa_cardTail",
|
|
196
|
+
"cardHead": "Jg-IJa_cardHead",
|
|
197
|
+
"groupToggle": "Jg-IJa_groupToggle",
|
|
198
|
+
"introWarn": "Jg-IJa_introWarn",
|
|
199
|
+
"groupChevron": "Jg-IJa_groupChevron",
|
|
200
|
+
"modeButton": "Jg-IJa_modeButton",
|
|
201
|
+
"button": "Jg-IJa_button",
|
|
202
|
+
"modal": "Jg-IJa_modal",
|
|
203
|
+
"expandButton": "Jg-IJa_expandButton",
|
|
204
|
+
"toolList": "Jg-IJa_toolList",
|
|
205
|
+
"detailOrigin": "Jg-IJa_detailOrigin",
|
|
206
|
+
"title": "Jg-IJa_title",
|
|
207
|
+
"groupCount": "Jg-IJa_groupCount",
|
|
208
|
+
"card": "Jg-IJa_card",
|
|
209
|
+
"switch": "Jg-IJa_switch",
|
|
210
|
+
"modeButtonActive": "Jg-IJa_modeButtonActive"
|
|
211
211
|
};
|
|
212
212
|
//#endregion
|
|
213
213
|
//#region src/client/parts.tsx
|
package/lib/index.js
CHANGED
|
@@ -12,18 +12,93 @@ import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
|
|
|
12
12
|
* **唯一会被求值器采纳的模式**,用它当缺省可以避免「存进去的 mode 与读回来
|
|
13
13
|
* 归一后的 mode 不一致」这种需要额外解释的状态。
|
|
14
14
|
*/
|
|
15
|
-
const EMPTY_POLICY = {
|
|
15
|
+
const EMPTY_POLICY = deepFreeze({
|
|
16
16
|
mode: "blacklist",
|
|
17
17
|
skills: [],
|
|
18
18
|
mcps: [],
|
|
19
19
|
showOfficialSkills: false
|
|
20
|
-
};
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* 冻结缺省策略(含里面的数组)。
|
|
23
|
+
*
|
|
24
|
+
* 它是**被所有调用方共享**的常量:`tests/agent/hooks.spec.ts` 的 `makeHarness` 直接把它
|
|
25
|
+
* 当作 `global`,生产侧也可能把它当缺省层返回。一次原地 `push` 就会让缺省策略永久带上
|
|
26
|
+
* 别人的名字,而且跨用例、跨会话串味(单跑不复现、全量偶发)。冻结后这种写入会直接抛。
|
|
27
|
+
*/
|
|
28
|
+
function deepFreeze(value) {
|
|
29
|
+
if (value === null || typeof value !== "object") return value;
|
|
30
|
+
for (const inner of Object.values(value)) deepFreeze(inner);
|
|
31
|
+
return Object.freeze(value);
|
|
32
|
+
}
|
|
21
33
|
/** Skill 名形状(与 `dsh-skill` 的命名一致,见设计 3.1)。 */
|
|
22
34
|
const SKILL_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
23
35
|
/** MCP server 名形状。由 `MCP_SERVER_NAME_MAX` 生成,长度约束不再手写第二遍。 */
|
|
24
36
|
const MCP_NAME_RE = new RegExp(`^[A-Za-z0-9_-]{1,32}$`);
|
|
25
37
|
const SORTED_UNIQUE = (names) => [...new Set(names)].sort();
|
|
26
38
|
/**
|
|
39
|
+
* 逐元素挑出合法名字,并把被丢弃的元素**原样**带出来(`previewValue` 与去重交给调用方)。
|
|
40
|
+
*
|
|
41
|
+
* **不能退回「正则挂在 zod 数组元素上」的写法**:`z.array(z.string().regex(…)).catch([])`
|
|
42
|
+
* 的 `.catch` 是整数组级别的,一个坏名字让整份名单失效(见 lenientPolicySchema 的注释)。
|
|
43
|
+
* 这里改成逐个判,最坏只丢那一条,且丢弃项可被用户看见。
|
|
44
|
+
*
|
|
45
|
+
* `pattern` 必须**不带 `g` 标志**:`RegExp.prototype.test` 对带 `g` 的正则会推进
|
|
46
|
+
* `lastIndex`,同一个正则复用会漏判隔项(这里用的是模块级共享正则)。
|
|
47
|
+
*/
|
|
48
|
+
function pickNames(raw, pattern) {
|
|
49
|
+
const names = [];
|
|
50
|
+
const dropped = [];
|
|
51
|
+
for (const item of raw) if (typeof item === "string" && pattern.test(item)) names.push(item);
|
|
52
|
+
else dropped.push(item);
|
|
53
|
+
return {
|
|
54
|
+
names,
|
|
55
|
+
dropped
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 丢弃项去重后再渲染:按**原值**去重(`Set` 对原始值按值、对对象按引用),
|
|
60
|
+
* 先渲染再去重会把 `1` 与 `"1"` 这类不同原值合并成一条,条数与实际不符。
|
|
61
|
+
*/
|
|
62
|
+
function previewDropped(items) {
|
|
63
|
+
return [...new Set(items)].map(previewValue);
|
|
64
|
+
}
|
|
65
|
+
/** 被丢弃条目的展示上限:单条超过这个长度就截断(用户输入长度不可控)。 */
|
|
66
|
+
const PREVIEW_MAX = 40;
|
|
67
|
+
/**
|
|
68
|
+
* 把被丢弃的元素写成一短段可读文本。**永不抛错**。
|
|
69
|
+
*
|
|
70
|
+
* `normalizePolicy` 的契约是「永不抛错」,而 `JSON.stringify` 遇到 `BigInt` 与循环引用
|
|
71
|
+
* 会抛 `TypeError`(实测 `{skills:[1n]}` → `TypeError: Do not know how to serialize a BigInt`),
|
|
72
|
+
* 所以这里必须兜住;字符串走 `JSON.stringify` 是为了让空串与前导空格在日志里可见
|
|
73
|
+
* (`""` / `" good"` 一眼可辨)。
|
|
74
|
+
*/
|
|
75
|
+
function previewValue(item) {
|
|
76
|
+
if (typeof item === "number" && !Number.isFinite(item)) return String(item);
|
|
77
|
+
let text;
|
|
78
|
+
if (typeof item === "string") text = JSON.stringify(clamp(item));
|
|
79
|
+
else try {
|
|
80
|
+
text = JSON.stringify(item) ?? `[${typeof item}]`;
|
|
81
|
+
} catch {
|
|
82
|
+
text = `[${typeof item}]`;
|
|
83
|
+
}
|
|
84
|
+
return clamp(text);
|
|
85
|
+
}
|
|
86
|
+
/** 按**码点**(不是 UTF-16 码元)截断,超长加省略号。 */
|
|
87
|
+
function clamp(text) {
|
|
88
|
+
if (text.length <= PREVIEW_MAX) return text;
|
|
89
|
+
return `${Array.from(text).slice(0, PREVIEW_MAX).join("")}…`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 该字段是否**整份**被 zod 丢掉——与「只丢了几个元素」区分开。
|
|
93
|
+
*
|
|
94
|
+
* 只剩「非数组(类型写错)」一种:数量超限**不再**由 zod 判(见 reconstruct 后的注释),
|
|
95
|
+
* 因为超限必须在元素过滤之后、按**过滤后的有效名字数**判,否则
|
|
96
|
+
* 「512 条合法 + 1 条 junk」会先因 513 条超限被整份 `.catch()` 掉。
|
|
97
|
+
*/
|
|
98
|
+
function listVoided(raw) {
|
|
99
|
+
return raw !== void 0 && !Array.isArray(raw);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
27
102
|
* 宽松的读取 schema:任何一项不合法都退回该层的缺省,由调用方补一条 warning。
|
|
28
103
|
* `mode` 可选(缺失时取调用方给的层缺省);名单元素必须过正则、数量不得超限。
|
|
29
104
|
*
|
|
@@ -36,8 +111,8 @@ const SORTED_UNIQUE = (names) => [...new Set(names)].sort();
|
|
|
36
111
|
*/
|
|
37
112
|
const lenientPolicySchema = (fallbackMode) => z.object({
|
|
38
113
|
mode: z.enum(["blacklist", "default"]).transform(() => "blacklist").catch(() => fallbackMode).default(() => fallbackMode),
|
|
39
|
-
skills: z.array(z.
|
|
40
|
-
mcps: z.array(z.
|
|
114
|
+
skills: z.array(z.unknown()).catch([]).default([]),
|
|
115
|
+
mcps: z.array(z.unknown()).catch([]).default([]),
|
|
41
116
|
showOfficialSkills: z.boolean().catch(false).default(false)
|
|
42
117
|
});
|
|
43
118
|
/**
|
|
@@ -51,22 +126,39 @@ function normalizePolicy(raw, fallbackMode) {
|
|
|
51
126
|
warning: `策略内容不合法,已回退为空策略:${parsed.error.message}`
|
|
52
127
|
};
|
|
53
128
|
const source = raw;
|
|
129
|
+
const skillsScan = pickNames(parsed.data.skills, SKILL_NAME_RE);
|
|
130
|
+
const mcpsScan = pickNames(parsed.data.mcps, MCP_NAME_RE);
|
|
131
|
+
const droppedSkills = previewDropped(skillsScan.dropped);
|
|
132
|
+
const droppedMcps = previewDropped(mcpsScan.dropped);
|
|
133
|
+
const skills = SORTED_UNIQUE(skillsScan.names);
|
|
134
|
+
const mcps = SORTED_UNIQUE(mcpsScan.names);
|
|
135
|
+
const skillsOverflow = skills.length > 512;
|
|
136
|
+
const mcpsOverflow = mcps.length > 512;
|
|
54
137
|
const policy = {
|
|
55
138
|
mode: parsed.data.mode,
|
|
56
|
-
skills:
|
|
57
|
-
mcps:
|
|
139
|
+
skills: skillsOverflow ? [] : skills,
|
|
140
|
+
mcps: mcpsOverflow ? [] : mcps,
|
|
58
141
|
showOfficialSkills: parsed.data.showOfficialSkills
|
|
59
142
|
};
|
|
60
143
|
const drifted = [];
|
|
61
|
-
if (source?.skills
|
|
62
|
-
if (source?.mcps
|
|
144
|
+
if (listVoided(source?.skills)) drifted.push("skills");
|
|
145
|
+
if (listVoided(source?.mcps)) drifted.push("mcps");
|
|
63
146
|
if (source?.showOfficialSkills !== void 0 && source.showOfficialSkills !== policy.showOfficialSkills) drifted.push("showOfficialSkills");
|
|
64
147
|
const migratedMode = source?.mode !== void 0 && source.mode !== policy.mode;
|
|
65
|
-
|
|
148
|
+
const dropSegment = (label, names) => names.length === 0 ? "" : `${label}:${names.slice(0, 5).join(", ")}${names.length > 5 ? ` 等 ${names.length} 项` : ""}`;
|
|
149
|
+
const droppedTotal = droppedSkills.length + droppedMcps.length;
|
|
150
|
+
const dropParts = [dropSegment("不合法 skill", droppedSkills), dropSegment("不合法 mcp", droppedMcps)].filter((part) => part !== "");
|
|
151
|
+
const droppedText = dropParts.length === 0 ? "" : `(${dropParts.join(";")})`;
|
|
152
|
+
const clauses = [];
|
|
153
|
+
if (drifted.length > 0) clauses.push(`已忽略字段:${drifted.join(", ")}`);
|
|
154
|
+
if (droppedTotal > 0) clauses.push("已丢弃不合法的名字");
|
|
155
|
+
if (skillsOverflow) clauses.push(`skills 有效名字 ${skills.length} 条超过上限 512,已整份忽略`);
|
|
156
|
+
if (mcpsOverflow) clauses.push(`mcps 有效名字 ${mcps.length} 条超过上限 512,已整份忽略`);
|
|
157
|
+
if (clauses.length > 0) {
|
|
66
158
|
const migrated = migratedMode ? `;mode 由「${String(source?.mode)}」归一到「${policy.mode}」(白名单已废弃,名单语义统一为黑名单)` : "";
|
|
67
159
|
return {
|
|
68
160
|
policy,
|
|
69
|
-
warning:
|
|
161
|
+
warning: `策略中有内容不合法,${clauses.join(";")}${droppedText}${migrated}`
|
|
70
162
|
};
|
|
71
163
|
}
|
|
72
164
|
if (migratedMode) return {
|
|
@@ -75,12 +167,6 @@ function normalizePolicy(raw, fallbackMode) {
|
|
|
75
167
|
};
|
|
76
168
|
return { policy };
|
|
77
169
|
}
|
|
78
|
-
function sameSet(raw, normalized) {
|
|
79
|
-
if (!Array.isArray(raw)) return false;
|
|
80
|
-
const asStrings = raw.filter((item) => typeof item === "string");
|
|
81
|
-
if (asStrings.length !== raw.length) return false;
|
|
82
|
-
return asStrings.length === normalized.length && SORTED_UNIQUE(asStrings).join("\n") === normalized.join("\n");
|
|
83
|
-
}
|
|
84
170
|
/**
|
|
85
171
|
* `JSON.parse` 一次,失败时折叠成 `{ ok: false, warning }`。
|
|
86
172
|
*
|
|
@@ -524,6 +610,8 @@ var PolicyStore = class {
|
|
|
524
610
|
fs;
|
|
525
611
|
lock;
|
|
526
612
|
logger;
|
|
613
|
+
/** 上一次已上报的全局警告指纹(`revision + warning`),见 `reportGlobalWarning`。 */
|
|
614
|
+
reportedGlobalWarning = "";
|
|
527
615
|
/** 按路径串行化的队列尾。每个写入者的 promise 接在上一个之后。 */
|
|
528
616
|
queues = /* @__PURE__ */ new Map();
|
|
529
617
|
constructor(deps) {
|
|
@@ -539,14 +627,32 @@ var PolicyStore = class {
|
|
|
539
627
|
revision: null,
|
|
540
628
|
exists: false
|
|
541
629
|
};
|
|
630
|
+
const revision = sha256Hex(text);
|
|
542
631
|
const { policy, warning } = parseGlobalPolicy(text);
|
|
632
|
+
if (warning !== void 0) this.reportGlobalWarning(path, revision, warning);
|
|
543
633
|
return {
|
|
544
634
|
policy,
|
|
545
|
-
revision
|
|
635
|
+
revision,
|
|
546
636
|
exists: true,
|
|
547
637
|
...warning === void 0 ? {} : { warning }
|
|
548
638
|
};
|
|
549
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* 把全局文件的解析警告**就地**记一条日志。
|
|
642
|
+
*
|
|
643
|
+
* 为什么不在调用方记:`loadGlobal` 有三个消费方——面板的 `readGlobalValue`、
|
|
644
|
+
* 工作区视图的 `buildWorkspaceView`、以及真正的执行路径 `agent/hooks` 的 `evaluate`。
|
|
645
|
+
* 只在路由层记的话,「用户从不打开面板」时坏策略**一行日志都没有**(skill 悄悄失效、
|
|
646
|
+
* 用户无从查起);分别记则每次 `agent/created` 都刷一条。
|
|
647
|
+
* 在唯一的数据源处记、并按 `revision + warning` 去重,三种情形一并解决:
|
|
648
|
+
* 内容不变只记一次,文件一改立刻再记一次。
|
|
649
|
+
*/
|
|
650
|
+
reportGlobalWarning(path, revision, warning) {
|
|
651
|
+
const stamp = `${revision}\n${warning}`;
|
|
652
|
+
if (stamp === this.reportedGlobalWarning) return;
|
|
653
|
+
this.reportedGlobalWarning = stamp;
|
|
654
|
+
this.logger.warn(`dsh-skill-scope: 全局策略文件(${path}):${warning}`);
|
|
655
|
+
}
|
|
550
656
|
async saveGlobal(policy, expected) {
|
|
551
657
|
const path = globalPolicyPath();
|
|
552
658
|
return await this.write(path, expected, () => serializeGlobalPolicy(policy));
|
|
@@ -1242,14 +1348,34 @@ function denyFor(toolNames, restrictableNames, hiddenServers, knownServers) {
|
|
|
1242
1348
|
*/
|
|
1243
1349
|
async function applyMcpRestriction(input) {
|
|
1244
1350
|
if (input.previous !== null && input.previous.key === input.key) return input.previous;
|
|
1245
|
-
input.
|
|
1246
|
-
|
|
1351
|
+
if (input.deny.length === 0) {
|
|
1352
|
+
releasePrevious(input);
|
|
1353
|
+
return null;
|
|
1354
|
+
}
|
|
1247
1355
|
const release = input.tools.restrict({ deny: [...input.deny] }, input.agent);
|
|
1356
|
+
releasePrevious(input);
|
|
1248
1357
|
return {
|
|
1249
1358
|
key: input.key,
|
|
1250
1359
|
release
|
|
1251
1360
|
};
|
|
1252
1361
|
}
|
|
1362
|
+
/**
|
|
1363
|
+
* 释放旧句柄,**失败只上报、不抛**。
|
|
1364
|
+
*
|
|
1365
|
+
* `release()` 会同步 emit `tools/change`(`ScopedLayers` 的 undo 里调 `onChange()`),
|
|
1366
|
+
* 若某个监听器在 emit 时抛错,异常会从 `release()` 里冒出来。裸调用的话:新层已挂上、
|
|
1367
|
+
* 旧层已撤、`applyMcpRestriction` 却抛错 ⇒ `applyRound` 不更新 `state.mcpKey` 与
|
|
1368
|
+
* `mcpDispose`,状态仍指着**已死**的旧句柄 —— 这正是「先注册后释放」要消灭的那个状态,
|
|
1369
|
+
* 从释放这一侧重新进来。仓内 `releaseOne`(`src/agent/hooks.ts`)用的是同一口径。
|
|
1370
|
+
*/
|
|
1371
|
+
function releasePrevious(input) {
|
|
1372
|
+
if (input.previous === null) return;
|
|
1373
|
+
try {
|
|
1374
|
+
input.previous.release();
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
input.onReleaseError?.(error);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1253
1379
|
//#endregion
|
|
1254
1380
|
//#region src/agent/skills.ts
|
|
1255
1381
|
const shadowHandles = /* @__PURE__ */ new WeakMap();
|
|
@@ -1494,6 +1620,8 @@ async function applyRound(deps, state, hidden, toolNames, knownServers, isActive
|
|
|
1494
1620
|
});
|
|
1495
1621
|
if (!isActive()) {
|
|
1496
1622
|
releaseOne(deps, "skill shadow", result.release);
|
|
1623
|
+
state.skillKey = "";
|
|
1624
|
+
state.skillDispose = null;
|
|
1497
1625
|
return;
|
|
1498
1626
|
}
|
|
1499
1627
|
state.skillDispose = result.release;
|
|
@@ -1509,10 +1637,15 @@ async function applyRound(deps, state, hidden, toolNames, knownServers, isActive
|
|
|
1509
1637
|
deny,
|
|
1510
1638
|
key: mcpKey,
|
|
1511
1639
|
previous: mcpRestrictionOf(state),
|
|
1512
|
-
agent: scope
|
|
1640
|
+
agent: scope,
|
|
1641
|
+
onReleaseError: (error) => {
|
|
1642
|
+
deps.logger.warn(`dsh-skill-scope: 撤销 mcp restriction 失败:${String(error)}`);
|
|
1643
|
+
}
|
|
1513
1644
|
}));
|
|
1514
1645
|
if (!isActive()) {
|
|
1515
1646
|
releaseOne(deps, "mcp restriction", next?.release ?? null);
|
|
1647
|
+
state.mcpKey = "";
|
|
1648
|
+
state.mcpDispose = null;
|
|
1516
1649
|
return;
|
|
1517
1650
|
}
|
|
1518
1651
|
state.mcpKey = mcpKey;
|
|
@@ -1586,7 +1719,8 @@ function installAgentHooks(ctx, deps) {
|
|
|
1586
1719
|
const created = {
|
|
1587
1720
|
applying: false,
|
|
1588
1721
|
pending: false,
|
|
1589
|
-
disposed: false
|
|
1722
|
+
disposed: false,
|
|
1723
|
+
inFlight: null
|
|
1590
1724
|
};
|
|
1591
1725
|
applyStates.set(agentId, created);
|
|
1592
1726
|
return created;
|
|
@@ -1630,7 +1764,24 @@ function installAgentHooks(ctx, deps) {
|
|
|
1630
1764
|
const applyState = applyStateFor(state.agent.id);
|
|
1631
1765
|
if (stopped || applyState.disposed) return Promise.resolve();
|
|
1632
1766
|
applyState.pending = true;
|
|
1633
|
-
|
|
1767
|
+
const running = applyState.inFlight;
|
|
1768
|
+
if (running !== null) return running;
|
|
1769
|
+
let settle = () => {};
|
|
1770
|
+
const flight = new Promise((resolve) => {
|
|
1771
|
+
settle = resolve;
|
|
1772
|
+
});
|
|
1773
|
+
applyState.inFlight = flight;
|
|
1774
|
+
(async () => {
|
|
1775
|
+
try {
|
|
1776
|
+
do
|
|
1777
|
+
await drainAgent(state, applyState, source);
|
|
1778
|
+
while (applyState.pending && !stopped && !applyState.disposed);
|
|
1779
|
+
} finally {
|
|
1780
|
+
applyState.inFlight = null;
|
|
1781
|
+
settle();
|
|
1782
|
+
}
|
|
1783
|
+
})();
|
|
1784
|
+
return flight;
|
|
1634
1785
|
};
|
|
1635
1786
|
const onCreated = async (payload) => {
|
|
1636
1787
|
if (stopped) return;
|
|
@@ -1644,10 +1795,10 @@ function installAgentHooks(ctx, deps) {
|
|
|
1644
1795
|
return;
|
|
1645
1796
|
}
|
|
1646
1797
|
const state = deps.states.ensure(agent);
|
|
1647
|
-
requestAgentApply(state, "agent/created");
|
|
1798
|
+
await requestAgentApply(state, "agent/created");
|
|
1648
1799
|
};
|
|
1649
1800
|
const onDisposed = (value) => {
|
|
1650
|
-
const agent = asAgentLike(value);
|
|
1801
|
+
const agent = asAgentLike((typeof value === "object" && value !== null ? value : null)?.agent ?? value);
|
|
1651
1802
|
if (agent === null) return;
|
|
1652
1803
|
const applyState = applyStates.get(agent.id);
|
|
1653
1804
|
if (applyState !== void 0) {
|
|
@@ -2518,15 +2669,23 @@ function assemble(ctx, deps = {}) {
|
|
|
2518
2669
|
const fetchRegister = readFetchRegister(ctx);
|
|
2519
2670
|
if (fetchRegister === null) {
|
|
2520
2671
|
ctx.logger.warn(`dsh-skill-scope: connection 服务在册但没有 fetch.register,路由未注册(策略仍生效)`);
|
|
2521
|
-
return;
|
|
2672
|
+
return () => {};
|
|
2522
2673
|
}
|
|
2523
|
-
|
|
2674
|
+
const release = registerRoutes(ctx, routeDeps, fetchRegister);
|
|
2675
|
+
let released = false;
|
|
2676
|
+
const dispose = async () => {
|
|
2677
|
+
if (released) return;
|
|
2678
|
+
released = true;
|
|
2679
|
+
await release();
|
|
2680
|
+
};
|
|
2681
|
+
disposeRoutes = dispose;
|
|
2682
|
+
return dispose;
|
|
2524
2683
|
});
|
|
2525
2684
|
return {
|
|
2526
2685
|
store,
|
|
2527
2686
|
states,
|
|
2528
2687
|
disposeHooks: disposeHooks.stopAll,
|
|
2529
|
-
disposeRoutes,
|
|
2688
|
+
disposeRoutes: () => disposeRoutes(),
|
|
2530
2689
|
reapplyAfterSave
|
|
2531
2690
|
};
|
|
2532
2691
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdance/dsh-skill-scope",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Skill and MCP visibility manager for DeepSeek Harness: the global layer sets a default, and each workspace can override any name both ways, with a sidebar panel and an input-card entry.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": "^22.19.0 || >=24.0.0",
|
|
18
|
-
"dsh": ">=0.2.2-rc.1 <0.
|
|
18
|
+
"dsh": ">=0.2.2-rc.1 <0.4.0-0"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsdown",
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"url": "git+https://github.com/dotdance/dsh-skill-scope.git"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@deepseek-ai/dsh-atomic-write": ">=0.2.2-rc.1 <0.
|
|
42
|
-
"@deepseek-ai/dsh-home-paths": ">=0.2.2-rc.1 <0.
|
|
41
|
+
"@deepseek-ai/dsh-atomic-write": ">=0.2.2-rc.1 <0.4.0-0",
|
|
42
|
+
"@deepseek-ai/dsh-home-paths": ">=0.2.2-rc.1 <0.4.0-0",
|
|
43
43
|
"zod": "^4.6.6"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@deepseek-ai/cordis": "4.0.6-alpha.1 || 4.1.0",
|
|
47
|
-
"@deepseek-ai/dsh-agent": ">=0.2.2-rc.1 <0.
|
|
48
|
-
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.1 <0.
|
|
49
|
-
"@deepseek-ai/dsh-host-webserver": ">=0.2.2-rc.1 <0.
|
|
50
|
-
"@deepseek-ai/dsh-skill": ">=0.2.2-rc.1 <0.
|
|
51
|
-
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.
|
|
47
|
+
"@deepseek-ai/dsh-agent": ">=0.2.2-rc.1 <0.4.0-0",
|
|
48
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.1 <0.4.0-0",
|
|
49
|
+
"@deepseek-ai/dsh-host-webserver": ">=0.2.2-rc.1 <0.4.0-0",
|
|
50
|
+
"@deepseek-ai/dsh-skill": ">=0.2.2-rc.1 <0.4.0-0",
|
|
51
|
+
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.4.0-0",
|
|
52
52
|
"react": "^18.2.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|