@fish-under-sea/dsh-approval-guide 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/README.en.md +154 -0
  2. package/README.md +68 -54
  3. package/package.json +3 -2
package/README.en.md ADDED
@@ -0,0 +1,154 @@
1
+ <div align="center">
2
+
3
+ # @fish-under-sea/dsh-approval-guide
4
+
5
+ **Adds a Chinese explanation to every DSH approval prompt: what it will do, what the risks are, and on what basis.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/@fish-under-sea/dsh-approval-guide?style=flat-square&label=npm&color=cb3837)](https://www.npmjs.com/package/@fish-under-sea/dsh-approval-guide)
8
+ ![license](https://img.shields.io/badge/license-MIT-green?style=flat-square)
9
+ ![node](https://img.shields.io/badge/node-%5E22.19.0%20%7C%7C%20%3E%3D24.0.0-339933?style=flat-square)
10
+ ![DSH](https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.2-4b6ef6?style=flat-square)
11
+ ![plugin](https://img.shields.io/badge/plugin-client%20%2B%20host-6b7280?style=flat-square)
12
+
13
+ [简体中文](README.md) · **English**
14
+
15
+ </div>
16
+
17
+ ## What Problem Does This Solve
18
+
19
+ The approval dialog already ships some Chinese UI strings ("等待审批", "拒绝", "允许一次"), but **the approval reason generated by the host is English-only**. The most common one looks like this:
20
+
21
+ ```text
22
+ escalate sandbox to danger-full-access: <one-line English reason from the model>
23
+ ```
24
+
25
+ The reader has to judge on their own what the command will actually do, how much it will unlock, and what the consequences are — and the English-only template raises that cost. This plugin injects a tiered Chinese explanation below the reason and the command, covering "what it will do / what the risks are / on what basis".
26
+
27
+ ## Result
28
+
29
+ The detail area inside the approval card becomes:
30
+
31
+ ```text
32
+ <original command>
33
+
34
+ What this approval will do
35
+ Escalate the file sandbox scope of this pwsh call to "fully open" (danger-full-access).
36
+ Effective only for this single call: no long-lived grant, no effect on later commands.
37
+ Risk
38
+ Once opened, this command is no longer confined by the workspace boundary: it can read
39
+ and write any file on the host, including system directories, other projects, SSH keys,
40
+ and credential files, and this execution no longer asks for your approval item by item.
41
+ Only allow it if you fully trust this command.
42
+ · Tool: pwsh
43
+ · Target permission: fully open (danger-full-access)
44
+ · Reason given by the model: <original text>
45
+ When in doubt, click "Reject" first: rejecting does not interrupt the conversation;
46
+ I can retry later with read-only or workspace-write instead.
47
+ ```
48
+
49
+ The explanation is always shown in Chinese and does not follow the UI language — switching the interface to English still leaves the Chinese prompt in place.
50
+
51
+ ### Tiered Copy
52
+
53
+ The Chinese explanation is produced by **static rules**: no extra model call, no API quota consumed, and it cannot be swayed by the requester's own wording.
54
+
55
+ | Target permission | Level | Key points of the risk copy |
56
+ | --- | --- | --- |
57
+ | `danger-full-access` | High (red title) | No longer confined by the workspace boundary; can read and write any file on the host (including system directories, other projects, SSH keys, and credential files); this execution no longer asks for approval item by item. |
58
+ | `workspace-write` | Caution | Can write to the current workspace directory and its subdirectories, plus the system temp directory; still cannot write outside the workspace. |
59
+ | Other modes | Caution | Not a built-in DSH mode — no precise scope can be given; prompts that the command will run at the requested permission. |
60
+ | No sandbox parameter | Caution | Generic fallback: the tool requests a higher permission for this single operation, effective only this time. |
61
+
62
+ ## Installation
63
+
64
+ ```sh
65
+ # Install from npm (recommended)
66
+ dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide
67
+ ```
68
+
69
+ `--profile` should be followed by the actual profile name on your machine: `desktop` for the desktop app, `web` for the web app.
70
+
71
+ Use `link:` to point at this directory only when you need to modify the source (the repo source is the install source — restart DSH after changes for them to take effect):
72
+
73
+ ```sh
74
+ dsh plugin --profile <profile> add "link:<absolute path to this directory>"
75
+ ```
76
+
77
+ After installation, you need to **restart the DSH app and refresh the page** for it to take effect (the web build has no in-place restart).
78
+
79
+ ### Uninstallation
80
+
81
+ ```sh
82
+ dsh plugin --profile <profile> remove @fish-under-sea/dsh-approval-guide
83
+ ```
84
+
85
+ ### Post-Install Self-Check
86
+
87
+ ```sh
88
+ dsh --profile <profile> --dump-config
89
+ ```
90
+
91
+ The end of the output should contain exactly one `- id: approval-guide` / `name: @fish-under-sea/dsh-approval-guide` entry. Multiple entries mean the plugin is mounted more than once, and the app will fail to start.
92
+
93
+ ## Usage
94
+
95
+ No configuration is needed after installation — the plugin automatically occupies the `conversation.approval.detail` slot of the approval detail area and appends the Chinese explanation to every approval prompt.
96
+
97
+ The explanation is resolved in a defense-in-depth order: first read the tool-call arguments `sandbox_permissions` / `justification`; if those are unavailable, parse the host reason template (`escalate sandbox to <mode>: <reason>`); if that also fails, fall back to the generic explanation. Even when every layer fails to produce a value, a generic Chinese explanation is still shown.
98
+
99
+ Coverage:
100
+
101
+ - All interactive approvals **with a correlated tool call**: sandbox permission escalation, asks triggered by hooks, and asks initiated by other plugins through the approval channel.
102
+
103
+ ## Configuration
104
+
105
+ **No configuration file.** This package has no configuration options and does not read or write any settings file — all rules are hardcoded in `lib/client.js`.
106
+
107
+ ## Compatibility and Boundaries
108
+
109
+ - Platform: pure browser plugin (`dsh.client.platform: web`); the host half is an empty implementation.
110
+ - Occupies the `conversation.approval.detail` sub-slot of the core package `@deepseek-ai/dsh-client-ui-approval`. The slot is of `single` type, sorted by priority in **ascending order** with the **smallest number rendered**; the official occupier `ApprovalCommand` uses the default priority 0, and this plugin registers with `priority: -1` to override it, while re-rendering the original command inside the component using the same logic (`useChat` to fetch the correlated tool call, parsing `argsRaw.command`) so no information is lost.
111
+ - When the component throws, the slot renderer reclaims the entry (abdicate), and the official `ApprovalCommand` automatically resumes rendering — the approval card never goes blank, and the approval flow is never blocked.
112
+ - Compatible with both generations of selectors: DSH 0.2.0 (`useSessionStatus`) and 0.1.x (`useSessionPendingInteraction`).
113
+
114
+ Data sources:
115
+
116
+ | Data | Source |
117
+ | --- | --- |
118
+ | Command and arguments of the correlated tool call | `useChat` selector (same as the official `ApprovalCommand`) |
119
+ | Tool name and approval reason | `useSessionPendingInteraction` / `useSessionStatus` selector (pending interaction with `kind === 'approval'`) |
120
+
121
+ ### Known Limitations
122
+
123
+ - If an approval request has **no correlated tool call** (missing `callId`), the core does not render the detail area, and this plugin has nowhere to insert. This is dictated by the core slot contract and cannot be worked around by this plugin.
124
+ - The Chinese explanation describes the risk at the "permission scope" layer; it does not judge whether the command itself is safe. You still need to read the command yourself.
125
+ - If the host changes the reason template (`escalate sandbox to <mode>: <reason>`), the first-layer argument lookup still works; only the second-layer fallback would stop working.
126
+
127
+ ## Development and Testing
128
+
129
+ ```sh
130
+ node packages/dsh-approval-guide/test/guide.test.mjs
131
+ ```
132
+
133
+ All 12 cases currently pass. The test loads the actual `lib/client.js` that goes into the browser: it uses `node:vm` to provide `window.__ModuleLoader__`, captures the factory registered by the bundle, instantiates it with a fake module table, and directly asserts on the element tree produced by the pure functions and the component. **Zero dependencies** — no need to install React or vitest.
134
+
135
+ > Do not use `node --test test/`: the test runner spawns child processes and captures their piped output, which fails with `EPERM` inside a restricted sandbox. Just run the test file directly.
136
+
137
+ Cases covered: tiered copy for the two sandbox modes, reason-template fallback parsing, unknown modes, generic approval fallback, corrupted argument JSON, no exception on empty input, component preserves the original command, degradation when pending interaction is unavailable, slot registration priority.
138
+
139
+ Directory layout:
140
+
141
+ | Path | Purpose |
142
+ | --- | --- |
143
+ | `lib/index.js` | Host half, empty implementation (pure browser plugin) |
144
+ | `lib/client.js` | Browser half: Chinese copy, tiering logic, approval detail component, slot registration |
145
+ | `cordis.patch.yml` | Bundle patch layer that inserts the plugin entry into the profile registry |
146
+ | `test/guide.test.mjs` | Zero-dependency tests |
147
+
148
+ ## Relationship with the Aggregation Package
149
+
150
+ > This package is one of the members of the [`@fish-under-sea/dsh-fish`](https://github.com/Fish-under-sea/dsh-fish) aggregation package; installing it alone affects only this single item.
151
+
152
+ ## License
153
+
154
+ MIT © Fish-under-sea
package/README.md CHANGED
@@ -1,10 +1,18 @@
1
+ <div align="center">
2
+
1
3
  # @fish-under-sea/dsh-approval-guide
2
4
 
3
- 给 DSH Web GUI 的审批弹窗补一段**中文说明**:这次审批会做什么、有什么风险、依据是什么。
5
+ **给 DSH 审批弹窗补一段中文说明:这次审批会做什么、有什么风险、依据是什么。**
6
+
7
+ [![npm](https://img.shields.io/npm/v/@fish-under-sea/dsh-approval-guide?style=flat-square&label=npm&color=cb3837)](https://www.npmjs.com/package/@fish-under-sea/dsh-approval-guide)
8
+ ![license](https://img.shields.io/badge/license-MIT-green?style=flat-square)
9
+ ![node](https://img.shields.io/badge/node-%5E22.19.0%20%7C%7C%20%3E%3D24.0.0-339933?style=flat-square)
10
+ ![DSH](https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.2-4b6ef6?style=flat-square)
11
+ ![plugin](https://img.shields.io/badge/plugin-client%20%2B%20host-6b7280?style=flat-square)
4
12
 
5
- 原英文理由与命令原文照旧显示,中文说明挂在它们下面,不替换任何现有内容。
13
+ **简体中文** · [English](README.en.md)
6
14
 
7
- > 许可证:MIT。
15
+ </div>
8
16
 
9
17
  ## 解决什么问题
10
18
 
@@ -24,22 +32,24 @@ escalate sandbox to danger-full-access: <模型填写的一句英文理由>
24
32
  <原命令>
25
33
 
26
34
  这次审批会做什么
27
- 把这一次 pwsh 调用的文件沙箱范围提升到「完全放开」(danger-full-access)。只对本次调用生效:
28
- 不产生长期授权,也不影响之后的命令。
35
+ 把这一次 pwsh 调用的文件沙箱范围提升到「完全放开」(danger-full-access)。
36
+ 只对本次调用生效:不产生长期授权,也不影响之后的命令。
29
37
  风险
30
- 放开后这条命令不再受工作区边界约束:它可以读写本机任意文件,包括系统目录、其它项目、
31
- SSH 密钥与凭据文件,本次执行也不再逐条征求你的同意。只有在你完全信任这条命令时才应允许。
38
+ 放开后这条命令不再受工作区边界约束:它可以读写本机任意文件,
39
+ 包括系统目录、其它项目、SSH 密钥与凭据文件,
40
+ 本次执行也不再逐条征求你的同意。只有在你完全信任这条命令时才应允许。
32
41
  · 工具:pwsh
33
42
  · 目标权限:完全放开(danger-full-access)
34
43
  · 模型给的理由:<原文>
35
- 拿不准就先点「拒绝」:拒绝不会中断对话,之后我可以换成只读、或只写工作区内的方式重试。
44
+ 拿不准就先点「拒绝」:拒绝不会中断对话,之后我可以换成只读、
45
+ 或只写工作区内的方式重试。
36
46
  ```
37
47
 
38
48
  说明一律中文显示,不跟随界面语言——界面切到英文时,中文提示仍然在。
39
49
 
40
50
  ### 文案分级
41
51
 
42
- 中文说明是**静态规则**生成的,不额外调用模型、不消耗 API 额度,也不会被请求方自己的说辞带偏。
52
+ 中文说明由**静态规则**生成,不额外调用模型、不消耗 API 额度,也不会被请求方自己的说辞带偏。
43
53
 
44
54
  | 目标权限 | 级别 | 风险文案要点 |
45
55
  | --- | --- | --- |
@@ -48,92 +58,96 @@ SSH 密钥与凭据文件,本次执行也不再逐条征求你的同意。只
48
58
  | 其它模式 | 注意 | 不是 DSH 内置模式,无法给出确切范围,提示按请求权限运行。 |
49
59
  | 无沙箱参数 | 注意 | 通用兜底:工具请求以更高权限执行本次操作,仅本次有效。 |
50
60
 
51
- ## 覆盖范围
52
-
53
- - 所有**带关联工具调用**的交互式审批:沙箱权限升级、hook 触发的 ask、其它插件通过审批通道发起的 ask。
54
- - 说明的取值按「纵深防御」分层:先看工具调用参数 `sandbox_permissions` / `justification`,取不到再解析宿主理由句式,再取不到走通用兜底。三层都拿不到时仍然显示通用中文说明。
55
-
56
- ### 已知限制
57
-
58
- - 审批请求若**不带关联工具调用**(`callId` 缺失),核心不会渲染详情区,本插件也就没有插入位置。这是核心插槽契约决定的,不是本插件可以绕过的。
59
- - 中文说明解释的是「权限范围」这一层风险,不判断命令本身是否安全。命令原文要自己看。
60
- - 宿主若调整理由句式(`escalate sandbox to <mode>: <理由>`),第一层参数取值仍然有效,只有第二层兜底会失效。
61
-
62
61
  ## 安装
63
62
 
64
- 需要 DSH 0.1.5-rc.1 或更高版本。
65
-
66
63
  ```sh
67
- dsh plugin --profile web add link:<本目录的绝对路径>
64
+ # 从 npm 安装(推荐)
65
+ dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide
68
66
  ```
69
67
 
70
- 例如:
68
+ `--profile` 后跟本机实际的 profile 名:桌面版 `desktop`,Web 版 `web`。
69
+
70
+ 要改源码时才用 `link:` 指向本目录(仓库源码即安装源,改完重启 DSH 即生效):
71
71
 
72
72
  ```sh
73
- dsh plugin --profile web add link:D:/Fish-code/DSH/plugins/dsh-approval-guide
73
+ dsh plugin --profile <profile> add "link:<本目录的绝对路径>"
74
74
  ```
75
75
 
76
- 安装后 **Web 端没有原地重启**,需要手动重启 DSH 应用、再刷新页面才会生效。
77
-
78
- 换机器复现:把本目录复制过去,改一下安装命令里的路径即可;也可以推到自己的 Git 仓库,用 GUI 的插件管理面板按 Git 地址安装(本包没有构建脚本,不需要放行 pnpm 的构建许可)。
76
+ 安装后需要**重启 DSH 应用并刷新页面**才会生效(Web 端没有原地重启)。
79
77
 
80
78
  ### 卸载
81
79
 
82
80
  ```sh
83
- dsh plugin --profile web remove @fish-under-sea/dsh-approval-guide
81
+ dsh plugin --profile <profile> remove @fish-under-sea/dsh-approval-guide
84
82
  ```
85
83
 
86
84
  ### 安装后自检
87
85
 
88
86
  ```sh
89
- dsh --profile web --dump-config
87
+ dsh --profile <profile> --dump-config
90
88
  ```
91
89
 
92
90
  输出末尾应恰好出现一行 `- id: approval-guide` / `name: @fish-under-sea/dsh-approval-guide`。多行即重复挂载,应用会启动失败。
93
91
 
94
- ## 测试
95
-
96
- ```sh
97
- node test/guide.test.mjs
98
- ```
92
+ ## 使用
99
93
 
100
- 测试装载的是真正会进浏览器的 `lib/client.js`:用 `node:vm` 提供 `window.__ModuleLoader__`,抓住 bundle 注册的 factory,再用假模块表实例化,直接断言纯函数与组件产出的元素树。**零依赖**,不需要安装 React 或 vitest。
94
+ 安装后无需任何操作——插件自动占用审批详情的 `conversation.approval.detail` 插槽,在每次审批弹窗里追加中文说明。
101
95
 
102
- > 不要用 `node --test test/`:测试运行器会派生子进程并捕获管道输出,在受限沙箱里会以 `EPERM` 失败。直接运行测试文件即可。
103
-
104
- 覆盖的用例:两种沙箱模式的分级文案、理由兜底解析、未知模式、通用审批兜底、参数 JSON 损坏、空输入不抛异常、组件保留命令原文、取不到 pending 时降级、插槽注册优先级。
96
+ 说明的取值按「纵深防御」分层:先看工具调用参数 `sandbox_permissions` / `justification`,取不到再解析宿主理由句式(`escalate sandbox to <mode>: <理由>`),再取不到走通用兜底。层层都拿不到时仍然显示通用中文说明。
105
97
 
106
- ## 设计说明
98
+ 覆盖范围:
107
99
 
108
- ### 挂载点
109
-
110
- 核心包 `@deepseek-ai/dsh-client-ui-approval` 把审批卡片渲染在 `conversation.composer` 插槽上,并把卡片内「详情区」交给子插槽 `conversation.approval.detail`。官方插槽目录记载该插槽当前占用者是 `@deepseek-ai/dsh-client-ui-chat` 的 `ApprovalCommand`,风险标注为 `shadows-shipped-ui`。
100
+ - 所有**带关联工具调用**的交互式审批:沙箱权限升级、hook 触发的 ask、其它插件通过审批通道发起的 ask。
111
101
 
112
- 核心注册表规则:
102
+ ## 配置
113
103
 
114
- - `single` 插槽**同级注册直接报错**,必须换一个优先级;
115
- - 插槽条目按优先级**升序**排列,**数字最小者渲染**。
104
+ **无配置文件。** 本包没有任何配置项,也不读写设置文件——所有规则硬编码在 `lib/client.js` 里。
116
105
 
117
- `ApprovalCommand` 用默认优先级 0,因此本插件注册 `priority: -1` 覆盖它,并在组件里用同一套逻辑(`useChat` 取关联工具调用、解析 `argsRaw.command`)把命令原文重新渲染回来,不丢信息。
106
+ ## 兼容与边界
118
107
 
119
- ### 取数来源
108
+ - 平台:纯浏览器插件(`dsh.client.platform: web`),宿主半区是空实现。
109
+ - 占用核心包 `@deepseek-ai/dsh-client-ui-approval` 的 `conversation.approval.detail` 子插槽。该插槽为 `single` 类型,按优先级**升序**排列、**数字最小者渲染**;官方占用者 `ApprovalCommand` 用默认优先级 0,本插件注册 `priority: -1` 覆盖它,并在组件里用同一套逻辑(`useChat` 取关联工具调用、解析 `argsRaw.command`)把命令原文重新渲染回来,不丢信息。
110
+ - 组件抛错时,插槽渲染器会回收该条目(abdicate),官方 `ApprovalCommand` 自动恢复渲染——审批卡不会留白,也不会卡住审批流程。
111
+ - 兼容 DSH 0.2.0(`useSessionStatus`)与 0.1.x(`useSessionPendingInteraction`)两代选择器。
120
112
 
121
- 组件不解析 DOM,也不监听远程事件,全部走插槽标准属性:
113
+ 数据源:
122
114
 
123
115
  | 数据 | 来源 |
124
116
  | --- | --- |
125
117
  | 关联工具调用的命令与参数 | `useChat` 选择器(与官方 `ApprovalCommand` 同款) |
126
- | 工具名与审批理由 | `useSessionPendingInteraction` 选择器(`kind === 'approval'` 的待办交互) |
118
+ | 工具名与审批理由 | `useSessionPendingInteraction` / `useSessionStatus` 选择器(`kind === 'approval'` 的待办交互) |
119
+
120
+ ### 已知限制
121
+
122
+ - 审批请求若**不带关联工具调用**(`callId` 缺失),核心不会渲染详情区,本插件也就没有插入位置。这是核心插槽契约决定的,不是本插件可以绕过的。
123
+ - 中文说明解释的是「权限范围」这一层风险,不判断命令本身是否安全。命令原文要自己看。
124
+ - 宿主若调整理由句式(`escalate sandbox to <mode>: <理由>`),第一层参数取值仍然有效,只有第二层兜底会失效。
127
125
 
128
- ### 失败降级
126
+ ## 开发与测试
129
127
 
130
- 组件抛错时,插槽渲染器会回收该条目(abdicate),官方 `ApprovalCommand` 自动恢复渲染——审批卡不会留白,也不会卡住审批流程。
128
+ ```sh
129
+ node packages/dsh-approval-guide/test/guide.test.mjs
130
+ ```
131
131
 
132
- ## 目录结构
132
+ 当前 12 个用例全部通过。测试装载的是真正会进浏览器的 `lib/client.js`:用 `node:vm` 提供 `window.__ModuleLoader__`,抓住 bundle 注册的 factory,再用假模块表实例化,直接断言纯函数与组件产出的元素树。**零依赖**,不需要安装 React 或 vitest。
133
+
134
+ > 不要用 `node --test test/`:测试运行器会派生子进程并捕获管道输出,在受限沙箱里会以 `EPERM` 失败。直接运行测试文件即可。
135
+
136
+ 覆盖的用例:两种沙箱模式的分级文案、理由兜底解析、未知模式、通用审批兜底、参数 JSON 损坏、空输入不抛异常、组件保留命令原文、取不到 pending 时降级、插槽注册优先级。
137
+
138
+ 目录结构:
133
139
 
134
140
  | 路径 | 作用 |
135
141
  | --- | --- |
136
142
  | `lib/index.js` | 宿主半区,空实现(纯浏览器插件) |
137
143
  | `lib/client.js` | 浏览器半区:中文文案、分级逻辑、审批详情组件、插槽注册 |
138
144
  | `cordis.patch.yml` | bundle 补丁层,把插件行插入 profile 名册 |
139
- | `test/guide.test.mjs` | 零依赖测试 |
145
+ | `test/guide.test.mjs` | 零依赖测试 |
146
+
147
+ ## 与聚合包的关系
148
+
149
+ > 本包是 [`@fish-under-sea/dsh-fish`](https://github.com/Fish-under-sea/dsh-fish) 聚合包的成员之一;单独安装只影响这一项。
150
+
151
+ ## 许可
152
+
153
+ MIT © Fish-under-sea
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fish-under-sea/dsh-approval-guide",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "在 DSH Web GUI 的审批弹窗里追加中文说明:这次审批会做什么、有什么风险、依据是什么。原英文理由与命令原文保留显示。",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -16,7 +16,8 @@
16
16
  "files": [
17
17
  "lib",
18
18
  "cordis.patch.yml",
19
- "README.md"
19
+ "README.md",
20
+ "README.en.md"
20
21
  ],
21
22
  "license": "MIT",
22
23
  "publishConfig": {