delete-guard-agent 0.5.1 → 0.6.1
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/README.md +5 -2
- package/SKILL.md +14 -0
- package/package.json +1 -1
- package/scripts/delete_guard/core.py +41 -1
- package/scripts/delete_guard/paths.py +159 -0
- package/scripts/delete_guard/rules/common.py +32 -0
package/README.md
CHANGED
|
@@ -134,8 +134,11 @@ python scripts/guard.py command "rm -rf /mnt/d/data" --json
|
|
|
134
134
|
| H11 | 目标是系统关键前缀(/usr /etc /bin /home…) | Linux | block |
|
|
135
135
|
| H12 | 目标是挂载点(删除作用于整个卷) | Linux/macOS | block |
|
|
136
136
|
| H13 | 目标是 macOS 家目录特殊目录(Documents/Library…) | macOS | block |
|
|
137
|
-
| H14 | 云/容器/ORM 工具破坏性动词(terraform destroy、prisma migrate reset、docker
|
|
137
|
+
| H14 | 云/容器/ORM 工具破坏性动词(terraform destroy、prisma migrate reset、docker 卷/容器删除、kubectl delete namespace、SQL DROP) | 全平台 | warn/block |
|
|
138
138
|
| H15 | 覆盖型销毁(通配 mv/cp 落入已存在目录、`>` 重定向清空非空文件) | 全平台 | warn |
|
|
139
|
+
| H16 | 目标是家目录根(`/home`、`/root`、`/home/<u>`、`/Users/<u>`、`C:\Users\<u>`) | 全平台 | block |
|
|
140
|
+
| H17 | 目标是凭据/密钥目录或文件(`.ssh` `.aws` `.gnupg` `.kube` `.docker` `.config/gh`、`id_rsa`、`.netrc`…) | 全平台 | block |
|
|
141
|
+
| H18 | git 还原/重置类动词(`reset --hard`、`restore <pathspec>`、`checkout --`、`stash clear/drop`、`gc --prune=now`、`reflog expire --expire=now`) | 全平台 | warn |
|
|
139
142
|
|
|
140
143
|
## 代码结构(0.2 起拆包;0.3 起 find/git 意图在 core.py 内原生解析)
|
|
141
144
|
|
|
@@ -168,7 +171,7 @@ python -m unittest discover tests -v
|
|
|
168
171
|
以下项已由 CI 的 `ubuntu-latest` / `windows-latest` / `macos-latest` runner
|
|
169
172
|
或真机 E2E 覆盖:
|
|
170
173
|
|
|
171
|
-
- [x] 单元测试(
|
|
174
|
+
- [x] 单元测试(145 个,含 H3/H4/H11-H18/find/git 断言、中文社区与第四/五轮事故回归、预筛一致性比对、过度拦截反例)在
|
|
172
175
|
ubuntu + windows + macos 三个 runner 上跑
|
|
173
176
|
- [x] macOS 真机回归(H3 APFS 大小写、H13 家目录特殊目录)——由
|
|
174
177
|
`macos-latest` runner 真机执行,不再是仅静态判定
|
package/SKILL.md
CHANGED
|
@@ -48,6 +48,20 @@ description: Use before running ANY destructive file operation (rm -rf, rd /s /q
|
|
|
48
48
|
删的是挂载进来的整个卷(rsync --delete 清空备份盘是运维最经典的整卷事故)。
|
|
49
49
|
8. **非判定宿主的平台语义不算数。** 在 WSL 里看不到 NTFS reparse 属性、
|
|
50
50
|
在 Linux 上验证不了 APFS 大小写语义。判定结果为"无法验证"时,去目标平台复跑。
|
|
51
|
+
9. **家目录和凭据目录不在"可清理"范围内,永远(判定器 H16/H17)。** `/home`、`/root`、
|
|
52
|
+
`/home/<user>`、`/Users/<user>`、`C:\Users\<user>` 是"这个人在机器上的
|
|
53
|
+
全部身份";`.ssh`、`.aws`、`.gnupg`、`.kube`、`.docker`、`.config/gh`、
|
|
54
|
+
`.netrc`、`id_rsa` 删除不可逆,私钥还必须按已泄露处理。事故:
|
|
55
|
+
claude-code#83058(~200GB 家目录)、STUPID-2026-0128(SSH/AWS/GH 凭据全毁)、
|
|
56
|
+
deepseek-harness#13675(%USERPROFILE% 下 86k 文件)。清理"缓存/临时文件"时,
|
|
57
|
+
路径必须显式落在具体项目目录内,且不得向上用 `..` 或家目录变量兜底。
|
|
58
|
+
10. **“恢复”动作比事故本身更容易毁掉剩下的东西(判定器 H18)。**
|
|
59
|
+
`git reset --hard`、`git restore <pathspec>`、`git checkout -- .`、
|
|
60
|
+
`git stash clear/drop`、`git gc --prune=now`、`git reflog expire --expire=now`
|
|
61
|
+
都不删路径,只把工作树与 index 写回 —— 未提交改动与未跟踪文件瞬间不可恢复。
|
|
62
|
+
事故现场还在时先停手:先 `git stash push` 或把目录整体复制一份,再谈清理。
|
|
63
|
+
claude-code#84829 里 agent 正是一次目录作用域的 `git restore`
|
|
64
|
+
把另一个 agent 的 rm 事故现场一起还原掉了,而它刚陈述过 bulk-op 教训。
|
|
51
65
|
|
|
52
66
|
## 操作流程
|
|
53
67
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "delete-guard-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Blast-radius judge for destructive commands on Windows, Linux and macOS: blocks filesystem-root and volume-root deletes, quote-chain degradation, NTFS/APFS case collisions, junction and symlink traversal, sudo-escalated deletes, system-prefix wipes and mount-point deletions before the agent executes them.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "xinghe-labs",
|
|
@@ -10,6 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
import ntpath
|
|
11
11
|
import os
|
|
12
12
|
import re
|
|
13
|
+
import time
|
|
13
14
|
from dataclasses import dataclass, field
|
|
14
15
|
|
|
15
16
|
from .paths import (
|
|
@@ -28,8 +29,10 @@ from .paths import (
|
|
|
28
29
|
SHELL_LAUNCHERS,
|
|
29
30
|
analysis_path,
|
|
30
31
|
cloud_tool_match,
|
|
32
|
+
git_destructive_match,
|
|
31
33
|
glob_base_dir,
|
|
32
34
|
has_cjk,
|
|
35
|
+
home_destruction,
|
|
33
36
|
human_bytes,
|
|
34
37
|
is_ancestor_of_cwd,
|
|
35
38
|
is_drive_root,
|
|
@@ -500,7 +503,9 @@ def case_collision(path: str, windows_layout: bool | None = None) -> str | None:
|
|
|
500
503
|
return None
|
|
501
504
|
|
|
502
505
|
|
|
503
|
-
def walk_blast_radius(
|
|
506
|
+
def walk_blast_radius(
|
|
507
|
+
path: str, max_entries: int = 20000, time_budget_s: float = 0.15
|
|
508
|
+
) -> BlastRadius:
|
|
504
509
|
br = BlastRadius(target=path)
|
|
505
510
|
if not os.path.exists(path):
|
|
506
511
|
br.note = "目标不存在(若命令仍会执行,说明路径在别处被改写过)"
|
|
@@ -518,7 +523,15 @@ def walk_blast_radius(path: str, max_entries: int = 20000) -> BlastRadius:
|
|
|
518
523
|
|
|
519
524
|
stack = [path]
|
|
520
525
|
seen = 0
|
|
526
|
+
# 时间预算:爆炸半径只作参考信息、不参与 verdict 分级,而判定跑在 hook
|
|
527
|
+
# 的同步路径上。WSL/9p 这类慢文件系统上单次 stat 可达毫秒级,
|
|
528
|
+
# `rm -rf ../..` 曾耗时 6-19s(INCIDENTS.md 第五轮结论)。超预算即截断,
|
|
529
|
+
# 宁可报“统计已截断”也不能拖住 agent。
|
|
530
|
+
deadline = time.monotonic() + time_budget_s
|
|
521
531
|
while stack:
|
|
532
|
+
if time.monotonic() > deadline:
|
|
533
|
+
br.truncated = True
|
|
534
|
+
break
|
|
522
535
|
cur = stack.pop()
|
|
523
536
|
try:
|
|
524
537
|
with os.scandir(cur) as it:
|
|
@@ -590,6 +603,11 @@ def is_mount_point(path: str) -> bool:
|
|
|
590
603
|
# ---------------------------------------------------------------------------
|
|
591
604
|
|
|
592
605
|
|
|
606
|
+
def _home_code(kind: str) -> str:
|
|
607
|
+
"""home_destruction 的类别 → 规则码。"""
|
|
608
|
+
return "H17_CREDENTIAL_TARGET" if kind == "cred" else "H16_HOME_ROOT"
|
|
609
|
+
|
|
610
|
+
|
|
593
611
|
def judge_command(
|
|
594
612
|
command: str,
|
|
595
613
|
cwd: str | None = None,
|
|
@@ -743,6 +761,15 @@ def judge_command(
|
|
|
743
761
|
# 事故依据进 evidence(动态命中形态专属依据与规则表依据合并)
|
|
744
762
|
hazards[-1].evidence = f"{evidence}"
|
|
745
763
|
|
|
764
|
+
# H18 git 还原/重置类动词(命令级判定):reset --hard / restore <pathspec>
|
|
765
|
+
# / checkout -- / stash clear / gc --prune=now —— 不删路径,只把工作树
|
|
766
|
+
# 写回 index,未提交改动与未跟踪文件瞬间不可恢复。
|
|
767
|
+
git_hit = git_destructive_match(command)
|
|
768
|
+
if git_hit:
|
|
769
|
+
shape, evidence = git_hit
|
|
770
|
+
add("H18_GIT_DESTRUCTIVE", repr(shape) + " 把工作树写回 index,未提交改动不可恢复")
|
|
771
|
+
hazards[-1].evidence = evidence
|
|
772
|
+
|
|
746
773
|
# 无目标的合成破坏性动词(git clean -f 默认当前目录):H9 在循环外补发
|
|
747
774
|
if (
|
|
748
775
|
not intent.targets
|
|
@@ -840,6 +867,15 @@ def judge_command(
|
|
|
840
867
|
if special:
|
|
841
868
|
add("H13_MACOS_HOME_SPECIAL", f"{target!r} 命中 macOS 家目录特殊目录 {special}")
|
|
842
869
|
|
|
870
|
+
# H16/H17 家目录根 & 凭据目录/文件:删除即不可逆、无回收余地。
|
|
871
|
+
# 家目录根只在递归删除时成灾(非递归只会 rmdir 失败),凭据目录/文件
|
|
872
|
+
# 即使单文件删除也已不可逆,故不受 recursive 约束。
|
|
873
|
+
hit = home_destruction(ap)
|
|
874
|
+
if hit:
|
|
875
|
+
kind, desc = hit
|
|
876
|
+
if kind == "cred" or intent.recursive:
|
|
877
|
+
add(_home_code(kind), f"{target!r} 命中{desc}")
|
|
878
|
+
|
|
843
879
|
unknowns.extend(unknowns_for_host())
|
|
844
880
|
if any(br.truncated for br in radii):
|
|
845
881
|
unknowns.append("爆炸半径统计已达上限,实际文件数更多")
|
|
@@ -886,6 +922,10 @@ def judge_path(path: str, cwd: str | None = None) -> dict:
|
|
|
886
922
|
special = macos_home_special(ap)
|
|
887
923
|
if special:
|
|
888
924
|
add("H13_MACOS_HOME_SPECIAL", f"{path!r} 命中 macOS 家目录特殊目录 {special}")
|
|
925
|
+
hit = home_destruction(ap)
|
|
926
|
+
if hit:
|
|
927
|
+
kind, desc = hit
|
|
928
|
+
add(_home_code(kind), f"{path!r} 命中{desc}")
|
|
889
929
|
|
|
890
930
|
unknowns.extend(unknowns_for_host())
|
|
891
931
|
|
|
@@ -201,6 +201,60 @@ def has_cjk(s: str) -> bool:
|
|
|
201
201
|
return False
|
|
202
202
|
|
|
203
203
|
|
|
204
|
+
# H16 家目录 / 凭据目录:递归删除这里 = 毁掉一个人在机器上的全部身份
|
|
205
|
+
# (SSH/AWS/GitHub 凭据、未备份的工作成果)。依据见 INCIDENTS.md 候选 21-23:
|
|
206
|
+
# 家目录整体 ~200GB(claude-code#83058)、700GB 主目录、
|
|
207
|
+
# %USERPROFILE% 下 86k 文件(deepseek-harness#13675)、~/.ssh 全毁。
|
|
208
|
+
POSIX_HOME_ROOTS = {"home", "root"}
|
|
209
|
+
|
|
210
|
+
# 凭据/密钥目录:按段序列匹配,不限前缀(~/.ssh、/home/u/.ssh、C:\Users\u\.ssh 同判)
|
|
211
|
+
CREDENTIAL_DIRS = {
|
|
212
|
+
(".ssh",), (".aws",), (".gnupg",), (".pki",), (".kube",), (".docker",),
|
|
213
|
+
(".config", "gh"), (".config", "gcloud"),
|
|
214
|
+
}
|
|
215
|
+
# 单个凭据文件(删掉一个私钥同样是不可逆的凭据丢失)
|
|
216
|
+
CREDENTIAL_FILES = {
|
|
217
|
+
".netrc", ".git-credentials", ".npmrc", ".pypirc",
|
|
218
|
+
"id_rsa", "id_ed25519", "id_ecdsa",
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def home_destruction(path: str) -> tuple[str, str] | None:
|
|
223
|
+
"""H16/H17:目标是家目录根本身、或家目录下的凭据目录/文件。
|
|
224
|
+
|
|
225
|
+
返回 ("home" | "cred", 描述文本),否则 None。
|
|
226
|
+
入参应是归一后的形态(analysis_path 已展开 ~ / $HOME / %USERPROFILE%)。
|
|
227
|
+
"""
|
|
228
|
+
p = path.strip().strip("'\"")
|
|
229
|
+
if not p:
|
|
230
|
+
return None
|
|
231
|
+
norm = p.replace("\\", "/")
|
|
232
|
+
# 盘符路径(C:/Users/...)与 POSIX 路径共用 split,但跳过驱动器段
|
|
233
|
+
segs = [s for s in norm.split("/") if s and not (len(s) == 2 and s[1] == ":")]
|
|
234
|
+
if not segs:
|
|
235
|
+
return None
|
|
236
|
+
low = [s.lower() for s in segs]
|
|
237
|
+
|
|
238
|
+
# 1) POSIX 家目录根:/home、/root、/home/<user>
|
|
239
|
+
if len(low) == 1 and low[0] in POSIX_HOME_ROOTS:
|
|
240
|
+
return "home", f"家目录根 `/{low[0]}`(所有用户数据与凭据)"
|
|
241
|
+
# 2) 家目录根:/home/<user>、/Users/<user>、C:\\Users\\<user>(恰好两段)
|
|
242
|
+
if len(low) == 2 and low[0] in ("home", "users"):
|
|
243
|
+
return "home", f"家目录根 `/{segs[0]}/{segs[1]}`(全部个人数据与凭据)"
|
|
244
|
+
|
|
245
|
+
# 3) 凭据目录:任一段序列命中 CREDENTIAL_DIRS
|
|
246
|
+
for cred in CREDENTIAL_DIRS:
|
|
247
|
+
n = len(cred)
|
|
248
|
+
for i in range(len(low) - n + 1):
|
|
249
|
+
if tuple(low[i:i + n]) == cred:
|
|
250
|
+
shown = segs[i] if n == 1 else "/".join(segs[i:i + n])
|
|
251
|
+
return "cred", f"凭据/密钥目录 `{shown}`"
|
|
252
|
+
# 4) 凭据文件
|
|
253
|
+
if low[-1] in CREDENTIAL_FILES:
|
|
254
|
+
return "cred", f"凭据文件 `{segs[-1]}`"
|
|
255
|
+
return None
|
|
256
|
+
|
|
257
|
+
|
|
204
258
|
def same_path(a: str, b: str) -> bool:
|
|
205
259
|
"""大小写敏感的字面比较(H3 用)。
|
|
206
260
|
|
|
@@ -374,6 +428,15 @@ def cloud_tool_match(command: str) -> tuple[str, str] | None:
|
|
|
374
428
|
if "--help" in norm or " -h " in norm:
|
|
375
429
|
return None
|
|
376
430
|
# SQL 破坏语句优先于工具表匹配(TRUNCATE/DROP 的破坏语义精确,block 级)
|
|
431
|
+
# docker 容器级删除:容器文件系统与日志随之销毁(STUPID-2026-0133 /
|
|
432
|
+
# claude-code#101241:用户只授权 restart,agent 跑了 docker rm,毁掉
|
|
433
|
+
# 唯一一份待诊断的崩溃日志)。不作用于卷,所以只 warn。
|
|
434
|
+
# 用 \b(?!i) 排除 docker rmi(删镜像,可重建,不是数据销毁)。
|
|
435
|
+
if re.search(r"\bdocker(\s+container)?\s+rm\b(?!i)", norm):
|
|
436
|
+
return "docker rm", "STUPID-2026-0133 (claude-code#101241)"
|
|
437
|
+
if re.search(r"\bdocker\s+container\s+prune\b", norm):
|
|
438
|
+
return "docker container prune", "STUPID-2026-0133 (claude-code#101241)"
|
|
439
|
+
|
|
377
440
|
sql_stmt = re.search(r"\b(drop\s+(table|database|schema)\b|truncate\b)", norm)
|
|
378
441
|
sql_client = re.search(
|
|
379
442
|
r"\b(psql|mysql|mariadb|sqlite3|sqlcmd|neon|supabase)\b"
|
|
@@ -403,6 +466,102 @@ def cloud_tool_match(command: str) -> tuple[str, str] | None:
|
|
|
403
466
|
return None
|
|
404
467
|
|
|
405
468
|
|
|
469
|
+
# git 的还原/重置类动词:不删路径,只把工作树与 index 写回。
|
|
470
|
+
# 它们不在任何"删除"词表里,却是事故后二次毁灭的主力动作
|
|
471
|
+
# (INCIDENTS.md 候选 32/33:claude-code#84829 用 git restore 把另一个
|
|
472
|
+
# agent 的 rm 事故现场一起还原掉)。
|
|
473
|
+
_GIT_SEG_SPLIT = re.compile(r"&&|\|\||;|\n|\|")
|
|
474
|
+
_GIT_GLOBAL_FLAGS_WITH_ARG = {"-c", "-C", "--git-dir", "--work-tree", "--namespace"}
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
def _git_segments(norm: str) -> list[list[str]]:
|
|
478
|
+
"""把命令拆成 shell 段,返回每段里 git 之后的子命令 token 列表。"""
|
|
479
|
+
out: list[list[str]] = []
|
|
480
|
+
for seg in _GIT_SEG_SPLIT.split(norm):
|
|
481
|
+
toks = seg.split()
|
|
482
|
+
for i, tok in enumerate(toks):
|
|
483
|
+
base = tok.replace("\\", "/").rsplit("/", 1)[-1]
|
|
484
|
+
if base in {"git", "git.exe"}:
|
|
485
|
+
out.append(toks[i + 1 :])
|
|
486
|
+
break
|
|
487
|
+
return out
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _git_sub_destructive(rest: list[str]) -> tuple[str, str] | None:
|
|
491
|
+
"""单个 git 段的破坏性判定;rest 为 git 之后的 token(保留大小写)。"""
|
|
492
|
+
idx = 0
|
|
493
|
+
# 跳过 -C <path> / -c key=value 这类带参数的全局选项
|
|
494
|
+
while idx < len(rest) and rest[idx] in _GIT_GLOBAL_FLAGS_WITH_ARG:
|
|
495
|
+
idx += 2
|
|
496
|
+
while idx < len(rest) and rest[idx].startswith("-"):
|
|
497
|
+
idx += 1
|
|
498
|
+
if idx >= len(rest):
|
|
499
|
+
return None
|
|
500
|
+
sub = rest[idx].lower()
|
|
501
|
+
args = rest[idx + 1 :]
|
|
502
|
+
|
|
503
|
+
if sub == "reset":
|
|
504
|
+
mode = next((a for a in args if a in {"--hard", "--merge", "--keep"}), None)
|
|
505
|
+
if mode:
|
|
506
|
+
return "git reset " + mode, "claude-code#84829, gist yurukusa 恢复指南"
|
|
507
|
+
return None
|
|
508
|
+
|
|
509
|
+
if sub == "restore":
|
|
510
|
+
# -S/--staged 单独出现只动 index(可反悔);-s/--source 与
|
|
511
|
+
# -W/--worktree 都会把工作树写回,是真正的销毁形态。
|
|
512
|
+
# 注意大小写:git 的 -S 与 -s 语义相反,判定前不能统一小写。
|
|
513
|
+
staged = any(a in {"--staged", "-S"} for a in args)
|
|
514
|
+
worktree = any(a in {"--worktree", "-W"} for a in args)
|
|
515
|
+
source = any(
|
|
516
|
+
a == "--source" or a.startswith("--source=") or a == "-s" for a in args
|
|
517
|
+
)
|
|
518
|
+
if not args or (staged and not worktree and not source):
|
|
519
|
+
return None
|
|
520
|
+
return "git restore <pathspec>", "claude-code#84829"
|
|
521
|
+
|
|
522
|
+
if sub == "checkout":
|
|
523
|
+
# checkout -- <path> / checkout . / checkout -f:把工作树写回 index
|
|
524
|
+
if "--" in args:
|
|
525
|
+
return "git checkout -- <pathspec>", "claude-code#84829"
|
|
526
|
+
if any(a in {"-f", "--force"} for a in args):
|
|
527
|
+
return "git checkout -f", "claude-code#84829"
|
|
528
|
+
# 无分支名、只给路径(. 或 ./ 或 :/):git 视为还原工作树
|
|
529
|
+
pathspecs = [a for a in args if not a.startswith("-")]
|
|
530
|
+
if pathspecs and all(p in {".", "./", ":/", ".."} for p in pathspecs):
|
|
531
|
+
return "git checkout " + pathspecs[0], "claude-code#84829"
|
|
532
|
+
return None
|
|
533
|
+
|
|
534
|
+
if sub == "stash" and args and args[0].lower() in {"clear", "drop"}:
|
|
535
|
+
return "git stash " + args[0].lower(), "claude-code#84829, gist yurukusa 恢复指南"
|
|
536
|
+
|
|
537
|
+
if sub == "gc" and any(a == "--prune=now" or a == "--prune" for a in args):
|
|
538
|
+
# --prune=now 把不可达对象立即清掉,reflog 兜底路径失效
|
|
539
|
+
return "git gc --prune=now", "gist yurukusa 恢复指南"
|
|
540
|
+
|
|
541
|
+
if sub == "reflog" and args and args[0].lower() == "expire" and any(
|
|
542
|
+
a in {"--expire=now", "--expire-unreachable=now"} for a in args
|
|
543
|
+
):
|
|
544
|
+
return "git reflog expire --expire=now", "gist yurukusa 恢复指南"
|
|
545
|
+
|
|
546
|
+
return None
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def git_destructive_match(command: str) -> tuple[str, str] | None:
|
|
550
|
+
"""H18:git 还原/重置类破坏性动词。返回 (命中形态, 事故依据) 或 None。"""
|
|
551
|
+
# 保留大小写:git 的 -S(--staged)与 -s(--source)语义相反
|
|
552
|
+
norm = _norm_cmd_preserve_case(command)
|
|
553
|
+
# 只读勘察命令里的命中词只是被搜索的文本(`git log --grep="reset --hard"`)
|
|
554
|
+
if _readonly_head(norm):
|
|
555
|
+
return None
|
|
556
|
+
if "--help" in norm or " -h " in norm:
|
|
557
|
+
return None
|
|
558
|
+
for rest in _git_segments(norm):
|
|
559
|
+
hit = _git_sub_destructive(rest)
|
|
560
|
+
if hit:
|
|
561
|
+
return hit
|
|
562
|
+
return None
|
|
563
|
+
|
|
564
|
+
|
|
406
565
|
def glob_base_dir(path: str) -> str | None:
|
|
407
566
|
"""返回 glob 目标的「可确定前缀」目录:从最右段开始剥掉通配符所在段。
|
|
408
567
|
|
|
@@ -57,4 +57,36 @@ RULES_COMMON: dict[str, tuple[str, str, str]] = {
|
|
|
57
57
|
"目标解析错误时没有任何回收余地",
|
|
58
58
|
"macrumors#1176135 (sudo rm -R / .Spotlight-v100), steam-for-linux 2015",
|
|
59
59
|
),
|
|
60
|
+
# H16/H17:家目录根与凭据目录 —— 删除它们等于抹掉一个人在机器上的
|
|
61
|
+
# 全部身份(私钥、云凭据、未备份的成果)。事故链见 INCIDENTS.md 候选 21-23:
|
|
62
|
+
# ~200GB 家目录(claude-code#83058)、700GB 主目录、%USERPROFILE% 下
|
|
63
|
+
# 86k 文件(deepseek-harness#13675)、~/.ssh 全毁(私钥须按泄露处理)。
|
|
64
|
+
"H16_HOME_ROOT": (
|
|
65
|
+
"block",
|
|
66
|
+
"目标是家目录根本身(/home、/root、/home/<user>、/Users/<user>、"
|
|
67
|
+
"C:\\Users\\<user>),删除会毁掉整台机器上的个人数据与全部凭据",
|
|
68
|
+
"claude-code#83058 (~200GB home), STUPID-2026-0128, "
|
|
69
|
+
"deepseek-harness#13675 (86k files under %USERPROFILE%)",
|
|
70
|
+
),
|
|
71
|
+
"H17_CREDENTIAL_TARGET": (
|
|
72
|
+
"block",
|
|
73
|
+
"目标是凭据/密钥目录或文件(.ssh/.aws/.gnupg/.kube/.docker、"
|
|
74
|
+
"id_rsa 等),删除不可逆且私钥必须按已泄露处理",
|
|
75
|
+
"STUPID-2026-0128 (SSH/AWS/GH credentials destroyed), "
|
|
76
|
+
"deepseek-harness#13675 (~/.ssh wiped)",
|
|
77
|
+
),
|
|
78
|
+
# H18:git 还原/重置类动词 —— 不删路径,只把工作树与 index 写回,
|
|
79
|
+
# 未提交改动与未跟踪文件瞬间不可恢复。任何以"是否删除路径"为中心的
|
|
80
|
+
# 规则都看不见它,而它正是事故后二次毁灭的主力动作。事故链见
|
|
81
|
+
# INCIDENTS.md 候选 32/33(claude-code#84829 用目录作用域的 git restore
|
|
82
|
+
# 把另一个 agent 的 rm 事故现场一起还原掉)。
|
|
83
|
+
"H18_GIT_DESTRUCTIVE": (
|
|
84
|
+
"warn",
|
|
85
|
+
"git 还原/重置类动词(reset --hard、restore <pathspec>、"
|
|
86
|
+
"checkout --、stash clear/drop、gc --prune=now)不删路径,只把"
|
|
87
|
+
"工作树与 index 写回 —— 未提交改动与未跟踪文件不可恢复,"
|
|
88
|
+
"且常被当作事故后的「恢复动作」执行",
|
|
89
|
+
"claude-code#84829 (git restore wiped uncommitted work), "
|
|
90
|
+
"gist yurukusa 恢复指南 (#64615 /rewind, #46444 worktree)",
|
|
91
|
+
),
|
|
60
92
|
}
|