File Protection and Version Management
This Skill uses MiniVCS to track all file operations with version history.
Runtime requirement: Python 3 is required to run scripts/minivcs/minivcs.py.
Script location: scripts/minivcs/minivcs.py in the same directory as this SKILL.md
(Before executing, first determine the directory containing this file. It is referred to as $SKILL_DIR below.)
Core mechanism:
- - Modify: Saves an incremental diff plus a full snapshot from before the modification, supporting rollback
- Delete: Moves the full file into
~/.openclaw/minivcs/trash/, supporting restore - All files are indexed, with different retention periods based on importance
- After every operation, the full record table is scanned automatically to find expired records and ask the user for confirmation
Usage limitations:
- - Binary files (images, PDFs, audio/video, etc.): Text diffs cannot be generated. For binary-file protection, MiniVCS stores a full local
.bak copy instead. This applies to binary-file backup/rollback protection, and deletion protection also stores a full local copy in ~/.openclaw/minivcs/trash/. The user must be informed before the operation because storage usage may be relatively high. - The first record cannot be rolled back: When a file is recorded for the first time, there is not yet any historical baseline, so that record has no snapshot. After that, each call to
record_modify following an edit automatically saves a snapshot, allowing rollback to the state before any edit. - Local storage notice: Protection data is stored locally under
~/.openclaw/minivcs/. This Skill does not provide encryption or remote sync.
Prerequisite Check: Confirm Python Is Installed
Before performing any operation, you must first check whether Python 3 is installed in the user's environment. This Skill requires Python 3 and should not run without it.
How to check
CODEBLOCK0
- - If the output is
Python 3.x.x, it is installed and you can continue - If it says
command not found or is not recognized as an internal or external command, stop and tell the user that this Skill requires Python 3
Dependency boundary
If Python 3 is missing:
- - Do not run dependency installation commands from this Skill
- Do not run remote install scripts such as INLINECODE12
- Do not write to shell config files such as
~/.zshrc or INLINECODE14 - Do not modify global environment variables on the user's behalf from this Skill
- Tell the user that Python 3 is required, and ask them to install it first or explicitly authorize a separate environment-setup flow
Note: On some Windows systems the command is python, while on macOS/Linux it is python3.
In all commands below that use python, replace it with the correct command for the actual environment.
Retention Policy
| File Type | Retention Days | Decision Rule |
|---|
| Important files | 14 days | System paths (/etc/, /root/, /usr/local/etc/, /opt/), user config directories (~/.ssh/, ~/.gnupg/, ~/.config/, ~/.openclaw/, ~/.kube/, ~/.docker/, ~/.aws/, ~/.azure/, ~/.local/share/), Windows system directories (C:\Windows\, C:\ProgramData\, C:\Program Files\), config files (.yaml/.toml/.env, etc.), entry files (main.py/index.ts, etc.) |
| Normal files |
7 days | All other files |
When each record is created, the expireAt (expiration timestamp) and expireAtDatetime (human-readable time) fields are set automatically.
Excluded Paths (Auto-Skip)
Files whose path contains any of the following segments are automatically skipped by record_modify and record_delete. These are generated, vendored, or cache directories that should not be version-tracked:
INLINECODE40 , .git, __pycache__, .venv, venv, .tox, .mypy_cache, .pytest_cache, .ruff_cache, dist, build, .next, .nuxt, INLINECODE53
When a file is skipped, the return value will contain "skipped": true and a "reason" field. The Agent should inform the user that the file was not tracked and explain why.
Binary File Size Warning
When a binary file exceeds 50 MB, the return value from record_modify (binary backup) will include:
- - INLINECODE57
- INLINECODE58 : a human-readable description of the file size and threshold
When sizeWarning is present, the Agent must explicitly inform the user of the file size and ask for confirmation before proceeding with any further binary backup operations on similarly large files.
Operation Flow
Step 1: Initialize the MiniVCS Working Directory
On first use, the storage directory is created automatically. No extra action is required:
CODEBLOCK1
All data is stored uniformly in ~/.openclaw/minivcs/:
~/.openclaw/minivcs/
logs.json # operation log (includes the expireAt field)
diffs/ # incremental patches for text file modifications
bases/ # baseline for the next comparison (named by full relative path, so no same-name conflicts)
snapshots/ # full snapshots before text file modifications (used for rollback)
trash/ # full backups of deleted files (used for restore)
backups/ # full `.bak` copies of binary files (used for rollback)
Step 2: Ask the User for Confirmation Before the Operation
Before deleting or modifying a file, you must explain the following to the user and wait for confirmation:
- 1. The file path to be operated on
- The operation type (modify / delete)
- The purpose and intent of the operation
- The possible impact
- Explain the local storage behavior: this Skill stores protection data under
~/.openclaw/minivcs/ - For text-file modifications, explain that MiniVCS stores diffs and snapshots so the file can be rolled back
- For deletions, explain that MiniVCS stores a full local copy in
~/.openclaw/minivcs/trash/ so the file can be restored - If the file is binary, explicitly explain that protection uses a full local copy rather than a text diff, and ask whether the user wants that local copy to be stored before deletion or binary-file protection
- If a binary backup returns
sizeWarning: true, the Agent must display the file size and warning message to the user, and ask for explicit confirmation before proceeding
If the file is binary and the user does not want a local stored copy, do not treat the operation as a protected delete/rollback flow under this Skill.
If the path is auto-skipped (return contains "skipped": true), inform the user that the file was not tracked and state the reason.
Example before the operation:
CODEBLOCK3
Example for a binary file before deletion:
CODEBLOCK4
After the operation completes, you must inform the user of the record result, for example:
# After a modification is completed
The modification to path/to/file.py has been completed, and this change has been recorded (Record ID: 1710000000000).
- Change summary: +5 lines, -2 lines
- Retention period: 7 days (expires at: 2026-03-20 10:00:00)
- Rollback available: yes (use restore 1710000000000 to recover the state before the modification)
If you want to view the diff or roll it back, let me know.
# After a deletion is completed
path/to/file.py has been moved to the trash and backed up (Record ID: 1710000001000).
- Retention period: 14 days (expires at: 2026-03-27 10:00:00) [important file]
If you want to restore this file, let me know.
Step 3: Operate on Files with MiniVCS
Modify a file (supports rollback)
Just call record once after each edit. The snapshot chain is formed automatically and supports rolling back to any historical state:
CODEBLOCK6
CODEBLOCK7
Python API:
CODEBLOCK8
Delete a file (supports restore)
Do not delete the file directly. Use record_delete instead, and the file is moved into trash automatically.
Before running record_delete:
- - Tell the user that a full local copy will be stored in INLINECODE69
- If the file is binary, explicitly ask whether they want that local copy to be stored
- Only proceed with protected deletion after the user confirms the local storage behavior
CODEBLOCK9
Python API:
CODEBLOCK10
Restore / Roll back
The same restore command handles both scenarios:
CODEBLOCK11
Python API:
result = vcs.restore_file(record_id="...")
# After DELETE succeeds: the record is marked as RESTORED and no longer appears in the trash list
# After MODIFY succeeds: the record is marked as ROLLED_BACK
# Repeated restore: returns {"success": False, "error": "already been restored/rolled_back"}
Step 4: Handle Expired Cleanup Notifications (must be done after every operation)
After each call to record_modify or record_delete, the return value contains the due_for_cleanup field.
If due_for_cleanup is not empty, the Agent must:
- 1. Show the user the list of expired records (sorted from earliest to latest)
- Ask which ones can be deleted and which ones need an extension
Example display format:
CODEBLOCK13
Handling after the user responds:
CODEBLOCK14
Command line:
# View all expired records
python "$SKILL_DIR/scripts/minivcs/minivcs.py" cleanup --project-root <project_root>
# Confirm cleanup
python "$SKILL_DIR/scripts/minivcs/minivcs.py" cleanup --confirm --project-root <project_root>
# Extend one record
python "$SKILL_DIR/scripts/minivcs/minivcs.py" extend <record_id> --project-root <project_root>
Other Common Operations
CODEBLOCK16
Record Field Reference
| Field | Type | Description |
|---|
| INLINECODE75 | string | Unique record ID (millisecond timestamp) |
| INLINECODE76 |
string | Relative or absolute path |
|
action | string |
MODIFY /
DELETE /
BINARY_BACKUP /
RESTORED /
ROLLED_BACK |
|
timestamp | number | Creation time (milliseconds) |
|
datetime | string | Creation time (human-readable) |
|
isImportant | bool | Whether the file is important |
|
retentionDays | number | Retention days (7 or 14) |
|
expireAt | number | Expiration time (milliseconds) |
|
expireAtDatetime | string | Expiration time (human-readable) |
|
diffFile | string | Diff patch path (MODIFY only) |
|
snapshotFile | string | Pre-modification snapshot path (only present when MODIFY has a snapshot) |
|
trashFile | string | Trash backup path (DELETE only) |
|
backupFile | string |
.bak copy path (BINARY_BACKUP only) |
|
summary | string | Change summary |
Full Operation Flow Diagram
CODEBLOCK17
文件保护与版本管理
本技能使用 MiniVCS 跟踪所有文件操作并记录版本历史。
运行时要求:需要 Python 3 来运行 scripts/minivcs/minivcs.py。
脚本位置:与本 SKILL.md 文件同目录下的 scripts/minivcs/minivcs.py
(执行前,请先确定包含此文件的目录。下文将其称为 $SKILL_DIR。)
核心机制:
- - 修改:保存增量差异以及修改前的完整快照,支持回滚
- 删除:将完整文件移至 ~/.openclaw/minivcs/trash/,支持恢复
- 所有文件均被索引,根据重要性设置不同的保留期限
- 每次操作后,自动扫描完整记录表,查找过期记录并请求用户确认
使用限制:
- - 二进制文件(图片、PDF、音视频等):无法生成文本差异。对于二进制文件保护,MiniVCS 会存储完整的本地 .bak 副本。这适用于二进制文件的备份/回滚保护,删除保护也会在 ~/.openclaw/minivcs/trash/ 中存储完整的本地副本。操作前必须告知用户,因为存储空间消耗可能相对较高。
- 首次记录无法回滚:当文件首次被记录时,尚不存在任何历史基线,因此该记录没有快照。此后,每次编辑后调用 record_modify 会自动保存快照,从而可以回滚到任意编辑前的状态。
- 本地存储说明:保护数据存储在本地 ~/.openclaw/minivcs/ 目录下。本技能不提供加密或远程同步功能。
前置条件检查:确认已安装 Python
在执行任何操作之前,必须首先检查用户环境中是否已安装 Python 3。本技能需要 Python 3,如果未安装则不应运行。
检查方法
bash
macOS / Linux
python3 --version
Windows (PowerShell)
python --version
- - 如果输出为 Python 3.x.x,则表示已安装,可以继续
- 如果显示 command not found 或 is not recognized as an internal or external command,则停止操作并告知用户本技能需要 Python 3
依赖边界
如果缺少 Python 3:
- - 不要运行本技能中的依赖安装命令
- 不要运行远程安装脚本,如 curl | bash
- 不要写入 shell 配置文件,如 ~/.zshrc 或 ~/.bash_profile
- 不要通过本技能代表用户修改全局环境变量
- 告知用户需要 Python 3,并要求用户先自行安装,或明确授权单独的环境设置流程
注意:在某些 Windows 系统上,命令是 python,而在 macOS/Linux 上是 python3。
在以下所有使用 python 的命令中,请根据实际环境替换为正确的命令。
保留策略
| 文件类型 | 保留天数 | 判定规则 |
|---|
| 重要文件 | 14 天 | 系统路径(/etc/、/root/、/usr/local/etc/、/opt/)、用户配置目录(~/.ssh/、~/.gnupg/、~/.config/、~/.openclaw/、~/.kube/、~/.docker/、~/.aws/、~/.azure/、~/.local/share/)、Windows 系统目录(C:\Windows\、C:\ProgramData\、C:\Program Files\)、配置文件(.yaml/.toml/.env 等)、入口文件(main.py/index.ts 等) |
| 普通文件 |
7 天 | 所有其他文件 |
每条记录创建时,会自动设置 expireAt(过期时间戳)和 expireAtDatetime(人类可读时间)字段。
排除路径(自动跳过)
路径包含以下任意片段的文件,recordmodify 和 recorddelete 会自动跳过。这些是生成、供应商或缓存目录,不应进行版本跟踪:
nodemodules、.git、pycache、.venv、venv、.tox、.mypycache、.pytestcache、.ruffcache、dist、build、.next、.nuxt、.turbo
当文件被跳过时,返回值将包含 skipped: true 和 reason 字段。代理应告知用户该文件未被跟踪并说明原因。
二进制文件大小警告
当二进制文件超过 50 MB 时,record_modify(二进制备份)的返回值将包含:
- - sizeWarning: true
- sizeWarningMessage:文件大小和阈值的可读描述
当存在 sizeWarning 时,代理必须明确告知用户文件大小,并在对类似大文件进行任何进一步的二进制备份操作前请求用户确认。
操作流程
步骤 1:初始化 MiniVCS 工作目录
首次使用时,存储目录会自动创建。无需额外操作:
bash
python $SKILLDIR/scripts/minivcs/minivcs.py history --project-root root>
所有数据统一存储在 ~/.openclaw/minivcs/ 中:
~/.openclaw/minivcs/
logs.json # 操作日志(包含 expireAt 字段)
diffs/ # 文本文件修改的增量补丁
bases/ # 下次比较的基线(按完整相对路径命名,避免同名冲突)
snapshots/ # 文本文件修改前的完整快照(用于回滚)
trash/ # 已删除文件的完整备份(用于恢复)
backups/ # 二进制文件的完整 .bak 副本(用于回滚)
步骤 2:操作前请求用户确认
在删除或修改文件之前,必须向用户解释以下内容并等待确认:
- 1. 要操作的文件路径
- 操作类型(修改/删除)
- 操作的目的和意图
- 可能的影响
- 解释本地存储行为:本技能将保护数据存储在 ~/.openclaw/minivcs/ 下
- 对于文本文件修改,解释 MiniVCS 会存储差异和快照,以便文件可以回滚
- 对于删除,解释 MiniVCS 会在 ~/.openclaw/minivcs/trash/ 中存储完整的本地副本,以便文件可以恢复
- 如果文件是二进制文件,明确解释保护使用完整的本地副本而非文本差异,并询问用户是否希望在删除或二进制文件保护前存储该本地副本
- 如果二进制备份返回 sizeWarning: true,代理必须向用户显示文件大小和警告消息,并在继续前请求明确确认
如果文件是二进制文件且用户不希望存储本地副本,则不要将此操作视为本技能下的受保护删除/回滚流程。
如果路径被自动跳过(返回值包含 skipped: true),告知用户该文件未被跟踪并说明原因。
操作前示例:
我将要对以下文件进行操作,请确认:
- - 文件:/path/to/file.py
- 操作:删除
- 原因:此文件已被新版本替代,不再使用
- 影响:需要确认没有其他模块导入此文件
- 本地存储:将在 ~/.openclaw/minivcs/trash/ 下存储完整的本地副本,以便日后恢复
- 保护:存储的副本将保留 7 天(重要文件为 14 天),期间可随时恢复
是否继续?
删除前二进制文件示例:
我将要删除以下二进制文件,请确认:
- - 文件:/path/to/file.pdf
- 操作:删除
- 原因:此文件不再需要
- 影响:原始文件将从当前位置移除
- 本地存储:为保护此二进制文件,我需要在 ~/.openclaw/minivcs/trash/ 下存储一个完整的本地副本
- 注意:二进制文件使用完整副本而非文本差异进行保护,因此可能占用更多磁盘空间
是否希望在删除前保留该本地备份?
操作完成后,必须告知用户记录结果,例如:
修改完成后
对 path/to/file.py 的修改已完成,此更改已记录(记录 ID:1710000000000)。
- - 更改摘要:+5 行,-2 行
- 保留期限:7 天(过期时间:2026-03-20 10:00:00)
- 可回滚:是(使用 restore 1710000000000 可恢复修改前的状态)
如需查看差异或回滚,请告知。
删除完成后
path/to/file.py 已移至回收站并备份(记录 ID:1710000001000)。