@dotdance/dsh-skill-scope 0.2.1 → 0.3.0-alpha.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/lib/client.js CHANGED
@@ -7,6 +7,24 @@ window.__ModuleLoader__.load({
7
7
  let react = require("react");
8
8
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ //#region src/shared/routes.ts
11
+ /**
12
+ * 插件自有四条路由的**路径段**(不含前导斜杠)。
13
+ *
14
+ * 宿主侧注册与客户端请求必须逐字符一致,否则**静默落 404**:
15
+ * - 宿主:`HostConnectionFetch.register({ path })` 的键是完整 pathname
16
+ * (`fetchRoutes.get(url.pathname)`),所以注册时要补 `/`,得到 `/api/skill-scope/global`;
17
+ * - 客户端:`post()` 内部同样补 `/`(`fetch('/' + route, …)`),所以这里存不带斜杠的形式。
18
+ *
19
+ * 两处共用同一张表,改一条路径只有一处可改。
20
+ */
21
+ const API_PATH = {
22
+ global: "api/skill-scope/global",
23
+ globalSave: "api/skill-scope/global/save",
24
+ workspace: "api/skill-scope/workspace",
25
+ workspaceSave: "api/skill-scope/workspace/save"
26
+ };
27
+ //#endregion
10
28
  //#region src/shared/unknown.ts
11
29
  /**
12
30
  * `unknown` 收窄工具。**全仓库唯一一份**。
@@ -55,17 +73,8 @@ window.__ModuleLoader__.load({
55
73
  this.code = code;
56
74
  }
57
75
  };
58
- /**
59
- * 四条路由。**不含前导斜杠**(`post` 会补上);这样字符串本身就是设计 6.2 里写的那个值,
60
- * 与 `src/routes/register.ts` 的 `ROUTES`(含 `/api` 前缀的完整 pathname)在语义上区分开:
61
- * 那边的值是「宿主注册用的完整 pathname」,这边是「客户端要拼的路径片段」。
62
- */
63
- const ROUTES = {
64
- global: "api/skill-scope/global",
65
- globalSave: "api/skill-scope/global/save",
66
- workspace: "api/skill-scope/workspace",
67
- workspaceSave: "api/skill-scope/workspace/save"
68
- };
76
+ /** 四条路由:路径段的唯一来源是 `src/shared/routes.ts`,`post` 会补前导斜杠。 */
77
+ const ROUTES = API_PATH;
69
78
  /** 默认超时。面板是交互入口,10 秒足够;超时必须兜底,不能让用户对着转圈等。 */
70
79
  const DEFAULT_TIMEOUT_MS = 1e4;
71
80
  /** 从错误信封里读 `code`,读不到就退回 `internal`(不假装知道是哪种失败)。 */
@@ -129,7 +138,7 @@ window.__ModuleLoader__.load({
129
138
  }
130
139
  //#endregion
131
140
  //#region \0dsh-css-module:/home/runner/work/dsh-skill-scope/dsh-skill-scope/src/client/styles.module.css?dsh-css-module
132
- 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_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_count{color:var(--dsw-alias-label-secondary,currentColor);font-size:13px}.Jg-IJa_badge{border:1px solid var(--dsw-alias-border-l3,currentColor);color:var(--dsw-alias-label-secondary,currentColor);white-space:nowrap;border-radius:999px;padding:1px 6px;font-size:11px;display:inline-block}.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_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_details{border:1px solid var(--dsw-alias-border-l2,currentColor);border-radius:8px;padding:8px 10px;font-size:12px}.Jg-IJa_detailsSummary{cursor:pointer;color:var(--dsw-alias-label-secondary,currentColor)}.Jg-IJa_detailsList{flex-direction:column;gap:4px;margin:8px 0 0;padding:0;list-style:none;display:flex}.Jg-IJa_detailsRow{justify-content:space-between;align-items:center;gap:10px;min-width:0;display:flex}.Jg-IJa_detailsName{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.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)}";
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_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)}";
133
142
  const tagId = "@dotdance/dsh-skill-scope/styles.module.css";
134
143
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
135
144
  const tag = document.createElement("style");
@@ -139,69 +148,63 @@ window.__ModuleLoader__.load({
139
148
  document.head.appendChild(tag);
140
149
  }
141
150
  var styles_module_default = {
151
+ "toolList": "Jg-IJa_toolList",
152
+ "sectionToggle": "Jg-IJa_sectionToggle",
142
153
  "modal": "Jg-IJa_modal",
154
+ "card": "Jg-IJa_card",
155
+ "panel": "Jg-IJa_panel",
156
+ "modeButton": "Jg-IJa_modeButton",
157
+ "cardName": "Jg-IJa_cardName",
158
+ "panelBody": "Jg-IJa_panelBody",
159
+ "search": "Jg-IJa_search",
143
160
  "expandButton": "Jg-IJa_expandButton",
144
- "header": "Jg-IJa_header",
161
+ "expandChevronOpen": "Jg-IJa_expandChevronOpen",
162
+ "groups": "Jg-IJa_groups",
163
+ "body": "Jg-IJa_body",
164
+ "sectionChevron": "Jg-IJa_sectionChevron",
165
+ "toolName": "Jg-IJa_toolName",
166
+ "switchTrack": "Jg-IJa_switchTrack",
145
167
  "cards": "Jg-IJa_cards",
146
- "card": "Jg-IJa_card",
147
168
  "overlay": "Jg-IJa_overlay",
148
- "groupTitle": "Jg-IJa_groupTitle",
149
- "panelHead": "Jg-IJa_panelHead",
150
- "sectionHead": "Jg-IJa_sectionHead",
151
- "detailKey": "Jg-IJa_detailKey",
152
- "switchTrack": "Jg-IJa_switchTrack",
169
+ "chip": "Jg-IJa_chip",
170
+ "sectionTitle": "Jg-IJa_sectionTitle",
171
+ "cardBody": "Jg-IJa_cardBody",
172
+ "section": "Jg-IJa_section",
153
173
  "button": "Jg-IJa_button",
154
- "expandChevron": "Jg-IJa_expandChevron",
155
- "body": "Jg-IJa_body",
156
- "expandChevronOpen": "Jg-IJa_expandChevronOpen",
157
- "groupChevron": "Jg-IJa_groupChevron",
158
- "badge": "Jg-IJa_badge",
159
- "detailValue": "Jg-IJa_detailValue",
160
- "cardMain": "Jg-IJa_cardMain",
174
+ "searchRow": "Jg-IJa_searchRow",
161
175
  "group": "Jg-IJa_group",
162
- "modeButtonActive": "Jg-IJa_modeButtonActive",
163
- "detailsRow": "Jg-IJa_detailsRow",
176
+ "closeButton": "Jg-IJa_closeButton",
177
+ "groupTitle": "Jg-IJa_groupTitle",
164
178
  "empty": "Jg-IJa_empty",
165
- "detailOrigin": "Jg-IJa_detailOrigin",
166
- "searchRow": "Jg-IJa_searchRow",
167
- "alert": "Jg-IJa_alert",
179
+ "switchThumb": "Jg-IJa_switchThumb",
168
180
  "searchIcon": "Jg-IJa_searchIcon",
169
- "detailsName": "Jg-IJa_detailsName",
170
- "panelBody": "Jg-IJa_panelBody",
171
- "search": "Jg-IJa_search",
172
- "groupCount": "Jg-IJa_groupCount",
173
- "panel": "Jg-IJa_panel",
174
- "introWarn": "Jg-IJa_introWarn",
175
- "sectionToggle": "Jg-IJa_sectionToggle",
176
- "sectionChevron": "Jg-IJa_sectionChevron",
181
+ "intro": "Jg-IJa_intro",
182
+ "switch": "Jg-IJa_switch",
183
+ "modeRow": "Jg-IJa_modeRow",
177
184
  "groupToggle": "Jg-IJa_groupToggle",
178
- "sectionChevronOpen": "Jg-IJa_sectionChevronOpen",
179
- "toolName": "Jg-IJa_toolName",
180
- "chip": "Jg-IJa_chip",
181
- "title": "Jg-IJa_title",
182
- "sectionTitle": "Jg-IJa_sectionTitle",
183
- "groups": "Jg-IJa_groups",
184
- "details": "Jg-IJa_details",
185
- "modeButton": "Jg-IJa_modeButton",
186
185
  "detailRow": "Jg-IJa_detailRow",
187
- "switchOn": "Jg-IJa_switchOn",
188
- "sectionCount": "Jg-IJa_sectionCount",
189
- "switch": "Jg-IJa_switch",
190
- "count": "Jg-IJa_count",
191
- "closeButton": "Jg-IJa_closeButton",
192
- "cardDisabled": "Jg-IJa_cardDisabled",
193
- "cardTail": "Jg-IJa_cardTail",
194
- "detailsSummary": "Jg-IJa_detailsSummary",
195
- "toolList": "Jg-IJa_toolList",
186
+ "modeButtonActive": "Jg-IJa_modeButtonActive",
187
+ "panelHead": "Jg-IJa_panelHead",
188
+ "groupCount": "Jg-IJa_groupCount",
196
189
  "cardDescription": "Jg-IJa_cardDescription",
190
+ "overridden": "Jg-IJa_overridden",
191
+ "detailValue": "Jg-IJa_detailValue",
192
+ "groupChevron": "Jg-IJa_groupChevron",
193
+ "sectionCount": "Jg-IJa_sectionCount",
197
194
  "cardHead": "Jg-IJa_cardHead",
198
- "detailsList": "Jg-IJa_detailsList",
199
- "section": "Jg-IJa_section",
200
- "intro": "Jg-IJa_intro",
201
- "cardBody": "Jg-IJa_cardBody",
202
- "switchThumb": "Jg-IJa_switchThumb",
203
- "modeRow": "Jg-IJa_modeRow",
204
- "cardName": "Jg-IJa_cardName"
195
+ "expandChevron": "Jg-IJa_expandChevron",
196
+ "cardTail": "Jg-IJa_cardTail",
197
+ "detailOrigin": "Jg-IJa_detailOrigin",
198
+ "cardMain": "Jg-IJa_cardMain",
199
+ "sectionChevronOpen": "Jg-IJa_sectionChevronOpen",
200
+ "cardDisabled": "Jg-IJa_cardDisabled",
201
+ "detailKey": "Jg-IJa_detailKey",
202
+ "switchOn": "Jg-IJa_switchOn",
203
+ "title": "Jg-IJa_title",
204
+ "alert": "Jg-IJa_alert",
205
+ "introWarn": "Jg-IJa_introWarn",
206
+ "sectionHead": "Jg-IJa_sectionHead",
207
+ "header": "Jg-IJa_header"
205
208
  };
206
209
  //#endregion
207
210
  //#region src/client/parts.tsx
@@ -354,22 +357,34 @@ window.__ModuleLoader__.load({
354
357
  })]
355
358
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
356
359
  className: styles_module_default.cardTail,
357
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
358
- tone: row.enabled ? "success" : "neutral",
359
- children: stateText
360
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
361
- type: "button",
362
- className: styles_module_default.expandButton,
363
- "aria-expanded": open,
364
- "aria-label": `${open ? props.collapseLabel : props.expandLabel}: ${row.name}`,
365
- onClick: () => {
366
- setOpen((previous) => !previous);
367
- },
368
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, {
369
- open,
370
- className: open ? `${styles_module_default.expandChevron} ${styles_module_default.expandChevronOpen}` : styles_module_default.expandChevron
360
+ children: [
361
+ row.overridden === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
362
+ className: styles_module_default.overridden,
363
+ "data-testid": "ws-overridden",
364
+ title: props.overriddenLabel,
365
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
366
+ tone: "danger",
367
+ children: props.overriddenLabel
368
+ })
369
+ }) : null,
370
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
371
+ tone: row.enabled ? "success" : "neutral",
372
+ children: stateText
373
+ }),
374
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
375
+ type: "button",
376
+ className: styles_module_default.expandButton,
377
+ "aria-expanded": open,
378
+ "aria-label": `${open ? props.collapseLabel : props.expandLabel}: ${row.name}`,
379
+ onClick: () => {
380
+ setOpen((previous) => !previous);
381
+ },
382
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, {
383
+ open,
384
+ className: open ? `${styles_module_default.expandChevron} ${styles_module_default.expandChevronOpen}` : styles_module_default.expandChevron
385
+ })
371
386
  })
372
- })]
387
+ ]
373
388
  })]
374
389
  }), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
375
390
  className: styles_module_default.cardBody,
@@ -421,22 +436,6 @@ window.__ModuleLoader__.load({
421
436
  });
422
437
  }
423
438
  /**
424
- * 一段可切换能力列表。
425
- *
426
- * **不变量 21(承重)**:这里**没有**按名字自由添加的输入框。用户只能切换清单里**已经存在**
427
- * 的名字;添加不存在的名字既没有输入口,也没有对应的写入字段。搜索框只做**过滤**,不产生新条目。
428
- *
429
- * 版式:分区头(标题 + 计数 + 折叠箭头)→ 两列卡片网格。搜索框在面板顶部统一渲染,
430
- * 本组件只接收 `externalQuery` 做过滤,因此「技能」与「MCP」被同一个词同时过滤。
431
- *
432
- * **来源分组(可选)**:当每一行都带 `group` 时,卡片不再平铺,而是按组渲染成若干
433
- * 可独立折叠的小节(见 `SkillGroups`)。只要有一行缺 `group`,整段就保持扁平 ——
434
- * 这样 MCP 段与工作区弹层的 MCP 段自动不受影响,两个面板共用同一段实现。
435
- */
436
- function CapabilityList(props) {
437
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilitySection, { ...props });
438
- }
439
- /**
440
439
  * 把行按 `group` 归拢,并**保持组内原有顺序**。
441
440
  *
442
441
  * 组的先后按**首次出现**决定,不排序:服务端的清单已按 skill 名做过稳定排序
@@ -478,8 +477,20 @@ window.__ModuleLoader__.load({
478
477
  function countText(rows) {
479
478
  return `${rows.filter((row) => row.enabled).length}/${rows.length}`;
480
479
  }
481
- /** 分区实现。折叠状态由本组件自己持有(默认展开),调用方不干预。 */
482
- function CapabilitySection(props) {
480
+ /**
481
+ * 一段可切换能力列表。折叠状态由本组件自己持有(默认展开),调用方不干预。
482
+ *
483
+ * **不变量 21(承重)**:这里**没有**按名字自由添加的输入框。用户只能切换清单里**已经存在**
484
+ * 的名字;添加不存在的名字既没有输入口,也没有对应的写入字段。搜索框只做**过滤**,不产生新条目。
485
+ *
486
+ * 版式:分区头(标题 + 计数 + 折叠箭头)→ 两列卡片网格。搜索框在面板顶部统一渲染,
487
+ * 本组件只接收 `externalQuery` 做过滤,因此「技能」与「MCP」被同一个词同时过滤。
488
+ *
489
+ * **来源分组(可选)**:当每一行都带 `group` 时,卡片不再平铺,而是按组渲染成若干
490
+ * 可独立折叠的小节(见 `SkillGroups`)。只要有一行缺 `group`,整段就保持扁平 ——
491
+ * 这样 MCP 段与工作区弹层的 MCP 段自动不受影响,两个面板共用同一段实现。
492
+ */
493
+ function CapabilityList(props) {
483
494
  const { rows, testIdPrefix } = props;
484
495
  const [open, setOpen] = (0, react.useState)(true);
485
496
  const query = (props.externalQuery ?? "").trim();
@@ -636,14 +647,214 @@ window.__ModuleLoader__.load({
636
647
  });
637
648
  }
638
649
  //#endregion
639
- //#region src/client/locales.ts
650
+ //#region src/client/panel-model.ts
651
+ /** 视图按钮的呈现顺序:全部 → 已启用 → 已禁用。`ViewBar` 按它渲染。 */
652
+ const VIEW_ORDER = [
653
+ "all",
654
+ "enabled",
655
+ "disabled"
656
+ ];
657
+ /**
658
+ * 工作区层的视图按钮:在 `VIEW_ORDER` 之后多一个「与全局不同」。
659
+ *
660
+ * **不放进 `VIEW_ORDER`**:全局层渲染它只会得到一个永远空着的列表 ——
661
+ * 全局层没有「上一层」,「与全局不同」在那里无定义。
662
+ */
663
+ const WORKSPACE_VIEW_ORDER = [...VIEW_ORDER, "overridden"];
664
+ /** 视图按钮的 `data-testid`;两面板共用,测试引用它而不手抄字符串。 */
665
+ const viewTestId = (view) => `view-${view}`;
666
+ /** 全局层的取值规则:名单里列的就是被关掉的(唯一语义)。 */
667
+ function isEnabled(names, name) {
668
+ return !names.includes(name);
669
+ }
670
+ /**
671
+ * Skill 行派生。两面板原为同一份实现,**分组与出处字段必须原样透传**:
672
+ * - `CapabilityList` 靠「每一行都有 `group`」决定是否启用分组;前端补默认值会把
673
+ * 「服务端没给」伪装成「给了空组」,MCP 段也会跟着被分组。
674
+ * - `origin` 只在有值时挂:`null`/`undefined` 都表示「无磁盘出处」,挂空串会破坏
675
+ * 「runtime skill 出文案 / MCP 行整行不渲染」那个判断。
676
+ *
677
+ * 入参用的是线上形状(`SkillRowValue`),不是「最小字段面」:多声明一份更窄的
678
+ * 本地类型只会让两个外壳的数据多过一道不必要的适配。
679
+ */
680
+ function toSkillRows(skills, isOpen, t, isOverridden = () => false) {
681
+ return skills.map((skill) => ({
682
+ name: skill.name,
683
+ description: skill.description,
684
+ source: skill.source,
685
+ enabled: isOpen(skill.name),
686
+ ...isOverridden(skill.name) ? { overridden: true } : {},
687
+ ...skill.group === void 0 ? {} : { group: skill.group },
688
+ ...skill.groupLabel === void 0 ? {} : { groupLabel: skill.groupLabel },
689
+ ...skill.sourceLabel === void 0 || skill.sourceLabel === null ? {} : { origin: skill.sourceLabel }
690
+ }));
691
+ }
692
+ /**
693
+ * MCP 行派生。与 `toSkillRows` 同形:**不排除任何行**——全局关掉的 server 也要留在
694
+ * 列表里,否则用户在工程里没有入口把它打开。
695
+ *
696
+ * 只读判定:未加载或宿主不允许限制都不可切换。
697
+ *
698
+ * `tools` 原样透传服务端的 `toolNames`(**不在这里排序、不去重、不改写前缀**):
699
+ * 展开区要显示的就是用户能在日志与源码里对得上的那串完整名字,服务端已保证次序稳定。
700
+ * 空数组也照传——`CapabilityCard` 用「空即不渲染工具段」来决定,前端不参与这个判断。
701
+ */
702
+ function toMcpRows(mcps, isOpen, t, isOverridden = () => false) {
703
+ return mcps.map((server) => {
704
+ const readonly = !server.restrictable || !server.loaded;
705
+ return {
706
+ name: server.serverName,
707
+ description: `${server.toolCount} tools`,
708
+ tools: server.toolNames,
709
+ source: server.source === "global" ? t("state.global") : t("state.scope"),
710
+ enabled: isOpen(server.serverName),
711
+ ...isOverridden(server.serverName) ? { overridden: true } : {},
712
+ ...readonly ? { readonly: true } : {}
713
+ };
714
+ });
715
+ }
716
+ //#endregion
717
+ //#region src/client/CapabilityPanel.tsx
718
+ /**
719
+ * 视图按钮。切换**只改组件状态**,不触发保存。
720
+ *
721
+ * 按钮集合由 `views` 注入:全局层用 `VIEW_ORDER`(三种),工作区层用
722
+ * `WORKSPACE_VIEW_ORDER`(多一个「与全局不同」)。
723
+ */
724
+ function ViewBar({ view, onChange, t, views = VIEW_ORDER }) {
725
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
726
+ className: styles_module_default.modeRow,
727
+ "data-testid": "view-row",
728
+ children: views.map((candidate) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
729
+ type: "button",
730
+ className: `${styles_module_default.modeButton} ${view === candidate ? styles_module_default.modeButtonActive : ""}`,
731
+ "aria-pressed": view === candidate,
732
+ "data-testid": viewTestId(candidate),
733
+ onClick: () => {
734
+ onChange(candidate);
735
+ },
736
+ children: t(`view.${candidate}`)
737
+ }, candidate))
738
+ });
739
+ }
740
+ /** 两段列表共用的词条包。抽一次,避免改文案时两处漂移。 */
741
+ function listLabels(t) {
742
+ return {
743
+ searchPlaceholder: t("search.placeholder"),
744
+ emptyText: t("state.empty"),
745
+ enabledLabel: t("state.enabled"),
746
+ disabledLabel: t("state.disabled"),
747
+ overriddenLabel: t("state.overridden"),
748
+ detailStateKey: t("detail.state"),
749
+ detailSourceKey: t("detail.source"),
750
+ detailToolsKey: t("detail.tools"),
751
+ expandLabel: t("action.expand"),
752
+ collapseLabel: t("action.collapse"),
753
+ ungroupedLabel: t("group.ungrouped"),
754
+ ungroupedOriginLabel: t("detail.originRuntime")
755
+ };
756
+ }
757
+ /**
758
+ * 搜索框 + 错误条 + 两段列表。
759
+ *
760
+ * 查询值是**一个**(`panel.query`),经 `CapabilityList` 的 `externalQuery` 同时喂给两段,
761
+ * 因此一个输入框**同筛两段**。
762
+ */
763
+ function CapabilityPanelBody(props) {
764
+ const { t, panel } = props;
765
+ const labels = listLabels(t);
766
+ const visible = (rows) => {
767
+ if (panel.view === "all") return rows;
768
+ if (panel.view === "overridden") return rows.filter((row) => row.overridden === true);
769
+ return rows.filter((row) => row.enabled === (panel.view === "enabled"));
770
+ };
771
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
772
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchRow, {
773
+ id: props.searchInputId,
774
+ value: panel.query,
775
+ onChange: panel.setQuery,
776
+ t
777
+ }),
778
+ panel.error === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorAlert, {
779
+ message: panel.error,
780
+ retryLabel: t("action.retry"),
781
+ onRetry: props.onRetry
782
+ }),
783
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityList, {
784
+ title: t("section.skills"),
785
+ sectionTitleId: "skill-scope-skills-title",
786
+ rows: visible(props.skills),
787
+ ...labels,
788
+ externalQuery: panel.query,
789
+ testIdPrefix: props.skillTestIdPrefix,
790
+ countLabel: t("count.unit"),
791
+ onToggle: (name, next) => {
792
+ panel.toggle(name, next, "skills");
793
+ }
794
+ }),
795
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityList, {
796
+ title: t("section.mcps"),
797
+ sectionTitleId: "skill-scope-mcps-title",
798
+ rows: visible(props.mcps),
799
+ ...labels,
800
+ externalQuery: panel.query,
801
+ testIdPrefix: props.mcpTestIdPrefix,
802
+ countLabel: t("count.unit"),
803
+ onToggle: (name, next) => {
804
+ panel.toggle(name, next, "mcps");
805
+ }
806
+ })
807
+ ] });
808
+ }
640
809
  /**
641
- * 面板共用的词条与值类型。
810
+ * 顶部统一搜索框:**一份**输入同时过滤技能与 MCP 两段。
642
811
  *
643
- * 两个面板共用 `NS` 与这里的字典:各写一份会让「同一句话两处不同」成为必然。
812
+ * 两个面板共用它,是为了让「同一个词在两段里同时生效」这条行为只有一处实现。
813
+ * 分工区各留一个输入框会让同一个词要输两遍,且两个框的过滤状态无法一致。
644
814
  */
815
+ function SearchRow({ id, value, onChange, t }) {
816
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
817
+ className: styles_module_default.searchRow,
818
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
819
+ className: styles_module_default.searchIcon,
820
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchIcon, {})
821
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
822
+ id,
823
+ className: styles_module_default.search,
824
+ type: "search",
825
+ value,
826
+ placeholder: t("search.placeholder"),
827
+ "aria-label": t("search.placeholder"),
828
+ onChange: (event) => {
829
+ onChange(readInputValue(event.target));
830
+ }
831
+ })]
832
+ });
833
+ }
834
+ /**
835
+ * 从受控输入框读值(受 `noUncheckedIndexedAccess` 约束,需显式判空)。
836
+ *
837
+ * 不直接用 `event.target.value`:`EventTarget` 上没有 `value`,需要先收窄类型。
838
+ */
839
+ function readInputValue(target) {
840
+ const value = asRecord(target)?.["value"];
841
+ return typeof value === "string" ? value : "";
842
+ }
843
+ //#endregion
844
+ //#region src/client/locales.ts
645
845
  /** locale 命名空间。与 `apply` 里 `ctx.locale.register(NS, ...)` 一致。 */
646
846
  const NS = "skill-scope";
847
+ /**
848
+ * 把 `{key}` 占位符替换成 `params` 里的值;`params` 缺失时原样返回。
849
+ *
850
+ * 宿主 i18n 的 `t` 与本文件的兜底词条都过这一层:替换规则只该有一份实现,
851
+ * 否则「宿主有 i18n」与「没有 i18n」两种路径下的文案可能不一致。
852
+ * 未在 `params` 里出现的占位符保持原样(缺参时报出可见的 `{key}` 比静默吞掉更好排查)。
853
+ */
854
+ function withParams(template, params) {
855
+ if (params === void 0) return template;
856
+ return Object.entries(params).reduce((text, [key, value]) => text.replaceAll(`{${key}}`, value), template);
857
+ }
647
858
  /** 中文词条(权威文案;英文是它的对照翻译)。 */
648
859
  const zh = {
649
860
  "panel.label": "全局 Skills",
@@ -652,6 +863,7 @@ window.__ModuleLoader__.load({
652
863
  "view.all": "全部",
653
864
  "view.enabled": "已启用",
654
865
  "view.disabled": "已禁用",
866
+ "view.overridden": "与全局不同",
655
867
  "section.skills": "Skill",
656
868
  "section.mcps": "MCP",
657
869
  "search.placeholder": "搜索",
@@ -666,6 +878,7 @@ window.__ModuleLoader__.load({
666
878
  "state.scope": "本作用域",
667
879
  "state.enabled": "已启用",
668
880
  "state.disabled": "已禁用",
881
+ "state.overridden": "与全局不同",
669
882
  "action.expand": "展开",
670
883
  "action.collapse": "收起",
671
884
  "detail.state": "状态",
@@ -674,7 +887,7 @@ window.__ModuleLoader__.load({
674
887
  "detail.originRuntime": "运行时注入(无磁盘文件)",
675
888
  "count.unit": "项",
676
889
  "group.ungrouped": "运行时注入",
677
- "workspace.intro": "下面是未被全局禁用的项, 改动对本 workspace 新 session 生效,不影响已有 session"
890
+ "workspace.intro": "初始默认继承全局配置;你可以覆盖修改 skill 开关状态,改动只对本 workspace 新开的会话生效。"
678
891
  };
679
892
  /** 英文词条。键必须与 `zh` 完全一致(少一条就是一段只显示 key 的界面)。 */
680
893
  const en = {
@@ -684,6 +897,7 @@ window.__ModuleLoader__.load({
684
897
  "view.all": "All",
685
898
  "view.enabled": "Enabled",
686
899
  "view.disabled": "Disabled",
900
+ "view.overridden": "Differs from global",
687
901
  "section.skills": "Skills",
688
902
  "section.mcps": "MCP",
689
903
  "search.placeholder": "Search",
@@ -698,6 +912,7 @@ window.__ModuleLoader__.load({
698
912
  "state.scope": "This scope",
699
913
  "state.enabled": "Enabled",
700
914
  "state.disabled": "Disabled",
915
+ "state.overridden": "Differs from global",
701
916
  "action.expand": "Expand",
702
917
  "action.collapse": "Collapse",
703
918
  "detail.state": "State",
@@ -706,99 +921,30 @@ window.__ModuleLoader__.load({
706
921
  "detail.originRuntime": "Runtime-injected (no file on disk)",
707
922
  "count.unit": "items",
708
923
  "group.ungrouped": "Runtime-injected",
709
- "workspace.intro": "Listed below are the items not disabled globally. Changes apply to new sessions in this workspace; existing sessions are unaffected."
924
+ "workspace.intro": "By default everything inherits the global configuration; you can override any skill switch here. Changes apply only to new sessions in this workspace."
710
925
  };
711
- //#endregion
712
- //#region src/client/CapabilityPanel.tsx
713
- /**
714
- * 全局面板与工作区弹层的**共享内核**。
715
- *
716
- * 两个面板原先各写一份行派生、开关接线与词条包(重构前 `GlobalPanel.tsx` 494 行、
717
- * `WorkspaceModal.tsx` 585 行)。逐段归一化比对后,可复用的是:
718
- *
719
- * 1. 纯函数(本文件上半部)—— 可单测、无 React
720
- * 2. `usePolicyPanel` —— 加载 / 乐观改 / 回滚,**保存的线上形状与合并策略由外壳注入**
721
- * 3. `CapabilityPanelBody` —— 视图条 + 搜索框 + 锁提示 + 错误条 + 两段 `CapabilityList`
722
- *
723
- * 两个外壳只保留**真正不同**的部分:
724
- * - 外壳:全局用 `styles.panel`(main 槽位内),工作区用 `overlay` + `modal` + 关闭按钮
725
- * - 标题与说明文案
726
- * - 工作区独有:非实时提示、顶部说明段(「下面是未被全局禁用的项…」)
727
- * - 保存请求体与响应合并
728
- *
729
- * 承重不变量(不可为「复用」而抹平):
730
- * - 视图按钮只是**列表谓词**,不发保存请求。
731
- * - 工作区保存后**只合并 `revision` 与 `policy`**,绝不整体替换视图(响应里的
732
- * `exists` 是写文件之前采集的旧值)。见 `docs/design.md`。
733
- */
734
- /** 视图按钮的呈现顺序:全部 → 已启用 → 已禁用。`ViewBar` 按它渲染。 */
735
- const VIEW_ORDER = [
736
- "all",
737
- "enabled",
738
- "disabled"
739
- ];
740
- /** 视图按钮的 `data-testid`;两面板共用,测试引用它而不手抄字符串。 */
741
- const viewTestId = (view) => `view-${view}`;
742
926
  /**
743
927
  * 无宿主 i18n 时的兜底词条。
744
928
  *
745
- * 两处原先各写一份:全局版直接用 `withParams`,工作区版内联展开了一遍同样的 `{k}`
746
- * 替换。合并成一份,行为等价(`params === undefined` 时原样返回)。
929
+ * 宿主 i18n 的取值器(`index.tsx` 的 `t`)与本函数都过 `withParams`:替换规则只有
930
+ * 一份实现,所以「有宿主 i18n」与「没有 i18n」两条路径的文案行为必然一致。
931
+ * 定义在 `zh` / `en` 之后:调用时才读字典,但顺序保持「字典在先」更容易读。
747
932
  */
748
933
  function createDefaultTranslate() {
749
934
  const dictionary = zh;
750
- return (key, params) => {
751
- const template = dictionary[key] ?? key;
752
- if (params === void 0) return template;
753
- return Object.entries(params).reduce((text, [k, v]) => text.replaceAll(`{${k}}`, v), template);
754
- };
755
- }
756
- /** 把任意抛出物收成一句可展示的文案:`Error` 取 message,其余 `String()`。 */
757
- function describeError(error) {
758
- return error instanceof Error ? error.message : String(error);
759
- }
760
- /** 名单里列的就是被关掉的(唯一语义)。 */
761
- function isEnabled(names, name) {
762
- return !names.includes(name);
763
- }
764
- /**
765
- * Skill 行派生。两面板原为同一份实现,**分组与出处字段必须原样透传**:
766
- * - `CapabilityList` 靠「每一行都有 `group`」决定是否启用分组;前端补默认值会把
767
- * 「服务端没给」伪装成「给了空组」,MCP 段也会跟着被分组。
768
- * - `origin` 只在有值时挂:`null`/`undefined` 都表示「无磁盘出处」,挂空串会破坏
769
- * 「runtime skill 出文案 / MCP 行整行不渲染」那个判断。
770
- */
771
- function toSkillRows(skills, policySkills, t) {
772
- return skills.map((skill) => ({
773
- name: skill.name,
774
- description: skill.description,
775
- source: skill.source,
776
- enabled: isEnabled(policySkills, skill.name),
777
- ...skill.group === void 0 ? {} : { group: skill.group },
778
- ...skill.groupLabel === void 0 ? {} : { groupLabel: skill.groupLabel },
779
- ...skill.sourceLabel === void 0 || skill.sourceLabel === null ? {} : { origin: skill.sourceLabel }
780
- }));
935
+ return (key, params) => withParams(dictionary[key] ?? key, params);
781
936
  }
937
+ //#endregion
938
+ //#region src/client/panel-state.ts
782
939
  /**
783
- * MCP 行派生。`excludeNames` 是工作区独有的「被全局关掉则不列出」(全局传空)。
784
- * 只读判定:未加载或宿主不允许限制都不可切换。
940
+ * 面板的**数据层**:`usePolicyPanel` 与它的入参/出参类型。
785
941
  *
786
- * `tools` 原样透传服务端的 `toolNames`(**不在这里排序、不去重、不改写前缀**):
787
- * 展开区要显示的就是用户能在日志与源码里对得上的那串完整名字,服务端已保证次序稳定。
788
- * 空数组也照传——`CapabilityCard` 用「空即不渲染工具段」来决定,前端不参与这个判断。
942
+ * 只管数据,不碰 JSX。两个外壳(全局面板、工作区弹层)用同一个 hook,把「保存的
943
+ * 线上形状与合并策略」作为参数注入 —— 这是两层唯一真正不同的地方。
789
944
  */
790
- function toMcpRows(mcps, policyMcps, t, excludeNames = []) {
791
- return mcps.filter((server) => !excludeNames.includes(server.serverName)).map((server) => {
792
- const readonly = !server.restrictable || !server.loaded;
793
- return {
794
- name: server.serverName,
795
- description: `${server.toolCount} tools`,
796
- tools: server.toolNames,
797
- source: server.source === "global" ? t("state.global") : t("state.scope"),
798
- enabled: isEnabled(policyMcps, server.serverName),
799
- ...readonly ? { readonly: true } : {}
800
- };
801
- });
945
+ /** 把任意抛出物收成一句可展示的文案:`Error` 取 message,其余 `String()`。 */
946
+ function describeError(error) {
947
+ return error instanceof Error ? error.message : String(error);
802
948
  }
803
949
  /**
804
950
  * 加载 + 三件改动操作。
@@ -806,7 +952,7 @@ window.__ModuleLoader__.load({
806
952
  * 回滚依赖**提交时刻捕获的快照**,不是 `value` 的闭包 —— 后者在连续快速点击时会拿到
807
953
  * 过期的值,回滚到更早的状态。提交串行化(`chain`),避免并发写入互相覆盖。
808
954
  */
809
- function usePolicyPanel({ load, save, mergeSaved }) {
955
+ function usePolicyPanel({ load, save, toggle: applyToggle, mergeSaved }) {
810
956
  const [value, setValue] = (0, react.useState)(null);
811
957
  const [error, setError] = (0, react.useState)(null);
812
958
  const [busy, setBusy] = (0, react.useState)(false);
@@ -846,19 +992,12 @@ window.__ModuleLoader__.load({
846
992
  const commit = (0, react.useCallback)(async (mutate) => {
847
993
  const current = valueRef.current;
848
994
  if (current === null) return;
849
- const nextPolicy = mutate(current);
850
- if (nextPolicy === null) return;
851
- setValue({
852
- ...current,
853
- policy: nextPolicy
854
- });
995
+ const next = mutate(current);
996
+ if (next === null) return;
997
+ setValue(next);
855
998
  setBusy(true);
856
999
  const snapshot = current;
857
- const optimistic = {
858
- ...snapshot,
859
- policy: nextPolicy
860
- };
861
- chain.current = chain.current.then(() => save(optimistic, nextPolicy)).then((saved) => {
1000
+ chain.current = chain.current.then(() => save(snapshot, next)).then((saved) => {
862
1001
  if (!alive.current) return;
863
1002
  setValue((prev) => prev === null ? prev : mergeSaved === void 0 ? saved : mergeSaved(prev, saved));
864
1003
  setError(null);
@@ -883,148 +1022,10 @@ window.__ModuleLoader__.load({
883
1022
  setQuery,
884
1023
  commit,
885
1024
  toggle: (0, react.useCallback)((name, next, which) => {
886
- commit((current) => {
887
- if (isEnabled(current.policy[which], name) === next) return null;
888
- current.policy[which].includes(name);
889
- const updated = next ? current.policy[which].filter((item) => item !== name) : [...current.policy[which], name];
890
- return {
891
- ...current.policy,
892
- [which]: updated
893
- };
894
- });
895
- }, [commit])
896
- };
897
- }
898
- /** 三个视图按钮。切换**只改组件状态**,不触发保存。 */
899
- function ViewBar({ view, onChange, t }) {
900
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
901
- className: styles_module_default.modeRow,
902
- "data-testid": "view-row",
903
- children: VIEW_ORDER.map((candidate) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
904
- type: "button",
905
- className: `${styles_module_default.modeButton} ${view === candidate ? styles_module_default.modeButtonActive : ""}`,
906
- "aria-pressed": view === candidate,
907
- "data-testid": viewTestId(candidate),
908
- onClick: () => {
909
- onChange(candidate);
910
- },
911
- children: t(`view.${candidate}`)
912
- }, candidate))
913
- });
914
- }
915
- /** 两段列表共用的词条包。抽一次,避免改文案时两处漂移。 */
916
- function listLabels(t) {
917
- return {
918
- searchPlaceholder: t("search.placeholder"),
919
- emptyText: t("state.empty"),
920
- enabledLabel: t("state.enabled"),
921
- disabledLabel: t("state.disabled"),
922
- detailStateKey: t("detail.state"),
923
- detailSourceKey: t("detail.source"),
924
- detailToolsKey: t("detail.tools"),
925
- expandLabel: t("action.expand"),
926
- collapseLabel: t("action.collapse"),
927
- ungroupedLabel: t("group.ungrouped"),
928
- ungroupedOriginLabel: t("detail.originRuntime")
1025
+ commit((current) => applyToggle(current, which, name, next));
1026
+ }, [commit, applyToggle])
929
1027
  };
930
1028
  }
931
- /**
932
- * 视图条 + 错误条 + 两段列表。
933
- *
934
- * 搜索框由外壳渲染(各自的位置与图标不同)、查询值经 `query` 传入
935
- * (`CapabilityList` 的 `externalQuery`),因此一个输入框**同筛两段**。
936
- */
937
- function CapabilityPanelBody(props) {
938
- const { t } = props;
939
- const labels = listLabels(t);
940
- const visible = (rows) => props.view === "all" ? rows : rows.filter((row) => row.enabled === (props.view === "enabled"));
941
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
942
- props.error === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorAlert, {
943
- message: props.error,
944
- retryLabel: t("action.retry"),
945
- onRetry: props.onRetry
946
- }),
947
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityList, {
948
- title: t("section.skills"),
949
- sectionTitleId: "skill-scope-skills-title",
950
- rows: visible(props.skills),
951
- ...labels,
952
- externalQuery: props.query,
953
- testIdPrefix: props.skillTestIdPrefix,
954
- countLabel: t("count.unit"),
955
- onToggle: props.onToggleSkill
956
- }),
957
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityList, {
958
- title: t("section.mcps"),
959
- sectionTitleId: "skill-scope-mcps-title",
960
- rows: visible(props.mcps),
961
- ...labels,
962
- externalQuery: props.query,
963
- testIdPrefix: props.mcpTestIdPrefix,
964
- countLabel: t("count.unit"),
965
- onToggle: props.onToggleMcp
966
- })
967
- ] });
968
- }
969
- /**
970
- * 顶部统一搜索框:**一份**输入同时过滤技能与 MCP 两段。
971
- *
972
- * 两个面板共用它,是为了让「同一个词在两段里同时生效」这条行为只有一处实现。
973
- * 分工区各留一个输入框会让同一个词要输两遍,且两个框的过滤状态无法一致。
974
- */
975
- function SearchRow({ id, value, onChange, t }) {
976
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
977
- className: styles_module_default.searchRow,
978
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
979
- className: styles_module_default.searchIcon,
980
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchIcon, {})
981
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
982
- id,
983
- className: styles_module_default.search,
984
- type: "search",
985
- value,
986
- placeholder: t("search.placeholder"),
987
- "aria-label": t("search.placeholder"),
988
- onChange: (event) => {
989
- onChange(readInputValue(event.target));
990
- }
991
- })]
992
- });
993
- }
994
- /**
995
- * 从受控输入框读值(受 `noUncheckedIndexedAccess` 约束,需显式判空)。
996
- *
997
- * 不直接用 `event.target.value`:`EventTarget` 上没有 `value`,需要先收窄类型。
998
- */
999
- function readInputValue(target) {
1000
- const value = asRecord(target)?.["value"];
1001
- return typeof value === "string" ? value : "";
1002
- }
1003
- function WiredCapabilityBody(props) {
1004
- const { t, panel } = props;
1005
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [props.searchInputId === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchRow, {
1006
- id: props.searchInputId,
1007
- value: panel.query,
1008
- onChange: panel.setQuery,
1009
- t
1010
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityPanelBody, {
1011
- t,
1012
- error: panel.error,
1013
- onRetry: props.onRetry,
1014
- query: panel.query,
1015
- view: panel.view,
1016
- skills: props.skills,
1017
- mcps: props.mcps,
1018
- onToggleSkill: (name, next) => {
1019
- panel.toggle(name, next, "skills");
1020
- },
1021
- onToggleMcp: (name, next) => {
1022
- panel.toggle(name, next, "mcps");
1023
- },
1024
- mcpTestIdPrefix: props.mcpTestIdPrefix,
1025
- skillTestIdPrefix: props.skillTestIdPrefix
1026
- })] });
1027
- }
1028
1029
  //#endregion
1029
1030
  //#region src/client/GlobalPanel.tsx
1030
1031
  /**
@@ -1048,16 +1049,33 @@ window.__ModuleLoader__.load({
1048
1049
  * `revision` 三态:`null` 表示「我期望文件还不存在」。原样透传,不做 `??` 折叠——
1049
1050
  * 把 `null` 折成 `undefined` 会改变服务端的守卫语义。
1050
1051
  */
1051
- const save = (0, react.useCallback)(async (current, nextPolicy) => post(ROUTES.globalSave, {
1052
- mode: nextPolicy.mode,
1053
- skills: nextPolicy.skills,
1054
- mcps: nextPolicy.mcps,
1052
+ const save = (0, react.useCallback)(async (current, next) => post(ROUTES.globalSave, {
1053
+ mode: next.policy.mode,
1054
+ skills: next.policy.skills,
1055
+ mcps: next.policy.mcps,
1055
1056
  revision: current.revision,
1056
1057
  ...sessionId === void 0 ? {} : { sessionId }
1057
1058
  }), [sessionId]);
1059
+ /**
1060
+ * 翻转一项:**改数组**(名字在名单里 = 关)。
1061
+ *
1062
+ * 全局层没有「上层」,因此没有三态可言:开关只有开/关,写回的就是黑名单本身。
1063
+ */
1064
+ const toggle = (0, react.useCallback)((current, which, name, open) => {
1065
+ if (isEnabled(current.policy[which], name) === open) return null;
1066
+ const updated = open ? current.policy[which].filter((item) => item !== name) : [...current.policy[which], name];
1067
+ return {
1068
+ ...current,
1069
+ policy: {
1070
+ ...current.policy,
1071
+ [which]: updated
1072
+ }
1073
+ };
1074
+ }, []);
1058
1075
  const panel = usePolicyPanel({
1059
1076
  load: (0, react.useCallback)(async () => loadGlobal(sessionId), [sessionId]),
1060
- save
1077
+ save,
1078
+ toggle
1061
1079
  });
1062
1080
  const refresh = () => {
1063
1081
  panel.refresh();
@@ -1078,8 +1096,8 @@ window.__ModuleLoader__.load({
1078
1096
  children: panel.error
1079
1097
  })]
1080
1098
  });
1081
- const skillRows = toSkillRows(value.inventory.skills, value.policy.skills, t);
1082
- const mcpRows = toMcpRows(value.inventory.mcps, value.policy.mcps, t);
1099
+ const skillRows = toSkillRows(value.inventory.skills, (name) => isEnabled(value.policy.skills, name), t);
1100
+ const mcpRows = toMcpRows(value.inventory.mcps, (name) => isEnabled(value.policy.mcps, name), t);
1083
1101
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1084
1102
  className: styles_module_default.panel,
1085
1103
  "data-testid": "global-panel",
@@ -1096,7 +1114,7 @@ window.__ModuleLoader__.load({
1096
1114
  onChange: panel.setView,
1097
1115
  t
1098
1116
  }),
1099
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WiredCapabilityBody, {
1117
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityPanelBody, {
1100
1118
  t,
1101
1119
  panel,
1102
1120
  skills: skillRows,
@@ -1111,6 +1129,43 @@ window.__ModuleLoader__.load({
1111
1129
  }
1112
1130
  //#endregion
1113
1131
  //#region src/client/WorkspaceModal.tsx
1132
+ /**
1133
+ * 工作区入口:输入框右侧的 chip + 点击后打开的弹层。
1134
+ *
1135
+ * **不变量 5(承重)**:工作区清单必须由**服务端**以 `scope: agent` 读取。
1136
+ * 客户端只传 `sessionId`——把 agent 对象塞进请求体既不可能(不可序列化)也不该做。
1137
+ * 面板因此不自行拼清单,只渲染服务端给的 `inventory`。
1138
+ *
1139
+ * **不变量 24 / C2**:无 live Agent 时**不许**假装是实时视图(必须出现「非实时」)。
1140
+ * 空白会话**有** live Agent,所以它是**实时**路径——两者不能混为一谈。
1141
+ *
1142
+ * 本文件是**外壳**:行派生、开关接线、视图条、列表主体都在 `CapabilityPanel.tsx`,
1143
+ * 与全局面板共用。这里只剩工作区弹层独有的部分——`overlay`+`modal` 外壳、关闭按钮、
1144
+ * 实时性提示、顶部说明段,以及保存响应「只合并 `revision` 与 `workspace`」
1145
+ * (响应里的 `exists` 是写文件之前采集的旧值,不能整体替换视图)。
1146
+ */
1147
+ /**
1148
+ * 三态取值:本层表里有这个键就听表,没有就跟随全局 —— 与服务端 `openResolver`
1149
+ * (`src/policy/evaluate.ts`)同一公式。
1150
+ *
1151
+ * 「全局层关掉的是什么」由共享内核的 `isEnabled` 判定(名单里列的就是被关掉的)。
1152
+ * 客户端那份实现不能改成 import 宿主代码:客户端产物与宿主是两份构建,跨端 import
1153
+ * 会把服务端模块拖进浏览器包。
1154
+ */
1155
+ function isOpen(value, which, name) {
1156
+ return value.workspace[which][name] ?? isEnabled(value.global[which], name);
1157
+ }
1158
+ /**
1159
+ * 是否「与全局不同」——**只由这一个条件决定**(用户明确要求)。
1160
+ *
1161
+ * 表里没有这个键 ⇒ 跟随全局 ⇒ 不是差异;
1162
+ * 表里有键且与全局同向 ⇒ 也不是差异(保存时这种条目会被服务端剔除,属于历史残留);
1163
+ * 表里有键且与全局反向 ⇒ 是差异 ⇒ 标红。
1164
+ */
1165
+ function isOverridden(value, which, name) {
1166
+ const local = value.workspace[which][name];
1167
+ return local !== void 0 && local !== isEnabled(value.global[which], name);
1168
+ }
1114
1169
  /** 取工程名:`cwd` 的 basename。用 `/` 与 `\` 都切,避免宿主报一个 Windows 路径时整条标题变成完整路径。 */
1115
1170
  function projectNameOf(cwd) {
1116
1171
  const parts = cwd.split(/[/\\]/).filter((part) => part !== "");
@@ -1142,21 +1197,40 @@ window.__ModuleLoader__.load({
1142
1197
  * 因此只合并 `revision`(下一次保存的乐观锁依据)与 `policy`(服务端规范化后的名单,
1143
1198
  * 比如排序、去重、上限截断)。其余视图字段保留读取时的那一份。
1144
1199
  */
1145
- const save = (0, react.useCallback)(async (current, nextPolicy) => post(ROUTES.workspaceSave, {
1200
+ const save = (0, react.useCallback)(async (current, next) => post(ROUTES.workspaceSave, {
1146
1201
  sessionId,
1147
- mode: nextPolicy.mode,
1148
- skills: nextPolicy.skills,
1149
- mcps: nextPolicy.mcps,
1202
+ workspace: next.workspace,
1150
1203
  revision: current.revision
1151
1204
  }), [sessionId]);
1205
+ /**
1206
+ * 翻转一项:**改表**,而且只在「与全局不同」时才往表里写键。
1207
+ *
1208
+ * 回到全局状态时**删键**(而不是写一个与全局同向的值):这样「表里的键 = 用户的显式
1209
+ * 决定」这条不变量在客户端也成立,红标与磁盘内容不会出现「本地已经恢复默认、文件里
1210
+ * 还留着一条将被服务端静默剔除的条目」这种短暂分叉。
1211
+ */
1212
+ const toggle = (0, react.useCallback)((current, which, name, open) => {
1213
+ const base = isEnabled(current.global[which], name);
1214
+ const next = { ...current.workspace[which] };
1215
+ if (open === base) delete next[name];
1216
+ else next[name] = open;
1217
+ return {
1218
+ ...current,
1219
+ workspace: {
1220
+ ...current.workspace,
1221
+ [which]: next
1222
+ }
1223
+ };
1224
+ }, []);
1152
1225
  const mergeSaved = (0, react.useCallback)((previous, saved) => ({
1153
1226
  ...previous,
1154
1227
  revision: saved.revision,
1155
- ...saved.policy === void 0 ? {} : { policy: saved.policy }
1228
+ ...saved.workspace === void 0 ? {} : { workspace: saved.workspace }
1156
1229
  }), []);
1157
1230
  const panel = usePolicyPanel({
1158
1231
  load: (0, react.useCallback)(async () => loadWorkspace(sessionId), [sessionId]),
1159
1232
  save,
1233
+ toggle,
1160
1234
  mergeSaved
1161
1235
  });
1162
1236
  const refresh = () => {
@@ -1183,9 +1257,8 @@ window.__ModuleLoader__.load({
1183
1257
  })
1184
1258
  })
1185
1259
  });
1186
- const disabledGlobally = value.disabledGlobally ?? [];
1187
- const skillRows = toSkillRows(value.inventory.skills, value.policy.skills, t);
1188
- const mcpRows = toMcpRows(value.inventory.mcps, value.policy.mcps, t, disabledGlobally);
1260
+ const skillRows = toSkillRows(value.inventory.skills, (name) => isOpen(value, "skills", name), t, (name) => isOverridden(value, "skills", name));
1261
+ const mcpRows = toMcpRows(value.inventory.mcps, (name) => isOpen(value, "mcps", name), t, (name) => isOverridden(value, "mcps", name));
1189
1262
  const project = projectNameOf(value.cwd);
1190
1263
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1191
1264
  className: styles_module_default.overlay,
@@ -1201,7 +1274,7 @@ window.__ModuleLoader__.load({
1201
1274
  className: styles_module_default.header,
1202
1275
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1203
1276
  className: styles_module_default.title,
1204
- children: t("workspace.title").replace("{project}", project)
1277
+ children: t("workspace.title", { project })
1205
1278
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1206
1279
  type: "button",
1207
1280
  className: styles_module_default.closeButton,
@@ -1234,14 +1307,15 @@ window.__ModuleLoader__.load({
1234
1307
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewBar, {
1235
1308
  view: panel.view,
1236
1309
  onChange: panel.setView,
1237
- t
1310
+ t,
1311
+ views: WORKSPACE_VIEW_ORDER
1238
1312
  })
1239
1313
  ]
1240
1314
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1241
1315
  className: styles_module_default.panelBody,
1242
1316
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1243
1317
  className: styles_module_default.body,
1244
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WiredCapabilityBody, {
1318
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityPanelBody, {
1245
1319
  t,
1246
1320
  panel,
1247
1321
  skills: skillRows,
@@ -1282,11 +1356,6 @@ window.__ModuleLoader__.load({
1282
1356
  const PANEL_ID = "skill-scope";
1283
1357
  const WORKSPACE_CHIP_ID = "skill-scope-workspace";
1284
1358
  const WORKSPACE_MODAL_ID = "skill-scope-workspace-modal";
1285
- /** 从 locale 服务取一个 `{name}` 占位符替换器;缺参数时保留原样(不塞 `undefined`)。 */
1286
- function withParams(template, params) {
1287
- if (params === void 0) return template;
1288
- return Object.entries(params).reduce((text, [key, value]) => text.replaceAll(`{${key}}`, value), template);
1289
- }
1290
1359
  /**
1291
1360
  * 装配客户端插件:注册词条与三个槽位,返回 `undefined`。
1292
1361
  *