dsh-delete-guard 0.0.0-stage → 2.2.3

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 ADDED
@@ -0,0 +1,257 @@
1
+ # Changelog
2
+
3
+ All notable changes to this plugin. Dates are the day the tarball was packed on
4
+ this machine (`temp/pack/dsh-delete-guard-<ver>.tgz`), which is the artifact
5
+ each profile actually ran.
6
+
7
+ The long-form reasoning behind every entry — what was measured, what was
8
+ rejected, what the trade-off costs — lives in the maintainer's engineering notes (`INCIDENTS.md`, not shipped since 2.2.0).
9
+
10
+ ## [2.2.3] — 2026-10-23
11
+
12
+ npm publish prerequisites; no behaviour change.
13
+
14
+ - READMEs (`zh`/`en`/`ja`): the first install line is now the registry spec
15
+ `dsh plugin --profile web add dsh-delete-guard`, with `github:deepestevan/dsh-delete-guard`
16
+ and the local tarball kept as the alternatives.
17
+ - `.github/workflows/publish.yml`: release-time publish over GitHub OIDC (trusted
18
+ publishing, `id-token: write`), no `NPM_TOKEN` secret. It upgrades npm first —
19
+ Node 22 ships npm 10, and trusted publishing needs ≥ 11.5.1.
20
+ - `test/run-all.mjs`: the e2e layer is gated on `win32`, so the same command is
21
+ green on the Linux CI runner (one suite skipped, reported as such). Verified by
22
+ forcing `process.platform='linux'`.
23
+ - `package.json`: `publishConfig.access` explicit; the root-package-only
24
+ `repository.directory` removed.
25
+
26
+ ## [2.2.2] — 2026-10-23
27
+
28
+ - All three READMEs now open the install section with the repository spec
29
+ (`dsh plugin --profile web add github:deepestevan/dsh-delete-guard`) and keep the
30
+ local tarball flow as the "you changed the source" alternative. A public repo
31
+ whose first command is a `pnpm pack` path is written for its author, not its user.
32
+
33
+ ## [2.2.1] — 2026-10-23
34
+
35
+ Registry metadata for the first publish; no behaviour change.
36
+
37
+ - `package.json`: `repository` / `homepage` / `bugs` / `author` filled with
38
+ `github.com/deepestevan/dsh-delete-guard`.
39
+ - `LICENSE`: copyright holder is the account name, not "contributors" — this is a
40
+ single-author project, and the handle is already the repo owner on every commit.
41
+
42
+ ## [2.2.0] — 2026-10-23
43
+
44
+ Publishing policy; no behaviour change. The repository now ships only what a user
45
+ or an integrator needs; the engineering notes moved out of it.
46
+
47
+ - `docs/` removed from the repository and from the package (`files`). The three
48
+ documents (design rationale, per-round incident log, release runbook) moved to
49
+ the maintainer's notes tree. They described how this plugin was built, not how to
50
+ use it — and one of them quoted a private hostname and UNC path from the
51
+ measurement that proved the 1.0.5 hole.
52
+ - What used to be a link now sits in the READMEs as one sentence: "the decision is
53
+ made on the statement's command word, the shape of the call, and program
54
+ position — never on a word appearing somewhere in the line." The threat model
55
+ stays in `SECURITY.md`.
56
+ - Reference for the split: the upstream project keeps architecture documents in its
57
+ repository `docs/` but publishes packages with a runtime-only `files` whitelist
58
+ (`packages/shell/tool-pwsh/package.json` → `locale/*.json`, `lib/index.js`,
59
+ `lib/types/**/*.d.ts`). Nothing in the published artifact is a build record.
60
+
61
+ ## [2.1.2] — 2026-10-23
62
+
63
+ - `docs/RELEASING.md` quoted this machine's absolute paths and user name
64
+ (`C:\Users\<user>\…`, the author's workspace layout). Generalised to
65
+ `%DSH_HOME%` / `<repo>\temp\pack`. A release runbook that leaks its author's
66
+ directory layout is not publishable.
67
+
68
+ ## [2.1.1] — 2026-10-23
69
+
70
+ - Three READMEs pointed at `docs/DESIGN.md` for both "judging criteria" and the
71
+ measurements. The measurements are in `INCIDENTS.md`; the pointer was split.
72
+
73
+ ## [2.1.0] — 2026-10-23
74
+
75
+ Docs restructure; no behaviour change. The README had become a lab notebook —
76
+ 361 lines of per-version forensics, defensive caveats and provenance maths — which
77
+ is the wrong document for a repository's front page.
78
+
79
+ - `README.md` rewritten as a release document: what it is in one line, the problem
80
+ it removes, install in three commands, a before/after of a blocked delete, what
81
+ gets redirected vs refused, the two tools, configuration, how to restore, then
82
+ the limits as one compact table. 361 → ~170 lines.
83
+ - The evidence moved verbatim (nothing retyped) into two documents:
84
+ `DESIGN.md` (why this shape: judging criteria, rejected alternatives, costs,
85
+ implementation notes) and `INCIDENTS.md` (per-round incidents, measurements,
86
+ and the lesson about verification method). These two, plus the release runbook,
87
+ were moved out of the repository in 2.2.0.
88
+ - `README.en.md` and `README.ja.md` rebuilt to the same shape and length.
89
+ - Stale cross-references (`README.md` 「已知限制」, `README.md` 「1.0.x 修的是
90
+ 什么」) repointed to `SECURITY.md` and this
91
+ changelog.
92
+
93
+ ## [2.0.2] — 2026-10-23
94
+
95
+ `trash_status` reported `Recycle Bin on F:: 59 item(s)` — the caller's drive
96
+ string already carries its colon and the render appended a second one. Found by
97
+ the live probe right after the 2.0.0 restart, i.e. by using the tool the way a
98
+ model does.
99
+
100
+ (2.0.1 carried the same code fix; it was superseded within the hour because its
101
+ changelog entry was written after packing, which breaks the "installed == packed"
102
+ invariant this file exists to protect.)
103
+
104
+ ## [2.0.0] — 2026-10-23
105
+
106
+ **Renamed: `dsh-recycle-bin-guard` → `dsh-delete-guard`** (cordis id
107
+ `recycle-bin-guard` → `delete-guard`, error `RecycleBinGuardError` →
108
+ `DeleteGuardError`, prompt section `delete-guard`). No behaviour change; the
109
+ package had never been published, so no alias is needed.
110
+
111
+ Why: the old name puts "guard" on the wrong noun. What is guarded is *deletion* —
112
+ the plugin refuses every unrecoverable delete and routes it into the bin. It does
113
+ not protect the bin; it protects the user from the bin being bypassed, and it also
114
+ refuses emptying the bin. Named for the bin, a reader can conclude the opposite of
115
+ what it does.
116
+
117
+ Measured on a local snapshot of the ecosystem index (4,377 plugins, from awesome-dsh-plugin.com):
118
+
119
+ - 3,740 names (85 %) start with `dsh-`; median name length 15, p90 22. `dsh-delete-guard` is 16.
120
+ - 62 names are `…-guard` with the **target** in the middle (`dsh-egress-guard`,
121
+ `dsh-write-rule-guard`, `dsh-tool-call-guard`, `dsh-disk-guard`). The target of
122
+ this one is deletion, so the convention points at `delete-guard`.
123
+ - `trash` and `recycle` appear in 0 of 4,377 names, so the old name had no search
124
+ overlap in the ecosystem; `dsh-safe-delete` (the closest neighbour) owns the
125
+ "safe delete" phrase.
126
+ - The platform stays out of the name (only ~10 of 4,377 put `win`/`windows` in it);
127
+ it belongs in the description and the `windows` topic, which both carry it.
128
+
129
+ ## [1.0.11] — 2026-10-23
130
+
131
+ Docs; no behaviour change.
132
+
133
+ - Three READMEs with a language switcher line at the top of each:
134
+ `README.md` (简体中文, the measurement log — GitHub's default display),
135
+ `README.en.md`, `README.ja.md`. The English and Japanese files contain no
136
+ Chinese prose; the switcher is the only CJK in the English one.
137
+ - Release runbook (`RELEASING.md`, maintainer-side): how to create the repository and set topics, with the
138
+ measured topic table (which topics this ecosystem actually uses, and the counts
139
+ they were measured at), plus the `gh repo create` / `gh repo edit` commands.
140
+ - `package.json` `keywords` aligned with the topic list.
141
+
142
+ ## [1.0.10] — 2026-10-23
143
+
144
+ Docs and test portability; no behaviour change.
145
+
146
+ - `test/dsh-install.mjs`: the two layers that import the host's schema validators
147
+ no longer hard-code this machine's DSH install path. They locate it
148
+ automatically and **report as skipped** (not failed) when there is none, with
149
+ `DSH_NODE_MODULES` as an override. A public repository cannot ship a test
150
+ command that only runs on the author's box.
151
+ - `README.en.md` / the release runbook: say how that lookup works and that a
152
+ `pass 0` run means the host layers were skipped.
153
+
154
+ ## [1.0.9] — 2026-10-23
155
+
156
+ Publishing metadata only; no behaviour change.
157
+
158
+ - Add `LICENSE` (MIT), `SECURITY.md`, `CHANGELOG.md`, `README.en.md`,
159
+ the release runbook.
160
+ - `package.json`: drop the `types` field — it pointed at `lib/index.d.ts`, which
161
+ has never existed, so TypeScript consumers resolved nothing. Declare
162
+ `"os": ["win32"]` (the Recycle Bin bridge is Win32-only). Ship the new
163
+ documents in the package (`files`).
164
+
165
+ ## [1.0.8] — 2026-10-23
166
+
167
+ Coverage for shells other than `pwsh`.
168
+
169
+ - **Persistent terminal is now inspected.** `terminal_send` types into a live
170
+ PTY and never passes through the `pwsh`/`bash` tools, so a delete there ran
171
+ unguarded (measured: `Remove-Item …` executed with the guard on the same call
172
+ path). The hook now reads a tool table (`SHELL_TOOLS`) instead of two hard-coded
173
+ names.
174
+ - **Git Bash paths are translated.** `rm -rf /c/tmp/x` used to be redirected with
175
+ the literal POSIX path, which Node resolves to `<cwd drive>:\c\tmp\x` — a
176
+ different location. `/x/…` and `/cygdrive/x/…` now become `X:\…`; `~`, `/tmp`,
177
+ `/usr` and other MSYS mount points are refused rather than guessed.
178
+
179
+ ## [1.0.7] — 2026-10-23
180
+
181
+ Emptying the Recycle Bin, in every spelling.
182
+
183
+ - 1.0.6 blocked only the literal `Clear-RecycleBin` at the start of a statement.
184
+ Also blocked now: `& "Clear-RecycleBin"`, `pwsh -Command "…"` and
185
+ `Start-Process … -ArgumentList "…"`, `-EncodedCommand` bodies (decoded before
186
+ judging), `SHEmptyRecycleBin`, and driving the bin items' own shell verbs
187
+ (`InvokeVerb('delete')`, `Verbs()` + `DoIt()`).
188
+ - Measured, not assumed: PowerShell rejects abbreviated cmdlet names (`Clear-R`,
189
+ `Get-Loc` → `CommandNotFoundException`), and the OS confirmation dialog only
190
+ covers the shell-verb path — `Clear-RecycleBin -Force`, `SHEmptyRecycleBin` and
191
+ deleting `$Recycle.Bin` contents directly are silent.
192
+
193
+ ## [1.0.6] — 2026-10-23
194
+
195
+ - Remove the dead capacity gate (`checkCapacity`, the bridge's `capacity` op, and
196
+ the `minFreeBytes` / `reserveBytes` config keys). On NTFS the bin shares the
197
+ item's volume, so a recycle is a rename that consumes no space; a free-space
198
+ gate could only refuse harmless deletes. The real question — does this volume
199
+ have a bin at all — is answered since 1.0.5.
200
+
201
+ ## [1.0.5] — 2026-10-23
202
+
203
+ - **Refuse locations that have no Recycle Bin** (UNC shares, exFAT/FAT32
204
+ volumes). `SHFileOperationW` with `FOF_ALLOWUNDO` does not fail there: it erases
205
+ the item, returns 0, and the "did the path leave?" check cannot tell that from
206
+ a recycle. Reproduced on a UNC share: file gone, no `$I`/`$R` record on any
207
+ local volume, `SHQueryRecycleBin` unchanged, tool reporting "Moved to the
208
+ Recycle Bin". The bridge now decides before the call
209
+ (`Test-RecyclableVolume`).
210
+
211
+ ## [1.0.4] — 2026-10-23
212
+
213
+ Structure instead of substrings.
214
+
215
+ - `.NET` erases are matched as **calls** (`::Delete(`, `.Delete(`, `.Delete()`),
216
+ not as the type literal `[System.IO.File]` — that pattern refused every
217
+ read-only System.IO call, e.g. reading a `.bat` file to count its bytes.
218
+ - Permanent-erase program names are matched in **program position** (command
219
+ word, launcher argument, or an inline shell body), so `Get-Content shred.exe`
220
+ and `grep -n "shred" *.md` are no longer refused.
221
+ - `Clear-RecycleBin` is matched in command position only, so searching for the
222
+ string in this README is allowed.
223
+ - Closed the reverse hole: the no-argument instance form
224
+ (`(Get-Item $p).Delete()`) was never caught.
225
+
226
+ ## [1.0.3] — 2026-10-18
227
+
228
+ - Evidence may not cross statements. `python -c "…del d['a']…" ; bash -c "echo ok"`
229
+ was refused because `bash` in one statement convicted the `del` in another. The
230
+ shell-inline and script-write rules are judged per statement; the two rules that
231
+ must stay whole-command (non-shell inline bodies, script-file writes) say why in
232
+ the code.
233
+
234
+ ## [1.0.2] — 2026-10-18
235
+
236
+ - **Block-wrapped deletes are seen.** `{` `}` joined the statement separators
237
+ (a real `Remove-Item` had run unguarded inside an `if (…) { … }`), and the
238
+ operand parser steps over wrapper prefixes (`(`, `&`, `.`, `$x =`).
239
+ - **Erases without a delete verb are denied** (`ERASE_CONSTRUCTS`).
240
+ - Flag values are no longer mistaken for targets
241
+ (`-ErrorAction SilentlyContinue`), splats are refused, and the whole-text
242
+ substring rules that refused read-only work were replaced by shape-specific
243
+ checks.
244
+
245
+ ## [1.0.1] — 2026-09-28
246
+
247
+ - Add the landing-side operand guard (`lib/move-guard.js`): the shell rules only
248
+ policed commands, so a direct `file_trash` call could target a drive root, the
249
+ Windows directory, or the session workspace root.
250
+ - Fix two stale tests that compiled the hand-written JSON Schema with the
251
+ `defineTool` DSL helpers and always reported `UNSUPPORTED_SCHEMA`.
252
+
253
+ ## [1.0.0] — 2026-09-25
254
+
255
+ - First working version: `tools/pre-execute` hook, the `file_trash` /
256
+ `trash_status` tools, the `SHFileOperationW(FOF_ALLOWUNDO)` bridge, and the
257
+ command-side rule table.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 deepestevan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,146 @@
1
+ # dsh-delete-guard
2
+
3
+ **English** | [简体中文](README.md) | [日本語](README.ja.md)
4
+
5
+ **An agent cannot delete what it cannot recover.**
6
+
7
+ A deletion has exactly two outcomes here: it lands in the Windows Recycle Bin
8
+ (restorable from Explorer), or it is refused and re-issued as a `file_trash`
9
+ call. There is no third one.
10
+
11
+ ```
12
+ agent: Remove-Item -Recurse -Force .\src
13
+ refused: The delete guard blocked this delete. Re-run this as: file_trash with paths = ["…\src"]
14
+ then: file_trash → moved to the Recycle Bin, "Restore" works
15
+ ```
16
+
17
+ ## The problem
18
+
19
+ In DSH a model's `pwsh` delete erases files outright: `ctx.fs` has no delete,
20
+ `ctx.shell` has only `execute()`, and nothing sits in between. One
21
+ `Remove-Item -Recurse -Force` takes a directory with it — no bin, no undo.
22
+
23
+ This plugin hooks `tools/pre-execute` (the seam the host actually routes every
24
+ tool call through), **refuses** those calls, and tells the model to use
25
+ `file_trash`. That tool moves items with `SHFileOperationW(FOF_ALLOWUNDO)` — the
26
+ same Win32 call Explorer uses — so the `$I`/`$R` metadata in `$Recycle.Bin` is
27
+ correct and Restore works.
28
+
29
+ Coverage goes past `Remove-Item`: pipelines, `xargs`, variable-built targets,
30
+ `if { }` blocks, inline `-Command` / `-EncodedCommand`, the persistent terminal,
31
+ Git Bash `/c/...` paths, and every spelling of emptying the bin.
32
+
33
+ ## Install
34
+
35
+ ```shell
36
+ # from npm
37
+ dsh plugin --profile web add dsh-delete-guard
38
+ # or straight from the repository
39
+ dsh plugin --profile web add github:deepestevan/dsh-delete-guard
40
+ # or from a local tarball (when you have changed the source)
41
+ pnpm pack --pack-destination ./temp/pack # bump `version` first
42
+ dsh plugin --profile web add file:./temp/pack/dsh-delete-guard-2.2.2.tgz
43
+ # restart dsh web: lib/*.js is loaded at process start
44
+ ```
45
+
46
+ Update with `remove` then `add`: a lone `add` can answer `Already up to date` and change
47
+ nothing, and `lib/*.js` is only reloaded when the process restarts.
48
+
49
+ ## What it blocks
50
+
51
+ **Redirected into the Recycle Bin**
52
+
53
+ ```
54
+ Remove-Item C:\tmp\a.txt del / erase / rd / rmdir / rm / unlink
55
+ Remove-Item -Recurse -Force C:\tmp\dir
56
+ if (Test-Path $p) { Remove-Item $p -Force }
57
+ terminal_send: "Remove-Item C:\tmp\a.txt"
58
+ ```
59
+
60
+ **Refused outright**
61
+
62
+ | Category | Examples |
63
+ | --- | --- |
64
+ | Targets that cannot be proven | `Remove-Item $(…)`, `… \| Remove-Item`, `xargs rm`, `Remove-Item @targets`, `-Recurse C:\tmp\*` |
65
+ | Dangerous paths | `C:\`, `\`, `C:\Windows`, `Program Files`, `..\..\`, Git Bash `~` and `/tmp` |
66
+ | Erases with no delete verb | `[System.IO.File]::Delete(…)`, `Invoke-Expression "…"`, `cmd /c del`, `robocopy /MIR`, `find -delete` |
67
+ | Permanent-erase tools | `shred`, `sdelete`, `srm`, `cipher /w`, `format X:` (matched in program position only) |
68
+ | Emptying the bin | `Clear-RecycleBin` (bare, `&`, child shell, `-EncodedCommand`), `SHEmptyRecycleBin`, driving bin items' shell verbs, deleting `$Recycle.Bin` contents |
69
+ | Locations without a bin | UNC shares and exFAT/FAT32 volumes, where "recycling" is a permanent erase |
70
+ | Deletes inside scripts | shell / Python / Node inline bodies, and writing delete text into `.ps1`/`.sh`/`.py` |
71
+
72
+ **Allowed**: read-only work, commands that only mention a delete word
73
+ (`Select-String -Pattern "Remove-Item"`, `Get-Content shred.exe`), and
74
+ **restoring** files out of the bin.
75
+
76
+ ## Two tools
77
+
78
+ | Tool | Purpose |
79
+ | --- | --- |
80
+ | `file_trash { paths, reason? }` | The only permitted way to delete. Moves to the Recycle Bin, reports per-path results, never falls back to a permanent erase |
81
+ | `trash_status { drive? }` | Item count and byte size of the bin on a volume, to confirm a deletion landed |
82
+
83
+ ## Configuration
84
+
85
+ Override in the profile's `cordis.patch.yml` (`config` is replaced as a whole
86
+ block — restate every key you want to keep):
87
+
88
+ | Key | Default | Meaning |
89
+ | --- | --- | --- |
90
+ | `enabled` | `true` | Master switch |
91
+ | `blockDestructiveCommands` | `true` | Intercept shell deletes and redirect to `file_trash` |
92
+ | `forbidEmptyRecycleBin` | `true` | Refuse emptying or modifying the bin |
93
+ | `forbidWipe` | `true` | Refuse `shred` / `sdelete` / `srm` / `cipher /w` / `format` |
94
+ | `blockScriptDeletes` | `true` | Refuse deletes in script files and inline strings |
95
+
96
+ ## Restoring a deleted file
97
+
98
+ Restoring is not a plugin feature and needs none: the bin belongs to the OS.
99
+ Explorer's right-click "Restore" works. From a script, read the
100
+ `X:\$Recycle.Bin\<SID>\$I*` records (offset 24 = original path length in chars,
101
+ offset 28 = UTF-16LE path), match the one you want, and `Move-Item` its paired `$R`
102
+ file back. The `$R`/`$I` names are random, so those records are the only index;
103
+ skip any whose payload is missing. Do not depend on the localized verb name.
104
+
105
+ ## What it does not cover
106
+
107
+ | Not covered | Why |
108
+ | --- | --- |
109
+ | Deletes already inside a script file | The guard never sees the body; it refuses the write and the inline forms it can see |
110
+ | Arbitrary C# through `Add-Type` (e.g. `DeleteFileW`) | Out of reach for text matching; only the bin-specific API is named and blocked |
111
+ | A command name assembled into a variable, then `& $c` | Cannot be evaluated textually |
112
+ | Execution channels outside the tool list (custom-named shells, third-party plugins) | The list is explicit — see below |
113
+ | A delete split across two terminal sends | Each send is judged on its own text |
114
+ | Non-Windows platforms | The bridge is `SHFileOperationW` |
115
+ | Free-space exhaustion | A same-volume NTFS recycle is a rename and consumes no space, so there is nothing to pre-check |
116
+
117
+ Covered shell tools: `pwsh`, `powershell`, `cmd`, `bash`, `sh`, `zsh`, `shell`,
118
+ `terminal_send`, `terminal_write`. Reasoning and measurements:
119
+ the decision is made on the statement's command word, the shape of the call, and program position — never on a word appearing somewhere in the line.
120
+
121
+ ## Tests
122
+
123
+ ```shell
124
+ node test/run-all.mjs
125
+ ```
126
+
127
+ 90 cases across five layers: command classification (49), `file_trash` operand
128
+ guard (15), host schema + hook wiring (11), host schema acceptance (5), live
129
+ end-to-end against the real Recycle Bin (10). `test/` is not shipped in the
130
+ tarball, so it must be green before packing; two layers load the host's own
131
+ validators and report **skipped** (not failed) where no DSH install exists.
132
+
133
+ ## Documentation
134
+
135
+ | File | Contents |
136
+ | --- | --- |
137
+ | [CHANGELOG.md](CHANGELOG.md) | Version summaries |
138
+ | [SECURITY.md](SECURITY.md) | Threat model: a policy layer, not a sandbox |
139
+ | [LICENSE](LICENSE) | MIT |
140
+
141
+ Design rationale, the per-round measurements and the release runbook are engineering
142
+ notes kept by the maintainer; they are not part of this repository or package.
143
+
144
+ ## License
145
+
146
+ MIT — see [LICENSE](LICENSE).
package/README.ja.md ADDED
@@ -0,0 +1,143 @@
1
+ # dsh-delete-guard
2
+
3
+ [English](README.en.md) | [简体中文](README.md) | **日本語**
4
+
5
+ **復元できないものは、エージェントに消させない。**
6
+
7
+ 削除の結果は 2 つだけです。Windows のごみ箱に入る(エクスプローラーから元に戻せる)
8
+ か、拒否されて `file_trash` 呼び出しに置き換わるか。それ以外はありません。
9
+
10
+ ```
11
+ agent: Remove-Item -Recurse -Force .\src
12
+ 拒否: The delete guard blocked this delete. Re-run this as: file_trash with paths = ["…\src"]
13
+ その後: file_trash → ごみ箱へ移動。「元に戻す」が使える
14
+ ```
15
+
16
+ ## 何を解決するか
17
+
18
+ DSH では、モデルが `pwsh` で削除を実行するとファイルはそのまま消えます。`ctx.fs` に
19
+ delete は無く、`ctx.shell` にあるのは `execute()` だけで、その間に何も挟まりません。
20
+ `Remove-Item -Recurse -Force` の一言でディレクトリごと消え、ごみ箱も取り消しもありません。
21
+
22
+ 本プラグインは `tools/pre-execute`(ホストがすべてのツール呼び出しを通す接点)にフックし、
23
+ そうした呼び出しを**拒否**して、`file_trash` を使うようモデルに伝えます。`file_trash` は
24
+ `SHFileOperationW(FOF_ALLOWUNDO)` で移動します——エクスプローラーと同じ Win32 API なので、
25
+ `$Recycle.Bin` の `$I`/`$R` メタデータが正しく作られ、「元に戻す」が機能します。
26
+
27
+ 対象は `Remove-Item` だけではありません。パイプ、`xargs`、変数で組み立てた対象、
28
+ `if { }` 内の削除、インラインの `-Command` / `-EncodedCommand`、永続ターミナル、
29
+ Git Bash の `/c/...` パス、ごみ箱を空にするあらゆる書き方に規則があります。
30
+
31
+ ## インストール
32
+
33
+ ```shell
34
+ # npm から導入
35
+ dsh plugin --profile web add dsh-delete-guard
36
+ # またはリポジトリから直接
37
+ dsh plugin --profile web add github:deepestevan/dsh-delete-guard
38
+ # またはローカルの tarball から(ソースを変更したとき)
39
+ pnpm pack --pack-destination ./temp/pack # 先に package.json の version を上げる
40
+ dsh plugin --profile web add file:./temp/pack/dsh-delete-guard-2.2.2.tgz
41
+ # dsh web を再起動(lib/*.js はプロセス起動時に読み込まれる)
42
+ ```
43
+
44
+ 更新は `remove` → `add` の 2 段階です。`add` だけだと `Already up to date` を返して何も
45
+ 変わらないことがあり、`lib/*.js` はプロセス再起動でしか読み直されません。
46
+
47
+ ## 何を止めるか
48
+
49
+ **ごみ箱へ誘導される**
50
+
51
+ ```
52
+ Remove-Item C:\tmp\a.txt del / erase / rd / rmdir / rm / unlink
53
+ Remove-Item -Recurse -Force C:\tmp\dir
54
+ if (Test-Path $p) { Remove-Item $p -Force }
55
+ terminal_send: "Remove-Item C:\tmp\a.txt"
56
+ ```
57
+
58
+ **そのまま拒否する**
59
+
60
+ | 区分 | 例 |
61
+ | --- | --- |
62
+ | 対象を証明できない | `Remove-Item $(…)`、`… \| Remove-Item`、`xargs rm`、`Remove-Item @targets`、`-Recurse C:\tmp\*` |
63
+ | 危険なパス | `C:\`、`\`、`C:\Windows`、`Program Files`、`..\..\`、Git Bash の `~` と `/tmp` |
64
+ | 削除動詞を伴わない消去 | `[System.IO.File]::Delete(…)`、`Invoke-Expression "…"`、`cmd /c del`、`robocopy /MIR`、`find -delete` |
65
+ | 完全消去ツール | `shred`、`sdelete`、`srm`、`cipher /w`、`format X:`(プログラム位置のみで判定) |
66
+ | ごみ箱の空化 | `Clear-RecycleBin`(素の形・`&`・子シェル・`-EncodedCommand`)、`SHEmptyRecycleBin`、ごみ箱項目のシェル動詞、`$Recycle.Bin` 配下の直接削除 |
67
+ | ごみ箱が無い場所 | UNC 共有と exFAT/FAT32 ボリューム(そこで「ごみ箱へ」は完全消去と同じ) |
68
+ | スクリプト内の削除 | シェル / Python / Node のインライン本体、および削除語を含むテキストの `.ps1`/`.sh`/`.py` への書き込み |
69
+
70
+ **許可される**:読み取り専用の作業、削除語に言及するだけのコマンド
71
+ (`Select-String -Pattern "Remove-Item"`、`Get-Content shred.exe`)、そしてごみ箱から
72
+ の**復元**。
73
+
74
+ ## 2 つのツール
75
+
76
+ | ツール | 役割 |
77
+ | --- | --- |
78
+ | `file_trash { paths, reason? }` | 唯一許可された削除手段。ごみ箱へ移動し、パスごとに結果を報告し、完全削除へフォールバックしない |
79
+ | `trash_status { drive? }` | そのボリュームのごみ箱の項目数とバイト数。削除が本当に入ったかの確認に使う |
80
+
81
+ ## 設定
82
+
83
+ プロファイルの `cordis.patch.yml` で上書きします(`config` はブロックごと置き換わるので、
84
+ 残したいキーはすべて書き直す):
85
+
86
+ | キー | 既定値 | 意味 |
87
+ | --- | --- | --- |
88
+ | `enabled` | `true` | 全体スイッチ |
89
+ | `blockDestructiveCommands` | `true` | シェル削除を横取りし `file_trash` へ誘導 |
90
+ | `forbidEmptyRecycleBin` | `true` | ごみ箱の空化・改変を拒否 |
91
+ | `forbidWipe` | `true` | `shred` / `sdelete` / `srm` / `cipher /w` / `format` を拒否 |
92
+ | `blockScriptDeletes` | `true` | スクリプトファイルとインライン文字列内の削除を拒否 |
93
+
94
+ ## 消したファイルを戻す
95
+
96
+ 復元はプラグインの機能ではなく、必要でもありません。ごみ箱は OS のものです。
97
+ エクスプローラーの右クリック「元に戻す」で戻せます。スクリプトからは
98
+ `X:\$Recycle.Bin\<SID>\$I*` のレコードを読み(オフセット 24 が元パスの文字数、
99
+ オフセット 28 から UTF-16LE のパス)、目的のものを探して対になる `$R` を
100
+ `Move-Item` で戻します。`$R`/`$I` の名前はランダムなので、そのレコードが唯一の索引です。
101
+ payload が無いレコードは飛ばし、ローカライズされた動詞名には依存しないこと。
102
+
103
+ ## 何を守らないか
104
+
105
+ | 対象外 | 理由 |
106
+ | --- | --- |
107
+ | スクリプトファイル内に既にある削除 | 本体をガードは見ない。書き込みと、見えるインライン形を拒否するまで |
108
+ | `Add-Type` で書いた任意の C#(`DeleteFileW` など) | テキスト判定の外。ごみ箱専用 API だけは名前で塞ぐ |
109
+ | コマンド名を変数に組み立てて `& $c` | テキストでは評価できない |
110
+ | ツール名リスト外の実行経路(独自名のシェル、第三者プラグイン) | リストは明示的(下記) |
111
+ | ターミナル送信 2 回に分けて組み立てた削除 | 1 回の送信のテキストしか見ていない |
112
+ | Windows 以外 | ブリッジが `SHFileOperationW` |
113
+ | 空き容量の枯渇 | 同一 NTFS ボリューム内のごみ箱移動は rename で、新しい容量を使わない |
114
+
115
+ 対象のシェルツール名:`pwsh`、`powershell`、`cmd`、`bash`、`sh`、`zsh`、`shell`、
116
+ `terminal_send`、`terminal_write`。判定は文の命令語・呼び出しの形・プログラム位置で行い、行内に語が現れたかどうかでは見ません。
117
+
118
+ ## テスト
119
+
120
+ ```shell
121
+ node test/run-all.mjs
122
+ ```
123
+
124
+ 5 層・90 ケース:コマンド分類(49)、`file_trash` オペランドガード(15)、ホストの
125
+ スキーマとフック配線(11)、ホストのスキーマ受理(5)、実ごみ箱に対するエンドツーエンド
126
+ (10)。`test/` は tarball に含まれないので、パック前に緑である必要があります。うち 2 層
127
+ はホスト自身の検証器を読み込むため、DSH のインストールが無い環境では失敗ではなく
128
+ **スキップ**として報告されます。
129
+
130
+ ## ドキュメント
131
+
132
+ | ファイル | 内容 |
133
+ | --- | --- |
134
+ | [CHANGELOG.md](CHANGELOG.md) | バージョン摘要 |
135
+ | [SECURITY.md](SECURITY.md) | 脅威モデル:サンドボックスではなくポリシー層 |
136
+ | [LICENSE](LICENSE) | MIT |
137
+
138
+ 設計の根拠、各回の実測値、リリース手順はメンテナ側のエンジニアリングノートであり、
139
+ このリポジトリにもパッケージにも含まれません。
140
+
141
+ ## ライセンス
142
+
143
+ MIT — [LICENSE](LICENSE)。