dsh-todo-board 0.13.4 → 0.13.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.md +19 -0
- package/README.md +30 -11
- package/client/client.js +1 -1
- package/lib/index.js +165 -0
- package/package.json +4 -4
- package/tools/check-approval-guard.mjs +123 -0
- package/tools/check-live.mjs +196 -0
- package/tools/check-permission-derive.mjs +163 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.5
|
|
4
|
+
|
|
5
|
+
**修 issue #2:`approval: 'never'` 下写板子必然失败——但按「只看 policy」修会把沙箱绕过去。**
|
|
6
|
+
|
|
7
|
+
- **问题。** 预设 `danger-full-access` = (沙箱 `danger-full-access`, 审批 `never`)。`never` 的规则是「需要审批的动作一律拒绝,连弹窗都没有」,而本插件的门无条件返回 `{kind:'ask'}`,于是 `add` / `update` / `reorder` / `dispatch` / `schedule` 全部报 `the user rejected tool "todo_board"`——**用户从没见过任何审批框**。无人值守的队列因此连「把下一步写进板子」都做不到。
|
|
8
|
+
- **issue 给的修法是 `effectivePolicy(session) === 'never'` 就 `return next()`。** 机制是对的(服务名 `approval`、方法名 `effectivePolicy`、`never` → `decide()` 直接 `rejected`,逐条对着 0.2.1-rc.2 源码核过),**但范围太宽**:`sandbox` / `approval` 是三个独立旋钮里的两个,`never` 完全可以配 `read-only` / `workspace-write`(预设显示 `custom`)。而本插件写 `board.json` 用的是**宿主权限、不经过 shell 沙箱**——沙箱受限时审批门是模型与这个文件之间唯一的东西。照那个改法,等于在受限沙箱下凭空开出一条宿主写通道。
|
|
9
|
+
- **改成两个条件同时成立才放行**:审批档 `never` **且** 沙箱是 `danger-full-access`。两个值分别取自**各自最权威的那一侧**,都不靠预设名猜:
|
|
10
|
+
- **沙箱**:把 `permissionPresets.current(session)` 返回的预设名用 `resolve` / `specOf` 解析回该预设的组合,只比 **`sandbox` 字段的值**。**为什么不直接比名字**:`presets` 是 `permissionPresets` 配置里的**一张表**(它自己的 Config schema 里就有 `presets`),名字只是标签,部署方有权把 `danger-full-access` 这个键指向别的组合;比名字在那样的表下会误判成「完全访问」。
|
|
11
|
+
- **审批档**:只从 `approval.effectivePolicy(session)` 读,**不从预设组合里读**(`dsh-experimental-auto-review` 读的是同一个 `current()`,但那是问"哪个预设",不是"要不要弹框")。`current()` 返回的是**预设的定义**而非旋钮的实时值:你先选 `auto`、之后把审批档改成 `never`,`derive()` 仍返回 `auto`,而 `auto` 的定义永远写着 `approval: ask`——拿这个字段当审批档,会把一个**真的**「完全访问 + never」的会话一直拒掉(这不是理论情形:`auto` 父会话派生的子会话就带着 `permission/preset: 'auto'` + 沙箱完全访问 + `approval/policy: 'never'`)。沙箱字段没有这个问题:`derive()` 的每个分支要么是按沙箱匹配上的,要么又显式复查过一次。
|
|
12
|
+
- **放行的只是本插件的门,不是自动审查**:预设显示 `auto` 时,审查那一层仍先跑一遍 LLM 风险评估,且它拒了就是最终裁决(`never` 下无人在场回答)。想要写板子完全不被打断就得用 `danger-full-access` 预设本身——README 里写明了这一点。
|
|
13
|
+
- **为什么完全访问下放行反而更安全**:沙箱已是 `danger-full-access` 时模型本来就能用文件工具直接改 `board.json`(预设自己的说明就是「完全文件访问,不弹审批框」)。硬要它走审批只会把它逼去手改 JSON——跳过参数校验、跳过 `seq` 计数、跳过原子替换。
|
|
14
|
+
- **`never` + 受限沙箱仍然拒绝**,但不再冒充「用户拒绝了」:改返回 `{kind:'deny', reason}`,错误里点名 `never`、说明沙箱没放开、并给出改回 `workspace-write` 或手动操作面板的出路。`deny` 的 `reason` 会被 `dsh-tools` 原样回传给模型(`lib/index.js:3322`)。
|
|
15
|
+
- **读不出来就照旧问**:`permissionState()` 在投影未注册时会**抛错**(真机日志里就有 `permissions session projection is not registered`),服务也可能不在。所有失败路径一律当作「无法证明弹框不可能」,继续 `ask`;绝不会被误读成「可以放行」。
|
|
16
|
+
- **测试。**
|
|
17
|
+
- 新增 `tools/check-approval-guard.mjs`(10 个变异,接进 `npm run guard`)。其中**第 1 个变异就是 issue 的原始提案**(改掉沙箱那一半、只看 policy),第 2 个是"直接比预设名"这个更诱人的简化,第 3 个则是**镜像方向**的错:把审批那一半也改成从预设组合里读(单看代码很像"更严格",实际会拒掉真的完全访问会话)——三条都必须被抓,这条守卫的作用就是证明这套测试能区分「按值判定」和「按名字 / 只看 policy / 从定义里读审批」这三种判定。
|
|
18
|
+
- 守卫跑 `check-live` 而不是 `smoke`:这些规则的意义在于**真实工具管线**怎么解析门,而 `smoke` 是直接调监听器的。锚点全部写成单行(`lib/index.js` 通篇 CRLF,用 `\n` 写的多行锚点会静默匹配不到,那种守卫会「通过」却什么也没测),并且**先验证每个锚点在文件里恰好出现一次**,否则拒绝运行。
|
|
19
|
+
- 新增 `tools/check-permission-derive.mjs`(接进 `npm test`):这条规则建立在「解析出来的预设组合里的 `sandbox` 一定等于真实沙箱」之上,而那是 **DSH 的行为**,不是本插件的假设就能算数的。它加载**真实的** `dsh-permission-presets`,用真实原型在「3 种沙箱 × 2 种审批档 × 5 种预设选择 × 3 张预设表」共 90 个状态上跑一遍 `derive()`,断言放行条件成立时真实沙箱**一定**是完全访问(本机 10 放行 / 80 拒绝,无一次误放行);顺带钉住门所读的 `current` / `resolve` / `specOf` / `effectivePolicy` 都还在。三张表里有一张是**把 `danger-full-access` 这个键改指向受限沙箱**的——它同时证明了「比名字会误判」不是理论担忧(该表下 `derive()` 真的会对着 `workspace-write` 会话返回 `"danger-full-access"`)。
|
|
20
|
+
- `check-live` 的审批桩补上 `effectivePolicy()` 与可切换的 `permissionPresets`(`current` / `resolve` / `specOf`),新增 9 组断言:完全访问 + `never` 不弹框且**真的没有问**(此时桩的裁决仍是 `rejected`,所以「没问」是被间接证明的)、受限沙箱仍拒且理由点名 policy、投影抛错仍拒、policy 抛错退回询问、**完全访问 + `ask` 照常弹框**、**预设表把 `danger-full-access` 这个键改指向受限沙箱时不放行**(钉住"不能比名字")、**`auto` + `never` 仍放行**(钉住"审批不能从预设定义里读")、**只有 `specOf` 没有 `resolve` 的构建仍能解析**(否则回退分支是死代码)。
|
|
21
|
+
|
|
3
22
|
## 0.13.4
|
|
4
23
|
|
|
5
24
|
**三处过度约束松绑,外加一个「计划 20 步、却只派 10 步」的不一致。**
|
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Let the agent finish one thing, then look up the next unfinished task **in the s
|
|
|
38
38
|
| [界面风格](#界面风格--skins) | 蓝白 / 素白 / 紧凑 / 随主题四套,一键循环切换 |
|
|
39
39
|
| [开发者日志](#开发者日志--developer-log) | 面板内切页看日志,出错才亮小圆点,默认只记本插件 |
|
|
40
40
|
| [长任务先规划](#长任务先规划--plan-a-long-task-first) | 明显分多步时先问你要不要拆,`/todo` 一键注入模板 |
|
|
41
|
-
| [模型工具与审批门](#模型工具--the-todo_board-tool) | AI 改板子走 DSH
|
|
41
|
+
| [模型工具与审批门](#模型工具--the-todo_board-tool) | AI 改板子走 DSH 原生审批框,不问就执行不了(沙箱已放开完全访问时除外) |
|
|
42
42
|
|
|
43
43
|
## 安装 / Install
|
|
44
44
|
|
|
@@ -292,7 +292,7 @@ peer 由 npm 的解析器执行(`includePrerelease: true`,所以 `0.2.0-rc.2
|
|
|
292
292
|
|
|
293
293
|
### AI 改板子要你批准 / Approval for board writes
|
|
294
294
|
|
|
295
|
-
**模型写板子走 DSH 的原生审批框**(`tools/pre-execute` → `ask` → `dsh-user-approval
|
|
295
|
+
**模型写板子走 DSH 的原生审批框**(`tools/pre-execute` → `ask` → `dsh-user-approval`),所以这不是提示词里的约定:不问就执行不了,而且被拒绝时模型收到的是一个**真正的失败结果**。门装在**工具注册表这一层**,在任何工具体执行之前——所以在门还有意义的档位下,模型没有绕过的路径(唯一例外见下面的「`never` 与完全访问」)。
|
|
296
296
|
|
|
297
297
|
| action | 要审批吗 | 为什么 |
|
|
298
298
|
| --- | --- | --- |
|
|
@@ -302,6 +302,10 @@ peer 由 npm 的解析器执行(`includePrerelease: true`,所以 `0.2.0-rc.2
|
|
|
302
302
|
| `add` / `schedule` / `update` / `reorder` / `dispatch` | **要** | 都在改板子(`dispatch` 也是:它替用户启动了队列;`schedule` 也是:它让这行到点自己跑) |
|
|
303
303
|
| 将来新增的写动作 | **要**(默认就是"要") | 白名单里没写的一律问——漏加一个动作必须失败关闭 |
|
|
304
304
|
|
|
305
|
+
**唯一的免问写操作**:当沙箱本身就是 `danger-full-access`、且审批档是 `never` 时(两个**旋钮**同时满足,与面板上显示的是哪个预设名无关),写操作**直接放行、不弹框**(**0.13.5 起**)。理由见下面「`never` 与完全访问」——那种组合下弹框必然被拒,而模型本来就能绕过这个工具直接改 `board.json`。
|
|
306
|
+
|
|
307
|
+
注意这条只说**本插件的门**不弹框。如果预设显示是 `auto`(自动审查),审查那一层仍然会先跑一遍 LLM 风险评估、并且**仍可能**拦下来——`never` 下它的结果是最终裁决,本插件的放行管不到它。想要「写板子完全不被打断」,用 `danger-full-access` 预设本身,别停在 `auto` 上。
|
|
308
|
+
|
|
305
309
|
**审批挡的是「改板子」,不是「跑队列」**:面板的 ▶、自动接续、定时到点派发都不需要审批——后两者根本不是工具调用,也在回合之外。「逐次确认」是默认,要少被打断就用 `/permission` 切档,不需要本插件实现"记住已授权"。
|
|
306
310
|
|
|
307
311
|
#### 该用哪个权限预设 / Which permission preset to use
|
|
@@ -315,21 +319,36 @@ peer 由 npm 的解析器执行(`includePrerelease: true`,所以 `0.2.0-rc.2
|
|
|
315
319
|
| 预设 | 沙箱 | 审批 | TODO 板能不能正常跑 |
|
|
316
320
|
| --- | --- | --- | --- |
|
|
317
321
|
| **`workspace-write`** | `workspace-write` | `ask` | ✅ **全都正常** |
|
|
318
|
-
| `danger-full-access` | `danger-full-access` | `never` |
|
|
322
|
+
| `danger-full-access` | `danger-full-access` | `never` | ✅ **0.13.5 起全都能用**(写操作不弹框,见下节) |
|
|
319
323
|
| `auto`(自动审查) | `danger-full-access` | `ask` | ⚠️ **自动接续可能静默中断** |
|
|
320
324
|
|
|
321
|
-
#####
|
|
325
|
+
##### `never` 与完全访问:为什么现在放行(0.13.5)
|
|
326
|
+
|
|
327
|
+
`never` 的规则是「需要审批的动作 → 一律拒绝,连弹窗都没有」。所以在 0.13.4 及以前,这个预设下写板子会失败并报 `the user rejected tool "todo_board"`——这句话**不是说你拒绝了**,是「没地方问,只好当作拒绝」,很容易误导。
|
|
322
328
|
|
|
323
|
-
|
|
329
|
+
0.13.5 起分情况处理。**放行的条件不是「审批档是 `never`」**,而是两个旋钮**同时**满足:
|
|
324
330
|
|
|
325
|
-
|
|
|
331
|
+
| 条件 | 为什么 |
|
|
326
332
|
| --- | --- |
|
|
327
|
-
|
|
|
328
|
-
|
|
|
333
|
+
| 审批档 = `never` | 弹框注定被拒,问也白问 |
|
|
334
|
+
| 沙箱 = `danger-full-access` | 这堵墙本来就没在挡人(见下) |
|
|
335
|
+
|
|
336
|
+
这两个值分别来自**各自最权威的那一侧**,都不是拿预设的名字去猜:
|
|
337
|
+
|
|
338
|
+
- **审批档**直接问审批服务(`approval.effectivePolicy(session)`)——它才是「这个会话到底要不要弹框」的权威来源。
|
|
339
|
+
- **沙箱**从当前预设解析出的组合里读。DSH 的预设表(`permissionPresets` 的 `presets`)是**可配置**的,名字只是标签,谁都能把 `danger-full-access` 这个键指向别的组合。插件把 `current(session)` 返回的预设名解析回它的组合,再比对 **`沙箱` 字段的值**——换个表也照样对。
|
|
340
|
+
|
|
341
|
+
**为什么审批档不能也从预设里读**:`current()` 返回的是**预设的定义**,不是旋钮的实时值。举例:你先选了 `auto`,之后又把审批档改成 `never`——此时 `derive()` 仍然返回 `auto`(它是「还选着的 Auto」),而 `auto` 这个预设的定义永远写着 `approval: ask`。要是拿这个字段当审批档,一个**真的**「完全访问 + never」的会话会被一直拒掉。沙箱字段没有这个问题:`derive()` 的每个分支都保证它与真实沙箱一致。
|
|
342
|
+
|
|
343
|
+
**为什么必须看沙箱**:`sandbox` 和 `approval` 是两个**互相独立**的旋钮,`never` 完全可以配 `read-only` / `workspace-write`(这时预设显示为 `custom`)。而本插件写 `board.json` 用的是**宿主权限,不经过 shell 沙箱**——沙箱受限时,审批门是模型与这个文件之间**唯一**的东西。那种情况下让 `never` 变成通行证,等于凭空开出一条沙箱没批准的写通道。所以:**`never` + 受限沙箱 → 照样拒绝**,只是错误信息现在会点名真正的原因,不再冒充「用户拒绝了」。
|
|
344
|
+
|
|
345
|
+
**为什么完全访问下放行反而更安全**:沙箱已经是 `danger-full-access` 时,模型本来就能用文件工具直接改 `board.json`——预设自己的说明就是「完全文件访问,不弹审批框」。硬要它走审批,只会把它逼去手改 JSON,而那样会跳过参数校验、跳过 `seq` 计数、跳过原子替换。让它用正规工具是两害相权。
|
|
346
|
+
|
|
347
|
+
**读不到就照旧问**:审批档或预设读不出来时(服务缺失、投影未注册),一律当成「问不出结果」,继续弹框,绝不当成「可以放行」。反过来,沙箱是 `danger-full-access` 但审批档是 `ask` 时也照常弹框——放行必须两个条件同时成立。
|
|
329
348
|
|
|
330
|
-
|
|
349
|
+
这两条假设跟着一条常驻检查(`tools/check-permission-derive.mjs`)走:它加载**真实的** `dsh-permission-presets`,把 `derive()` 在「3 种沙箱 × 2 种审批档 × 5 种预设选择 × 3 张预设表」共 90 个状态上跑一遍,断言放行条件成立时真实沙箱**一定**是完全访问。所以哪天 DSH 改了 `derive()` 的行为,这里会先响。
|
|
331
350
|
|
|
332
|
-
|
|
351
|
+
大白话:**「完全权限」放开的是「能碰什么」;现在它也能让"不用问"生效,但只在沙箱确实没在挡的时候。**
|
|
333
352
|
|
|
334
353
|
##### 为什么 `auto`(自动审查)也会挡
|
|
335
354
|
|
|
@@ -434,7 +453,7 @@ ctx.get('connection').requestRejection(request) // dsh-client-connection
|
|
|
434
453
|
|
|
435
454
|
- **用脚本 / curl 直接往板子里写,从此也不可用了**——那正是要堵的那条通道。需要程序化写入就用模型工具(会走审批),或嵌进 DSH 里。
|
|
436
455
|
- **面板被 401 挡住的唯一情形,是浏览器没有那份会话 cookie**。那时插件日志会写明原因和解法,**面板页脚也会直接说**:用 `dsh web` 打印的那条带 token 的地址重开页面即可。
|
|
437
|
-
- **`danger-full-access`(审批档 `never
|
|
456
|
+
- **`danger-full-access`(审批档 `never`)下模型写板子不再弹框,而是直接放行**(0.13.5 起):那种组合里弹框注定被拒,而沙箱已经不是限制,放行反而避免了模型去手改 `board.json`。**`never` 配受限沙箱(预设显示 `custom`)仍然拒绝**——那时审批是唯一的防线。
|
|
438
457
|
- 本插件保证的是**这条路由**不再接受任意本机进程;它不替代 DSH 自身对整个 Web 面的安全模型。
|
|
439
458
|
|
|
440
459
|
## License
|
package/client/client.js
CHANGED
|
@@ -109,7 +109,7 @@ const SKINS = [
|
|
|
109
109
|
* host and browser halves of one release are one build. `client-smoke.mjs` pins
|
|
110
110
|
* the two together, because a footer that lies is worse than no footer.
|
|
111
111
|
*/
|
|
112
|
-
const BUILD = '0.13.
|
|
112
|
+
const BUILD = '0.13.5'
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* How often a VISIBLE panel re-reads the board.
|
package/lib/index.js
CHANGED
|
@@ -2609,6 +2609,150 @@ async function maybeWriteHandoffSummary(todo, source) {
|
|
|
2609
2609
|
return '执行 ' + action + where
|
|
2610
2610
|
}
|
|
2611
2611
|
|
|
2612
|
+
/**
|
|
2613
|
+
* Look one service up the way {@link harnessConnection} does: this context
|
|
2614
|
+
* first, then the application root, and `undefined` rather than a throw when
|
|
2615
|
+
* the provider is absent or its accessor fails.
|
|
2616
|
+
*/
|
|
2617
|
+
function serviceNamed(name) {
|
|
2618
|
+
const rootCtx = ctx.root === undefined ? ctx : ctx.root
|
|
2619
|
+
for (const source of [ctx, rootCtx]) {
|
|
2620
|
+
try {
|
|
2621
|
+
if (source === undefined || source === null || typeof source.get !== 'function') continue
|
|
2622
|
+
const service = source.get(name)
|
|
2623
|
+
if (service === undefined || service === null) continue
|
|
2624
|
+
return service
|
|
2625
|
+
} catch (err) {
|
|
2626
|
+
/* fall through to the next source */
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
return undefined
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
/**
|
|
2633
|
+
* This session's approval policy, or `undefined` when it cannot be read.
|
|
2634
|
+
*
|
|
2635
|
+
* `never` is the one value that matters, because `dsh-user-approval`'s
|
|
2636
|
+
* `decide()` returns `rejected` on it BEFORE consulting any answerer
|
|
2637
|
+
* (`lib/index.js:175`). So under `never` an `ask` is not "a question the user
|
|
2638
|
+
* may decline" — it is a guaranteed denial, phrased as if the user had said no
|
|
2639
|
+
* to a dialog they never saw. Reading the policy is how the gate tells those
|
|
2640
|
+
* two situations apart.
|
|
2641
|
+
*
|
|
2642
|
+
* Every failure path returns `undefined`, which reads as "cannot prove
|
|
2643
|
+
* prompts are impossible" and therefore keeps the gate asking.
|
|
2644
|
+
*/
|
|
2645
|
+
function approvalPolicyOf(session) {
|
|
2646
|
+
if (session === undefined || session === null) return undefined
|
|
2647
|
+
try {
|
|
2648
|
+
const approval = serviceNamed('approval')
|
|
2649
|
+
if (approval === undefined || typeof approval.effectivePolicy !== 'function') {
|
|
2650
|
+
return undefined
|
|
2651
|
+
}
|
|
2652
|
+
const policy = approval.effectivePolicy(session)
|
|
2653
|
+
return policy === 'never' || policy === 'ask' ? policy : undefined
|
|
2654
|
+
} catch (err) {
|
|
2655
|
+
/* an unreadable policy must not be mistaken for a permissive one */
|
|
2656
|
+
return undefined
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
/**
|
|
2661
|
+
* Whether the deployment has ALREADY granted this write on its own.
|
|
2662
|
+
*
|
|
2663
|
+
* The condition is deliberately narrow, and it is NOT "the policy is
|
|
2664
|
+
* `never`". `sandbox` and `approval` are two of the three independent
|
|
2665
|
+
* permission knobs (`permission/preset`, `sandbox/mode`, `approval/policy`),
|
|
2666
|
+
* so `never` can be paired with a `read-only` or `workspace-write` sandbox —
|
|
2667
|
+
* the preset then reads back as `custom`. That pairing matters here because
|
|
2668
|
+
* this plugin writes `board.json` with HOST privileges: the write never
|
|
2669
|
+
* passes through the sandbox at all, so under a restricted sandbox the
|
|
2670
|
+
* approval gate is the only thing standing between the model and the file.
|
|
2671
|
+
* Auto-allowing on `never` alone would hand out a write channel the sandbox
|
|
2672
|
+
* deliberately withheld.
|
|
2673
|
+
*
|
|
2674
|
+
* So the two knobs are read from whichever source is authoritative for each:
|
|
2675
|
+
* the SANDBOX from the resolved preset bundle, the APPROVAL POLICY from
|
|
2676
|
+
* `approval.effectivePolicy(session)` — which is why this function opens with
|
|
2677
|
+
* that check rather than trusting anything the permission table says.
|
|
2678
|
+
*
|
|
2679
|
+
* The sandbox half comes from the RESOLVED bundle and not from the preset's
|
|
2680
|
+
* NAME. `presets` is a configurable table (`permissionPresets`'s own Config
|
|
2681
|
+
* schema declares it), and driving the shipped `derive()` over the whole knob
|
|
2682
|
+
* grid shows the difference is not academic: point the key `danger-full-access`
|
|
2683
|
+
* at a `workspace-write` bundle and `derive()` starts returning that very name
|
|
2684
|
+
* for a `workspace-write` session. A name is a label. `bundle.sandbox`, by
|
|
2685
|
+
* contrast, equals the session's real sandbox in every branch of `derive()` —
|
|
2686
|
+
* each branch either matched on it or explicitly re-checked it.
|
|
2687
|
+
*
|
|
2688
|
+
* The APPROVAL half must NOT come from the bundle, for the mirror-image reason:
|
|
2689
|
+
* `derive()` deliberately keeps returning the live `auto` preset once the
|
|
2690
|
+
* policy moves to `never` ("a still-selected Auto also matches the `never`
|
|
2691
|
+
* approval policy"), and `auto`'s bundle documents approval `ask` forever. A
|
|
2692
|
+
* gate that read approval off that bundle would keep refusing a session that
|
|
2693
|
+
* really is full-access + never.
|
|
2694
|
+
*
|
|
2695
|
+
* Everything unreadable answers `false`, i.e. keep asking. That direction is
|
|
2696
|
+
* the point: if `resolve`/`specOf` ever vanish from this service, the plugin
|
|
2697
|
+
* degrades to its old "always ask" behaviour — it does not start guessing.
|
|
2698
|
+
*/
|
|
2699
|
+
function writeAlreadyUnrestricted(session) {
|
|
2700
|
+
if (approvalPolicyOf(session) !== 'never') return false
|
|
2701
|
+
try {
|
|
2702
|
+
const presets = serviceNamed('permissionPresets')
|
|
2703
|
+
if (presets === undefined || typeof presets.current !== 'function') return false
|
|
2704
|
+
// `current()` folds the session's permission projection and THROWS when
|
|
2705
|
+
// that projection is not registered ("permissions session projection is
|
|
2706
|
+
// not registered" appears in real logs), which the catch below absorbs.
|
|
2707
|
+
const spec = presetSpecOf(presets, presets.current(session))
|
|
2708
|
+
if (spec === undefined || spec === null) return false
|
|
2709
|
+
return spec.sandbox === 'danger-full-access'
|
|
2710
|
+
} catch (err) {
|
|
2711
|
+
return false
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
/**
|
|
2716
|
+
* Resolve one preset name to its knob bundle, or `undefined` when this build
|
|
2717
|
+
* cannot say. `resolve` is the documented accessor but throws by design for
|
|
2718
|
+
* `custom` and unknown names; `specOf` is the same lookup without the throw.
|
|
2719
|
+
* Both are tried, and a build offering neither yields `undefined` — which the
|
|
2720
|
+
* caller reads as "cannot prove full access", never as "full access".
|
|
2721
|
+
*/
|
|
2722
|
+
function presetSpecOf(presets, name) {
|
|
2723
|
+
if (typeof presets.resolve === 'function') {
|
|
2724
|
+
try {
|
|
2725
|
+
const spec = presets.resolve(name)
|
|
2726
|
+
return spec === undefined ? undefined : spec
|
|
2727
|
+
} catch (err) {
|
|
2728
|
+
return undefined
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
if (typeof presets.specOf !== 'function') return undefined
|
|
2732
|
+
try {
|
|
2733
|
+
return presets.specOf(name)
|
|
2734
|
+
} catch (err) {
|
|
2735
|
+
return undefined
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2739
|
+
/**
|
|
2740
|
+
* The denial used when prompts are impossible but the sandbox does not
|
|
2741
|
+
* already permit the write. Same outcome as letting the `ask` fail, but the
|
|
2742
|
+
* reason names the actual cause instead of blaming the user.
|
|
2743
|
+
*/
|
|
2744
|
+
function noPromptsReason(action, input) {
|
|
2745
|
+
return (
|
|
2746
|
+
'AI 要修改待办板,但本会话的审批策略是 `never`:审批框被禁用,' +
|
|
2747
|
+
'需要审批的动作会被直接拒绝,所以这次写入没有发生(不是你点了拒绝)。' +
|
|
2748
|
+
'待办板由插件以宿主权限写盘,不经过 shell 沙箱,' +
|
|
2749
|
+
'因此在沙箱未放开完全文件访问时,审批是唯一的确认方式。' +
|
|
2750
|
+
'改用 `workspace-write` 预设、或把审批策略改回 `ask` 即可放行,' +
|
|
2751
|
+
'也可以直接在浮动面板里操作。本次尝试:' +
|
|
2752
|
+
approvalDetail(action, input)
|
|
2753
|
+
)
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2612
2756
|
ctx.on('tools/pre-execute', (exec, next) => {
|
|
2613
2757
|
if (exec === undefined || exec === null || exec.name !== TOOL_NAME) return next()
|
|
2614
2758
|
// `createExecution` freezes the model's arguments onto the execution, and
|
|
@@ -2618,6 +2762,27 @@ async function maybeWriteHandoffSummary(todo, source) {
|
|
|
2618
2762
|
exec.arguments !== null && typeof exec.arguments === 'object' ? exec.arguments : {}
|
|
2619
2763
|
const action = typeof input.action === 'string' ? input.action : 'list'
|
|
2620
2764
|
if (APPROVAL_FREE_ACTIONS.indexOf(action) >= 0) return next()
|
|
2765
|
+
|
|
2766
|
+
const agent = exec.agent
|
|
2767
|
+
const session = agent === undefined || agent === null ? undefined : agent.session
|
|
2768
|
+
|
|
2769
|
+
// `danger-full-access` grants full file access AND disables prompts, so the
|
|
2770
|
+
// write adds no capability the deployment did not already grant — and an
|
|
2771
|
+
// `ask` there is GUARANTEED to be denied, which turns the gate into a wall
|
|
2772
|
+
// that blocks the unattended queue the board exists for. Worse, the wall is
|
|
2773
|
+
// the wrong shape: a model that wants a row on the board can still reach
|
|
2774
|
+
// `board.json` with the file tools under that sandbox, and hand-editing it
|
|
2775
|
+
// skips validation, the `seq` counter and the atomic replace. Letting the
|
|
2776
|
+
// proper tool through is the safer of the two.
|
|
2777
|
+
if (writeAlreadyUnrestricted(session)) return next()
|
|
2778
|
+
|
|
2779
|
+
// Prompts are impossible but the sandbox does NOT already permit the write.
|
|
2780
|
+
// Denying is the same verdict the `ask` would reach, so nothing is weakened;
|
|
2781
|
+
// the reason is just true about why.
|
|
2782
|
+
if (approvalPolicyOf(session) === 'never') {
|
|
2783
|
+
return { kind: 'deny', reason: noPromptsReason(action, input) }
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2621
2786
|
return { kind: 'ask', reason: 'AI 要修改待办板:' + approvalDetail(action, input) }
|
|
2622
2787
|
})
|
|
2623
2788
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-todo-board",
|
|
3
|
-
"version": "0.13.
|
|
4
|
-
"description": "跨会话 TODO 板:右上角浮窗、按工作目录分组、可拖动排序;每条待办可选「提醒 / 自动续跑 / 自动新开会话」三档执行模式,截图 Ctrl+V 直接粘贴成附图(派发时作为真正的图片发给模型),可设定本地时间到点才执行,双勾选(AI 完成 / 用户验收)—— 勾上右勾的行会移入下方独立的「已完成」列表,每条待办还能带备注并在面板内直接编辑。三套可切换的界面风格(票据 / 素白 / 紧凑)。长任务可以让模型先拆成步骤再按顺序执行(`/todo <目标>` 或直接粘模板;一次调用写入整份计划、一次审批)。AI 完成一项后自动查找同目录下一条未完成待办并继续执行;AI 改板子一律先经 DSH
|
|
3
|
+
"version": "0.13.5",
|
|
4
|
+
"description": "跨会话 TODO 板:右上角浮窗、按工作目录分组、可拖动排序;每条待办可选「提醒 / 自动续跑 / 自动新开会话」三档执行模式,截图 Ctrl+V 直接粘贴成附图(派发时作为真正的图片发给模型),可设定本地时间到点才执行,双勾选(AI 完成 / 用户验收)—— 勾上右勾的行会移入下方独立的「已完成」列表,每条待办还能带备注并在面板内直接编辑。三套可切换的界面风格(票据 / 素白 / 紧凑)。长任务可以让模型先拆成步骤再按顺序执行(`/todo <目标>` 或直接粘模板;一次调用写入整份计划、一次审批)。AI 完成一项后自动查找同目录下一条未完成待办并继续执行;AI 改板子一律先经 DSH 原生审批框(沙箱已放开完全访问、审批档为 never 时除外),板子路由另需浏览器会话凭据。",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
],
|
|
49
49
|
"scripts": {
|
|
50
50
|
"check": "node --check lib/index.js && node --check client/client.js",
|
|
51
|
-
"test": "node tools/smoke.mjs && node tools/client-smoke.mjs && node tools/retry-loop.mjs && node tools/check-http.mjs && node tools/check-live.mjs && node tools/check-fence-parity.mjs && node tools/check-session-format.mjs && node tools/check-template-parity.mjs",
|
|
52
|
-
"guard": "node tools/check-clamp-guard.mjs && node tools/check-row-guard.mjs && node tools/check-host-guard.mjs && node tools/check-autoreview-guard.mjs && node tools/check-nudge-settings-guard.mjs",
|
|
51
|
+
"test": "node tools/smoke.mjs && node tools/client-smoke.mjs && node tools/retry-loop.mjs && node tools/check-http.mjs && node tools/check-live.mjs && node tools/check-permission-derive.mjs && node tools/check-fence-parity.mjs && node tools/check-session-format.mjs && node tools/check-template-parity.mjs",
|
|
52
|
+
"guard": "node tools/check-clamp-guard.mjs && node tools/check-row-guard.mjs && node tools/check-host-guard.mjs && node tools/check-autoreview-guard.mjs && node tools/check-nudge-settings-guard.mjs && node tools/check-approval-guard.mjs",
|
|
53
53
|
"test:browser": "node tools/check-browser.mjs"
|
|
54
54
|
},
|
|
55
55
|
"dsh": {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Mutation check: the approval-`never` rules must actually fail when broken.
|
|
2
|
+
// Mutates lib/index.js in memory, runs check-live, then restores byte-for-byte.
|
|
3
|
+
//
|
|
4
|
+
// Driven by check-live rather than smoke: the whole point of these rules is how
|
|
5
|
+
// the REAL tool pipeline resolves a gate, and smoke's `inject` calls the
|
|
6
|
+
// listener directly.
|
|
7
|
+
//
|
|
8
|
+
// Every anchor is a SINGLE line on purpose — lib/index.js is CRLF throughout, so
|
|
9
|
+
// a multi-line anchor written with `\n` silently matches nothing, and a guard
|
|
10
|
+
// whose mutation never applies reports success while testing nothing.
|
|
11
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { execFileSync } from 'node:child_process';
|
|
13
|
+
|
|
14
|
+
const TARGET = 'D:/DSH/plugin/dsh-todo-board/lib/index.js';
|
|
15
|
+
const original = readFileSync(TARGET);
|
|
16
|
+
|
|
17
|
+
const MUTATIONS = [
|
|
18
|
+
{
|
|
19
|
+
// This is the shape the issue proposed. It reads well and is too broad:
|
|
20
|
+
// it would hand out a host-privileged write channel under a sandbox the
|
|
21
|
+
// user restricted, because our board write never passes through it.
|
|
22
|
+
name: 'the bypass ignores the sandbox and fires on `never` alone (the original proposal)',
|
|
23
|
+
from: ' const spec = presetSpecOf(presets, presets.current(session))',
|
|
24
|
+
to: " const spec = { sandbox: 'danger-full-access', approval: 'never' }",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
// The tempting simplification: `current()` already returned the name, so why
|
|
28
|
+
// resolve it back to the bundle? Because `presets` is a configurable table
|
|
29
|
+
// and a key is just a label — point it at a restricted sandbox and derive()
|
|
30
|
+
// hands that name back for a restricted session.
|
|
31
|
+
name: 'the sandbox half trusts the preset NAME instead of the bundle value',
|
|
32
|
+
from: " return spec.sandbox === 'danger-full-access'",
|
|
33
|
+
to: " return presets.current(session) === 'danger-full-access'",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
// The mirror-image mistake, and the subtler one: the bundle LOOKS like it
|
|
37
|
+
// carries approval, but the live `auto` bundle documents `ask` forever while
|
|
38
|
+
// the real policy is `never`, so this refuses a genuinely unrestricted
|
|
39
|
+
// session.
|
|
40
|
+
name: 'the approval half is re-read from the preset bundle instead of the policy service',
|
|
41
|
+
from: " return spec.sandbox === 'danger-full-access'",
|
|
42
|
+
to: " return spec.sandbox === 'danger-full-access' && spec.approval === 'never'",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'the bypass disappears, so full access + never asks and is auto-denied again',
|
|
46
|
+
from: ' if (writeAlreadyUnrestricted(session)) return next()',
|
|
47
|
+
to: ' if (false) return next()',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'the bypass drops the policy requirement (full access alone skips the ask)',
|
|
51
|
+
from: " if (approvalPolicyOf(session) !== 'never') return false",
|
|
52
|
+
to: ' if (false) return false',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'an unreadable policy is read as `never` instead of as unknown',
|
|
56
|
+
from: ' /* an unreadable policy must not be mistaken for a permissive one */',
|
|
57
|
+
to: " return 'never'; /* mutant */",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'the never-denial is replaced by a plain pass-through',
|
|
61
|
+
from: " return { kind: 'deny', reason: noPromptsReason(action, input) }",
|
|
62
|
+
to: ' return next()',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'the policy is read from a service name that does not exist',
|
|
66
|
+
from: " const approval = serviceNamed('approval')",
|
|
67
|
+
to: " const approval = serviceNamed('userApproval')",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'the presets are read from a service name that does not exist',
|
|
71
|
+
from: " const presets = serviceNamed('permissionPresets')",
|
|
72
|
+
to: " const presets = serviceNamed('permissions')",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'the specOf fallback is dropped, so a resolve-less build cannot resolve at all',
|
|
76
|
+
from: " if (typeof presets.specOf !== 'function') return undefined",
|
|
77
|
+
to: ' return undefined',
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
// Refuse to run if any anchor is not present EXACTLY once: a duplicated anchor
|
|
82
|
+
// would mutate a different site than the one described.
|
|
83
|
+
const text = original.toString('utf8');
|
|
84
|
+
let anchorsOk = true;
|
|
85
|
+
for (const mutation of MUTATIONS) {
|
|
86
|
+
const count = text.split(mutation.from).length - 1;
|
|
87
|
+
if (count !== 1) {
|
|
88
|
+
console.log('BAD ANCHOR (' + count + ' occurrences): ' + mutation.name);
|
|
89
|
+
anchorsOk = false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!anchorsOk) {
|
|
93
|
+
console.log('\nfixed the anchors above; nothing was mutated');
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let caughtCount = 0;
|
|
98
|
+
try {
|
|
99
|
+
for (const mutation of MUTATIONS) {
|
|
100
|
+
writeFileSync(TARGET, text.replace(mutation.from, mutation.to));
|
|
101
|
+
let caught = false;
|
|
102
|
+
try {
|
|
103
|
+
execFileSync(process.execPath, ['tools/check-live.mjs'], {
|
|
104
|
+
cwd: 'D:/DSH/plugin/dsh-todo-board',
|
|
105
|
+
stdio: 'pipe',
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
caught = true;
|
|
109
|
+
}
|
|
110
|
+
console.log((caught ? 'caught: ' : 'MISSED: ') + mutation.name);
|
|
111
|
+
if (caught) caughtCount += 1;
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
writeFileSync(TARGET, original);
|
|
115
|
+
console.log('original restored');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
console.log(
|
|
119
|
+
caughtCount === MUTATIONS.length
|
|
120
|
+
? '\nall ' + MUTATIONS.length + ' approval mutations caught; original restored and passing'
|
|
121
|
+
: '\n' + (MUTATIONS.length - caughtCount) + ' mutation(s) NOT caught',
|
|
122
|
+
);
|
|
123
|
+
process.exit(caughtCount === MUTATIONS.length ? 0 : 1);
|
package/tools/check-live.mjs
CHANGED
|
@@ -94,11 +94,24 @@ const promptStub = {
|
|
|
94
94
|
*/
|
|
95
95
|
const approvalCalls = []
|
|
96
96
|
let approvalVerdict = 'unavailable'
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The session's approval POLICY, which is a different question from the verdict
|
|
100
|
+
* for one call. Under `never`, `dsh-user-approval` rejects before consulting any
|
|
101
|
+
* answerer, so an `ask` is a guaranteed denial rather than a question. Kept
|
|
102
|
+
* separately controllable because the gate must tell those apart.
|
|
103
|
+
*/
|
|
104
|
+
let approvalPolicy = 'ask'
|
|
105
|
+
|
|
97
106
|
const approvalStub = {
|
|
98
107
|
async request(request) {
|
|
99
108
|
approvalCalls.push({ toolName: request.toolName, reason: request.reason })
|
|
100
109
|
return approvalVerdict
|
|
101
110
|
},
|
|
111
|
+
effectivePolicy() {
|
|
112
|
+
if (approvalPolicy === 'THROWS') throw new Error('approval: policy unreadable')
|
|
113
|
+
return approvalPolicy
|
|
114
|
+
},
|
|
102
115
|
}
|
|
103
116
|
|
|
104
117
|
root.plugin({
|
|
@@ -406,6 +419,189 @@ assert.ok(
|
|
|
406
419
|
)
|
|
407
420
|
console.log('live-gate OK — reads and the cheap marks pass, writes ask, deny/grant both honoured')
|
|
408
421
|
|
|
422
|
+
// -- `never`: precise, not blanket ------------------------------------------
|
|
423
|
+
//
|
|
424
|
+
// `never` is NOT a synonym for "full access". `sandbox` and `approval` are two
|
|
425
|
+
// of the three independent permission knobs, so `never` can sit beside a
|
|
426
|
+
// `read-only` or `workspace-write` sandbox (the derived preset then reads back
|
|
427
|
+
// as `custom`). That distinction is load-bearing here because this plugin
|
|
428
|
+
// writes `board.json` with HOST privileges — the write never passes through the
|
|
429
|
+
// sandbox — so under a restricted sandbox the gate is the only thing between
|
|
430
|
+
// the model and the file. Both halves are pinned below.
|
|
431
|
+
//
|
|
432
|
+
// `approvalVerdict` is still `rejected` here, which is what makes the first
|
|
433
|
+
// assertion strong: if the gate wrongly asked, the call would be DENIED.
|
|
434
|
+
|
|
435
|
+
let presetName = 'danger-full-access'
|
|
436
|
+
// Mirrors `permissionPresets`'s own table shape: a name resolves to a bundle of
|
|
437
|
+
// the two knob values. `presetSpec` lets a case redefine what a KEY means, which
|
|
438
|
+
// is a thing the real Config schema permits and the reason the gate compares
|
|
439
|
+
// knob values instead of the preset's name.
|
|
440
|
+
const PRESET_SPECS = {
|
|
441
|
+
'danger-full-access': { sandbox: 'danger-full-access', approval: 'never' },
|
|
442
|
+
'workspace-write': { sandbox: 'workspace-write', approval: 'ask' },
|
|
443
|
+
// `auto`'s bundle documents approval `ask` even after the policy moves to
|
|
444
|
+
// `never` — see the "auto + never" case below.
|
|
445
|
+
auto: { sandbox: 'danger-full-access', approval: 'ask' },
|
|
446
|
+
}
|
|
447
|
+
let presetSpec = null
|
|
448
|
+
const permissionPresetsStub = {
|
|
449
|
+
current() {
|
|
450
|
+
if (presetName === 'THROWS') {
|
|
451
|
+
throw new Error('permission: permissions session projection is not registered')
|
|
452
|
+
}
|
|
453
|
+
return presetName
|
|
454
|
+
},
|
|
455
|
+
resolve(name) {
|
|
456
|
+
const spec = presetSpec === null ? PRESET_SPECS[name] : presetSpec
|
|
457
|
+
if (spec === undefined) throw new Error('permission: unknown preset "' + name + '"')
|
|
458
|
+
return spec
|
|
459
|
+
},
|
|
460
|
+
specOf(name) {
|
|
461
|
+
return presetSpec === null ? PRESET_SPECS[name] : presetSpec
|
|
462
|
+
},
|
|
463
|
+
}
|
|
464
|
+
root.reflect.provide('permissionPresets', permissionPresetsStub, undefined)
|
|
465
|
+
|
|
466
|
+
approvalPolicy = 'never'
|
|
467
|
+
presetName = 'danger-full-access'
|
|
468
|
+
const beforeUnrestricted = approvalCalls.length
|
|
469
|
+
const unrestricted = await callTool({ action: 'add', title: '无人值守探针' })
|
|
470
|
+
assert.equal(
|
|
471
|
+
unrestricted.isError,
|
|
472
|
+
false,
|
|
473
|
+
'full file access with prompts disabled lets the write through: ' +
|
|
474
|
+
JSON.stringify(unrestricted).slice(0, 200),
|
|
475
|
+
)
|
|
476
|
+
assert.equal(
|
|
477
|
+
approvalCalls.length,
|
|
478
|
+
beforeUnrestricted,
|
|
479
|
+
'and it opens no dialog, because that dialog could only ever be auto-rejected',
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
presetName = 'workspace-write'
|
|
483
|
+
const beforeRestricted = approvalCalls.length
|
|
484
|
+
const restricted = await callTool({ action: 'add', title: '不该落盘的探针' })
|
|
485
|
+
assert.equal(
|
|
486
|
+
restricted.isError,
|
|
487
|
+
true,
|
|
488
|
+
'prompts disabled over a RESTRICTED sandbox still refuses the write',
|
|
489
|
+
)
|
|
490
|
+
assert.ok(
|
|
491
|
+
String(restricted.error?.message ?? '').includes('审批策略是 `never`'),
|
|
492
|
+
'and the reason names the policy: ' + restricted.error?.message,
|
|
493
|
+
)
|
|
494
|
+
assert.ok(
|
|
495
|
+
!String(restricted.error?.message ?? '').includes('the user rejected'),
|
|
496
|
+
'specifically NOT the wording for a dialog the user never saw',
|
|
497
|
+
)
|
|
498
|
+
assert.equal(approvalCalls.length, beforeRestricted, 'and no dead dialog was opened')
|
|
499
|
+
|
|
500
|
+
const afterRestricted = await callTool({ action: 'list' })
|
|
501
|
+
assert.ok(
|
|
502
|
+
!afterRestricted.value.todos.some((todo) => todo.title === '不该落盘的探针'),
|
|
503
|
+
'and nothing reached the board',
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
// A projection that is not registered is a real, observed failure mode (it is
|
|
507
|
+
// in the shipped logs). It must read as "cannot prove full access", not as one.
|
|
508
|
+
presetName = 'THROWS'
|
|
509
|
+
const unregisteredProjection = await callTool({ action: 'add', title: '投影未注册探针' })
|
|
510
|
+
assert.equal(
|
|
511
|
+
unregisteredProjection.isError,
|
|
512
|
+
true,
|
|
513
|
+
'a throwing preset projection refuses rather than assuming full access',
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
// The mirror image: an unreadable POLICY must not read as `never` either.
|
|
517
|
+
approvalPolicy = 'THROWS'
|
|
518
|
+
presetName = 'danger-full-access'
|
|
519
|
+
approvalVerdict = 'allowed-once'
|
|
520
|
+
const beforeUnreadable = approvalCalls.length
|
|
521
|
+
const unreadablePolicy = await callTool({ action: 'add', title: '策略读不到探针' })
|
|
522
|
+
assert.equal(
|
|
523
|
+
unreadablePolicy.isError,
|
|
524
|
+
false,
|
|
525
|
+
'an unreadable policy falls back to asking instead of deciding on its own',
|
|
526
|
+
)
|
|
527
|
+
assert.equal(
|
|
528
|
+
approvalCalls.length,
|
|
529
|
+
beforeUnreadable + 1,
|
|
530
|
+
'and the channel really was asked — that is what fail-closed means here',
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
// Full access ALONE must not skip the ask: only full access AND `never` does.
|
|
534
|
+
// Without this, a redeployed preset table could silently widen the bypass.
|
|
535
|
+
approvalPolicy = 'ask'
|
|
536
|
+
presetName = 'danger-full-access'
|
|
537
|
+
const beforeAskFull = approvalCalls.length
|
|
538
|
+
const askWithFullAccess = await callTool({ action: 'add', title: 'ask 与完全访问探针' })
|
|
539
|
+
assert.equal(askWithFullAccess.isError, false, 'policy ask still works normally')
|
|
540
|
+
assert.equal(
|
|
541
|
+
approvalCalls.length,
|
|
542
|
+
beforeAskFull + 1,
|
|
543
|
+
'and full access alone does NOT skip the ask',
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
// The `auto` branch. `derive()` deliberately keeps returning the live `auto`
|
|
547
|
+
// preset once the policy moves to `never` ("a still-selected Auto also matches
|
|
548
|
+
// the `never` approval policy"), while `auto`'s bundle goes on documenting
|
|
549
|
+
// approval `ask`. So the approval half MUST come from the policy service, not
|
|
550
|
+
// from the bundle — a gate that read it off the bundle would keep refusing a
|
|
551
|
+
// session that really is full-access + never. The sandbox half is still fine to
|
|
552
|
+
// read there: `derive()` only returns `auto` when the sandbox matches.
|
|
553
|
+
approvalPolicy = 'never'
|
|
554
|
+
presetName = 'auto'
|
|
555
|
+
const beforeAutoWithNever = approvalCalls.length
|
|
556
|
+
const autoWithNever = await callTool({ action: 'add', title: 'auto 与 never 探针' })
|
|
557
|
+
assert.equal(
|
|
558
|
+
autoWithNever.isError,
|
|
559
|
+
false,
|
|
560
|
+
'auto over full access with the policy at never proceeds: ' + JSON.stringify(autoWithNever).slice(0, 200),
|
|
561
|
+
)
|
|
562
|
+
assert.equal(approvalCalls.length, beforeAutoWithNever, 'and without opening a dialog')
|
|
563
|
+
|
|
564
|
+
// The preset NAME is not the thing being trusted. `permissionPresets`'s Config
|
|
565
|
+
// schema declares `presets` as a table, so a deployment may point the key
|
|
566
|
+
// `danger-full-access` at any bundle it likes; the gate must read the knob
|
|
567
|
+
// values. Here the key keeps its reassuring name while granting only a
|
|
568
|
+
// `workspace-write` sandbox, which must NOT unlock the bypass.
|
|
569
|
+
approvalPolicy = 'never'
|
|
570
|
+
presetName = 'danger-full-access'
|
|
571
|
+
presetSpec = { sandbox: 'workspace-write', approval: 'never' }
|
|
572
|
+
const beforeRedefined = approvalCalls.length
|
|
573
|
+
const redefinedPreset = await callTool({ action: 'add', title: '被重定义的预设探针' })
|
|
574
|
+
assert.equal(
|
|
575
|
+
redefinedPreset.isError,
|
|
576
|
+
true,
|
|
577
|
+
'a "danger-full-access" key that carries a restricted sandbox does NOT unlock the write',
|
|
578
|
+
)
|
|
579
|
+
assert.ok(
|
|
580
|
+
String(redefinedPreset.error?.message ?? '').includes('审批策略是 `never`'),
|
|
581
|
+
'and it is refused for the policy reason, like any other restricted sandbox',
|
|
582
|
+
)
|
|
583
|
+
assert.equal(approvalCalls.length, beforeRedefined, 'with no dialog opened')
|
|
584
|
+
presetSpec = null
|
|
585
|
+
|
|
586
|
+
// `resolve` and `specOf` are the same lookup with different error behaviour, so
|
|
587
|
+
// a build offering only the non-throwing one must still resolve. Without this
|
|
588
|
+
// the fallback is untested code that only a future DSH would ever reach.
|
|
589
|
+
const resolveBackup = permissionPresetsStub.resolve
|
|
590
|
+
delete permissionPresetsStub.resolve
|
|
591
|
+
approvalPolicy = 'never'
|
|
592
|
+
presetName = 'danger-full-access'
|
|
593
|
+
const viaSpecOf = await callTool({ action: 'add', title: 'specOf 回退探针' })
|
|
594
|
+
assert.equal(
|
|
595
|
+
viaSpecOf.isError,
|
|
596
|
+
false,
|
|
597
|
+
'a build with only specOf still reads the knob values: ' + JSON.stringify(viaSpecOf).slice(0, 200),
|
|
598
|
+
)
|
|
599
|
+
permissionPresetsStub.resolve = resolveBackup
|
|
600
|
+
|
|
601
|
+
console.log(
|
|
602
|
+
'live-never OK — full access + never proceeds, a restricted sandbox still refuses, unreadable knobs keep asking',
|
|
603
|
+
)
|
|
604
|
+
|
|
409
605
|
// -- the fence on a really-injected route ------------------------------------
|
|
410
606
|
|
|
411
607
|
const api = routes.find((r) => r.path === '/dsh-todo-board/api')
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does the 0.13.5 approval rule hold against the REAL `dsh-permission-presets`?
|
|
3
|
+
*
|
|
4
|
+
* The rule lets a board write through WITHOUT approval when the session's
|
|
5
|
+
* effective sandbox is `danger-full-access` and the approval policy is `never`.
|
|
6
|
+
* The sandbox half is read from the resolved preset bundle:
|
|
7
|
+
*
|
|
8
|
+
* specOf(current(session)).sandbox === 'danger-full-access'
|
|
9
|
+
*
|
|
10
|
+
* That is only sound if a derived preset's bundle really describes the session's
|
|
11
|
+
* sandbox, for every table a deployment can configure. So this drives the
|
|
12
|
+
* SHIPPED `derive()` over the whole knob grid and asserts the security property
|
|
13
|
+
* itself:
|
|
14
|
+
*
|
|
15
|
+
* the condition holds ==> the session really is
|
|
16
|
+
* (sandbox danger-full-access, approval never)
|
|
17
|
+
*
|
|
18
|
+
* It also pins the API the gate reads (`current`, `resolve`, `specOf`), because
|
|
19
|
+
* those silently disappearing would drop the plugin back to "always ask" — safe,
|
|
20
|
+
* but it would look like a bug.
|
|
21
|
+
*
|
|
22
|
+
* `derive()` touches only `this.presets`, `this.specOf`, `this.autoAdmit` and
|
|
23
|
+
* `this.ctx.{shell.sandboxMode, approval.config.policy}`, so the real prototype
|
|
24
|
+
* runs against a fabricated receiver. That beats reading the source: this is the
|
|
25
|
+
* shipped implementation.
|
|
26
|
+
*
|
|
27
|
+
* node tools/check-permission-derive.mjs
|
|
28
|
+
*
|
|
29
|
+
* Requires the DSH install; skipped loudly if it is missing.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import assert from 'node:assert/strict'
|
|
33
|
+
import { existsSync } from 'node:fs'
|
|
34
|
+
|
|
35
|
+
const DSH =
|
|
36
|
+
process.env.DSHTB_DSH ??
|
|
37
|
+
'C:/Users/XIAO/AppData/Roaming/npm/node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai/'
|
|
38
|
+
const PP = 'file:///' + DSH + 'dsh-permission-presets/lib/index.js'
|
|
39
|
+
const UA = 'file:///' + DSH + 'dsh-user-approval/lib/index.js'
|
|
40
|
+
|
|
41
|
+
if (!existsSync(DSH + 'dsh-permission-presets/lib/index.js')) {
|
|
42
|
+
console.error('SKIP: the real dsh-permission-presets runtime is not reachable at ' + PP)
|
|
43
|
+
console.error(' set DSHTB_DSH to its @deepseek-ai directory to run this check.')
|
|
44
|
+
process.exit(0)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const pp = await import(PP)
|
|
48
|
+
const ua = await import(UA)
|
|
49
|
+
const proto = pp.PermissionPresetService.prototype
|
|
50
|
+
const approvalProto = ua.ApprovalService.prototype
|
|
51
|
+
|
|
52
|
+
// -- the API the gate reads --------------------------------------------------
|
|
53
|
+
|
|
54
|
+
for (const method of ['current', 'resolve', 'specOf', 'derive', 'permissionState']) {
|
|
55
|
+
assert.equal(
|
|
56
|
+
typeof proto[method],
|
|
57
|
+
'function',
|
|
58
|
+
'PermissionPresetService.' + method + ' is what the approval gate reads; it moved',
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
assert.equal(
|
|
62
|
+
typeof approvalProto.effectivePolicy,
|
|
63
|
+
'function',
|
|
64
|
+
'ApprovalService.effectivePolicy is what the approval gate reads; it moved',
|
|
65
|
+
)
|
|
66
|
+
assert.equal(pp.AUTO_PRESET, 'auto', 'the live-Auto name the derive() branch compares against')
|
|
67
|
+
assert.equal(pp.CUSTOM_PRESET, 'custom', 'the derived not-a-preset name')
|
|
68
|
+
|
|
69
|
+
console.log('derive OK — the service API the approval gate reads is all present')
|
|
70
|
+
|
|
71
|
+
// -- the security property, over the whole grid ------------------------------
|
|
72
|
+
|
|
73
|
+
const DEFAULT_TABLE = {
|
|
74
|
+
'workspace-write': { sandbox: 'workspace-write', approval: 'ask', name: 'workspace-write' },
|
|
75
|
+
'danger-full-access': {
|
|
76
|
+
sandbox: 'danger-full-access',
|
|
77
|
+
approval: 'never',
|
|
78
|
+
name: 'danger-full-access',
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
// `presets` is a Config field, so this is a deployment that is allowed to exist.
|
|
82
|
+
// The key keeps a reassuring name while granting a restricted sandbox.
|
|
83
|
+
const REDEFINED_TABLE = {
|
|
84
|
+
'danger-full-access': {
|
|
85
|
+
sandbox: 'workspace-write',
|
|
86
|
+
approval: 'never',
|
|
87
|
+
name: 'danger-full-access',
|
|
88
|
+
description: 'redefined by a deployment',
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
const TABLES = [
|
|
92
|
+
['default', DEFAULT_TABLE, undefined],
|
|
93
|
+
['default, auto live', DEFAULT_TABLE, { sandbox: 'danger-full-access', approval: 'ask' }],
|
|
94
|
+
['redefined', REDEFINED_TABLE, undefined],
|
|
95
|
+
]
|
|
96
|
+
const SANDBOXES = ['read-only', 'workspace-write', 'danger-full-access']
|
|
97
|
+
const APPROVALS = ['ask', 'never']
|
|
98
|
+
const LAST_SELECTED = [null, 'workspace-write', 'danger-full-access', 'auto', 'custom']
|
|
99
|
+
|
|
100
|
+
function receiver(table, autoAdmit) {
|
|
101
|
+
const self = {
|
|
102
|
+
presets: table,
|
|
103
|
+
autoAdmit,
|
|
104
|
+
ctx: { shell: { sandboxMode: 'read-only' }, approval: { config: { policy: 'ask' } } },
|
|
105
|
+
}
|
|
106
|
+
self.specOf = (name) => proto.specOf.call(self, name)
|
|
107
|
+
return self
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let allowed = 0
|
|
111
|
+
let refused = 0
|
|
112
|
+
const lyingNames = []
|
|
113
|
+
|
|
114
|
+
for (const [label, table, autoAdmit] of TABLES) {
|
|
115
|
+
for (const sandbox of SANDBOXES) {
|
|
116
|
+
for (const approval of APPROVALS) {
|
|
117
|
+
for (const lastSelected of LAST_SELECTED) {
|
|
118
|
+
const self = receiver(table, autoAdmit)
|
|
119
|
+
const name = proto.derive.call(self, { preset: lastSelected, sandbox, approval })
|
|
120
|
+
const spec = proto.specOf.call(self, name)
|
|
121
|
+
|
|
122
|
+
// The plugin's condition, verbatim.
|
|
123
|
+
const policyIsNever = approval === 'never'
|
|
124
|
+
const sandboxIsFullAccess = spec !== undefined && spec !== null && spec.sandbox === 'danger-full-access'
|
|
125
|
+
const gateWouldAllow = policyIsNever && sandboxIsFullAccess
|
|
126
|
+
|
|
127
|
+
const where = `[${label}] knobs=(${sandbox}, ${approval}) lastSelected=${lastSelected} -> "${name}"`
|
|
128
|
+
|
|
129
|
+
if (name === 'danger-full-access' && sandbox !== 'danger-full-access') {
|
|
130
|
+
lyingNames.push(where)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (gateWouldAllow) {
|
|
134
|
+
allowed += 1
|
|
135
|
+
assert.equal(sandbox, 'danger-full-access', 'the rule must never allow a restricted sandbox: ' + where)
|
|
136
|
+
assert.equal(approval, 'never', 'the rule must never allow while prompts are possible: ' + where)
|
|
137
|
+
} else {
|
|
138
|
+
refused += 1
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
assert.ok(allowed > 0, 'the rule never fired in any probed state — the check would be vacuous')
|
|
146
|
+
assert.ok(refused > 0, 'every probed state allowed — the check would be vacuous')
|
|
147
|
+
|
|
148
|
+
console.log(
|
|
149
|
+
`derive OK — the rule held in all ${allowed + refused} probed states ` +
|
|
150
|
+
`(${allowed} allowed, ${refused} refused) against the shipped derive()`,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
// The probe's other finding, and the reason the gate compares knob VALUES rather
|
|
154
|
+
// than the preset's name. If a future DSH stops returning a misleading name here,
|
|
155
|
+
// this is informational rather than a failure — the security property above is
|
|
156
|
+
// what must hold, and it holds either way.
|
|
157
|
+
console.log(
|
|
158
|
+
lyingNames.length === 0
|
|
159
|
+
? 'derive note — a redefined table did NOT produce a misleading name in this build'
|
|
160
|
+
: `derive note — a redefined table DOES make the name lie (${lyingNames.length} state(s)), ` +
|
|
161
|
+
'which is why the gate compares the resolved bundle, not the name:\n ' +
|
|
162
|
+
lyingNames[0],
|
|
163
|
+
)
|