dsh-delete-guard 2.2.3 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +313 -0
- package/README.en.md +79 -12
- package/README.ja.md +65 -11
- package/README.md +59 -7
- package/SECURITY.md +127 -3
- package/cordis.patch.yml +2 -0
- package/lib/guard.js +256 -167
- package/lib/index.js +187 -6
- package/lib/move-guard.js +17 -0
- package/lib/rewrite-guard.js +925 -0
- package/lib/shell-text.js +205 -0
- package/lib/staging.js +292 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
**让 agent 删不掉「恢复不了」的东西。**
|
|
6
6
|
|
|
7
7
|
删除只有两条路:进 Windows 回收站(资源管理器里能还原),或者被拦下来换成一次
|
|
8
|
-
`file_trash`
|
|
8
|
+
`file_trash` 调用。没有第三条:**把文件内容写没了,和把它删掉是同一件事。**
|
|
9
9
|
|
|
10
10
|
```
|
|
11
11
|
agent: Remove-Item -Recurse -Force .\src
|
|
@@ -13,6 +13,12 @@ agent: Remove-Item -Recurse -Force .\src
|
|
|
13
13
|
随后: file_trash → 移入回收站,「还原」可用
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
```
|
|
17
|
+
agent: $lines=Get-Content $f; $idx=(…Select-String…).LineNumber; Set-Content $f $lines[0..($idx-2)]
|
|
18
|
+
被拒: …`$idx` is offset by arithmetic in a slice endpoint, it is never checked for $null…
|
|
19
|
+
Fix, then re-run: if (-not $idx) { throw "anchor not found" }
|
|
20
|
+
```
|
|
21
|
+
|
|
16
22
|
## 解决什么问题
|
|
17
23
|
|
|
18
24
|
DSH 里模型执行 `pwsh` 的删除命令,文件是被直接抹掉的:`ctx.fs` 没有 delete,
|
|
@@ -27,6 +33,11 @@ DSH 里模型执行 `pwsh` 的删除命令,文件是被直接抹掉的:`ctx.
|
|
|
27
33
|
`-Command` / `-EncodedCommand`、持久终端里敲的命令、Git Bash 的 `/c/...` 路径、以及清空
|
|
28
34
|
回收站的各种写法,各有对应规则。
|
|
29
35
|
|
|
36
|
+
还有一类**没有删除动词**的毁灭:把文件读进来、算一刀、再覆盖回同一个文件。
|
|
37
|
+
`$lines[0..($null-2)]` 在 PowerShell 里不是错误,而是 `$lines[0..-2]`,即「首行 + 末两行」
|
|
38
|
+
——605 行可以这样被静默保存成 24 行。这类命令既不能进回收站(网络共享根本没有回收站),
|
|
39
|
+
也不能靠事后比对发现,所以守卫在写入前就按「读改写同一文件」和「未断言的切片端点」拒绝。
|
|
40
|
+
|
|
30
41
|
## 安装
|
|
31
42
|
|
|
32
43
|
```shell
|
|
@@ -36,7 +47,7 @@ dsh plugin --profile web add dsh-delete-guard
|
|
|
36
47
|
dsh plugin --profile web add github:deepestevan/dsh-delete-guard
|
|
37
48
|
# 或者从本地 tarball(改过源码时用这条)
|
|
38
49
|
pnpm pack --pack-destination ./temp/pack # 先升 package.json 的 version
|
|
39
|
-
dsh plugin --profile web add file:./temp/pack/dsh-delete-guard-2.
|
|
50
|
+
dsh plugin --profile web add file:./temp/pack/dsh-delete-guard-2.4.2.tgz
|
|
40
51
|
# 重启 dsh web:lib/*.js 只在进程启动时加载
|
|
41
52
|
```
|
|
42
53
|
|
|
@@ -66,15 +77,22 @@ terminal_send: "Remove-Item C:\tmp\a.txt"
|
|
|
66
77
|
| 清空回收站 | `Clear-RecycleBin`(含 `&`、子壳、`-EncodedCommand` 形态)、`SHEmptyRecycleBin`、对回收站条目驱动 shell 动词、直接删 `$Recycle.Bin` 内容 |
|
|
67
78
|
| 没有回收站的位置 | UNC 共享、exFAT/FAT32 卷(在那里"回收"等于永久擦除) |
|
|
68
79
|
| 脚本内删除 | 内联 shell / Python / Node 体里的删除动词与擦除调用;把含删除的文本写进 `.ps1`/`.sh`/`.py` |
|
|
80
|
+
| **读改写同一个文件** | `(Get-Content $f) \| Set-Content $f`、`$c = Get-Content $f; Set-Content $f $c`、`sed -i $f`、`cat $f > $f`、`::ReadAllText` → `::WriteAllText`——新内容来自唯一的副本,写坏就没得还原。带 `.bak` 备份或临时文件校验步骤的写法放行 |
|
|
81
|
+
| **未断言的切片端点** | 同一命令里既写文件、又用 `$idx ± n` 当区间端点(`$l[0..($idx-2)]`、`-First ($i-1)`),而 `$idx` 从没检查过 `$null`。`$null` 在 PowerShell 里不报错:`0..($null-2)` 就是 `0..-2` = 首行 + 末两行 |
|
|
82
|
+
| **读动词折进写语句里** | `Set-Content $f (Get-Content $f \| Select-Object -First 10)`:一行里既读又截断再写回,是事故最紧凑的拼法 |
|
|
83
|
+
| **经变量调用的 shell** | `$shellPath='…bash.exe'; & $shellPath -c "rm -rf …"`:程序名不是字面量,正文无法判定 |
|
|
69
84
|
|
|
70
85
|
**放行**:只读命令、只提到删除词的操作(`Select-String -Pattern "Remove-Item"`、
|
|
71
|
-
`Get-Content shred.exe
|
|
86
|
+
`Get-Content shred.exe`)、从回收站**还原**文件、`Add-Content` / `>>` / `-Append`
|
|
87
|
+
(追加不替换)、写 `$null` / `/dev/null`、以及**带 `.bak` 备份或临时文件校验**的整档重写
|
|
88
|
+
(事故记录 §6 的那套写法原样通过)。另外,`node -e` / `python -c` 体里**提到**擦除工具名的文本不算程序名——
|
|
89
|
+
只有把它交给 `exec` / `execSync` / `spawn` / `system` / `subprocess.*` 才算(`bash -c` 体是 shell 文本,仍按整段判)。
|
|
72
90
|
|
|
73
91
|
## 两个工具
|
|
74
92
|
|
|
75
93
|
| 工具 | 作用 |
|
|
76
94
|
| --- | --- |
|
|
77
|
-
| `file_trash { paths, reason? }` |
|
|
95
|
+
| `file_trash { paths, reason? }` | 唯一允许的删除方式。本地条目移入回收站;共享条目先复制到本地卷、校验、回收副本,之后才删原件(见「网络共享」)。逐条报告成功与失败 |
|
|
78
96
|
| `trash_status { drive? }` | 报告该卷回收站的项目数与占用,用于确认删除确实落进了回收站 |
|
|
79
97
|
|
|
80
98
|
## 配置
|
|
@@ -88,6 +106,9 @@ terminal_send: "Remove-Item C:\tmp\a.txt"
|
|
|
88
106
|
| `forbidEmptyRecycleBin` | `true` | 禁止清空或改动回收站 |
|
|
89
107
|
| `forbidWipe` | `true` | 禁止 `shred` / `sdelete` / `srm` / `cipher /w` / `format` |
|
|
90
108
|
| `blockScriptDeletes` | `true` | 禁止脚本文件与内联字符串里的删除 |
|
|
109
|
+
| `blockTruncatingWrites` | `true` | 禁止「读改写同一文件」与「未断言的切片端点 + 写文件」 |
|
|
110
|
+
| `uncRecoverableMove` | `true` | 共享删除:先复制到本地 NTFS 卷 + 校验 + 回收副本,再删原件;`false` 则纯拒绝 |
|
|
111
|
+
| `stagingRoot` | `%LOCALAPPDATA%\dsh-delete-guard\staging` | 共享删除的暂存目录(必须在有回收站的本地卷上) |
|
|
91
112
|
|
|
92
113
|
## 恢复已删的文件
|
|
93
114
|
|
|
@@ -101,6 +122,27 @@ terminal_send: "Remove-Item C:\tmp\a.txt"
|
|
|
101
122
|
反查;动词还原后可能残留孤儿 `$I` 记录,跳过 payload 缺失的即可。资源管理器里右键
|
|
102
123
|
「还原」与之一致,只是脚本化时别依赖本地化的动词名。
|
|
103
124
|
|
|
125
|
+
## 网络共享(没有回收站)
|
|
126
|
+
|
|
127
|
+
UNC 路径下不存在回收站:`SHFileOperationW` 在那里是**擦除并返回成功**,所以桥接会先拒绝。
|
|
128
|
+
`file_trash` 于是做人在这种情况下的做法,一次调用完成,顺序固定:
|
|
129
|
+
|
|
130
|
+
1. 把条目复制到有回收站的本地 NTFS 卷(`%LOCALAPPDATA%\dsh-delete-guard\staging\<时间戳>-<名字>`,可用 `stagingRoot` 改);
|
|
131
|
+
2. 对照原件校验:相对路径集合、条目类型、每个文件的大小;
|
|
132
|
+
3. 把暂存目录送进回收站——副本这时可还原;
|
|
133
|
+
4. 最后才删除原件。
|
|
134
|
+
|
|
135
|
+
**保证的范围要说清**:可恢复的是**内容**(在本地回收站里),不是**原路径**——共享上没有回收站放它,
|
|
136
|
+
第 4 步就是一次普通永久删除。所以顺序本身就是安全属性:第 4 步之前的任何失败都不碰原件,第 4 步只在
|
|
137
|
+
桥接确认暂存副本已进回收站之后才跑。
|
|
138
|
+
|
|
139
|
+
还原时落点是暂存路径而不是原共享路径(回收站的 `$I` 记的是暂存位置),所以工具会把该路径打出来。
|
|
140
|
+
|
|
141
|
+
会被拒绝,且都在复制之前停住:共享根(`\\host\share`)与只有主机名的形态、树里含**重解析点**
|
|
142
|
+
(junction/符号链接:复制要么把目标内容一起复制进来、要么需要权限重建链接)、暂存卷**空间不足**。
|
|
143
|
+
|
|
144
|
+
`uncRecoverableMove: false` 退回 2.3.0 的纯拒绝,且什么都不删。
|
|
145
|
+
|
|
104
146
|
## 不挡什么
|
|
105
147
|
|
|
106
148
|
| 不覆盖 | 原因 |
|
|
@@ -112,6 +154,10 @@ terminal_send: "Remove-Item C:\tmp\a.txt"
|
|
|
112
154
|
| 终端里分两次发送才拼出的删除 | 每次 send 只看到这一次的文本 |
|
|
113
155
|
| 非 Windows 平台 | 桥接是 `SHFileOperationW` |
|
|
114
156
|
| 空余空间不足时的删除 | NTFS 同卷回收是 rename,不占新空间,没有可预检的东西 |
|
|
157
|
+
| **没读过就覆盖**(`echo x > 既有文件.md`、`Invoke-WebRequest -OutFile $f`、`git checkout -- f`) | 这是「有意重写」,不是读改写:新内容不依赖旧内容,`write`/`edit` 工具也做同一件事。按动词列举覆盖写入会连构建日志、生成配置一起拒绝,正是本插件否掉的做法 |
|
|
158
|
+
| 读改写里的**间接**写(编译器、`npm run build`、`robocopy` 覆盖产物) | 写入发生在子进程内部,命令文本里没有可判定的目标 |
|
|
159
|
+
| 写完之后再比对体积(截断熔断) | 需要覆盖前的旧内容才能回滚:`tools/post-execute` 只能把结果改成反馈,撤不回已截断的内容;每轮 shell 调用快照整棵树是 O(工作区),而且本次事故的目标在 UNC 共享上,任何工作区快照都不包含它 |
|
|
160
|
+
| 把共享上的东西 `Move-Item` / `robocopy /MOV` 到本地 | 那是"移动"不是"删除":内容到了目标位置,但共享上的原件被永久 unlink,没有回收站记录。要留记录就得走 `file_trash` |
|
|
115
161
|
|
|
116
162
|
覆盖的 shell 工具名:`pwsh`、`powershell`、`cmd`、`bash`、`sh`、`zsh`、`shell`、
|
|
117
163
|
`terminal_send`、`terminal_write`。判定看的是语句的命令词、调用的形态和程序位置,不是「这一行里出现过这个词」。
|
|
@@ -122,9 +168,11 @@ terminal_send: "Remove-Item C:\tmp\a.txt"
|
|
|
122
168
|
node test/run-all.mjs
|
|
123
169
|
```
|
|
124
170
|
|
|
125
|
-
|
|
126
|
-
宿主 schema 受理(5)、对真实回收站的端到端(
|
|
171
|
+
148 项、八层:命令分类(50)、覆盖守卫(30)、规则漏洞(12)、暂存删除(8)、`file_trash` 操作数守卫(15)、
|
|
172
|
+
宿主 schema 与钩子接线(14)、宿主 schema 受理(5)、对真实回收站的端到端(14,含真 `\\localhost\C$` 路径)。`test/` 不进 tarball,所以打包前必须
|
|
127
173
|
全绿;其中两层会加载宿主自己的校验器,找不到 DSH 安装时报「跳过」而非失败。
|
|
174
|
+
覆盖守卫那一层里,"事故命令必须被拒" 与 "42 条日常命令必须照常放行" 用的是同一份文件:
|
|
175
|
+
只拦住事故、却把 `npm run build` 也拒掉的规则不算修好。
|
|
128
176
|
|
|
129
177
|
## 文档
|
|
130
178
|
|
|
@@ -132,9 +180,13 @@ node test/run-all.mjs
|
|
|
132
180
|
| --- | --- |
|
|
133
181
|
| [CHANGELOG.md](CHANGELOG.md) | 版本摘要 |
|
|
134
182
|
| [SECURITY.md](SECURITY.md) | 威胁模型:策略层,不是沙箱 |
|
|
183
|
+
| [docs/incidents/](docs/incidents/) | 事故记录:每条规则背后的实测与逐字命令(不进 npm 包,见 `files`) |
|
|
135
184
|
| [LICENSE](LICENSE) | MIT |
|
|
136
185
|
|
|
137
|
-
|
|
186
|
+
事故记录留在仓库里,因为它就是规则的证据:一条规则若说不清"当初哪条命令、在什么条件下、
|
|
187
|
+
造成了什么后果",接手的人就只能靠猜去维护它。设计取舍、逐轮实测与发布跑批仍属维护者侧的
|
|
188
|
+
工程笔记,不随仓库与包发布。(2.2.0 曾把笔记整体移出仓库,起因是里面带私有主机名与 UNC
|
|
189
|
+
路径;记录留在仓库时按同一条标准脱敏。)
|
|
138
190
|
|
|
139
191
|
## 许可
|
|
140
192
|
|
package/SECURITY.md
CHANGED
|
@@ -15,12 +15,31 @@ command line.
|
|
|
15
15
|
- An agent deleting files the user still needs — the ordinary failure mode. Every
|
|
16
16
|
recognised delete is refused and redirected to `file_trash`
|
|
17
17
|
(`SHFileOperationW(FOF_ALLOWUNDO)`), so the item is recoverable from Explorer.
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
- Volumes whose file system has no bin at all (exFAT/FAT32): refused before the
|
|
19
|
+
shell is called, because `SHFileOperationW` erases there and still reports
|
|
20
|
+
success.
|
|
21
|
+
- **Deletion on a share, which has no bin.** `file_trash` copies the item to a
|
|
22
|
+
local NTFS volume, verifies the copy (entry set, kinds, sizes), recycles the
|
|
23
|
+
staging folder, and only then removes the original. The guarantee is about
|
|
24
|
+
**content**, not about the original path: after a successful delete the bytes are
|
|
25
|
+
in the local bin and the item at the share path is gone, because there is no bin
|
|
26
|
+
on that volume to hold it. The step order is the safety property — any failure
|
|
27
|
+
before the last step leaves the original untouched, and the last step runs only
|
|
28
|
+
after the bridge confirms the staged copy is in the bin. A share root, a tree
|
|
29
|
+
containing a reparse point, and a staging volume without room are all refused
|
|
30
|
+
before any copy.
|
|
21
31
|
- Irreversible side doors: permanent-erase programs, erases performed through
|
|
22
32
|
.NET APIs, `Invoke-Expression`, deletes delegated to `cmd.exe`, and every
|
|
23
33
|
spelling of emptying the Recycle Bin.
|
|
34
|
+
- **Content destroyed without a delete verb**: a command that reads a file and
|
|
35
|
+
overwrites that same file (`Get-Content f … | Set-Content f`, `sed -i f`,
|
|
36
|
+
`cat f > f`), and a command that slices with an unchecked `$null`-able endpoint
|
|
37
|
+
and then writes the result. Both are refused, and the refusal names the
|
|
38
|
+
copy-then-verify recipe that makes the write undoable. This is the one class
|
|
39
|
+
where routing to the bin cannot help: on a UNC share there is no bin
|
|
40
|
+
(`scripts/recycle-bin.ps1` refuses it), so prevention is the whole remedy.
|
|
41
|
+
Record:
|
|
42
|
+
[docs/incidents/2026-11-14-full-file-rewrite-truncation.md](docs/incidents/2026-11-14-full-file-rewrite-truncation.md).
|
|
24
43
|
|
|
25
44
|
## Out of scope (by design, and verified as limits)
|
|
26
45
|
|
|
@@ -38,6 +57,111 @@ a security read:
|
|
|
38
57
|
`zsh`, `shell`, `terminal_send`, `terminal_write`) are not inspected at all.
|
|
39
58
|
- Deletes inside a script file whose body the guard never sees: it refuses the
|
|
40
59
|
write and the inline forms it can see, not the executed body.
|
|
60
|
+
- Overwrites that do not read the file first (`echo x > notes.md`,
|
|
61
|
+
`Invoke-WebRequest -OutFile`, `git checkout --`). Those are deliberate rewrites,
|
|
62
|
+
not read-modify-write: the new content does not depend on the old, and refusing
|
|
63
|
+
them would mean refusing `write`/`edit` too. README 「不挡什么」 lists them.
|
|
64
|
+
- Post-hoc rollback. There is no "compare the size afterwards and restore": the
|
|
65
|
+
old bytes are needed *before* the write, `tools/post-execute` can only turn a
|
|
66
|
+
result into feedback, and a per-call tree snapshot is O(workspace) and would
|
|
67
|
+
still miss a target outside the workspace.
|
|
68
|
+
- A rule that asks. `{ kind: 'ask' }` resolves to allow in the same tick wherever
|
|
69
|
+
approvals are auto-granted — the default for unattended deployments — so this
|
|
70
|
+
plugin denies rather than asks. A rule that only looks present is worse than no
|
|
71
|
+
rule.
|
|
72
|
+
- Staging a share delete is a *copy*, not an image: ACLs, alternate data streams,
|
|
73
|
+
sparse ranges and ownership are not reproduced (timestamps are), and the
|
|
74
|
+
verification compares entry sets, kinds and sizes rather than hashes. Content
|
|
75
|
+
recovery is the goal; a byte-for-byte clone is not what you get. The cost is also
|
|
76
|
+
honest: O(size) in time and the same in free space on the staging volume, so a
|
|
77
|
+
very large tree can exceed the tool call's timeout.
|
|
78
|
+
|
|
79
|
+
## Why there is no permanent-delete tool
|
|
80
|
+
|
|
81
|
+
Issue #2 asks for one: a tool that really erases when the user asked for it,
|
|
82
|
+
gated by a `user_request` / `user_quote` field. It is refused, and the reason is
|
|
83
|
+
not that permanent deletion is never legitimate — a user can always do it in
|
|
84
|
+
Explorer, or run a script themselves. The reason is that **the gate would be
|
|
85
|
+
authored by the thing it is meant to guard.**
|
|
86
|
+
|
|
87
|
+
Three layers, and only the first has a machine judge:
|
|
88
|
+
|
|
89
|
+
| Layer | Question | Judge |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| 1 | did these characters come from the user? | the plugin, mechanically — `source.kind === 'user'` plus an `rpcId` on the `user/message` event |
|
|
92
|
+
| 2 | does that sentence mean "this file may be destroyed"? | nobody, automatically |
|
|
93
|
+
| 3 | should it run *now*? | a human — `{ kind: 'ask' }` where approvals are real; on a box with `approval policy: never` that resolves to allow, so the only remaining human gate is a command the person runs |
|
|
94
|
+
|
|
95
|
+
A verbatim quote can be checked. Intent cannot, because **the same characters
|
|
96
|
+
carry both readings**: "永久删除 a.md", "不要永久删除 a.md", "别永久删除 a.md",
|
|
97
|
+
"能永久删除 a.md 吗", "你上次说的『永久删除 a.md』是指哪一步" all contain the
|
|
98
|
+
affirmative token, and the last three are not instructions at all. A lexical
|
|
99
|
+
filter over negations is an enumeration treadmill, and it fails in the direction
|
|
100
|
+
of *allowing* — the token is present — which for a destructive action is the worst
|
|
101
|
+
direction to fail in. Adding a semantic model to classify the sentence only moves
|
|
102
|
+
the trust question up one level. (Even the provenance check needs care: `user/message`
|
|
103
|
+
also carries `agent-instructions` from `AGENTS.md`, `runtime-context` and spliced
|
|
104
|
+
agent input, so a filter that does not key on `source.kind` would let the agent
|
|
105
|
+
author its own permission slip.)
|
|
106
|
+
|
|
107
|
+
**Measured, on why the surrounding design cannot compensate.** 126 real guard
|
|
108
|
+
denials across 58 sessions (300 newest session logs on this machine, 2026-11-24),
|
|
109
|
+
classified by what the model did before the next user turn:
|
|
110
|
+
|
|
111
|
+
| follow-up | share |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| changed approach (typically by following the recipe the deny message names: copy to `.bak`, use `edit`) | 78% |
|
|
114
|
+
| `file_trash` within 5 tool calls | 14% |
|
|
115
|
+
| re-attempted a shape the guard would block | 4% |
|
|
116
|
+
| diagnosed first (`read`, `grep`, `Test-Path`) | 3% |
|
|
117
|
+
| wrote a delete into a script and ran that path | 0.8% |
|
|
118
|
+
| **stopped without another tool call** | **0%** |
|
|
119
|
+
|
|
120
|
+
A block does not end a turn; it re-routes. And the re-route follows the
|
|
121
|
+
alternative the deny message names — which is why every refusal here names one.
|
|
122
|
+
There is no acceptable alternative for "make it unrecoverable", so a
|
|
123
|
+
`permanent_delete` tool would be the shortest path to a goal the model had already
|
|
124
|
+
been told to pursue, with a fabricated-or-misapplied quote as its receipt.
|
|
125
|
+
|
|
126
|
+
**What would be honest**, if this is ever revisited: the gate is a real approval or
|
|
127
|
+
a command the human runs (`scripts/purge-bin-entry.ps1`, keyed off the `$I` record),
|
|
128
|
+
and `user_quote` is an audit field — never the key. Anything else is an audited
|
|
129
|
+
permanent delete with a receipt the agent wrote itself.
|
|
130
|
+
|
|
131
|
+
Note the asymmetry: "no permanent delete" is a policy, not an invariant — `Add-Type`
|
|
132
|
+
C# still reaches `DeleteFileW`, as the README's 「不挡什么」 table says. The choice
|
|
133
|
+
above keeps the *easy* path safe, which is what a policy layer can actually do.
|
|
134
|
+
|
|
135
|
+
## How the rules were calibrated (2026-11-25)
|
|
136
|
+
|
|
137
|
+
The rules from 2.3.0 / 2.4.0 each came from one incident. 2.4.2 came from a
|
|
138
|
+
measurement: **62,131 shell commands that actually ran on this machine** (5,746 session
|
|
139
|
+
logs), re-classified with the matcher as it stood. 1,580 would be refused; **432 of those
|
|
140
|
+
were false positives (0.70% of every command ever run here)**. Records:
|
|
141
|
+
`docs/incidents/2026-11-24-rule-false-positive-sweep.md` (evidence) and
|
|
142
|
+
`docs/incidents/2026-11-24-fix-plan-2-4-2.md` (plan, including the direction that was
|
|
143
|
+
rejected and why).
|
|
144
|
+
|
|
145
|
+
Two things from that exercise are worth keeping in view when changing a rule:
|
|
146
|
+
|
|
147
|
+
**1. A shape list is the same mistake as a verb list.** The first proposal was to refuse
|
|
148
|
+
only commands containing a discard token (`[a..b]`, `-First`, `Select-Object`). Measurements
|
|
149
|
+
saw four rebuilds that contain none of them and destroy a whole file anyway
|
|
150
|
+
(`| Where-Object { -not … }`, `for { … continue }`, `-replace '(?s)^.*$'`). The rule keeps
|
|
151
|
+
"reads the same file it writes" as its shape and adds **order** and **recoverability** —
|
|
152
|
+
it does not trade one word list for another.
|
|
153
|
+
|
|
154
|
+
**2. A count is not a shape.** After the change the sweep's `real` count fell 1,148 → 852,
|
|
155
|
+
which reads like 296 dangerous commands were let through. A mechanical check said otherwise:
|
|
156
|
+
across the 5,917 commands now allowed, **none** are "same file, read before write". The drop
|
|
157
|
+
was the sweep's own classifier mislabeling write-then-read-back as a whole-file rewrite. The
|
|
158
|
+
acceptance criteria were rewritten as a shape gate because of this.
|
|
159
|
+
|
|
160
|
+
**3. A dry run must not become an instruction.** `Remove-Item x -WhatIf` classified as
|
|
161
|
+
`rewrite`, and the rewrite branch tells the model to re-run the call as `file_trash` — so a
|
|
162
|
+
user asking to preview was advised to destroy the file. Dry runs are now rendered as
|
|
163
|
+
previews. The tempting fix (drop `-WhatIf` statements from classification) was measured and
|
|
164
|
+
rejected: the word in a comment or a string then exempts a real write.
|
|
41
165
|
|
|
42
166
|
## Reporting
|
|
43
167
|
|