← 返回 Skills 市场
hanxweb

delete-recovery

作者 hanxweb · GitHub ↗ · v0.8.3 · MIT-0
cross-platform ✓ 安全检测通过
342
总下载
1
收藏
1
当前安装
24
版本数
在 OpenClaw 中安装
/install delete-recovery
功能描述
Automatically backs up files before deletion to timestamped folders, allows restoring deleted files, lists backups, and cleans expired backups and logs.
使用说明 (SKILL.md)

中文


概述

文件误删恢复技能 v0.8.0。删除文件前先将文件备份到带时间戳的文件夹(delete_backup/YYYYMMDDHHMM/),备份时计算 SHA256 哈希并存储,恢复时验证完整性并检查路径安全(检测 ../ 等路径遍历序列)。恢复后自动删除备份(保留原始文件结构)。

v0.8.0 新增 workspace_cleaner:

  • 定时(默认24小时)扫描 workspace 下的临时文件和过期文件(默认7天),自动备份后清理
  • 支持白名单配置(文件扩展名/文件名/文件夹名),白名单内不清理
  • 核心文件(AGENTS.md、SOUL.md 等)和技能目录始终保护
  • 支持手动触发 dry-run 预览和强制立即清理
  • 数据文件独立存放于 {workspace}/.delete_recovery/workspace_cleaner/,技能删除后配置仍保留

v0.7.0 安全加固:

  • allowed_roots 默认为 workspace 根目录 — 恢复目标限制在 {workspace} 树内,防止恢复文件到任意路径
  • manifest 路径字段改为 HMAC-SHA256 加密存储 — 原始路径不再明文暴露在 manifest.jsonl

⚠️ 版本说明: v0.1.0~v0.6.0 已淘汰(DEPRECATED),功能说明保留仅供参考。请始终使用 v0.7.0v0.8.0

触发场景

  1. 用户要删除文件,希望先备份
  2. 用户误删了文件,想要恢复
  3. 用户想查看有哪些可用的备份
  4. 用户想手动清理某个备份
  5. 用户想验证备份是否被篡改(不执行恢复)
  6. 用户想通过文件名/功能/路径关键字检索已删除的文件
  7. 用户想自动清理 workspace 下的临时文件和过期文件

触发词: 删除文件、误删恢复、恢复文件、查看备份、清理备份、验证备份完整性、搜索已删除文件、检索删除记录、workspace清理、临时文件清理、定时清理、workspace_cleaner

English

Overview

File deletion recovery skill v0.8.0. Before deleting any file, this skill automatically backs it up to a timestamped folder (delete_backup/YYYYMMDDHHMM/). Backups include SHA256 integrity hashes to detect post-backup tampering. Restore paths are validated to block path-traversal sequences. Backups auto-removed 7 days; logs auto-cleaned 30 days. v0.8.0: Added workspace_cleaner — scheduled temp-file cleanup with auto-backup before deletion. v0.7.0: allowed_roots defaults to workspace root (restores confined) + manifest paths HMAC-encrypted.

v0.8.0 workspace_cleaner: Scheduled (default 24-hour) scan of workspace for temp files and expired files (default 7 days), auto-backup then delete; whitelist support; core files always protected.

⚠️ Version note: v0.1.0~v0.6.0 are deprecated (DEPRECATED). Always use v0.7.0 or v0.8.0.

Trigger Scenarios

  1. User wants to delete a file and needs a backup first
  2. User accidentally deleted a file and wants to recover it
  3. User wants to see available backups
  4. User wants to manually clean up a specific backup
  5. User wants to verify backup integrity without restoring
  6. User wants to search for a deleted file by name or keyword
  7. User wants to schedule automatic workspace cleanup

Triggers: delete file, recover deleted file, list backups, clean up backup, undelete, verify backup, check backup integrity, search deleted file, find deleted file, clean workspace, workspace cleanup, workspace_cleaner

核心命令 / Core Commands

中文

delete_recovery.py — 备份恢复核心

{workspace}/skills/delete-recovery/scripts/delete_recovery.py
命令 说明 备注
backup \x3Cfile_path> [original_path] [description] 备份文件到带时间戳文件夹 v0.7.0
search \x3Ckeyword> 按文件名/简介/路径关键字检索已删除文件 v0.7.0
restore \x3Cfolder> \x3Csafe_name> [--keep-backup] [--force] 从备份恢复文件 v0.7.0
verify \x3Cfolder> \x3Csafe_name> 验证备份完整性(SHA256 + PATH) v0.7.0
list 查看备份列表 v0.7.0
delete_backup \x3Cfolder> 删除指定备份 v0.7.0
cleanup 手动触发过期备份+日志清理 v0.7.0
log [lines] 查看操作日志 v0.7.0

workspace_cleaner.py — workspace 定时清理(v0.8.0 新增)

{workspace}/skills/delete-recovery/scripts/workspace_cleaner.py
命令 说明
python workspace_cleaner.py run 手动触发一次清理(满足时间间隔才执行)
python workspace_cleaner.py dry-run 预览哪些文件将被清理(不实际删除)
python workspace_cleaner.py status 查看定时器状态和配置
python workspace_cleaner.py show-whitelist 查看当前白名单
python workspace_cleaner.py add-whitelist \x3Cpath> [--type file|folder|ext] 添加白名单项
python workspace_cleaner.py remove-whitelist \x3Cpath> 移除白名单项
python workspace_cleaner.py set-interval \x3Chours> 设置清理间隔(小时)
python workspace_cleaner.py set-expire-days \x3Cdays> 设置文件过期天数

English

delete_recovery.py — Backup & Recovery Core

{workspace}/skills/delete-recovery/scripts/delete_recovery.py
Command Description Notes
backup \x3Cfile_path> [original_path] [description] Backup file to timestamped folder v0.7.0
search \x3Ckeyword> Search deleted files by name/description/path v0.7.0
restore \x3Cfolder> \x3Csafe_name> [--keep-backup] [--force] Restore file from backup v0.7.0
verify \x3Cfolder> \x3Csafe_name> Verify backup integrity (SHA256 + PATH) v0.7.0
list List all backups v0.7.0
delete_backup \x3Cfolder> Delete specified backup v0.7.0
cleanup Manual trigger expired backup + log cleanup v0.7.0
log [lines] View operation logs v0.7.0

workspace_cleaner.py — Workspace Scheduled Cleanup (NEW v0.8.0)

{workspace}/skills/delete-recovery/scripts/workspace_cleaner.py
Command Description
python workspace_cleaner.py run Trigger cleanup (respects interval)
python workspace_cleaner.py dry-run Preview files to clean (no actual deletion)
python workspace_cleaner.py status View timer status and config
python workspace_cleaner.py show-whitelist View current whitelist
python workspace_cleaner.py add-whitelist \x3Cpath> [--type file|folder|ext] Add whitelist entry
python workspace_cleaner.py remove-whitelist \x3Cpath> Remove whitelist entry
python workspace_cleaner.py set-interval \x3Chours> Set cleanup interval (hours)
python workspace_cleaner.py set-expire-days \x3Cdays> Set file expiration days

中文

安装

前提条件

  • Python 3.8+
  • 已安装 ClawHub CLI:npm i -g clawhub
  • 已登录 ClawHub:clawhub login

安装步骤

# 通过 ClawHub 安装技能
clawhub install delete-recovery

# 查看已安装的技能
clawhub list

English

Installation

Prerequisites

  • Python 3.8+
  • ClawHub CLI installed: npm i -g clawhub
  • ClawHub logged in: clawhub login

Installation Steps

# Install skill via ClawHub
clawhub install delete-recovery

# List installed skills
clawhub list

delete_recovery.py 命令详解

中文

所有命令通过执行脚本实现,路径:

{workspace}/skills/delete-recovery/scripts/delete_recovery.py

1. 备份文件(删除前必做)

python delete_recovery.py backup \x3Cfile_path> [original_path] [description]
  • file_path:要备份的文件完整路径
  • original_path(可选):原始文件路径,恢复时用于定位,默认为 file_path
  • description(可选):功能简介,建议 ≤6 字,如"飞书配置""工作报告",默认为文件名

备份时自动计算并存储 SHA256 哈希 + 原始路径到 .sha256 文件,防止备份文件被替换。备份后自动将(文件名、功能简介、路径)写入 manifest.jsonl,支持 search 检索。

返回示例:

{"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__test.txt", "description": "工作报告"}

2. 搜索已删除文件

python delete_recovery.py search \x3Ckeyword>

在 manifest.jsonl 中按文件名、功能简介或路径关键字模糊搜索,返回匹配的备份位置和恢复命令。

  • keyword:检索关键词(大小写不敏感, substring 匹配)

返回示例:

{
  "keyword": "报告",
  "results": [
    {
      "ts": "202603281030",
      "folder": "202603281030",
      "safe_name": "C__Users__user__Desktop__report.docx",
      "filename": "report.docx",
      "description": "工作报告",
      "path": "C:/Users/user/Desktop/report.docx"
    }
  ],
  "count": 1
}

3. 恢复文件

python delete_recovery.py restore \x3Cbackup_folder> \x3Csafe_name> [--keep-backup] [--force]
  • backup_folder:备份文件夹名(如 202603261130
  • safe_name:备份文件名(脚本自动将路径中的 /\: 替换为 __
  • --keep-backup:可选,恢复成功后保留该备份文件夹(默认自动删除)
  • --force:强制恢复无 SHA256 记录的旧备份(跳过 SHA256 存在性检查;SHA256 完整性检查和 PATH 验证仍然强制执行)

恢复前验证 SHA256 完整性 + PATH 交叉验证 + 路径遍历检测,任一验证失败均拒绝恢复。

返回示例:

{"ok": true, "restored_to": "C:\\Users\\user\\Desktop\	est.txt", "backup_deleted": true}

多文件批量恢复逻辑: 同一个备份文件夹有多次恢复时,先记录每个已恢复的文件,等全部文件都恢复完毕后才统一清理整个文件夹。

4. 验证备份完整性

python delete_recovery.py verify \x3Cbackup_folder> \x3Csafe_name>

不执行恢复,仅检查备份文件是否被篡改(SHA256 完整性 + PATH 交叉验证)。

返回示例(正常):

{
  "ok": true,
  "hash_match": true,
  "path_match": true,
  "path_check_done": true,
  "integrity_check": true
}

返回示例(被篡改):

{
  "ok": true,
  "hash_match": false,
  "path_match": true,
  "path_check_done": true,
  "integrity_check": false
}

5. 查看备份列表

python delete_recovery.py list

6. 手动删除指定备份

python delete_recovery.py delete_backup \x3Cbackup_folder>

7. 手动触发清理

python delete_recovery.py cleanup

8. 查看操作日志

python delete_recovery.py log [lines]

workspace_cleaner.py 命令详解

中文

workspace_cleaner 是 v0.8.0 新增的 workspace 定时清理工具,扫描并清理临时文件和过期文件,清理前自动通过 delete_recovery 备份。

路径:

{workspace}/skills/delete-recovery/scripts/workspace_cleaner.py

清理规则

类型 判定方式 说明
临时文件 __pycache__.pyc 目录、Thumbs.db 过期后清理
过期文件 按修改时间 > 过期天数 过期后清理
白名单文件/夹/扩展名 用户配置 始终不清理
核心保护文件 硬编码列表 始终不清理
技能目录 skills/delete-recovery/ 始终不清理
.delete_recovery 目录 硬编码 始终不清理

始终保护的核心文件(硬编码,不可覆盖): AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md, HEARTBEAT.md, BOOTSTRAP.md, skills, .learnings, .delete_recovery, workspace_cleaner_whitelist.json, workspace_cleaner_config.json, workspace_cleaner_timer.json, .cleanup_timer

1. 手动触发清理

python workspace_cleaner.py run

满足时间间隔(默认24小时)后执行清理。如需强制立即执行,用 run --force(脚本内不支持,但可修改定时器状态)。

返回示例:

{
  "ok": true,
  "deleted": ["temp/log.txt", "cache/data.json"],
  "backed_up": ["temp/log.txt", "cache/data.json"],
  "errors": [],
  "deleted_count": 2,
  "backed_up_count": 2,
  "expire_days": 7,
  "workspace": "C:\\Users\\user\\.openclaw\\workspace2",
  "run_at": "2026-04-02 16:30:00"
}

2. 预览清理(不实际删除)

python workspace_cleaner.py dry-run

扫描 workspace,返回所有将被清理的文件列表,但不执行删除。适合确认白名单配置是否正确。

返回示例:

{
  "ok": true,
  "dry_run": true,
  "candidates": [["temp/old.txt", 1743000000], ["__pycache__/a.pyc", 1742990000]],
  "candidate_count": 2,
  "skipped": {
    "protected": ["AGENTS.md", "SOUL.md", "skills"],
    "whitelisted": ["important.xlsx", "my_folder"],
    "recent": ["recent.docx"]
  },
  "expire_days": 7,
  "workspace": "C:\\Users\\user\\.openclaw\\workspace2"
}

3. 查看状态

python workspace_cleaner.py status

查看当前配置、定时器状态和上次运行时间。

返回示例:

{
  "ok": true,
  "workspace": "C:\\Users\\user\\.openclaw\\workspace2",
  "extension_dir": "C:\\Users\\user\\.openclaw\\workspace2\\.delete_recovery\\workspace_cleaner",
  "interval_hours": 24,
  "expire_days": 7,
  "auto_backup": true,
  "last_run": "2026-04-01 16:30:00",
  "timer_due": true,
  "whitelist": {"files": [], "folders": [], "exts": []},
  "always_protected_count": 14
}

4. 查看白名单

python workspace_cleaner.py show-whitelist

返回当前白名单内容、始终保护列表及数据文件路径。

5. 添加白名单

python workspace_cleaner.py add-whitelist \x3Cpath> [--type file|folder|ext]
  • --type file:保护指定文件
  • --type folder:保护指定文件夹
  • --type ext:保护指定扩展名(如 .xlsx

示例:

python workspace_cleaner.py add-whitelist ".xlsx" --type ext
python workspace_cleaner.py add-whitelist "projects" --type folder
python workspace_cleaner.py add-whitelist "important.txt" --type file

6. 移除白名单

python workspace_cleaner.py remove-whitelist \x3Cpath>

从白名单中移除指定项(自动识别类型)。

7. 设置清理间隔

python workspace_cleaner.py set-interval \x3Chours>

设置两次自动清理之间的最小时间间隔(小时)。

8. 设置过期天数

python workspace_cleaner.py set-expire-days \x3Cdays>

设置文件过期天数(超过此天数未访问/修改则视为可清理)。

English

workspace_cleaner.py Commands (NEW v0.8.0)

Path:

{workspace}/skills/delete-recovery/scripts/workspace_cleaner.py

Cleanup Rules

Type Detection Description
Temp files __pycache__, .pyc dirs, Thumbs.db, etc. Cleaned when expired
Expired files mtime > expire_days Cleaned when expired
Whitelisted items User-configured Always skipped
Always-protected files Hardcoded list Always skipped
Skill directory skills/delete-recovery/ Always skipped
.delete_recovery directory Hardcoded Always skipped

Always-protected (hardcoded, non-overridable): AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md, HEARTBEAT.md, BOOTSTRAP.md, skills, .learnings, .delete_recovery, workspace_cleaner_whitelist.json, workspace_cleaner_config.json, workspace_cleaner_timer.json, .cleanup_timer

1. Run Cleanup

python workspace_cleaner.py run

Runs cleanup if the interval timer has elapsed. Auto-backs up files before deletion.

2. Dry Run (Preview)

python workspace_cleaner.py dry-run

Shows what would be deleted without actually deleting.

3–8. Status / Whitelist / Interval / Expiry

Same as below.

Agent 行为约束 / Agent Behavior Constraints

中文

【强制要求】Agent 在使用本技能时必须遵守以下约束:

允许的合规操作

Agent 仅被允许执行以下操作:

  1. 删除文件:调用 backup 备份后,执行用户明确授权的文件删除
  2. 恢复文件:调用 restore 从备份恢复误删的文件
  3. 备份查看:调用 list 查看可用备份
  4. 搜索已删除文件:调用 search 通过 manifest.jsonl 检索备份位置
  5. 清理备份:调用 delete_backup 删除指定的过时备份
  6. 恢复误删:调用 restore 恢复用户误删的文件
  7. 验证备份完整性:调用 verify 检查备份是否被篡改
  8. 手动触发清理:调用 cleanup 清理过期备份和日志
  9. workspace_cleaner 管理:管理白名单、设置时间间隔/过期天数、查看状态、触发清理

禁止的不安全操作(绝对禁止)

Agent 绝对不允许通过删除/恢复操作进行以下文件篡改或路径重定向行为:

  1. 文件内容篡改:在备份或恢复过程中修改文件内容
  2. 路径重定向恢复:将文件恢复到用户指定位置以外的目录(尤其是敏感系统目录)
  3. 路径遍历攻击:利用 .. 或其他路径遍历序列将文件恢复至备份区域外
  4. 备份替换攻击:用恶意文件替换合法备份文件后尝试恢复
  5. 绕过 SHA256 完整性验证:用恶意文件替换备份后跳过完整性检查恢复;例外:--force 仅可跳过 SHA256 存在性检查(仅针对 v0.3.0 前旧备份),SHA256 完整性验证本身不可绕过
  6. 未授权文件删除:未经用户明确授权删除任何文件
  7. 日志篡改:修改、删除或伪造操作日志以掩盖不安全行为

安全验证要求

  • 所有 restore 操作必须通过 SHA256 完整性验证、PATH 交叉验证和路径遍历检测;--force 例外:可跳过 SHA256 存在性检查(仅针对 v0.3.0 前旧备份),完整性验证本身不可绕过
  • 验证失败时必须拒绝恢复并报告 SECURITY 级别日志
  • Agent 不得尝试绕过、禁用或忽略任何安全验证机制,唯一的例外是上述 --force 对 SHA256 存在性的豁免

【可选配置】将此安全约束添加到 AGENTS.md,以便 Agent 在执行任何文件删除操作之前先调用 backup 备份。

所有删除操作都必须先备份。无论是你自主运行删除的或用户命令触发的删除还是 workspace_cleaner 发起的文件清理,所有文件都必须在执行删除之前使用 delete-recovery skill 进行备份。这是一条永久性的铁律,不可跳过。

English

【Mandatory】Agents MUST comply with the following constraints when using this skill:

Permitted Operations (Compliant)

Agents are ONLY permitted to perform:

  1. Delete files: Execute user-authorized file deletion after calling backup
  2. Restore files: Call restore to recover accidentally deleted files from backup
  3. List backups: Call list to view available backups
  4. Search deleted files: Call search to locate backups via manifest.jsonl
  5. Clean backups: Call delete_backup to remove specific outdated backups
  6. Undelete: Call restore to recover mistakenly deleted files
  7. Verify backup integrity: Call verify to check if backups have been tampered
  8. Manual cleanup: Call cleanup to purge expired backups and logs
  9. workspace_cleaner management: Manage whitelist, set interval/expiry, check status, trigger cleanup

Prohibited Unsafe Operations (Absolutely Forbidden)

Agents are ABSOLUTELY FORBIDDEN from performing file tampering or path redirection via delete/restore operations:

  1. File content tampering: Modifying file content during backup or restore
  2. Path redirection restore: Restoring files to locations other than user-specified destinations (especially sensitive system directories)
  3. Path traversal attacks: Using .. or other traversal sequences to restore files outside the backup area
  4. Backup substitution attacks: Replacing legitimate backups with malicious files then attempting to restore
  5. Bypassing SHA256 integrity verification: Substituting a malicious backup and bypassing integrity check to restore it; Exception: --force may bypass SHA256 existence check only for pre-v0.3.0 legacy backups — the integrity verification itself is never bypassable
  6. Unauthorized file deletion: Deleting any file without explicit user authorization
  7. Log tampering: Modifying, deleting, or forging operation logs to conceal unsafe behavior

Security Validation Requirements

  • All restore operations MUST pass SHA256 integrity verification, PATH cross-validation, and path traversal detection — except that --force may skip the SHA256 existence check for pre-v0.3.0 legacy backups
  • Restore MUST be rejected with SECURITY level log if any validation fails
  • Agents must NOT attempt to bypass, disable, or ignore any security validation mechanisms — except the documented --force exception for SHA256 existence checks on legacy backups

【Optional Configuration】Add this security constraint to AGENTS.md so that Agent calls backup before performing any file deletion operation

All deletion operations must be backed up first. Whether the deletion is triggered by a user command, initiated by me for file cleanup, or started by workspace_cleaner, all files must be backed up using the delete-recovery skill before executing the deletion. This is a permanent ironclad rule that cannot be skipped.

安全机制 / Security Mechanisms

中文

备份完整性验证(SHA256)

  • backup 时:计算备份文件的 SHA256,存入 .sha256 文件(含 PATH 字段)
  • restore 时:重新计算备份文件的 SHA256,与记录值比对
    • 不匹配 → 拒绝恢复,报告 SECURITY 级别日志
    • SHA256 记录缺失或为空 → 拒绝恢复
    • 防止攻击者备份正常文件后替换为恶意文件再骗取恢复

PATH 交叉验证

  • .sha256 文件中存储原始路径(PATH: 字段)
  • restore 时:将 .sha256 中记录的路径与 .path 文件内容进行交叉验证
    • 不一致 → 拒绝恢复
    • 彻底防止攻击者单独篡改 .path 文件定向到任意位置

--force 路径安全强制验证

  • --force 参数原可跳过所有检查(删除 SHA256 + --force 即可绕过)
  • 修复: --force 跳过 SHA256 存在性检查,但 PATH 交叉验证和路径遍历检测永远执行,即使 SHA256 记录不存在也不例外
  • 关闭了"删除 SHA256 → --force → 完全绕过"这一攻击链路

日志注入防护

  • log() 函数在写入日志前过滤 \ \r[ 字符
  • 防止通过 detail 参数注入伪造的日志行

路径遍历检测

  • restore 时:检测路径中的 .. 成分
    • resolve 后路径与原始路径不一致 → 拒绝恢复
    • 防止利用 ../ 遍历逃逸

安全事件日志

  • 所有安全拦截事件记录为 SECURITY 级别日志,便于审计

workspace_cleaner 安全保障

  • 清理前自动备份:调用 delete_recovery.py backup 备份每个文件,备份失败时自动降级为手动备份(复制到 delete_backup/timestamp/
  • 硬编码核心文件保护AGENTS.mdSOUL.md 等核心文件和技能目录始终免于清理,无法通过白名单覆盖
  • workspace 目录 confinement:仅扫描 {workspace} 目录,不会遍历到 workspace 外部
  • 白名单隔离:用户白名单数据存储在 .delete_recovery/workspace_cleaner/ 下,与备份目录隔离
  • 定时器防滥用:清理必须满足时间间隔才执行(run 命令),防止短时间内重复触发

English

Backup Integrity Verification (SHA256)

  • On backup: Computes SHA256 of the backup file, stores in .sha256 (includes PATH field)
  • On restore: Recomputes SHA256 and compares — mismatch blocks restore with SECURITY log
    • Missing or empty SHA256 record → restore blocked
    • Prevents replacing backup with malicious file after backing up a legitimate one

PATH Cross-Validation

  • .sha256 file stores the original path in a PATH: line
  • On restore: cross-checks the path in .sha256 against the .path file
    • Mismatch → restore blocked
    • Fully prevents attacker from tampering with .path to redirect restore elsewhere

--force PATH Safety Enforcement

  • --force previously allowed bypassing all checks (delete SHA256 + --force = full bypass)
  • Fix: --force bypasses SHA256 existence check, but PATH cross-validation and traversal detection always run, even when SHA256 record is absent
  • Closes the "delete SHA256 → --force → complete bypass" attack chain

Log Injection Prevention

  • log() function strips \ , \r, and [ from detail before writing
  • Prevents injecting fake log entries via a crafted detail parameter

Path Traversal Detection

  • On restore: Detects .. path components
    • Resolved path differs from original → restore blocked
    • Prevents ../ escape sequences

Security Event Logging

  • All security blocks logged at SECURITY level for audit trail

workspace_cleaner Security Guards

  • Auto-backup before deletion: Calls delete_recovery.py backup for each file; falls back to manual copy if subprocess fails
  • Hardcoded core-file protection: Core files (AGENTS.md, SOUL.md, etc.) and skill directory are always protected — cannot be overridden by whitelist
  • Workspace root confinement: Only scans {workspace} directory, never traverses outside
  • Whitelist isolation: User whitelist stored in .delete_recovery/workspace_cleaner/, separate from backup directory
  • Timer enforcement: Cleanup requires the time interval to have elapsed (run command), preventing rapid re-triggering

自动清理规则 / Auto-Cleanup Rules

中文

类型 保留时间 说明
备份文件夹 7天 超过7天的备份自动清理
日志文件 30天 超过30天的日志自动清理
workspace_cleaner 过期文件 用户配置(默认7天) workspace_cleaner 扫描时清理(v0.8.0)

脚本每次启动时自动执行清理,无需手动调用(delete_recovery.py 侧)。workspace_cleaner 需通过 cron 或定期触发。

English

Type Retention Description
Backup folders 7 days Backups older than 7 days are auto-deleted
Log files 30 days Logs older than 30 days are auto-deleted
workspace_cleaner expired files User-configured (default 7 days) Cleaned during workspace_cleaner scan (v0.8.0)

delete_recovery.py runs cleanup on every script invocation. workspace_cleaner requires cron or periodic triggering.

文件结构 / File Structure

中文

v0.6.0 重大变更:备份和日志存储位置移至 workspace 根目录,技能目录被删除时备份仍可存活。

v0.7.0 安全加固:manifest 路径字段改为 HMAC-SHA256 加密存储,不再明文暴露原始路径。

v0.8.0 workspace_cleaner: 新增定时清理工具,独立数据目录,清理前自动备份。

workspace2/                               ← 工作区根目录(备份独立于技能目录)
├── .delete_recovery/                     ← 数据根目录(v0.6.0+,技能删除后仍存活)
│   ├── delete_backup/                    ← 备份存储(7天自动清理)
│   │   ├── manifest.jsonl               ← 检索索引:文件名/功能简介/**加密路径(v0.7.0)**
│   │   ├── log/                        ← 日志目录
│   │   │   └── log.txt                ← 操作日志(30天自动清理)
│   │   ├── YYYYMMDDHHMM/             ← 时间戳文件夹
│   │   │   ├── C__Users__...         ← 备份文件
│   │   │   ├── C__Users__...path    ← 原始路径记录(解密用,始终保留)
│   │   │   ├── C__Users__...sha256  ← SHA256 + PATH 交叉验证记录(v0.3.0)
│   │   │   └── .restored              ← 已恢复文件清单
│   │   └── temp_existing/             ← 恢复时暂存已有文件
│   └── workspace_cleaner/              ← workspace_cleaner 数据目录(v0.8.0)
│       ├── workspace_cleaner_whitelist.json  ← 用户白名单配置
│       ├── workspace_cleaner_config.json    ← 运行配置(间隔、过期天数)
│       └── workspace_cleaner_timer.json     ← 定时器状态

{workspace}/skills/delete-recovery/          ← 技能目录(可独立删除,不影响备份)
├── SKILL.md
├── README.md
├── scripts/
│   ├── delete_recovery.py               ← 核心脚本(含安全验证,v0.7.0)
│   ├── safe_path.py                     ← 路径安全验证模块(v0.3.1)
│   └── workspace_cleaner.py              ← workspace 定时清理脚本(v0.8.0)
└── example/
    └── example.txt

v0.7.0 manifest path encryption: manifest.jsonlpath 字段存储 HMAC-SHA256 哈希(格式:HASH_PREFIX:HMAC_TAG),而非明文路径。解密由备份文件夹内的 .path 文件负责。filename 和 description 字段保持明文以支持按文件名检索。

.path 文件作用: 每个备份文件旁边有一个同名 .path 文件,存储原始文件路径,用于恢复时定位目标位置。

.sha256 文件作用(v0.3.0): 存储备份文件的 SHA256 哈希 + 原始路径(交叉验证用),防止备份被篡改后注入恶意文件。

workspace_cleaner 数据文件(v0.8.0):

  • workspace_cleaner_whitelist.json:用户白名单(文件/文件夹/扩展名),可手动编辑
  • workspace_cleaner_config.json:运行配置(间隔小时数、过期天数、auto_backup 开关)
  • workspace_cleaner_timer.json:定时器状态(上次运行时间)

English

v0.6.0 major change: backup and log storage moved to workspace root, so backups survive even if the skill folder is deleted.

v0.7.0 security hardening: manifest path field is now HMAC-SHA256 encrypted (not plaintext).

v0.8.0 workspace_cleaner: New scheduled cleanup tool with isolated data directory and auto-backup before deletion.

workspace2/                               ← Workspace root (backups independent of skill directory)
├── .delete_recovery/                     ← Data root directory (v0.6.0+, survives skill deletion)
│   ├── delete_backup/                    ← Backup storage (7-day auto-cleanup)
│   │   ├── manifest.jsonl               ← Retrieval index: filename / description /**encrypted path (v0.7.0)**
│   │   ├── log/                        ← Logs directory
│   │   │   └── log.txt                ← Operation logs (30-day auto-cleanup)
│   │   ├── YYYYMMDDHHMM/             ← Timestamp folder
│   │   │   ├── C__Users__...         ← Backup file
│   │   │   ├── C__Users__...path    ← Original path record (plaintext, always retained)
│   │   │   ├── C__Users__...sha256  ← SHA256 + PATH cross-validation record (v0.3.0)
│   │   │   └── .restored              ← Restored files manifest
│   │   └── temp_existing/             ← Conflict files staged during recovery
│   └── workspace_cleaner/              ← workspace_cleaner data directory (v0.8.0)
│       ├── workspace_cleaner_whitelist.json  ← User whitelist config
│       ├── workspace_cleaner_config.json    ← Runtime config (interval, expire_days)
│       └── workspace_cleaner_timer.json     ← Timer state

{workspace}/skills/delete-recovery/          ← Skill directory (can be deleted independently)
├── SKILL.md
├── README.md
├── scripts/
│   ├── delete_recovery.py               ← Core script (with security checks, v0.7.0)
│   ├── safe_path.py                     ← Path safety validator module (v0.3.1)
│   └── workspace_cleaner.py              ← workspace cleaner script (v0.8.0)
└── example/
    └── example.txt

v0.7.0 manifest path encryption: The manifest.jsonl path field stores an HMAC-SHA256 hash (format: HASH_PREFIX:HMAC_TAG), not the plaintext path. Decryption always uses the .path file in the backup folder. Filename and description remain in plaintext to support filename-based search.

完整使用示例 / Full Usage Example

中文

场景:用户要删除桌面上的 report.docx

Step 1:先备份(建议加上功能简介)

python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" "C:\Users\user\Desktop\report.docx" "工作报告"

Step 2:执行删除(由用户自行完成)

Step 3:用户误删后想恢复,先搜索

# 搜索已删除的文件
python delete_recovery.py search "报告"
# 返回:folder + safe_name + description + path,AI 根据结果执行 restore

Step 4:恢复

python delete_recovery.py restore 202603281030 "C__Users__user__Desktop__report.docx"
# 恢复成功后 manifest 中的索引自动被剔除

Step 5:验证备份完整性(可选)

python delete_recovery.py verify 202603281030 "C__Users__user__Desktop__report.docx"

场景:workspace_cleaner 定时清理(v0.8.0)

# 查看状态和下次可清理时间
python workspace_cleaner.py status

# 预览哪些文件将被清理(不实际删除)
python workspace_cleaner.py dry-run

# 手动触发一次清理
python workspace_cleaner.py run

# 添加白名单(保护重要文件)
python workspace_cleaner.py add-whitelist ".xlsx" --type ext
python workspace_cleaner.py add-whitelist "projects" --type folder

# 调整清理参数
python workspace_cleaner.py set-interval 12   # 改为12小时清理一次
python workspace_cleaner.py set-expire-days 3  # 3天未修改视为过期

English

# 1. Backup before deletion (with description)
python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" "C:\Users\user\Desktop\report.docx" "Work Report"

# 2. User performs deletion (manually)

# 3. Search for deleted file
python delete_recovery.py search "report"
# AI parses results to get folder + safe_name, then calls restore

# 4. Accidentally deleted — restore
python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx"
# With --keep-backup
python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --keep-backup
# Force restore pre-v0.3.0 backup (no SHA256 record)
python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force

# 5. Verify backup integrity (optional)
python delete_recovery.py verify 202603261130 "C__Users__user__Desktop__report.docx"

# workspace_cleaner usage (v0.8.0 NEW)
python workspace_cleaner.py status
python workspace_cleaner.py dry-run
python workspace_cleaner.py run
python workspace_cleaner.py add-whitelist ".xlsx" --type ext
python workspace_cleaner.py set-interval 12
python workspace_cleaner.py set-expire-days 3

安全加固说明 / Security Hardening

中文

⚠️ 版本说明: v0.1.0~v0.6.0 已淘汰。请始终使用 v0.7.0v0.8.0

攻击场景 防御方式 v0.7.0 v0.8.0
备份后替换文件内容 SHA256 完整性验证
备份后替换 + 删除 SHA256 绕过检查 SHA256 强制要求(缺失/为空拒绝恢复)
篡改 .path 定向到其他目录 PATH 交叉验证(.sha256 中 PATH 与 .path 对比)
利用 ../ 路径遍历逃逸 路径遍历检测
--force 跳过所有检查 --force 强制 PATH 验证(即使 SHA256 缺失)
日志注入 detail 中过滤 `\
\r [`
恢复逃逸到 workspace 外 allowed_roots 默认为 workspace 根目录
manifest 明文暴露路径 HMAC-SHA256 加密路径字段
workspace_cleaner 无备份清理 清理前自动备份
workspace_cleaner 核心文件误删 硬编码核心文件保护

说明(v0.7.0+v0.8.0): allowed_roots 现默认为 workspace 根目录——恢复目标被限制在 {workspace} 树内,阻止恢复文件到任意系统路径。workspace_cleaner 的安全机制独立于 delete_recovery,不依赖 SHA256/PATH 验证(因为清理的是临时/过期文件,备份用途为恢复而非安全防护)。安全防护依赖 workspace 目录 confinement + 核心文件硬编码保护 + 白名单隔离。备份文件存在于 {workspace}/.delete_recovery/delete_backup/,请仅在受信任的环境中使用本技能。

English

⚠️ Version note: v0.1.0~v0.6.0 are deprecated. Always use v0.7.0 or v0.8.0.

Attack Scenario Defense v0.7.0 v0.8.0
Replace backup with malicious file after backup SHA256 integrity check
Replace backup + delete SHA256 to bypass SHA256 strictly required (missing/empty blocks restore)
Tamper .path to redirect restore elsewhere PATH cross-validation (.sha256 PATH vs .path file)
Use ../ traversal to escape backup area Path traversal detection
--force bypasses all checks --force still enforces PATH validation (even without SHA256)
Log injection `\
, \r, [` stripped from detail
Restore escapes workspace allowed_roots defaults to workspace root
Manifest exposes original paths HMAC-SHA256 encryption of path field
workspace_cleaner deletes without backup Auto-backup before deletion
workspace_cleaner deletes core files Hardcoded core-file protection

Note (v0.7.0+v0.8.0): allowed_roots now defaults to workspace root — restores are confined to the {workspace} tree, preventing arbitrary system-path writes. workspace_cleaner security is independent of delete_recovery SHA256/PATH validation (it cleans temp/expired files, backup is for recovery not security hardening). Protection relies on workspace root confinement + hardcoded core-file protection + whitelist isolation. Backup files live in {workspace}/.delete_recovery/delete_backup/ — deploy only in trusted environments.

安全设计决策说明 / Security Design Decisions

中文

本节直接回应审查中提出的设计关切。

Q1:为什么不默认限制恢复目标目录(allowed_roots)?

A: 作为文件恢复工具,核心需求是将文件恢复到原始位置——而原始位置可能是用户硬盘上的任意目录。强制限定 allowed_roots 会使工具无法恢复原本不在"白名单"内的文件,根本上违背工具的设计目的。v0.7.0 起 allowed_roots 默认为 workspace 根目录作为安全默认值,如需恢复 workspace 外的文件,可将 allowed_roots 设为 None

防护范围说明: SHA256 + PATH 交叉验证可以防护"备份后单独替换备份文件"这一路径,但无法防护"同时拥有 delete_backup/ 目录写权限的攻击者同时替换备份文件 + .sha256 + .path 三者"的情况。因此本技能的安全性依赖于文件系统权限的保护——请确保 delete_backup/ 目录仅对可信进程开放写权限。../ 路径遍历逃逸由独立的遍历检测保护,不受此影响。

Q2:--force 参数为什么不直接跳过所有检查?

A: --force 仅用于恢复没有 SHA256 记录的旧备份--force 的行为已严格受限:

检查项 正常 restore --force restore
SHA256 完整性验证(文件内容未篡改) ✅ 强制 ✅ 强制
SHA256 存在性检查 ✅ 缺失则阻止 ❌ 跳过(v0.3.0前旧备份无此记录)
PATH 交叉验证(.sha256中路径 vs .path文件) ✅ 强制 强制执行,不可绕过
路径遍历检测(../ 逃逸) ✅ 强制 强制执行,不可绕过

简言之:--force 只豁免「SHA256 记录不存在」这件事本身,不豁免任何实质性安全检查。

Q3:manifest.jsonl 为什么存储原始文件路径,是否泄露敏感信息?(v0.7.0 已加密)

A(v0.7.0): v0.7.0 起,manifest 中的 path 字段改为 HMAC-SHA256 加密格式(HASH_PREFIX:HMAC_TAG),原始路径不再明文暴露。解密恢复由 .path 文件负责,manifest 仅存加密指纹。filename 和 description 字段保持明文以支持按文件名检索。

Q4:workspace_cleaner 清理时备份失败怎么办?(v0.8.0 新增)

A: workspace_cleaner 在调用 delete_recovery.py backup 备份失败时,会自动降级为直接复制文件到 delete_backup/timestamp/(手动备份模式),不依赖 delete_recovery.py 的完整安全验证。如果手动备份也失败(权限问题等),该文件会被跳过并在结果中报告错误。备份失败的 文件不会被删除。

English

This section directly addresses reviewer concerns.

Q1: Why does allowed_roots default to workspace root?

A: allowed_roots defaults to [WORKSPACE_ROOT] as a deliberate security default. As a recovery tool, the remaining use case — restoring files originally outside the workspace — is served by explicitly setting allowed_roots=None. The workspace root confinement prevents accidental or malicious restore to arbitrary system paths.

Scope of protection: SHA256 + PATH cross-validation guards against "replace the backup file after it was originally created," but does not protect against an attacker who simultaneously controls write access to delete_backup/ and replaces all three files (backup + .sha256 + .path) together. Therefore, the skill's security depends on filesystem permissions protecting delete_backup/ — only deploy in environments where that directory is write-protected from untrusted processes. Path-traversal escape (../) is independently blocked and unaffected by this limitation.

Q2: Why doesn't --force skip all security checks?

A: --force is only intended for restoring legacy backups that lack SHA256 records. --force is strictly limited:

Check Normal restore --force restore
SHA256 integrity (content not tampered) ✅ Always ✅ Always
SHA256 existence check ✅ Blocked if missing ❌ Bypassed (legacy backups pre-date SHA256)
PATH cross-validation (.sha256 PATH vs .path file) ✅ Always Always, non-bypassable
Path traversal detection (../ escape) ✅ Always Always, non-bypassable

In short: --force only waives "SHA256 record is absent" as a condition — it never skips any substantive security check.

Q3: Why does manifest.jsonl store original paths — is this sensitive information leakage?

A: The path field in manifest.jsonl is stored as HMAC-SHA256 encrypted (HASH_PREFIX:HMAC_TAG) — original paths are no longer readable. The plaintext original path is always retrievable from the .path file in the backup folder. Filename and description remain in plaintext to support filename-based search.

Q4: What happens if workspace_cleaner backup fails?

A: If delete_recovery.py backup fails, workspace_cleaner falls back to a manual copy directly into delete_backup/timestamp/ (no SHA256/PATH validation in this fallback). If even the manual backup fails (e.g., permission error), the file is skipped and reported as an error — it is NOT deleted.

注意事项 / Notes

中文

  1. 删除前必备份:所有删除操作前都应先调用 backup,防止误删
  2. 恢复时目标冲突:如果原位置已有文件,会自动将旧文件暂存到 temp_existing/ 目录
  3. 恢复后自动删备份:默认情况下,恢复成功后会自动删除对应备份(多文件时等全部恢复完再清理);使用 --keep-backup 可保留
  4. 路径编码:备份文件名将 \/: 替换为 __,恢复时需使用转换后的名称
  5. 时间触发清理:7天备份清理和30天日志清理改为时间触发(默认24小时间隔),不再每次命令都执行全量扫描;cleanup 命令本身不受影响,仍立即执行全量清理
  6. manifest 增量操作:restore/delete_backup 时按需压缩 manifest(候选集≤100条时全量rewrite,>100条时追加墓碑标记);list/search/log 时自动检查并触发增量压缩
  7. 安全验证:restore 时自动进行 SHA256 完整性 + PATH 交叉验证 + 遍历检测,如验证失败会明确报错
  8. 旧备份恢复:无 SHA256 记录的旧备份使用 restore --force 可强制恢复(完整性检查跳过,但 PATH 验证和遍历检测仍然生效,不可绕过)
  9. 检索索引backup 自动追加索引,restore 成功后自动剔除;过期备份文件夹对应的索引随 cleanup 或脚本启动时自动清理
  10. workspace 目录限制(v0.7.0):恢复目标被限制在 workspace 根目录内,阻止恢复文件到任意系统路径;如需恢复 workspace 外的文件,请手动设置 allowed_roots=None
  11. manifest 路径加密(v0.7.0):manifest 中的原始路径字段已改为 HMAC-SHA256 加密,无法通过直接查看 manifest 获取原始路径;解密完全由 .path 文件负责
  12. workspace_cleaner 定时清理(v0.8.0):需通过 cron 或定期触发;默认24小时间隔,7天过期文件;核心文件和技能目录始终保护
  13. workspace_cleaner 备份降级(v0.8.0):delete_recovery.py 备份失败时自动降级为手动备份;手动备份也失败则跳过该文件(不删除)

English

  1. Always backup before deleting: Call backup before any deletion
  2. Restore target conflict: Existing files moved to temp_existing/ before restoring
  3. Auto-delete backup after restore: Default behavior (multi-file: all restored → then delete); use --keep-backup to retain
  4. Path encoding: \, /, : replaced with __ in backup filenames
  5. Time-triggered cleanup: 7-day backup and 30-day log cleanup are time-triggered (default 24-hour interval), not run on every command; cleanup command itself still runs full cleanup immediately
  6. Incremental manifest: restore/delete_backup use on-demand manifest compaction; list/search/log auto-check and compact oversized manifests
  7. Security checks: Restore automatically fails with clear error if SHA256 integrity, PATH cross-validation, or path traversal check fails
  8. Legacy backup restore: Backups without SHA256 records use restore --force to force restore (integrity check skipped, but PATH validation and traversal detection still apply, non-bypassable)
  9. Manifest index: backup auto-indexes; restore auto-removes index entry; stale entries pruned on cleanup or script startup
  10. Workspace root confinement (v0.7.0): Restore destinations are confined to workspace root — files cannot be restored to arbitrary system paths; set allowed_roots=None to restore outside workspace
  11. Manifest path encryption (v0.7.0): Original paths in manifest.jsonl are HMAC-SHA256 encrypted — cannot be read by inspecting the manifest file; decryption always uses the .path file in the backup folder
  12. workspace_cleaner scheduled cleanup (v0.8.0): Requires cron or periodic triggering; default 24-hour interval, 7-day expiry; core files and skill directory always protected
  13. workspace_cleaner backup fallback (v0.8.0): Falls back to manual copy if delete_recovery.py backup fails; skips (does not delete) if even manual backup fails

delete-recovery

安全使用建议
This skill appears to do what it claims: it backs up files to {workspace}/.delete_recovery, verifies SHA256 and path checks on restore, and offers a workspace_cleaner that backs up before deleting. Before installing, note: (1) backups and manifests live outside the skill folder and will survive skill deletion — review and secure {workspace}/.delete_recovery if that matters, (2) legacy backups can be restored with --force which relaxes SHA256 existence checks (the code asserts path checks still run), so avoid using --force unless you understand the risk, (3) the 'automatic 24-hour run' is implemented as time-gated behavior when the script runs (there's no bundled background scheduler), and (4) review the whitelist and ALWAYS_PROTECTED lists to ensure they match your expectations. If you want stronger confinement, confirm allowed_roots remains set to your workspace root (the code sets this by default). If any of these trade-offs are unacceptable, review or modify the source before deployment.
功能分析
Type: OpenClaw Skill Name: delete-recovery Version: 0.8.3 The skill bundle provides a robust file backup and recovery system with significant security hardening. Key features include SHA256 integrity checks, HMAC-encrypted manifest paths to protect privacy, and mandatory path cross-validation to prevent redirection attacks (implemented in `safe_path.py` and `delete_recovery.py`). A `workspace_cleaner.py` utility includes hardcoded protections for core system files (e.g., `AGENTS.md`, `SOUL.md`) and enforces workspace confinement. The code demonstrates high security awareness, specifically addressing path traversal and backup substitution risks, with no evidence of malicious intent or data exfiltration.
能力评估
Purpose & Capability
Name/description match the included scripts and the declared behavior: backups, restore, manifest search, integrity checks, and a workspace cleaner. No unrelated env vars, binaries, or external services are requested.
Instruction Scope
SKILL.md limits agent actions to backup/restore/list/search/clean, and the code implements these. Two caveats: (1) the code exposes a --force option to relax SHA256 existence checks for legacy backups (the code documents that PATH traversal and cross-checks still run), and (2) wording in the docs implies a 24-hour automatic run but the implementation uses time-based checks when the script is invoked (there is no background daemon in the bundle). Both are documented in the SKILL.md but may be surprising.
Install Mechanism
Instruction-only install (no install spec). Provided code files run locally and create workspace-local data; no external downloads or package installs are performed by the skill.
Credentials
No environment variables, credentials, or external config paths are requested. All storage is under {workspace}/.delete_recovery as described in the documentation.
Persistence & Privilege
Skill does not request always:true and is user-invocable. It creates persistent data under the workspace (.delete_recovery) which intentionally survives skill removal — the SKILL.md calls this out as a trade-off. The agent may invoke the skill autonomously by default (normal for skills).
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install delete-recovery
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /delete-recovery 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.8.3
Version 0.8.3 of delete-recovery - No code or documentation changes detected in this release. - Maintains all features, security constraints, and commands as described in v0.8.0. - No impact on user triggers, agent permissions, or behavior.
v0.8.1
No changes since v0.8.0. - Version 0.8.1 was released with no file or documentation changes. - Behavior and features remain identical to v0.8.0.
v0.8.0
v0.8.0 introduces workspace_cleaner: scheduled cleanup with auto-backup before deletion. - New script: workspace_cleaner.py for scheduled workspace file cleanup. - Automatically backs up files via delete_recovery before deleting temporary or expired files. - Supports manual and scheduled cleanup, whitelist configuration, and dry-run preview. - Workspace_cleaner data/config is stored outside the skill directory and survives skill uninstall. - Core delete_recovery features (backup, restore, manifest search, verification) are unchanged.
v0.7.1
Version 0.7.1 of delete-recovery - No code or documentation changes detected in this version. - All features and behaviors remain unchanged from v0.7.0.
v0.7.0
delete-recovery v0.7.0 - Restores are now confined to the workspace root by default; `allowed_roots` is set to workspace (stricter path confinement). - Manifest `path` fields are HMAC-SHA256 encrypted; original file paths are no longer readable in manifest.jsonl. - Security documentation updated to reflect new defaults and hardening. - No functional change to backup, restore, or search commands aside from new path security features. - Internal: Migration to new manifest encryption does not affect backup/restore usability for end users.
v0.6.5
No code or documentation changes in this version; version bump only.
v0.6.4
No changes detected in this version. - Version number updated to 0.6.4. - No file or documentation changes present in this release.
v0.6.3
No changes since v0.6.2. - No file changes detected in this version.
v0.6.2
No changes in code or logic for v0.6.2. - No file changes detected in this release. - Behavior and functionality are unchanged from the previous version. - Safe to upgrade with zero impact on workflows.
v0.6.1
- Removed temporary test file `delete_backup/temp_existing/example.txt`. - Removed backup operation log file `log.txt`. - No functional changes; cleanup of sample and log files only.
v0.6.0
v0.6.0 improves speed and efficiency with new time-based cleanup and incremental manifest operations. - Backup cleanup (7 days) and log cleanup (30 days) are now triggered by a timer (default: every 24 hours), not on every command. - Manifest index now uses incremental updates; compression and cleanup only occur as needed on restore or delete operations. - List, search, and log commands will auto-compress an oversized manifest file. - Overall command response speed is improved by 60–75%. - No change to user-facing features or security constraints.
v0.5.3
## v0.5.3 - No file changes detected in this release. - Behavior and features remain the same as previous version (v0.5.0).
v0.5.2
delete-recovery v0.5.2 - No code or documentation changes detected from previous version. - Behavior, usage, and features remain unchanged.
v0.5.1
delete-recovery v0.5.1 - Added fast search for deleted files via a new manifest.jsonl index; enables retrieval by filename, brief description (≤6 chars), or path keyword. - New search command allows quick lookup of backup location and restore command for deleted files. - Manifest index entries are removed automatically once restore is successful. - All backup, restore, listing, cleanup, and integrity verification functions remain, with strict security constraints.
v0.5.0
delete-recovery v0.5.0 introduces fast search for deleted backups - Added manifest.jsonl index for every backup, enabling rapid search of deleted files by filename, function description (≤6 chars), or path keyword. - New `search` command lets users instantly locate deleted files and get restore commands from backup index. - Backup and restore logic now automatically updates manifest: entries are added on backup, and removed after successfully restore. - Existing security and integrity checks for backup and restore remain fully enforced.
v0.4.0
delete-recovery v0.4.0 - Updated all scripts, paths, and documentation references from v0.3.0 to v0.4.0. - No functional changes detected; command usage, triggers, and security constraints remain the same. - Documentation and sample command paths now reference the new version directory. - Ensures continued integrity, safety, and behavior as per strict agent constraints.
v0.3.3
# delete-recovery v0.3.0 ### 中文 文件删除安全网——备份、恢复、SHA256完整性校验、路径交叉验证、全自动清理。 ### English A safety net for file deletion — backup, recovery, SHA256 integrity verification, path cross-validation, and fully automatic cleanup. --- ### 中文 一款轻量的 OpenClaw skill,在删除文件前自动将其备份到带时间戳的文件夹。**v0.3.0 新增 SHA256 强制校验 + PATH 交叉验证**,修复了 v0.2.0 中 SHA256 可被绕过的安全漏洞,防止恶意文件注入攻击。误删后一键恢复,过期备份和日志全自动清理,无需人工干预。 ### English A lightweight OpenClaw skill that automatically backs up files to timestamped folders before deletion. **v0.3.0 adds mandatory SHA256 integrity checks and PATH cross-validation**, fixing a security bypass vulnerability in v0.2.0 and preventing malicious file injection attacks. Recover accidentally deleted files with one click, and expired backups and logs are automatically cleaned up without manual intervention. --- ## 功能特性 / Features ### 中文 - **删除前自动备份** — 删除任何文件前,自动备份到带时间戳的文件夹 - **SHA256 强制校验(v0.3.0 修复)** — 备份时计算哈希,恢复时验证;SHA256 记录缺失或为空时 restore 默认阻止(无法再通过删除文件绕过) - **PATH 交叉验证(v0.3.0 新增)** — `.sha256` 文件中绑定原始路径,恢复时双向交叉验证,彻底防止 `.path` 文件被篡改定向到任意位置 - **路径遍历防护** — 检测 `../` 逃逸序列,拒绝恢复目标超出合法范围 - **一键恢复** — 将误删文件恢复到原始位置 - **多文件安全处理** — 同一备份文件夹含多文件时,须全部恢复完毕才删除备份 - **自动清理** — 备份7天后自动删除,日志30天后自动删除,完全自动化 - **冲突保护恢复** — 恢复时若目标位置已有文件,自动移到 `temp_existing/` 暂存 - **完整操作日志** — 每次备份、恢复、清理、安全拦截操作均有记录(含 SECURITY 级别) - **`--force` 恢复旧备份(v0.3.0 新增)** — 对 v0.3.0 之前创建的旧备份(无 SHA256 记录),可用 `--force` 强制恢复(路径验证仍生效) ### English - **Automatic backup before deletion** — Automatically backs up any file to a timestamped folder before deletion - **Mandatory SHA256 integrity check (v0.3.0 fixed)** — Computes hash during backup and verifies during recovery; missing or empty SHA256 record now blocks restore by default (bypass attack eliminated) - **PATH cross-validation (NEW in v0.3.0)** — SHA256 file now stores FILE_HASH + PATH; restore performs cross-check between `.sha256` record and `.path` file, fully preventing `.path` redirection attacks - **Path traversal protection** — Detects `../` escape sequences and blocks restores outside the valid directory range - **One-click recovery** — Restores accidentally deleted files to their original location - **Multi-file safe handling** — When a backup folder contains multiple files, all must be restored before deleting the backup - **Automatic cleanup** — Backups are deleted after 7 days and logs after 30 days, fully automated - **Conflict-protected recovery** — If a file already exists at the restore destination, it is automatically moved to `temp_existing/` for staging - **Complete operation logs** — Every backup, restore, cleanup, and security interception operation is logged (including SECURITY level) - **`--force` for legacy backups (NEW in v0.3.0)** — Use `--force` to restore pre-v0.3.0 backups that lack SHA256 records (path validation still applies) --- ## 安装方式 / Installation ### 中文 ### 通过 ClawdHub 安装(推荐) ```bash # 安装最新版(v0.3.0) clawdhub install delete-recovery # 安装指定版本 clawdhub install delete-recovery --version 0.3.0 ``` ### 手动安装 将 `delete-recovery-0.3.0` 文件夹复制到本地 Agent 的 OpenClaw workspace 的 `skills/` 目录下。 ### English ### Install via ClawdHub (Recommended) ```bash # Install latest version (v0.3.0) clawdhub install delete-recovery # Install specific version clawdhub install delete-recovery --version 0.3.0 ``` ### Manual Installation Copy the `delete-recovery-0.3.0` folder to the `skills/` directory in your local Agent's OpenClaw workspace. --- ## 快速开始 / Quick Start ### 中文 ### 1. 删除前备份 ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # 示例 python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. 恢复误删文件 ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # 恢复 v0.3.0 之前的旧备份(无 SHA256 记录) python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. 验证备份完整性 ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` 不执行恢复,仅检查备份文件是否被篡改(SHA256 完整性 + PATH 交叉验证)。 ### 4. 查看所有备份 ```bash python delete_recovery.py list ``` ### 5. 手动删除指定备份 ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. 手动触发清理 ```bash python delete_recovery.py cleanup ``` ### 7. 查看操作日志 ```bash python delete_recovery.py log [lines] ``` ### English ### 1. Backup Before Deletion ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # Example python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. Restore Accidentally Deleted Files ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # Restore pre-v0.3.0 backup (no SHA256 record) using --force python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. Verify Backup Integrity ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` Does not perform recovery. Checks SHA256 integrity AND PATH cross-validation to detect any tampering. ### 4. List All Backups ```bash python delete_recovery.py list ``` ### 5. Manually Delete Specified Backup ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. Manually Trigger Cleanup ```bash python delete_recovery.py cleanup ``` ### 7. View Operation Logs ```bash python delete_recovery.py log [lines] ``` --- ## 安全机制详解(v0.3.0)/ Security Mechanisms Explained (v0.3.0) ### 中文 ### 场景1:备份被替换 攻击者先备份一个正常文件,然后用恶意文件替换备份目录中的文件,诱导恢复。 **防御:** backup 时计算 SHA256 并存储;restore 时验证哈希,不匹配则拒绝恢复。即使攻击者删除了 `.sha256` 文件,restore 也会被阻止(除非使用 `--force`,且路径验证仍然生效)。 ### 场景2:.path 文件被篡改 攻击者修改 `.path` 文件内容,将恢复目标指向系统目录(如 `C:\Windows\System32\evil.exe`)。 **防御:** v0.3.0 新增 `.sha256` 文件中的 PATH 字段。restore 时读取 `.sha256` 中存储的原始路径,与 `.path` 文件内容进行交叉验证,二者不一致则拒绝恢复。 ### 场景3:SHA256 记录被删除绕过 攻击者直接删除或置空 `.sha256` 文件,试图绕过完整性检查。 **防御:** v0.3.0 修复此漏洞——SHA256 记录缺失或为空时,restore 默认阻止并报错,不再跳过完整性检查。 ### 场景4:路径遍历 攻击者在目标路径中构造 `../../../dangerous/evil.exe`,试图逃逸到合法目录范围外。 **防御:** `_is_path_safe()` 检测 `..` 成分,resolve 后路径不在合法范围则拒绝。 ### English ### Scenario 1: Backup Replaced An attacker first backs up a normal file, then replaces the file in the backup directory with a malicious one to induce recovery. **Defense:** Compute and store SHA256 during backup; verify hash during restore and reject if mismatched. If the attacker also deletes the `.sha256` file to bypass the check, restore is still blocked by default (unless `--force` is used, and path validation still applies). ### Scenario 2: .path File Tampered An attacker modifies the `.path` file content to point the restore target to a system directory (e.g., `C:\Windows\System32\evil.exe`). **Defense:** v0.3.0 stores the original path in the `.sha256` file (in the `PATH:` line). On restore, the path from `.sha256` is cross-checked against the `.path` file — any mismatch is blocked. ### Scenario 3: SHA256 Record Deleted to Bypass Check An attacker deletes or empties the `.sha256` file to bypass integrity checks. **Defense:** v0.3.0 fixes this — missing or empty SHA256 record now blocks restore by default. The only escape hatch is `--force`, but path cross-validation still runs. ### Scenario 4: Path Traversal An attacker constructs `../../../dangerous/evil.exe` in the target path to escape outside the allowed directory. **Defense:** `_is_path_safe()` detects `..` components and rejects if the resolved path is outside the valid range. --- ## SHA256 文件格式(v0.3.0)/ SHA256 File Format (v0.3.0) ### 中文 `.sha256` 文件采用结构化格式,同时存储文件哈希和原始路径: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**:格式版本号,用于未来兼容升级 - **`FILE_HASH:`**:备份文件的 SHA256 哈希(64位十六进制) - **`PATH:`**:备份时的原始文件路径(与 `.path` 文件内容一致,用于交叉验证) ### English The `.sha256` file uses a structured format that stores both the file hash and original path: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**: Format version marker for future compatibility - **`FILE_HASH:`**: SHA256 hash of the backup file (64 hex characters) - **`PATH:`**: Original file path at backup time (mirrors `.path` file; used for cross-validation) --- ## 文件结构 / File Structure ### 中文 ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill 定义 ├── README.md — 使用指南(本文) ├── CLAWDHUB.md — ClawdHub 发布元数据 ├── log.txt — 操作日志(30天自动清理) ├── delete_backup/ — 备份存储(7天自动清理) │ ├── YYYYMMDDHHMM/ — 时间戳备份文件夹 │ │ ├── C__Users__... — 备份文件 │ │ ├── C__Users__...path — 原始路径记录 │ │ ├── C__Users__...sha256 — SHA256 完整性 + PATH 交叉验证记录(v0.3.0) │ │ └── .restored — 已恢复文件清单 │ └── temp_existing/ — 恢复时暂存冲突文件 └── scripts/ ├── delete_recovery.py — 核心脚本(含安全验证) └── safe_path.py — 路径安全验证模块(v0.3.0) ``` ### English ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill definition ├── README.md — User guide (this document) ├── CLAWDHUB.md — ClawdHub publishing metadata ├── log.txt — Operation logs (auto-cleaned after 30 days) ├── delete_backup/ — Backup storage (auto-cleaned after 7 days) │ ├── YYYYMMDDHHMM/ — Timestamped backup folder │ │ ├── C__Users__... — Backup file │ │ ├── C__Users__...path — Original path record │ │ ├── C__Users__...sha256 — SHA256 + PATH cross-validation record (v0.3.0) │ │ └── .restored — Restored files manifest │ └── temp_existing/ — Conflict files staged during recovery └── scripts/ ├── delete_recovery.py — Core script (with security checks) └── safe_path.py — Path safety validation module (v0.3.0) ``` --- ## 工作流程 / Workflow ### 中文 ``` 用户决定删除文件 │ ▼ ① backup 命令 ← 第一步必须做(v0.3.0 自动生成 SHA256 + PATH 记录) │ ▼ ② 用户执行删除操作 │ ▼(后续如需恢复) ③ restore 命令 ← v0.3.0:完整性 + PATH 交叉验证 + 遍历检测 │ ▼ 备份自动删除 ←(除非使用了 --keep-backup) ``` ### English ``` User decides to delete file │ ▼ ① backup command ← Must do first (v0.3.0 auto-generates SHA256 + PATH record) │ ▼ ② User performs deletion │ ▼(If recovery needed later) ③ restore command ← v0.3.0: integrity + PATH cross-validation + traversal detection │ ▼ Backup auto-deleted ←(Unless --keep-backup is used) ``` --- ## 依赖环境 / Dependencies ### 中文 - Python 3.6+ - OpenClaw 1.0+(含 skill 支持) ### English - Python 3.6+ - OpenClaw 1.0+ (with skill support) --- ## 更新日志 / Changelog ### 中文 ### v0.3.0(2026-03-27) — 当前版本 **安全修复:** - 【最关键】SHA256 记录改为**强制要求** — 缺失或为空时 restore **默认阻止**,修复了"删除 `.sha256` 文件即可绕过完整性检查"的严重漏洞 - 【安全增强】`.sha256` 文件新增 `PATH:` 行 — restore 时双向交叉验证 `.sha256` 中存储的路径与 `.path` 文件内容,彻底防止 `.path` 篡改攻击 - 【Bug 修复】修复 `allowed_roots` 死代码 — `allowed_roots=[]`(空列表)现正确表示"无路径限制"(不再误判为禁止所有路径) - 【安全调整】`allowed_roots` 默认为空 — 安全防护主要依赖完整性 + 路径交叉验证,而非固定目录限制,更适合恢复工具的实际场景 - 【接口变更】restore 新增 `--force` 参数 — 跳过 SHA256 存在性检查,用于强制恢复 v0.3.0 之前的旧备份(路径验证仍生效) - 【Bug 修复】`verify` 命令新增 PATH 交叉验证结果 — 同时报告 hash_match 和 path_match 两个检查的结果 **完整变更:** - `safe_path.py`:完全重写 `verify_integrity_and_path()`,新增 `write_sha256_file()` / `read_sha256_file()`,格式改为 `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`:集成新版安全 API,`--force` 参数,`verify` 返回 path_match - 更新 SKILL.md / README.md / CLAWDHUB.md ### v0.2.0(2026-03-26)— 上一版本 - 新增 `safe_path.py` 路径安全验证模块 - backup 时自动计算并存储 SHA256 哈希(`.sha256` 文件) - restore 时验证备份完整性(SHA256 比对),完整性不符拒绝恢复 - restore 时验证恢复路径(防止 `.path` 篡改 + 路径遍历) - 所有安全拦截事件记录为 `SECURITY` 级别日志 - 新增 `verify` 命令:手动检查备份完整性(不执行恢复) - 新增 `safe_path.py` 独立工具:可单独调用 `compute <file_path>` 计算 SHA256 ### v0.1.0(2026-03-26) - 基础备份/恢复/清理功能 - 7天自动清理备份,30天自动清理日志 - 多文件批量恢复保护 - 冲突保护恢复 ### English ### v0.3.0 (2026-03-27) — Current Version **Security fixes:** - 【Critical】SHA256 record is now **STRICTLY REQUIRED** — missing or empty SHA256 blocks restore by default, fixing the critical bypass vulnerability where deleting `.sha256` disabled integrity checks - 【Security enhancement】`.sha256` file now stores `PATH:` line — restore performs cross-check between the path stored in `.sha256` and the `.path` file, fully preventing `.path` redirection attacks - 【Bug fix】Fixed `allowed_roots` dead code — `allowed_roots=[]` (empty list) now correctly means "no restriction" (previously falsely blocked all paths) - 【Security adjustment】`allowed_roots` defaults to empty — primary security comes from integrity + path cross-validation rather than fixed directory restrictions, which is more appropriate for a recovery tool - 【Interface change】restore command gains `--force` flag — bypasses SHA256 existence check to restore pre-v0.3.0 backups (path validation still applies) - 【Bug fix】`verify` command now reports PATH cross-validation result — returns both hash_match and path_match **Complete changes:** - `safe_path.py`: Fully rewritten `verify_integrity_and_path()`, new `write_sha256_file()` / `read_sha256_file()`, format changed to `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`: Integrated new security API, `--force` flag, `verify` returns path_match - Updated SKILL.md / README.md / CLAWDHUB.md ### v0.2.0 (2026-03-26) — Previous Version - Added `safe_path.py` path safety validation module - SHA256 hash computed and stored on backup (`.sha256` file) - Restore verifies SHA256 integrity — blocks restore if hash mismatch - Restore validates destination path — prevents `.path` tampering and path traversal - All security blocks logged at `SECURITY` level - Added `verify` command: manually check backup integrity without restoring - Added `safe_path.py` standalone tool: `python safe_path.py compute <file>` ### v0.1.0 (2026-03-26) - Basic backup/restore/cleanup functionality - 7-day auto backup cleanup, 30-day auto log cleanup - Multi-file batch recovery protection - Conflict-protected recovery --- ### 中文 *如有问题或建议,欢迎反馈!* ### English *For questions or suggestions, feedback is welcome!*
v0.3.2
# delete-recovery v0.3.0 ### 中文 文件删除安全网——备份、恢复、SHA256完整性校验、路径交叉验证、全自动清理。 ### English A safety net for file deletion — backup, recovery, SHA256 integrity verification, path cross-validation, and fully automatic cleanup. --- ### 中文 一款轻量的 OpenClaw skill,在删除文件前自动将其备份到带时间戳的文件夹。**v0.3.0 新增 SHA256 强制校验 + PATH 交叉验证**,修复了 v0.2.0 中 SHA256 可被绕过的安全漏洞,防止恶意文件注入攻击。误删后一键恢复,过期备份和日志全自动清理,无需人工干预。 ### English A lightweight OpenClaw skill that automatically backs up files to timestamped folders before deletion. **v0.3.0 adds mandatory SHA256 integrity checks and PATH cross-validation**, fixing a security bypass vulnerability in v0.2.0 and preventing malicious file injection attacks. Recover accidentally deleted files with one click, and expired backups and logs are automatically cleaned up without manual intervention. --- ## 功能特性 / Features ### 中文 - **删除前自动备份** — 删除任何文件前,自动备份到带时间戳的文件夹 - **SHA256 强制校验(v0.3.0 修复)** — 备份时计算哈希,恢复时验证;SHA256 记录缺失或为空时 restore 默认阻止(无法再通过删除文件绕过) - **PATH 交叉验证(v0.3.0 新增)** — `.sha256` 文件中绑定原始路径,恢复时双向交叉验证,彻底防止 `.path` 文件被篡改定向到任意位置 - **路径遍历防护** — 检测 `../` 逃逸序列,拒绝恢复目标超出合法范围 - **一键恢复** — 将误删文件恢复到原始位置 - **多文件安全处理** — 同一备份文件夹含多文件时,须全部恢复完毕才删除备份 - **自动清理** — 备份7天后自动删除,日志30天后自动删除,完全自动化 - **冲突保护恢复** — 恢复时若目标位置已有文件,自动移到 `temp_existing/` 暂存 - **完整操作日志** — 每次备份、恢复、清理、安全拦截操作均有记录(含 SECURITY 级别) - **`--force` 恢复旧备份(v0.3.0 新增)** — 对 v0.3.0 之前创建的旧备份(无 SHA256 记录),可用 `--force` 强制恢复(路径验证仍生效) ### English - **Automatic backup before deletion** — Automatically backs up any file to a timestamped folder before deletion - **Mandatory SHA256 integrity check (v0.3.0 fixed)** — Computes hash during backup and verifies during recovery; missing or empty SHA256 record now blocks restore by default (bypass attack eliminated) - **PATH cross-validation (NEW in v0.3.0)** — SHA256 file now stores FILE_HASH + PATH; restore performs cross-check between `.sha256` record and `.path` file, fully preventing `.path` redirection attacks - **Path traversal protection** — Detects `../` escape sequences and blocks restores outside the valid directory range - **One-click recovery** — Restores accidentally deleted files to their original location - **Multi-file safe handling** — When a backup folder contains multiple files, all must be restored before deleting the backup - **Automatic cleanup** — Backups are deleted after 7 days and logs after 30 days, fully automated - **Conflict-protected recovery** — If a file already exists at the restore destination, it is automatically moved to `temp_existing/` for staging - **Complete operation logs** — Every backup, restore, cleanup, and security interception operation is logged (including SECURITY level) - **`--force` for legacy backups (NEW in v0.3.0)** — Use `--force` to restore pre-v0.3.0 backups that lack SHA256 records (path validation still applies) --- ## 安装方式 / Installation ### 中文 ### 通过 ClawdHub 安装(推荐) ```bash # 安装最新版(v0.3.0) clawdhub install delete-recovery # 安装指定版本 clawdhub install delete-recovery --version 0.3.0 ``` ### 手动安装 将 `delete-recovery-0.3.0` 文件夹复制到本地 Agent 的 OpenClaw workspace 的 `skills/` 目录下。 ### English ### Install via ClawdHub (Recommended) ```bash # Install latest version (v0.3.0) clawdhub install delete-recovery # Install specific version clawdhub install delete-recovery --version 0.3.0 ``` ### Manual Installation Copy the `delete-recovery-0.3.0` folder to the `skills/` directory in your local Agent's OpenClaw workspace. --- ## 快速开始 / Quick Start ### 中文 ### 1. 删除前备份 ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # 示例 python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. 恢复误删文件 ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # 恢复 v0.3.0 之前的旧备份(无 SHA256 记录) python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. 验证备份完整性 ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` 不执行恢复,仅检查备份文件是否被篡改(SHA256 完整性 + PATH 交叉验证)。 ### 4. 查看所有备份 ```bash python delete_recovery.py list ``` ### 5. 手动删除指定备份 ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. 手动触发清理 ```bash python delete_recovery.py cleanup ``` ### 7. 查看操作日志 ```bash python delete_recovery.py log [lines] ``` ### English ### 1. Backup Before Deletion ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # Example python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. Restore Accidentally Deleted Files ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # Restore pre-v0.3.0 backup (no SHA256 record) using --force python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. Verify Backup Integrity ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` Does not perform recovery. Checks SHA256 integrity AND PATH cross-validation to detect any tampering. ### 4. List All Backups ```bash python delete_recovery.py list ``` ### 5. Manually Delete Specified Backup ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. Manually Trigger Cleanup ```bash python delete_recovery.py cleanup ``` ### 7. View Operation Logs ```bash python delete_recovery.py log [lines] ``` --- ## 安全机制详解(v0.3.0)/ Security Mechanisms Explained (v0.3.0) ### 中文 ### 场景1:备份被替换 攻击者先备份一个正常文件,然后用恶意文件替换备份目录中的文件,诱导恢复。 **防御:** backup 时计算 SHA256 并存储;restore 时验证哈希,不匹配则拒绝恢复。即使攻击者删除了 `.sha256` 文件,restore 也会被阻止(除非使用 `--force`,且路径验证仍然生效)。 ### 场景2:.path 文件被篡改 攻击者修改 `.path` 文件内容,将恢复目标指向系统目录(如 `C:\Windows\System32\evil.exe`)。 **防御:** v0.3.0 新增 `.sha256` 文件中的 PATH 字段。restore 时读取 `.sha256` 中存储的原始路径,与 `.path` 文件内容进行交叉验证,二者不一致则拒绝恢复。 ### 场景3:SHA256 记录被删除绕过 攻击者直接删除或置空 `.sha256` 文件,试图绕过完整性检查。 **防御:** v0.3.0 修复此漏洞——SHA256 记录缺失或为空时,restore 默认阻止并报错,不再跳过完整性检查。 ### 场景4:路径遍历 攻击者在目标路径中构造 `../../../dangerous/evil.exe`,试图逃逸到合法目录范围外。 **防御:** `_is_path_safe()` 检测 `..` 成分,resolve 后路径不在合法范围则拒绝。 ### English ### Scenario 1: Backup Replaced An attacker first backs up a normal file, then replaces the file in the backup directory with a malicious one to induce recovery. **Defense:** Compute and store SHA256 during backup; verify hash during restore and reject if mismatched. If the attacker also deletes the `.sha256` file to bypass the check, restore is still blocked by default (unless `--force` is used, and path validation still applies). ### Scenario 2: .path File Tampered An attacker modifies the `.path` file content to point the restore target to a system directory (e.g., `C:\Windows\System32\evil.exe`). **Defense:** v0.3.0 stores the original path in the `.sha256` file (in the `PATH:` line). On restore, the path from `.sha256` is cross-checked against the `.path` file — any mismatch is blocked. ### Scenario 3: SHA256 Record Deleted to Bypass Check An attacker deletes or empties the `.sha256` file to bypass integrity checks. **Defense:** v0.3.0 fixes this — missing or empty SHA256 record now blocks restore by default. The only escape hatch is `--force`, but path cross-validation still runs. ### Scenario 4: Path Traversal An attacker constructs `../../../dangerous/evil.exe` in the target path to escape outside the allowed directory. **Defense:** `_is_path_safe()` detects `..` components and rejects if the resolved path is outside the valid range. --- ## SHA256 文件格式(v0.3.0)/ SHA256 File Format (v0.3.0) ### 中文 `.sha256` 文件采用结构化格式,同时存储文件哈希和原始路径: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**:格式版本号,用于未来兼容升级 - **`FILE_HASH:`**:备份文件的 SHA256 哈希(64位十六进制) - **`PATH:`**:备份时的原始文件路径(与 `.path` 文件内容一致,用于交叉验证) ### English The `.sha256` file uses a structured format that stores both the file hash and original path: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**: Format version marker for future compatibility - **`FILE_HASH:`**: SHA256 hash of the backup file (64 hex characters) - **`PATH:`**: Original file path at backup time (mirrors `.path` file; used for cross-validation) --- ## 文件结构 / File Structure ### 中文 ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill 定义 ├── README.md — 使用指南(本文) ├── CLAWDHUB.md — ClawdHub 发布元数据 ├── log.txt — 操作日志(30天自动清理) ├── delete_backup/ — 备份存储(7天自动清理) │ ├── YYYYMMDDHHMM/ — 时间戳备份文件夹 │ │ ├── C__Users__... — 备份文件 │ │ ├── C__Users__...path — 原始路径记录 │ │ ├── C__Users__...sha256 — SHA256 完整性 + PATH 交叉验证记录(v0.3.0) │ │ └── .restored — 已恢复文件清单 │ └── temp_existing/ — 恢复时暂存冲突文件 └── scripts/ ├── delete_recovery.py — 核心脚本(含安全验证) └── safe_path.py — 路径安全验证模块(v0.3.0) ``` ### English ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill definition ├── README.md — User guide (this document) ├── CLAWDHUB.md — ClawdHub publishing metadata ├── log.txt — Operation logs (auto-cleaned after 30 days) ├── delete_backup/ — Backup storage (auto-cleaned after 7 days) │ ├── YYYYMMDDHHMM/ — Timestamped backup folder │ │ ├── C__Users__... — Backup file │ │ ├── C__Users__...path — Original path record │ │ ├── C__Users__...sha256 — SHA256 + PATH cross-validation record (v0.3.0) │ │ └── .restored — Restored files manifest │ └── temp_existing/ — Conflict files staged during recovery └── scripts/ ├── delete_recovery.py — Core script (with security checks) └── safe_path.py — Path safety validation module (v0.3.0) ``` --- ## 工作流程 / Workflow ### 中文 ``` 用户决定删除文件 │ ▼ ① backup 命令 ← 第一步必须做(v0.3.0 自动生成 SHA256 + PATH 记录) │ ▼ ② 用户执行删除操作 │ ▼(后续如需恢复) ③ restore 命令 ← v0.3.0:完整性 + PATH 交叉验证 + 遍历检测 │ ▼ 备份自动删除 ←(除非使用了 --keep-backup) ``` ### English ``` User decides to delete file │ ▼ ① backup command ← Must do first (v0.3.0 auto-generates SHA256 + PATH record) │ ▼ ② User performs deletion │ ▼(If recovery needed later) ③ restore command ← v0.3.0: integrity + PATH cross-validation + traversal detection │ ▼ Backup auto-deleted ←(Unless --keep-backup is used) ``` --- ## 依赖环境 / Dependencies ### 中文 - Python 3.6+ - OpenClaw 1.0+(含 skill 支持) ### English - Python 3.6+ - OpenClaw 1.0+ (with skill support) --- ## 更新日志 / Changelog ### 中文 ### v0.3.0(2026-03-27) — 当前版本 **安全修复:** - 【最关键】SHA256 记录改为**强制要求** — 缺失或为空时 restore **默认阻止**,修复了"删除 `.sha256` 文件即可绕过完整性检查"的严重漏洞 - 【安全增强】`.sha256` 文件新增 `PATH:` 行 — restore 时双向交叉验证 `.sha256` 中存储的路径与 `.path` 文件内容,彻底防止 `.path` 篡改攻击 - 【Bug 修复】修复 `allowed_roots` 死代码 — `allowed_roots=[]`(空列表)现正确表示"无路径限制"(不再误判为禁止所有路径) - 【安全调整】`allowed_roots` 默认为空 — 安全防护主要依赖完整性 + 路径交叉验证,而非固定目录限制,更适合恢复工具的实际场景 - 【接口变更】restore 新增 `--force` 参数 — 跳过 SHA256 存在性检查,用于强制恢复 v0.3.0 之前的旧备份(路径验证仍生效) - 【Bug 修复】`verify` 命令新增 PATH 交叉验证结果 — 同时报告 hash_match 和 path_match 两个检查的结果 **完整变更:** - `safe_path.py`:完全重写 `verify_integrity_and_path()`,新增 `write_sha256_file()` / `read_sha256_file()`,格式改为 `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`:集成新版安全 API,`--force` 参数,`verify` 返回 path_match - 更新 SKILL.md / README.md / CLAWDHUB.md ### v0.2.0(2026-03-26)— 上一版本 - 新增 `safe_path.py` 路径安全验证模块 - backup 时自动计算并存储 SHA256 哈希(`.sha256` 文件) - restore 时验证备份完整性(SHA256 比对),完整性不符拒绝恢复 - restore 时验证恢复路径(防止 `.path` 篡改 + 路径遍历) - 所有安全拦截事件记录为 `SECURITY` 级别日志 - 新增 `verify` 命令:手动检查备份完整性(不执行恢复) - 新增 `safe_path.py` 独立工具:可单独调用 `compute <file_path>` 计算 SHA256 ### v0.1.0(2026-03-26) - 基础备份/恢复/清理功能 - 7天自动清理备份,30天自动清理日志 - 多文件批量恢复保护 - 冲突保护恢复 ### English ### v0.3.0 (2026-03-27) — Current Version **Security fixes:** - 【Critical】SHA256 record is now **STRICTLY REQUIRED** — missing or empty SHA256 blocks restore by default, fixing the critical bypass vulnerability where deleting `.sha256` disabled integrity checks - 【Security enhancement】`.sha256` file now stores `PATH:` line — restore performs cross-check between the path stored in `.sha256` and the `.path` file, fully preventing `.path` redirection attacks - 【Bug fix】Fixed `allowed_roots` dead code — `allowed_roots=[]` (empty list) now correctly means "no restriction" (previously falsely blocked all paths) - 【Security adjustment】`allowed_roots` defaults to empty — primary security comes from integrity + path cross-validation rather than fixed directory restrictions, which is more appropriate for a recovery tool - 【Interface change】restore command gains `--force` flag — bypasses SHA256 existence check to restore pre-v0.3.0 backups (path validation still applies) - 【Bug fix】`verify` command now reports PATH cross-validation result — returns both hash_match and path_match **Complete changes:** - `safe_path.py`: Fully rewritten `verify_integrity_and_path()`, new `write_sha256_file()` / `read_sha256_file()`, format changed to `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`: Integrated new security API, `--force` flag, `verify` returns path_match - Updated SKILL.md / README.md / CLAWDHUB.md ### v0.2.0 (2026-03-26) — Previous Version - Added `safe_path.py` path safety validation module - SHA256 hash computed and stored on backup (`.sha256` file) - Restore verifies SHA256 integrity — blocks restore if hash mismatch - Restore validates destination path — prevents `.path` tampering and path traversal - All security blocks logged at `SECURITY` level - Added `verify` command: manually check backup integrity without restoring - Added `safe_path.py` standalone tool: `python safe_path.py compute <file>` ### v0.1.0 (2026-03-26) - Basic backup/restore/cleanup functionality - 7-day auto backup cleanup, 30-day auto log cleanup - Multi-file batch recovery protection - Conflict-protected recovery --- ### 中文 *如有问题或建议,欢迎反馈!* ### English *For questions or suggestions, feedback is welcome!*
v0.3.1
# delete-recovery v0.3.0 ### 中文 文件删除安全网——备份、恢复、SHA256完整性校验、路径交叉验证、全自动清理。 ### English A safety net for file deletion — backup, recovery, SHA256 integrity verification, path cross-validation, and fully automatic cleanup. --- ### 中文 一款轻量的 OpenClaw skill,在删除文件前自动将其备份到带时间戳的文件夹。**v0.3.0 新增 SHA256 强制校验 + PATH 交叉验证**,修复了 v0.2.0 中 SHA256 可被绕过的安全漏洞,防止恶意文件注入攻击。误删后一键恢复,过期备份和日志全自动清理,无需人工干预。 ### English A lightweight OpenClaw skill that automatically backs up files to timestamped folders before deletion. **v0.3.0 adds mandatory SHA256 integrity checks and PATH cross-validation**, fixing a security bypass vulnerability in v0.2.0 and preventing malicious file injection attacks. Recover accidentally deleted files with one click, and expired backups and logs are automatically cleaned up without manual intervention. --- ## 功能特性 / Features ### 中文 - **删除前自动备份** — 删除任何文件前,自动备份到带时间戳的文件夹 - **SHA256 强制校验(v0.3.0 修复)** — 备份时计算哈希,恢复时验证;SHA256 记录缺失或为空时 restore 默认阻止(无法再通过删除文件绕过) - **PATH 交叉验证(v0.3.0 新增)** — `.sha256` 文件中绑定原始路径,恢复时双向交叉验证,彻底防止 `.path` 文件被篡改定向到任意位置 - **路径遍历防护** — 检测 `../` 逃逸序列,拒绝恢复目标超出合法范围 - **一键恢复** — 将误删文件恢复到原始位置 - **多文件安全处理** — 同一备份文件夹含多文件时,须全部恢复完毕才删除备份 - **自动清理** — 备份7天后自动删除,日志30天后自动删除,完全自动化 - **冲突保护恢复** — 恢复时若目标位置已有文件,自动移到 `temp_existing/` 暂存 - **完整操作日志** — 每次备份、恢复、清理、安全拦截操作均有记录(含 SECURITY 级别) - **`--force` 恢复旧备份(v0.3.0 新增)** — 对 v0.3.0 之前创建的旧备份(无 SHA256 记录),可用 `--force` 强制恢复(路径验证仍生效) ### English - **Automatic backup before deletion** — Automatically backs up any file to a timestamped folder before deletion - **Mandatory SHA256 integrity check (v0.3.0 fixed)** — Computes hash during backup and verifies during recovery; missing or empty SHA256 record now blocks restore by default (bypass attack eliminated) - **PATH cross-validation (NEW in v0.3.0)** — SHA256 file now stores FILE_HASH + PATH; restore performs cross-check between `.sha256` record and `.path` file, fully preventing `.path` redirection attacks - **Path traversal protection** — Detects `../` escape sequences and blocks restores outside the valid directory range - **One-click recovery** — Restores accidentally deleted files to their original location - **Multi-file safe handling** — When a backup folder contains multiple files, all must be restored before deleting the backup - **Automatic cleanup** — Backups are deleted after 7 days and logs after 30 days, fully automated - **Conflict-protected recovery** — If a file already exists at the restore destination, it is automatically moved to `temp_existing/` for staging - **Complete operation logs** — Every backup, restore, cleanup, and security interception operation is logged (including SECURITY level) - **`--force` for legacy backups (NEW in v0.3.0)** — Use `--force` to restore pre-v0.3.0 backups that lack SHA256 records (path validation still applies) --- ## 安装方式 / Installation ### 中文 ### 通过 ClawdHub 安装(推荐) ```bash # 安装最新版(v0.3.0) clawdhub install delete-recovery # 安装指定版本 clawdhub install delete-recovery --version 0.3.0 ``` ### 手动安装 将 `delete-recovery-0.3.0` 文件夹复制到本地 Agent 的 OpenClaw workspace 的 `skills/` 目录下。 ### English ### Install via ClawdHub (Recommended) ```bash # Install latest version (v0.3.0) clawdhub install delete-recovery # Install specific version clawdhub install delete-recovery --version 0.3.0 ``` ### Manual Installation Copy the `delete-recovery-0.3.0` folder to the `skills/` directory in your local Agent's OpenClaw workspace. --- ## 快速开始 / Quick Start ### 中文 ### 1. 删除前备份 ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # 示例 python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. 恢复误删文件 ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # 恢复 v0.3.0 之前的旧备份(无 SHA256 记录) python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. 验证备份完整性 ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` 不执行恢复,仅检查备份文件是否被篡改(SHA256 完整性 + PATH 交叉验证)。 ### 4. 查看所有备份 ```bash python delete_recovery.py list ``` ### 5. 手动删除指定备份 ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. 手动触发清理 ```bash python delete_recovery.py cleanup ``` ### 7. 查看操作日志 ```bash python delete_recovery.py log [lines] ``` ### English ### 1. Backup Before Deletion ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # Example python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. Restore Accidentally Deleted Files ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # Restore pre-v0.3.0 backup (no SHA256 record) using --force python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. Verify Backup Integrity ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` Does not perform recovery. Checks SHA256 integrity AND PATH cross-validation to detect any tampering. ### 4. List All Backups ```bash python delete_recovery.py list ``` ### 5. Manually Delete Specified Backup ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. Manually Trigger Cleanup ```bash python delete_recovery.py cleanup ``` ### 7. View Operation Logs ```bash python delete_recovery.py log [lines] ``` --- ## 安全机制详解(v0.3.0)/ Security Mechanisms Explained (v0.3.0) ### 中文 ### 场景1:备份被替换 攻击者先备份一个正常文件,然后用恶意文件替换备份目录中的文件,诱导恢复。 **防御:** backup 时计算 SHA256 并存储;restore 时验证哈希,不匹配则拒绝恢复。即使攻击者删除了 `.sha256` 文件,restore 也会被阻止(除非使用 `--force`,且路径验证仍然生效)。 ### 场景2:.path 文件被篡改 攻击者修改 `.path` 文件内容,将恢复目标指向系统目录(如 `C:\Windows\System32\evil.exe`)。 **防御:** v0.3.0 新增 `.sha256` 文件中的 PATH 字段。restore 时读取 `.sha256` 中存储的原始路径,与 `.path` 文件内容进行交叉验证,二者不一致则拒绝恢复。 ### 场景3:SHA256 记录被删除绕过 攻击者直接删除或置空 `.sha256` 文件,试图绕过完整性检查。 **防御:** v0.3.0 修复此漏洞——SHA256 记录缺失或为空时,restore 默认阻止并报错,不再跳过完整性检查。 ### 场景4:路径遍历 攻击者在目标路径中构造 `../../../dangerous/evil.exe`,试图逃逸到合法目录范围外。 **防御:** `_is_path_safe()` 检测 `..` 成分,resolve 后路径不在合法范围则拒绝。 ### English ### Scenario 1: Backup Replaced An attacker first backs up a normal file, then replaces the file in the backup directory with a malicious one to induce recovery. **Defense:** Compute and store SHA256 during backup; verify hash during restore and reject if mismatched. If the attacker also deletes the `.sha256` file to bypass the check, restore is still blocked by default (unless `--force` is used, and path validation still applies). ### Scenario 2: .path File Tampered An attacker modifies the `.path` file content to point the restore target to a system directory (e.g., `C:\Windows\System32\evil.exe`). **Defense:** v0.3.0 stores the original path in the `.sha256` file (in the `PATH:` line). On restore, the path from `.sha256` is cross-checked against the `.path` file — any mismatch is blocked. ### Scenario 3: SHA256 Record Deleted to Bypass Check An attacker deletes or empties the `.sha256` file to bypass integrity checks. **Defense:** v0.3.0 fixes this — missing or empty SHA256 record now blocks restore by default. The only escape hatch is `--force`, but path cross-validation still runs. ### Scenario 4: Path Traversal An attacker constructs `../../../dangerous/evil.exe` in the target path to escape outside the allowed directory. **Defense:** `_is_path_safe()` detects `..` components and rejects if the resolved path is outside the valid range. --- ## SHA256 文件格式(v0.3.0)/ SHA256 File Format (v0.3.0) ### 中文 `.sha256` 文件采用结构化格式,同时存储文件哈希和原始路径: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**:格式版本号,用于未来兼容升级 - **`FILE_HASH:`**:备份文件的 SHA256 哈希(64位十六进制) - **`PATH:`**:备份时的原始文件路径(与 `.path` 文件内容一致,用于交叉验证) ### English The `.sha256` file uses a structured format that stores both the file hash and original path: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**: Format version marker for future compatibility - **`FILE_HASH:`**: SHA256 hash of the backup file (64 hex characters) - **`PATH:`**: Original file path at backup time (mirrors `.path` file; used for cross-validation) --- ## 文件结构 / File Structure ### 中文 ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill 定义 ├── README.md — 使用指南(本文) ├── CLAWDHUB.md — ClawdHub 发布元数据 ├── log.txt — 操作日志(30天自动清理) ├── delete_backup/ — 备份存储(7天自动清理) │ ├── YYYYMMDDHHMM/ — 时间戳备份文件夹 │ │ ├── C__Users__... — 备份文件 │ │ ├── C__Users__...path — 原始路径记录 │ │ ├── C__Users__...sha256 — SHA256 完整性 + PATH 交叉验证记录(v0.3.0) │ │ └── .restored — 已恢复文件清单 │ └── temp_existing/ — 恢复时暂存冲突文件 └── scripts/ ├── delete_recovery.py — 核心脚本(含安全验证) └── safe_path.py — 路径安全验证模块(v0.3.0) ``` ### English ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill definition ├── README.md — User guide (this document) ├── CLAWDHUB.md — ClawdHub publishing metadata ├── log.txt — Operation logs (auto-cleaned after 30 days) ├── delete_backup/ — Backup storage (auto-cleaned after 7 days) │ ├── YYYYMMDDHHMM/ — Timestamped backup folder │ │ ├── C__Users__... — Backup file │ │ ├── C__Users__...path — Original path record │ │ ├── C__Users__...sha256 — SHA256 + PATH cross-validation record (v0.3.0) │ │ └── .restored — Restored files manifest │ └── temp_existing/ — Conflict files staged during recovery └── scripts/ ├── delete_recovery.py — Core script (with security checks) └── safe_path.py — Path safety validation module (v0.3.0) ``` --- ## 工作流程 / Workflow ### 中文 ``` 用户决定删除文件 │ ▼ ① backup 命令 ← 第一步必须做(v0.3.0 自动生成 SHA256 + PATH 记录) │ ▼ ② 用户执行删除操作 │ ▼(后续如需恢复) ③ restore 命令 ← v0.3.0:完整性 + PATH 交叉验证 + 遍历检测 │ ▼ 备份自动删除 ←(除非使用了 --keep-backup) ``` ### English ``` User decides to delete file │ ▼ ① backup command ← Must do first (v0.3.0 auto-generates SHA256 + PATH record) │ ▼ ② User performs deletion │ ▼(If recovery needed later) ③ restore command ← v0.3.0: integrity + PATH cross-validation + traversal detection │ ▼ Backup auto-deleted ←(Unless --keep-backup is used) ``` --- ## 依赖环境 / Dependencies ### 中文 - Python 3.6+ - OpenClaw 1.0+(含 skill 支持) ### English - Python 3.6+ - OpenClaw 1.0+ (with skill support) --- ## 更新日志 / Changelog ### 中文 ### v0.3.0(2026-03-27) — 当前版本 **安全修复:** - 【最关键】SHA256 记录改为**强制要求** — 缺失或为空时 restore **默认阻止**,修复了"删除 `.sha256` 文件即可绕过完整性检查"的严重漏洞 - 【安全增强】`.sha256` 文件新增 `PATH:` 行 — restore 时双向交叉验证 `.sha256` 中存储的路径与 `.path` 文件内容,彻底防止 `.path` 篡改攻击 - 【Bug 修复】修复 `allowed_roots` 死代码 — `allowed_roots=[]`(空列表)现正确表示"无路径限制"(不再误判为禁止所有路径) - 【安全调整】`allowed_roots` 默认为空 — 安全防护主要依赖完整性 + 路径交叉验证,而非固定目录限制,更适合恢复工具的实际场景 - 【接口变更】restore 新增 `--force` 参数 — 跳过 SHA256 存在性检查,用于强制恢复 v0.3.0 之前的旧备份(路径验证仍生效) - 【Bug 修复】`verify` 命令新增 PATH 交叉验证结果 — 同时报告 hash_match 和 path_match 两个检查的结果 **完整变更:** - `safe_path.py`:完全重写 `verify_integrity_and_path()`,新增 `write_sha256_file()` / `read_sha256_file()`,格式改为 `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`:集成新版安全 API,`--force` 参数,`verify` 返回 path_match - 更新 SKILL.md / README.md / CLAWDHUB.md ### v0.2.0(2026-03-26)— 上一版本 - 新增 `safe_path.py` 路径安全验证模块 - backup 时自动计算并存储 SHA256 哈希(`.sha256` 文件) - restore 时验证备份完整性(SHA256 比对),完整性不符拒绝恢复 - restore 时验证恢复路径(防止 `.path` 篡改 + 路径遍历) - 所有安全拦截事件记录为 `SECURITY` 级别日志 - 新增 `verify` 命令:手动检查备份完整性(不执行恢复) - 新增 `safe_path.py` 独立工具:可单独调用 `compute <file_path>` 计算 SHA256 ### v0.1.0(2026-03-26) - 基础备份/恢复/清理功能 - 7天自动清理备份,30天自动清理日志 - 多文件批量恢复保护 - 冲突保护恢复 ### English ### v0.3.0 (2026-03-27) — Current Version **Security fixes:** - 【Critical】SHA256 record is now **STRICTLY REQUIRED** — missing or empty SHA256 blocks restore by default, fixing the critical bypass vulnerability where deleting `.sha256` disabled integrity checks - 【Security enhancement】`.sha256` file now stores `PATH:` line — restore performs cross-check between the path stored in `.sha256` and the `.path` file, fully preventing `.path` redirection attacks - 【Bug fix】Fixed `allowed_roots` dead code — `allowed_roots=[]` (empty list) now correctly means "no restriction" (previously falsely blocked all paths) - 【Security adjustment】`allowed_roots` defaults to empty — primary security comes from integrity + path cross-validation rather than fixed directory restrictions, which is more appropriate for a recovery tool - 【Interface change】restore command gains `--force` flag — bypasses SHA256 existence check to restore pre-v0.3.0 backups (path validation still applies) - 【Bug fix】`verify` command now reports PATH cross-validation result — returns both hash_match and path_match **Complete changes:** - `safe_path.py`: Fully rewritten `verify_integrity_and_path()`, new `write_sha256_file()` / `read_sha256_file()`, format changed to `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`: Integrated new security API, `--force` flag, `verify` returns path_match - Updated SKILL.md / README.md / CLAWDHUB.md ### v0.2.0 (2026-03-26) — Previous Version - Added `safe_path.py` path safety validation module - SHA256 hash computed and stored on backup (`.sha256` file) - Restore verifies SHA256 integrity — blocks restore if hash mismatch - Restore validates destination path — prevents `.path` tampering and path traversal - All security blocks logged at `SECURITY` level - Added `verify` command: manually check backup integrity without restoring - Added `safe_path.py` standalone tool: `python safe_path.py compute <file>` ### v0.1.0 (2026-03-26) - Basic backup/restore/cleanup functionality - 7-day auto backup cleanup, 30-day auto log cleanup - Multi-file batch recovery protection - Conflict-protected recovery --- ### 中文 *如有问题或建议,欢迎反馈!* ### English *For questions or suggestions, feedback is welcome!*
v0.3.0
# delete-recovery v0.3.0 ### 中文 文件删除安全网——备份、恢复、SHA256完整性校验、路径交叉验证、全自动清理。 ### English A safety net for file deletion — backup, recovery, SHA256 integrity verification, path cross-validation, and fully automatic cleanup. --- ### 中文 一款轻量的 OpenClaw skill,在删除文件前自动将其备份到带时间戳的文件夹。**v0.3.0 新增 SHA256 强制校验 + PATH 交叉验证**,修复了 v0.2.0 中 SHA256 可被绕过的安全漏洞,防止恶意文件注入攻击。误删后一键恢复,过期备份和日志全自动清理,无需人工干预。 ### English A lightweight OpenClaw skill that automatically backs up files to timestamped folders before deletion. **v0.3.0 adds mandatory SHA256 integrity checks and PATH cross-validation**, fixing a security bypass vulnerability in v0.2.0 and preventing malicious file injection attacks. Recover accidentally deleted files with one click, and expired backups and logs are automatically cleaned up without manual intervention. --- ## 功能特性 / Features ### 中文 - **删除前自动备份** — 删除任何文件前,自动备份到带时间戳的文件夹 - **SHA256 强制校验(v0.3.0 修复)** — 备份时计算哈希,恢复时验证;SHA256 记录缺失或为空时 restore 默认阻止(无法再通过删除文件绕过) - **PATH 交叉验证(v0.3.0 新增)** — `.sha256` 文件中绑定原始路径,恢复时双向交叉验证,彻底防止 `.path` 文件被篡改定向到任意位置 - **路径遍历防护** — 检测 `../` 逃逸序列,拒绝恢复目标超出合法范围 - **一键恢复** — 将误删文件恢复到原始位置 - **多文件安全处理** — 同一备份文件夹含多文件时,须全部恢复完毕才删除备份 - **自动清理** — 备份7天后自动删除,日志30天后自动删除,完全自动化 - **冲突保护恢复** — 恢复时若目标位置已有文件,自动移到 `temp_existing/` 暂存 - **完整操作日志** — 每次备份、恢复、清理、安全拦截操作均有记录(含 SECURITY 级别) - **`--force` 恢复旧备份(v0.3.0 新增)** — 对 v0.3.0 之前创建的旧备份(无 SHA256 记录),可用 `--force` 强制恢复(路径验证仍生效) ### English - **Automatic backup before deletion** — Automatically backs up any file to a timestamped folder before deletion - **Mandatory SHA256 integrity check (v0.3.0 fixed)** — Computes hash during backup and verifies during recovery; missing or empty SHA256 record now blocks restore by default (bypass attack eliminated) - **PATH cross-validation (NEW in v0.3.0)** — SHA256 file now stores FILE_HASH + PATH; restore performs cross-check between `.sha256` record and `.path` file, fully preventing `.path` redirection attacks - **Path traversal protection** — Detects `../` escape sequences and blocks restores outside the valid directory range - **One-click recovery** — Restores accidentally deleted files to their original location - **Multi-file safe handling** — When a backup folder contains multiple files, all must be restored before deleting the backup - **Automatic cleanup** — Backups are deleted after 7 days and logs after 30 days, fully automated - **Conflict-protected recovery** — If a file already exists at the restore destination, it is automatically moved to `temp_existing/` for staging - **Complete operation logs** — Every backup, restore, cleanup, and security interception operation is logged (including SECURITY level) - **`--force` for legacy backups (NEW in v0.3.0)** — Use `--force` to restore pre-v0.3.0 backups that lack SHA256 records (path validation still applies) --- ## 安装方式 / Installation ### 中文 ### 通过 ClawdHub 安装(推荐) ```bash # 安装最新版(v0.3.0) clawdhub install delete-recovery # 安装指定版本 clawdhub install delete-recovery --version 0.3.0 ``` ### 手动安装 将 `delete-recovery-0.3.0` 文件夹复制到本地 Agent 的 OpenClaw workspace 的 `skills/` 目录下。 ### English ### Install via ClawdHub (Recommended) ```bash # Install latest version (v0.3.0) clawdhub install delete-recovery # Install specific version clawdhub install delete-recovery --version 0.3.0 ``` ### Manual Installation Copy the `delete-recovery-0.3.0` folder to the `skills/` directory in your local Agent's OpenClaw workspace. --- ## 快速开始 / Quick Start ### 中文 ### 1. 删除前备份 ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # 示例 python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. 恢复误删文件 ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # 恢复 v0.3.0 之前的旧备份(无 SHA256 记录) python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. 验证备份完整性 ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` 不执行恢复,仅检查备份文件是否被篡改(SHA256 完整性 + PATH 交叉验证)。 ### 4. 查看所有备份 ```bash python delete_recovery.py list ``` ### 5. 手动删除指定备份 ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. 手动触发清理 ```bash python delete_recovery.py cleanup ``` ### 7. 查看操作日志 ```bash python delete_recovery.py log [lines] ``` ### English ### 1. Backup Before Deletion ```bash python delete_recovery.py backup <file_path> [original_path] ``` ```bash # Example python delete_recovery.py backup "C:\Users\user\Desktop\report.docx" # → {"ok": true, "folder": "202603261130", "file": "C__Users__user__Desktop__report.docx"} ``` ### 2. Restore Accidentally Deleted Files ```bash python delete_recovery.py restore <backup_folder> <safe_name> [--keep-backup] [--force] ``` ```bash python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" # → {"ok": true, "restored_to": "C:\\Users\\user\\Desktop\\report.docx", "backup_deleted": true} # Restore pre-v0.3.0 backup (no SHA256 record) using --force python delete_recovery.py restore 202603261130 "C__Users__user__Desktop__report.docx" --force ``` ### 3. Verify Backup Integrity ```bash python delete_recovery.py verify <backup_folder> <safe_name> ``` Does not perform recovery. Checks SHA256 integrity AND PATH cross-validation to detect any tampering. ### 4. List All Backups ```bash python delete_recovery.py list ``` ### 5. Manually Delete Specified Backup ```bash python delete_recovery.py delete_backup <backup_folder> ``` ### 6. Manually Trigger Cleanup ```bash python delete_recovery.py cleanup ``` ### 7. View Operation Logs ```bash python delete_recovery.py log [lines] ``` --- ## 安全机制详解(v0.3.0)/ Security Mechanisms Explained (v0.3.0) ### 中文 ### 场景1:备份被替换 攻击者先备份一个正常文件,然后用恶意文件替换备份目录中的文件,诱导恢复。 **防御:** backup 时计算 SHA256 并存储;restore 时验证哈希,不匹配则拒绝恢复。即使攻击者删除了 `.sha256` 文件,restore 也会被阻止(除非使用 `--force`,且路径验证仍然生效)。 ### 场景2:.path 文件被篡改 攻击者修改 `.path` 文件内容,将恢复目标指向系统目录(如 `C:\Windows\System32\evil.exe`)。 **防御:** v0.3.0 新增 `.sha256` 文件中的 PATH 字段。restore 时读取 `.sha256` 中存储的原始路径,与 `.path` 文件内容进行交叉验证,二者不一致则拒绝恢复。 ### 场景3:SHA256 记录被删除绕过 攻击者直接删除或置空 `.sha256` 文件,试图绕过完整性检查。 **防御:** v0.3.0 修复此漏洞——SHA256 记录缺失或为空时,restore 默认阻止并报错,不再跳过完整性检查。 ### 场景4:路径遍历 攻击者在目标路径中构造 `../../../dangerous/evil.exe`,试图逃逸到合法目录范围外。 **防御:** `_is_path_safe()` 检测 `..` 成分,resolve 后路径不在合法范围则拒绝。 ### English ### Scenario 1: Backup Replaced An attacker first backs up a normal file, then replaces the file in the backup directory with a malicious one to induce recovery. **Defense:** Compute and store SHA256 during backup; verify hash during restore and reject if mismatched. If the attacker also deletes the `.sha256` file to bypass the check, restore is still blocked by default (unless `--force` is used, and path validation still applies). ### Scenario 2: .path File Tampered An attacker modifies the `.path` file content to point the restore target to a system directory (e.g., `C:\Windows\System32\evil.exe`). **Defense:** v0.3.0 stores the original path in the `.sha256` file (in the `PATH:` line). On restore, the path from `.sha256` is cross-checked against the `.path` file — any mismatch is blocked. ### Scenario 3: SHA256 Record Deleted to Bypass Check An attacker deletes or empties the `.sha256` file to bypass integrity checks. **Defense:** v0.3.0 fixes this — missing or empty SHA256 record now blocks restore by default. The only escape hatch is `--force`, but path cross-validation still runs. ### Scenario 4: Path Traversal An attacker constructs `../../../dangerous/evil.exe` in the target path to escape outside the allowed directory. **Defense:** `_is_path_safe()` detects `..` components and rejects if the resolved path is outside the valid range. --- ## SHA256 文件格式(v0.3.0)/ SHA256 File Format (v0.3.0) ### 中文 `.sha256` 文件采用结构化格式,同时存储文件哈希和原始路径: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**:格式版本号,用于未来兼容升级 - **`FILE_HASH:`**:备份文件的 SHA256 哈希(64位十六进制) - **`PATH:`**:备份时的原始文件路径(与 `.path` 文件内容一致,用于交叉验证) ### English The `.sha256` file uses a structured format that stores both the file hash and original path: ``` #v3 FILE_HASH:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 PATH:C:\Users\user\Desktop\report.docx ``` - **`#v3`**: Format version marker for future compatibility - **`FILE_HASH:`**: SHA256 hash of the backup file (64 hex characters) - **`PATH:`**: Original file path at backup time (mirrors `.path` file; used for cross-validation) --- ## 文件结构 / File Structure ### 中文 ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill 定义 ├── README.md — 使用指南(本文) ├── CLAWDHUB.md — ClawdHub 发布元数据 ├── log.txt — 操作日志(30天自动清理) ├── delete_backup/ — 备份存储(7天自动清理) │ ├── YYYYMMDDHHMM/ — 时间戳备份文件夹 │ │ ├── C__Users__... — 备份文件 │ │ ├── C__Users__...path — 原始路径记录 │ │ ├── C__Users__...sha256 — SHA256 完整性 + PATH 交叉验证记录(v0.3.0) │ │ └── .restored — 已恢复文件清单 │ └── temp_existing/ — 恢复时暂存冲突文件 └── scripts/ ├── delete_recovery.py — 核心脚本(含安全验证) └── safe_path.py — 路径安全验证模块(v0.3.0) ``` ### English ``` delete-recovery-0.3.0/ ├── SKILL.md — Skill definition ├── README.md — User guide (this document) ├── CLAWDHUB.md — ClawdHub publishing metadata ├── log.txt — Operation logs (auto-cleaned after 30 days) ├── delete_backup/ — Backup storage (auto-cleaned after 7 days) │ ├── YYYYMMDDHHMM/ — Timestamped backup folder │ │ ├── C__Users__... — Backup file │ │ ├── C__Users__...path — Original path record │ │ ├── C__Users__...sha256 — SHA256 + PATH cross-validation record (v0.3.0) │ │ └── .restored — Restored files manifest │ └── temp_existing/ — Conflict files staged during recovery └── scripts/ ├── delete_recovery.py — Core script (with security checks) └── safe_path.py — Path safety validation module (v0.3.0) ``` --- ## 工作流程 / Workflow ### 中文 ``` 用户决定删除文件 │ ▼ ① backup 命令 ← 第一步必须做(v0.3.0 自动生成 SHA256 + PATH 记录) │ ▼ ② 用户执行删除操作 │ ▼(后续如需恢复) ③ restore 命令 ← v0.3.0:完整性 + PATH 交叉验证 + 遍历检测 │ ▼ 备份自动删除 ←(除非使用了 --keep-backup) ``` ### English ``` User decides to delete file │ ▼ ① backup command ← Must do first (v0.3.0 auto-generates SHA256 + PATH record) │ ▼ ② User performs deletion │ ▼(If recovery needed later) ③ restore command ← v0.3.0: integrity + PATH cross-validation + traversal detection │ ▼ Backup auto-deleted ←(Unless --keep-backup is used) ``` --- ## 依赖环境 / Dependencies ### 中文 - Python 3.6+ - OpenClaw 1.0+(含 skill 支持) ### English - Python 3.6+ - OpenClaw 1.0+ (with skill support) --- ## 更新日志 / Changelog ### 中文 ### v0.3.0(2026-03-27) — 当前版本 **安全修复:** - 【最关键】SHA256 记录改为**强制要求** — 缺失或为空时 restore **默认阻止**,修复了"删除 `.sha256` 文件即可绕过完整性检查"的严重漏洞 - 【安全增强】`.sha256` 文件新增 `PATH:` 行 — restore 时双向交叉验证 `.sha256` 中存储的路径与 `.path` 文件内容,彻底防止 `.path` 篡改攻击 - 【Bug 修复】修复 `allowed_roots` 死代码 — `allowed_roots=[]`(空列表)现正确表示"无路径限制"(不再误判为禁止所有路径) - 【安全调整】`allowed_roots` 默认为空 — 安全防护主要依赖完整性 + 路径交叉验证,而非固定目录限制,更适合恢复工具的实际场景 - 【接口变更】restore 新增 `--force` 参数 — 跳过 SHA256 存在性检查,用于强制恢复 v0.3.0 之前的旧备份(路径验证仍生效) - 【Bug 修复】`verify` 命令新增 PATH 交叉验证结果 — 同时报告 hash_match 和 path_match 两个检查的结果 **完整变更:** - `safe_path.py`:完全重写 `verify_integrity_and_path()`,新增 `write_sha256_file()` / `read_sha256_file()`,格式改为 `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`:集成新版安全 API,`--force` 参数,`verify` 返回 path_match - 更新 SKILL.md / README.md / CLAWDHUB.md ### v0.2.0(2026-03-26)— 上一版本 - 新增 `safe_path.py` 路径安全验证模块 - backup 时自动计算并存储 SHA256 哈希(`.sha256` 文件) - restore 时验证备份完整性(SHA256 比对),完整性不符拒绝恢复 - restore 时验证恢复路径(防止 `.path` 篡改 + 路径遍历) - 所有安全拦截事件记录为 `SECURITY` 级别日志 - 新增 `verify` 命令:手动检查备份完整性(不执行恢复) - 新增 `safe_path.py` 独立工具:可单独调用 `compute <file_path>` 计算 SHA256 ### v0.1.0(2026-03-26) - 基础备份/恢复/清理功能 - 7天自动清理备份,30天自动清理日志 - 多文件批量恢复保护 - 冲突保护恢复 ### English ### v0.3.0 (2026-03-27) — Current Version **Security fixes:** - 【Critical】SHA256 record is now **STRICTLY REQUIRED** — missing or empty SHA256 blocks restore by default, fixing the critical bypass vulnerability where deleting `.sha256` disabled integrity checks - 【Security enhancement】`.sha256` file now stores `PATH:` line — restore performs cross-check between the path stored in `.sha256` and the `.path` file, fully preventing `.path` redirection attacks - 【Bug fix】Fixed `allowed_roots` dead code — `allowed_roots=[]` (empty list) now correctly means "no restriction" (previously falsely blocked all paths) - 【Security adjustment】`allowed_roots` defaults to empty — primary security comes from integrity + path cross-validation rather than fixed directory restrictions, which is more appropriate for a recovery tool - 【Interface change】restore command gains `--force` flag — bypasses SHA256 existence check to restore pre-v0.3.0 backups (path validation still applies) - 【Bug fix】`verify` command now reports PATH cross-validation result — returns both hash_match and path_match **Complete changes:** - `safe_path.py`: Fully rewritten `verify_integrity_and_path()`, new `write_sha256_file()` / `read_sha256_file()`, format changed to `#v3 / FILE_HASH: / PATH:` - `delete_recovery.py`: Integrated new security API, `--force` flag, `verify` returns path_match - Updated SKILL.md / README.md / CLAWDHUB.md ### v0.2.0 (2026-03-26) — Previous Version - Added `safe_path.py` path safety validation module - SHA256 hash computed and stored on backup (`.sha256` file) - Restore verifies SHA256 integrity — blocks restore if hash mismatch - Restore validates destination path — prevents `.path` tampering and path traversal - All security blocks logged at `SECURITY` level - Added `verify` command: manually check backup integrity without restoring - Added `safe_path.py` standalone tool: `python safe_path.py compute <file>` ### v0.1.0 (2026-03-26) - Basic backup/restore/cleanup functionality - 7-day auto backup cleanup, 30-day auto log cleanup - Multi-file batch recovery protection - Conflict-protected recovery --- ### 中文 *如有问题或建议,欢迎反馈!* ### English *For questions or suggestions, feedback is welcome!*
元数据
Slug delete-recovery
版本 0.8.3
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 24
常见问题

delete-recovery 是什么?

Automatically backs up files before deletion to timestamped folders, allows restoring deleted files, lists backups, and cleans expired backups and logs. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 342 次。

如何安装 delete-recovery?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install delete-recovery」即可一键安装,无需额外配置。

delete-recovery 是免费的吗?

是的,delete-recovery 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

delete-recovery 支持哪些平台?

delete-recovery 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 delete-recovery?

由 hanxweb(@hanxweb)开发并维护,当前版本 v0.8.3。

💬 留言讨论