dsh-perm-gate 0.2.1-beta.3 → 0.2.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.ja.md +50 -0
- package/CHANGELOG.ko.md +50 -0
- package/CHANGELOG.md +78 -1
- package/INSTALL.ja.md +30 -8
- package/INSTALL.ko.md +30 -9
- package/INSTALL.md +31 -10
- package/INSTALL.zh.md +27 -8
- package/README.ja.md +75 -15
- package/README.ko.md +75 -16
- package/README.md +73 -33
- package/README.zh.md +54 -23
- package/cordis.patch.yml +15 -3
- package/lib/client.js +34 -117
- package/lib/client.js.map +1 -1
- package/lib/config.d.ts +16 -0
- package/lib/config.js +6 -0
- package/lib/index.d.ts +16 -5
- package/lib/index.js +42 -14
- package/lib/runtime.d.ts +65 -5
- package/lib/runtime.js +180 -8
- package/package.json +17 -8
package/README.zh.md
CHANGED
|
@@ -12,26 +12,30 @@
|
|
|
12
12
|
- [日本語 changelog](./CHANGELOG.ja.md)
|
|
13
13
|
- [한국어 changelog](./CHANGELOG.ko.md)
|
|
14
14
|
|
|
15
|
-
> **兼容性说明:** v0.2.1-beta.
|
|
15
|
+
> **兼容性说明:** v0.2.1-beta.5 自带 `ja` / `ko` 字典,但官方 DSH 的 `LocaleRuntime`
|
|
16
16
|
> 只暴露 `zh` / `en`(`LOCALE_IDS = ["zh", "en"]`)。在原版 DSH 上选择 `ja` / `ko`
|
|
17
17
|
> 会报 `locale "<id>" is not registered`。请使用更新了 `LOCALE_IDS`
|
|
18
18
|
> (locale-settings.ts)与 `LOCALES` 标签(client/index.ts)的 DSH fork 并重新构建。
|
|
19
19
|
|
|
20
20
|
> **▼ DSH 版本适配**
|
|
21
21
|
>
|
|
22
|
-
>
|
|
23
|
-
>
|
|
24
|
-
> | 0.1.0-rc.7 ~ 0.1.1-rc.x | ✅ | `ctx.settings.register(ns, schema, { base })` | ✅ `tools/pre-execute` 一致 | ✅ 仅类型导入 |
|
|
25
|
-
> | 0.1.2-alpha.2+ / 0.1.2-rc.1 | ✅ | `register` 仍保留(另加 `installSection`) | ✅ `tools/pre-execute` 一致 | ✅ 仅类型导入 |
|
|
22
|
+
> 两个 DSH 版本线从两个长期分支分别维护,各有一套版本号系列、`engines.dsh`
|
|
23
|
+
> 和 npm 分发标签([发布布局](./RELEASING.md)):
|
|
26
24
|
>
|
|
27
|
-
>
|
|
28
|
-
>
|
|
29
|
-
>
|
|
30
|
-
>
|
|
31
|
-
>
|
|
32
|
-
>
|
|
25
|
+
> | DSH 版本 | 分支 | 版本号 | npm 标签 |
|
|
26
|
+
> | --- | --- | --- | --- |
|
|
27
|
+
> | 0.1.0-rc.7 ~ 0.1.1-rc.x | `legacy` | `1.x` | `@legacy` |
|
|
28
|
+
> | 0.1.2-alpha.1+(含 0.1.5-rc.2) | `main` | `0.2.x` | `@latest` |
|
|
29
|
+
>
|
|
30
|
+
> `@deepseek-ai/dsh-client-runtime` 在 `0.1.2-alpha.1` 中已被**移除**——不仅仅是更名。
|
|
31
|
+
> `legacy` 线仍通过它访问 `ctx.slots`;`main` 从
|
|
32
|
+
> `@deepseek-ai/dsh-client-ui-renderer/client` 获得相同的声明。两处版本敏感
|
|
33
|
+
> 接缝通过**能力探测**处理,而非版本号检查:(1)设置注册使用 `register`,两线
|
|
34
|
+
> 都存在(`installSection` 是新增项,不是替代);(2)`effectivePolicy` 在两
|
|
35
|
+
> 线上都是 user-approval 服务的**私有**方法,因此通过 `typeof` 探测读取,缺失
|
|
36
|
+
> 或抛错时降级为「策略未知」。
|
|
33
37
|
|
|
34
|
-
版本 **0.2.1-beta.
|
|
38
|
+
版本 **0.2.1-beta.5** —— 变更见 [Changelog](./CHANGELOG.md)。
|
|
35
39
|
|
|
36
40
|
一个**单一自足、确定性优先、fail-closed** 的 DeepSeek Harness 权限门插件。
|
|
37
41
|
|
|
@@ -54,7 +58,8 @@
|
|
|
54
58
|
- **会话放行** — 精确的 `(工具, 规范化 fingerprint)` grant,带 `TTL` + `maxUses`;换目标绝不复用。子代理继承但不可自授。
|
|
55
59
|
- **纯函数规则引擎** — glob/regex 编译 + ReDoS 上限、坏规则 loud fail、按源内容哈希缓存。
|
|
56
60
|
- **审计** — 每次决策写为 `{ignorable:true}` 事件并带 `callId`;模型可见理由与记录一致。
|
|
57
|
-
-
|
|
61
|
+
- **自动审查档位**(机器值 `permissive`)——一个**独立审批模式**(区别于只读、完全权限与白名单档),既不是"自动审批",也不授予泛化权限。前端只暴露**一个开关**(`permissive`),后台四个审批策略**可组合**、由插件设置决定——仍对 P0 保持 fail-closed。权限下拉框与设置行都按产品名「自动审查」显示,且不带图标。
|
|
62
|
+
- **沙箱提权自动答复**(`trustEscalation`)— 沙箱提权是从 shell / pwsh / edit 工具**体内部**(`tools/pre-execute` 之后)发出的,所以门禁从未见过它,一个它自动放行的调用仍会弹出确认。开启后,门禁以 `callId` 精确匹配已放行调用并直接答复。
|
|
58
63
|
|
|
59
64
|
## 安装
|
|
60
65
|
|
|
@@ -83,12 +88,17 @@ dsh plugin --profile web add dsh-perm-gate
|
|
|
83
88
|
|
|
84
89
|
规则示例:见 [examples/permissions.example.yaml](./examples/permissions.example.yaml)。
|
|
85
90
|
|
|
86
|
-
##
|
|
91
|
+
## 自动审查档位(机器值 `permissive`)
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
自动审查是权限下拉框里一个**独立审批档**,与只读 / 工作区内修改 / 完全权限 / 白名单平行。
|
|
94
|
+
它不是泛化的"自动审批"、也不授予泛化权限:只会在人类/LLM 接缝**之前**收窄或放宽决策,
|
|
90
95
|
P0 硬拒绝始终单调且不可协商。
|
|
91
96
|
|
|
97
|
+
下拉框里的名字是**宿主提供的产品名**,不是逐语言的字典项:DSH 0.1.2 对插件档位在**两个**权限界面上
|
|
98
|
+
(通用设置默认档行、输入栏权限选择器)都原样渲染补丁里的 `name:`,只给三个内置档提供自己的本地化
|
|
99
|
+
标签,因此 `cordis.patch.yml` 直接写中文名,对所有会话一致。该档位**不画图标**——选择器的图标只按
|
|
100
|
+
三个内置值取。
|
|
101
|
+
|
|
92
102
|
`cordis.yml`:
|
|
93
103
|
|
|
94
104
|
```yaml
|
|
@@ -101,6 +111,7 @@ P0 硬拒绝始终单调且不可协商。
|
|
|
101
111
|
permissiveStrategies: # 后台策略,可组合
|
|
102
112
|
trustAutoAllow: true # 作用域内安全操作自动放行;危险/未知转 ask
|
|
103
113
|
alwaysConfirm: false # 一律逐次 ask;允许控件附带重复允许/迁白名单按钮
|
|
114
|
+
trustEscalation: true # 门禁已放行的调用,其自身的沙箱提权免确认
|
|
104
115
|
llmAssist: false # 先由 LLM 分类裁决;ask/无分类器时回退到人工
|
|
105
116
|
```
|
|
106
117
|
(llmAssist 的真实接收 LLM 在设置页填 `classifierEndpoint` / `classifierModel`,OpenAI 兼容的自定义 API
|
|
@@ -110,16 +121,36 @@ P0 硬拒绝始终单调且不可协商。
|
|
|
110
121
|
「允许控件」含两个扩展按钮:**本会话重复允许该类**(会话限次 grant,`approveRepeat`)与
|
|
111
122
|
**允许所有类型**(把命令词持久写进 `permissions.yaml` 的 allow 白名单,`approveAllowEverywhere`)。
|
|
112
123
|
`llmAssist` 调用配置的真实 LLM(任意 OpenAI 兼容 API)自动裁决 `ask`,结果不确定/出错时回退人工
|
|
113
|
-
接缝——始终 fail-closed。`
|
|
124
|
+
接缝——始终 fail-closed。`trustEscalation`(档位开启时默认开)答复门禁已放行的调用在其工具体内
|
|
125
|
+
提出的 `sandbox_permissions` 提权;见下文。`permissive` 关闭时,门禁行为与之前完全一致。
|
|
126
|
+
|
|
127
|
+
### 沙箱提权:为何 `safe` 裁决仍会弹窗
|
|
128
|
+
|
|
129
|
+
一个工具调用可能触发**两个独立的审批**。门禁负责第一个——它的 `ask`,在 `tools/pre-execute`
|
|
130
|
+
瀑布上。第二个来自工具体内部的 `approveEscalation`,在 `tools/execute` 时刻,只要模型传了
|
|
131
|
+
`sandbox_permissions` + `justification`;此时 `tools/pre-execute` 已结算,门禁的放行从未到达它。
|
|
132
|
+
LLM 评定为 `safe` 且门禁自动放行的调用因此仍会弹出确认。
|
|
133
|
+
|
|
134
|
+
`trustEscalation` 填补这个缺口。门禁记住每个它正面向上放行的调用(以宿主 `callId` 为键,提权
|
|
135
|
+
请求会重复该值),并在本处自行答复 `allowed-once`。它仅在**全部满足**时适用:
|
|
136
|
+
|
|
137
|
+
- 自动审查档位开启且 `trustEscalation` 开启;
|
|
138
|
+
- 请求携带门禁放行的 `callId`,且工具名匹配;
|
|
139
|
+
- 原因为已知的提权,指明 `workspace-write` 或 `danger-full-access`。
|
|
140
|
+
|
|
141
|
+
其余所有情况——未知原因、不同的调用、门禁要求或拒绝的调用、`approval: never` 透传——都保持交给人
|
|
142
|
+
工,因此未来 DSH 措辞变更时 fail-closed。自动答复记录在事件流中
|
|
143
|
+
(`verdict: "escalation-auto"`,`mode: <目标模式>`)。关闭开关可使沙箱放宽保持人工审批,其余
|
|
144
|
+
自动放行不变。
|
|
114
145
|
|
|
115
146
|
### 权限下拉里可选档位
|
|
116
147
|
|
|
117
148
|
`cordis.patch.yml` 在 DSH 的 `permission.config.presets` 里新增了 `permissive` preset
|
|
118
|
-
(`sandbox: workspace-write`、`approval: ask`、名称
|
|
119
|
-
|
|
149
|
+
(`sandbox: workspace-write`、`approval: ask`、名称 **自动审查**),位于工作区内修改与
|
|
150
|
+
完全权限之间。DSH 的 bundle patch 对这个 map 是**整表替换**而非逐键合并,所以该文件还必须重述三个内置档
|
|
120
151
|
(`read-only` / `workspace-write` / `danger-full-access`,取自
|
|
121
152
|
`@deepseek-ai/dsh-base/cordis.patch.yml`);`test/patch-presets.spec.ts` 固定了这份键集合。因此会话权限
|
|
122
|
-
|
|
153
|
+
下拉里会出现「自动审查」这个**独立可选审批档**,而不是"auto-approval"档。
|
|
123
154
|
|
|
124
155
|
门禁**只在 `gatePresets` 列出的档位里生效**(默认 `['permissive']`,即本插件新增的那一档)。在其余任何档位
|
|
125
156
|
(Read Only、Workspace Write、Full access、`custom`)里,门禁的判定流程**完全不运行**:不放行、不弹审批、
|
|
@@ -131,8 +162,8 @@ Full access 之间。DSH 的 bundle patch 对这个 map 是**整表替换**而
|
|
|
131
162
|
|
|
132
163
|
### 在 UI 里可配置
|
|
133
164
|
|
|
134
|
-
该档位也可在运行时从 **设置 → 插件 →
|
|
135
|
-
`settings.plugins.tab` 页面):一个开关切换 `permissive
|
|
165
|
+
该档位也可在运行时从 **设置 → 插件 → 自动审查** 调整(插件浏览器端渲染的
|
|
166
|
+
`settings.plugins.tab` 页面):一个开关切换 `permissive`,四个开关编辑后台
|
|
136
167
|
`permissiveStrategies`。host 端 live 读取该命名空间,改动对下一条工具调用即时生效,无需重启。
|
|
137
168
|
这是一个独立审批类,**不是** DSH 的"auto-approval"档。
|
|
138
169
|
|
|
@@ -156,7 +187,7 @@ Full access 之间。DSH 的 bundle patch 对这个 map 是**整表替换**而
|
|
|
156
187
|
调用文本命中任一关键词(大小写不敏感子串)即直接拒绝,且先于白名单 / 授权 / LLM。黑名单在设置
|
|
157
188
|
卡片中按列表查看与增删(预置条目带标签,可一键恢复预置);未设置或为空时应用预置列表——黑名单
|
|
158
189
|
不会静默关闭。
|
|
159
|
-
|
|
190
|
+
该档位在权限选择器中**不显示图标**:选择器的图标只按三个内置值取,插件新增的档位是纯文字。
|
|
160
191
|
|
|
161
192
|
|
|
162
193
|
## CLI(独立 dry-run)
|
package/cordis.patch.yml
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# dsh-perm-gate profile patch.
|
|
2
2
|
#
|
|
3
3
|
# Two jobs:
|
|
4
|
-
# 1) Add the plugin's own "
|
|
4
|
+
# 1) Add the plugin's own "自动审查" session approval tier to the DSH
|
|
5
5
|
# permission picker, and restate the built-in tiers it must not drop.
|
|
6
6
|
# 2) Insert the plugin itself (host half) into the profile.
|
|
7
7
|
#
|
|
8
|
+
# The tier's DISPLAY NAME is the Chinese product label, matching every official
|
|
9
|
+
# 0.1.2 permission label (仅可查看 / 工作区内修改 / 完全权限) in a zh session. Both
|
|
10
|
+
# permission surfaces — the General-settings default row and the composer
|
|
11
|
+
# picker — render a host-supplied name verbatim unless the value is one of the
|
|
12
|
+
# three built-ins, so a single `name:` string is what both show; neither surface
|
|
13
|
+
# is localized per-dictionary for plugin-contributed tiers. The machine value
|
|
14
|
+
# stays `permissive`: it is the key `gatePresets` matches and the value the
|
|
15
|
+
# permission projection reports, so only the label text is user-facing.
|
|
16
|
+
#
|
|
17
|
+
# The tier carries no icon. The built-in glyphs the composer draws are keyed by
|
|
18
|
+
# the three built-in values, and a plugin tier deliberately has none.
|
|
19
|
+
#
|
|
8
20
|
# The DSH bundle patch REPLACES the whole `permission.config.presets` map (it
|
|
9
21
|
# does not merge per key), so this file MUST restate every tier that should
|
|
10
22
|
# survive. The authoritative built-in set is
|
|
@@ -31,8 +43,8 @@
|
|
|
31
43
|
permissive:
|
|
32
44
|
sandbox: workspace-write
|
|
33
45
|
approval: ask
|
|
34
|
-
name:
|
|
35
|
-
description:
|
|
46
|
+
name: 自动审查
|
|
47
|
+
description: 独立审批档 —— 作用域内安全操作自动放行,危险/未知越界转人工确认(审批强度可在「设置 → 插件 → 自动审查」调整)。
|
|
36
48
|
danger-full-access:
|
|
37
49
|
sandbox: danger-full-access
|
|
38
50
|
approval: never
|
package/lib/client.js
CHANGED
|
@@ -12,14 +12,16 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
const NS = "dsh-perm-gate";
|
|
13
13
|
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
14
14
|
const zh = {
|
|
15
|
-
"card.title": "
|
|
16
|
-
"card.description": "
|
|
17
|
-
"card.permissive": "
|
|
15
|
+
"card.title": "自动审查",
|
|
16
|
+
"card.description": "独立审批档位:与只读 / 完全权限 / 白名单平行,在会话权限下拉中显示为「自动审查」。前端只暴露一个开关;后台四个审批策略可组合、由此处设置决定,仍对 P0 硬拒绝保持 fail-closed。",
|
|
17
|
+
"card.permissive": "启用自动审查档位",
|
|
18
18
|
"card.permissiveHint": "关闭时门禁行为与此前完全一致。",
|
|
19
19
|
"card.strategies": "后台审批策略(至少一个生效;可组合)",
|
|
20
20
|
"card.strategy.trustAutoAllow": "trustAutoAllow — 作用域内安全操作自动放行,危险/未知转 ask(中间档基线)",
|
|
21
21
|
"card.strategy.alwaysConfirm": "alwaysConfirm — 一律逐次 ask;审批面板「允许控件」含两个扩展按钮:「本会话重复允许该类」(会话语限次 grant)与「允许所有类型」(命令词持久迁入 rulesFile 白名单)",
|
|
22
22
|
"card.strategy.llmAssist": "llmAssist — 自定义 LLM 按风险分级裁决:safe 自动放行;deletion/credential/remote/system/bulk 硬风险自动拒绝;neutral 进入确认学习;失败/超时回退人工",
|
|
23
|
+
"card.strategy.trustEscalation": "trustEscalation — 沙箱升级免确认:本门禁已放行的调用,其工具内部发起的沙箱提权(shell / pwsh / edit 的 sandbox_permissions)由门禁直接批准,不再弹窗",
|
|
24
|
+
"card.strategy.trustEscalationHint": "沙箱提权审批发生在 tools/pre-execute 之后、工具体内部,门禁原本看不到它,因此「LLM 判安全已自动放行」的调用仍会弹窗要求你批准提权。开启后,仅对门禁确实放行过的那一次调用(按 callId 精确匹配)免确认,其余一律照旧走人工;目标模式非 workspace-write / danger-full-access 或理由无法识别时同样回退人工。关闭后提权保持人工把关。",
|
|
23
25
|
"card.readonly": "只读",
|
|
24
26
|
"card.unavailable": "设置命名空间不可用:请确认 dsh-perm-gate 已装配进 profile。",
|
|
25
27
|
"card.llmReceiver": "llmAssist 接收 LLM(OpenAI 兼容,可用自定义 API)",
|
|
@@ -119,14 +121,16 @@ window.__ModuleLoader__.load({
|
|
|
119
121
|
};
|
|
120
122
|
/** English dictionary (keys mirror zh). */
|
|
121
123
|
const en = {
|
|
122
|
-
"card.title": "
|
|
123
|
-
"card.description": "Independent approval
|
|
124
|
-
"card.permissive": "Enable
|
|
124
|
+
"card.title": "自动审查 (Auto review)",
|
|
125
|
+
"card.description": "Independent approval tier, parallel to read-only / full-access / whitelist, shown as 自动审查 in the session permission picker. The front-end exposes a single switch; the four backend approval strategies are combinable via this panel and still fail-closed against P0 hard-deny.",
|
|
126
|
+
"card.permissive": "Enable the 自动审查 tier",
|
|
125
127
|
"card.permissiveHint": "When off, the gate behaves exactly as before.",
|
|
126
128
|
"card.strategies": "Backend approval strategies (at least one effective; combinable)",
|
|
127
129
|
"card.strategy.trustAutoAllow": "trustAutoAllow — safe in-scope ops auto-allow; dangerous/unknown ask (baseline middle tier)",
|
|
128
130
|
"card.strategy.alwaysConfirm": "alwaysConfirm — every crossing asks; the approval \"allow controls\" get two extended buttons: \"repeat-allow this type this session\" (bounded session grant) and \"allow every occurrence\" (persist the command word into the rulesFile whitelist)",
|
|
129
131
|
"card.strategy.llmAssist": "llmAssist — a custom LLM grades risk: safe auto-allows; deletion/credential/remote/system/bulk hard risks auto-deny; neutral enters confirm-learning; failure/timeout falls back to the human",
|
|
132
|
+
"card.strategy.trustEscalation": "trustEscalation — sandbox escalation without a prompt: for a call this gate already allowed, the sandbox widening a shell / pwsh / edit tool raises from inside itself is approved here instead of asking you",
|
|
133
|
+
"card.strategy.trustEscalationHint": "A sandbox escalation is asked from inside the tool body, after tools/pre-execute, so the gate never saw it — a call the LLM graded safe and the gate auto-allowed still prompted you to approve the widening. With this on, only the exact call the gate allowed (matched by callId) skips the prompt; everything else goes to the human as before, as does any unrecognized reason or a target other than workspace-write / danger-full-access. Turn it off to keep widening human-gated.",
|
|
130
134
|
"card.readonly": "Read-only",
|
|
131
135
|
"card.unavailable": "Settings namespace unavailable: make sure dsh-perm-gate is assembled into this profile.",
|
|
132
136
|
"card.llmReceiver": "llmAssist receiving LLM (OpenAI-compatible; any custom API)",
|
|
@@ -742,6 +746,29 @@ window.__ModuleLoader__.load({
|
|
|
742
746
|
}
|
|
743
747
|
})]
|
|
744
748
|
}),
|
|
749
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
750
|
+
style: rowStyle,
|
|
751
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
752
|
+
htmlFor: "plugin-config-perm-gate-escalation",
|
|
753
|
+
style: { fontSize: "12px" },
|
|
754
|
+
children: t("card.strategy.trustEscalation")
|
|
755
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
756
|
+
id: "plugin-config-perm-gate-escalation",
|
|
757
|
+
type: "checkbox",
|
|
758
|
+
checked: strategies.trustEscalation ?? true,
|
|
759
|
+
disabled: readonly || !effective,
|
|
760
|
+
onChange: (event) => {
|
|
761
|
+
scope.set("permissiveStrategies", {
|
|
762
|
+
...strategies,
|
|
763
|
+
trustEscalation: event.currentTarget.checked
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
})]
|
|
767
|
+
}),
|
|
768
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
769
|
+
style: hintStyle,
|
|
770
|
+
children: t("card.strategy.trustEscalationHint")
|
|
771
|
+
}),
|
|
745
772
|
strategies.llmAssist === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
746
773
|
style: sectionStyle,
|
|
747
774
|
children: [
|
|
@@ -1390,115 +1417,6 @@ window.__ModuleLoader__.load({
|
|
|
1390
1417
|
});
|
|
1391
1418
|
}
|
|
1392
1419
|
//#endregion
|
|
1393
|
-
//#region src/client/permission-icon.ts
|
|
1394
|
-
/**
|
|
1395
|
-
* Permission-picker icon decoration for the Permissive tier.
|
|
1396
|
-
*
|
|
1397
|
-
* dsh-auto-mode injects a shield glyph onto its "Auto" permission menu item
|
|
1398
|
-
* via a `data-*` attribute + a CSS mask. This module does the same for the
|
|
1399
|
-
* "Permissive" preset so the two approval tiers look consistent in the
|
|
1400
|
-
* dropdown. It only annotates the item; the preset itself comes from
|
|
1401
|
-
* `cordis.patch.yml` (the `permission.config.presets` table).
|
|
1402
|
-
*
|
|
1403
|
-
* Pure DOM + CSS, no @deepseek-ai value imports (client bundle purity).
|
|
1404
|
-
*/
|
|
1405
|
-
const PLUGIN_ID = "dsh-perm-gate";
|
|
1406
|
-
const ICON_ATTRIBUTE = "data-dsh-perm-gate-icon";
|
|
1407
|
-
/** Labels of the Permissive preset item, current + future localized variants. */
|
|
1408
|
-
const PERMISSIVE_LABELS = /* @__PURE__ */ new Set([
|
|
1409
|
-
"Permissive",
|
|
1410
|
-
"Permissive 审批档",
|
|
1411
|
-
"Permissive 审批档位"
|
|
1412
|
-
]);
|
|
1413
|
-
/** Same shield glyph as dsh-auto-mode so the two approval tiers match visually. */
|
|
1414
|
-
const ICON_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\"><path d=\"M8.21.9l6.58 2.47v3.64c0 4.99-3.74 7.2-6.58 8.29C5.36 14.21 1.62 12 1.62 7.01V3.37L8.21.9Z\" fill=\"none\" stroke=\"black\" stroke-width=\"1.32\" stroke-linejoin=\"round\"/><path d=\"M8.75 3.65 5.95 8.2h2.08l-.78 4.15 2.82-4.9H8.12l.63-3.8Z\" fill=\"black\"/></svg>";
|
|
1415
|
-
function iconStyles() {
|
|
1416
|
-
const mask = `url("data:image/svg+xml,${encodeURIComponent(ICON_SVG)}")`;
|
|
1417
|
-
return `
|
|
1418
|
-
[${ICON_ATTRIBUTE}]::before {
|
|
1419
|
-
content: "";
|
|
1420
|
-
display: inline-block;
|
|
1421
|
-
flex: 0 0 auto;
|
|
1422
|
-
width: 16px;
|
|
1423
|
-
height: 16px;
|
|
1424
|
-
background-color: var(--dsw-alias-label-tertiary, currentColor);
|
|
1425
|
-
-webkit-mask-image: ${mask};
|
|
1426
|
-
mask-image: ${mask};
|
|
1427
|
-
-webkit-mask-position: center;
|
|
1428
|
-
mask-position: center;
|
|
1429
|
-
-webkit-mask-repeat: no-repeat;
|
|
1430
|
-
mask-repeat: no-repeat;
|
|
1431
|
-
-webkit-mask-size: contain;
|
|
1432
|
-
mask-size: contain;
|
|
1433
|
-
}
|
|
1434
|
-
[${ICON_ATTRIBUTE}='trigger']::before {
|
|
1435
|
-
width: 14px;
|
|
1436
|
-
height: 14px;
|
|
1437
|
-
margin-right: 6px;
|
|
1438
|
-
}
|
|
1439
|
-
`;
|
|
1440
|
-
}
|
|
1441
|
-
/** The permission dropdown menu (lists the permission presets as menuitems). */
|
|
1442
|
-
function isPermissionMenu(menu) {
|
|
1443
|
-
return menu.matches("[role=\"menu\"]") && Array.from(menu.querySelectorAll("button[role=\"menuitem\"]")).length >= 4;
|
|
1444
|
-
}
|
|
1445
|
-
/** Whether one menuitem is the Permissive preset. */
|
|
1446
|
-
function isPermissiveMenuItem(element) {
|
|
1447
|
-
if (!element.matches("button[role=\"menuitem\"]")) return false;
|
|
1448
|
-
const label = (element.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
1449
|
-
if (!PERMISSIVE_LABELS.has(label)) return false;
|
|
1450
|
-
return element.closest("[role=\"menu\"]") !== null;
|
|
1451
|
-
}
|
|
1452
|
-
/** The collapsed permission-picker trigger (opens the presets menu). */
|
|
1453
|
-
function isPermissionTrigger(element) {
|
|
1454
|
-
return element.matches("button[aria-haspopup=\"menu\"]") && PERMISSIVE_LABELS.has((element.textContent ?? "").replace(/\s+/g, " ").trim());
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Annotate the Permissive permission menuitems with the icon attribute, plus
|
|
1458
|
-
* the collapsed picker trigger when its label names the Permissive preset.
|
|
1459
|
-
* Unknown DOM shapes simply never match, so decoration stays conservative.
|
|
1460
|
-
*/
|
|
1461
|
-
function decorate(document) {
|
|
1462
|
-
for (const marked of document.querySelectorAll(`[${ICON_ATTRIBUTE}]`)) if (!isPermissiveMenuItem(marked) && !isPermissionTrigger(marked)) marked.removeAttribute(ICON_ATTRIBUTE);
|
|
1463
|
-
for (const menu of document.querySelectorAll("[role=\"menu\"]")) {
|
|
1464
|
-
if (!isPermissionMenu(menu)) continue;
|
|
1465
|
-
for (const item of menu.querySelectorAll("button[role=\"menuitem\"]")) if (isPermissiveMenuItem(item)) item.setAttribute(ICON_ATTRIBUTE, "menu");
|
|
1466
|
-
}
|
|
1467
|
-
for (const trigger of document.querySelectorAll("button[aria-haspopup=\"menu\"]")) if (isPermissionTrigger(trigger)) trigger.setAttribute(ICON_ATTRIBUTE, "trigger");
|
|
1468
|
-
}
|
|
1469
|
-
/** Install the Permissive tile icon into the permission picker; returns the disposer. */
|
|
1470
|
-
function installPermissivePermissionIcon(document) {
|
|
1471
|
-
for (const existing of document.querySelectorAll("style[data-plugin]")) if (existing.getAttribute("data-plugin") === PLUGIN_ID) existing.remove();
|
|
1472
|
-
const style = document.createElement("style");
|
|
1473
|
-
style.dataset.plugin = PLUGIN_ID;
|
|
1474
|
-
style.dataset.pluginCss = `${PLUGIN_ID}/permission-icon`;
|
|
1475
|
-
style.textContent = iconStyles();
|
|
1476
|
-
document.head.appendChild(style);
|
|
1477
|
-
let active = true;
|
|
1478
|
-
let queued = false;
|
|
1479
|
-
const scan = () => {
|
|
1480
|
-
if (!active || queued) return;
|
|
1481
|
-
queued = true;
|
|
1482
|
-
queueMicrotask(() => {
|
|
1483
|
-
queued = false;
|
|
1484
|
-
if (active) decorate(document);
|
|
1485
|
-
});
|
|
1486
|
-
};
|
|
1487
|
-
decorate(document);
|
|
1488
|
-
const observer = new MutationObserver(scan);
|
|
1489
|
-
observer.observe(document.documentElement, {
|
|
1490
|
-
childList: true,
|
|
1491
|
-
characterData: true,
|
|
1492
|
-
subtree: true
|
|
1493
|
-
});
|
|
1494
|
-
return () => {
|
|
1495
|
-
active = false;
|
|
1496
|
-
observer.disconnect();
|
|
1497
|
-
for (const marked of document.querySelectorAll(`[${ICON_ATTRIBUTE}]`)) marked.removeAttribute(ICON_ATTRIBUTE);
|
|
1498
|
-
style.remove();
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
//#endregion
|
|
1502
1420
|
//#region src/client/feed.ts
|
|
1503
1421
|
/** Fetch decision events for one session; `since > 0` returns only newer ones. */
|
|
1504
1422
|
async function fetchEvents(sessionId, since) {
|
|
@@ -1582,7 +1500,7 @@ window.__ModuleLoader__.load({
|
|
|
1582
1500
|
"deny-keyword": "黑名单关键词",
|
|
1583
1501
|
default: "默认策略",
|
|
1584
1502
|
ask: "默认策略",
|
|
1585
|
-
permissive: "
|
|
1503
|
+
permissive: "自动审查放行",
|
|
1586
1504
|
classifier: "LLM 裁决",
|
|
1587
1505
|
"llm-safe": "LLM 判定安全",
|
|
1588
1506
|
"llm-learned": "LLM 学习放行",
|
|
@@ -2548,7 +2466,6 @@ window.__ModuleLoader__.load({
|
|
|
2548
2466
|
zh,
|
|
2549
2467
|
en
|
|
2550
2468
|
}), "dsh-perm-gate: dictionaries");
|
|
2551
|
-
ctx.effect(() => installPermissivePermissionIcon(globalThis.document), "dsh-perm-gate: permission icon");
|
|
2552
2469
|
ctx.slots.inject("conversation.input.dock", function* () {
|
|
2553
2470
|
yield ctx.slots.register({
|
|
2554
2471
|
name: "conversation.input.dock",
|