cursor-guard 1.0.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,30 +1,31 @@
1
1
  # Cursor Guard
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/cursor-guard)](https://www.npmjs.com/package/cursor-guard)
4
+ [![license](https://img.shields.io/github/license/zhangqiang8vipp/cursor-guard)](LICENSE)
5
+
3
6
  Protects your code from accidental AI overwrite or deletion in [Cursor](https://cursor.com).
4
7
 
5
- 保护你的代码免受 [Cursor](https://cursor.com) AI 代理意外覆写或删除。
8
+ **[中文文档](README.zh-CN.md)**
6
9
 
7
10
  ---
8
11
 
9
- ## What It Does / 功能介绍
12
+ ## What It Does
10
13
 
11
14
  When Cursor's AI agent edits your files, there's a risk of accidental overwrites, deletions, or loss of work. **Cursor Guard** enforces a safety protocol:
12
15
 
13
- Cursor AI 代理编辑你的文件时,可能会意外覆盖、删除或丢失代码。**Cursor Guard** 强制执行一套安全协议:
14
-
15
- - **Mandatory pre-write snapshots / 强制写前快照** Git commit or shadow copy before any destructive operation / 在任何破坏性操作前自动 Git 提交或影子拷贝
16
- - **Read before Write / 先读后写** The agent must read a file before overwriting it / 代理必须先读取文件内容,才能覆写
17
- - **Review before apply / 预览再执行** Diff previews and explicit confirmation for dangerous ops / 危险操作前展示 diff 预览并要求确认
18
- - **Deterministic recovery / 确定性恢复** Clear priority-ordered recovery paths (Git shadow copies → conversation context → editor history) / 按优先级的恢复路径(Git 影子拷贝 → 对话上下文 → 编辑器历史)
19
- - **Configurable scope / 可配置保护范围** Protect only what matters via `.cursor-guard.json` / 通过配置文件只保护你关心的文件
20
- - **Secrets filtering / 敏感文件过滤** — Sensitive files (`.env`, keys, certificates) are auto-excluded from backups / `.env`、密钥、证书等敏感文件自动排除
21
- - **Auto-backup script / 自动备份脚本** — A PowerShell watcher that periodically snapshots to a dedicated Git branch without disturbing your working tree / 定期快照到独立 Git 分支,不干扰工作区
16
+ - **Mandatory pre-write snapshots** Git commit or shadow copy before any destructive operation
17
+ - **Read before Write** — The agent must read a file before overwriting it
18
+ - **Review before apply**Diff previews and explicit confirmation for dangerous ops
19
+ - **Deterministic recovery** Clear priority-ordered recovery paths (Git shadow copies conversation context editor history)
20
+ - **Configurable scope**Protect only what matters via `.cursor-guard.json`
21
+ - **Secrets filtering**Sensitive files (`.env`, keys, certificates) are auto-excluded from backups
22
+ - **Auto-backup script** A PowerShell watcher that periodically snapshots to a dedicated Git branch without disturbing your working tree
22
23
 
23
24
  ---
24
25
 
25
- ## Installation / 安装
26
+ ## Installation
26
27
 
27
- ### Method 1: npm install / 方式一:npm 安装
28
+ ### Method 1: npm
28
29
 
29
30
  ```bash
30
31
  npm install cursor-guard
@@ -32,106 +33,98 @@ npm install cursor-guard
32
33
 
33
34
  After installation, copy the skill files to your Cursor skills directory:
34
35
 
35
- 安装后,将技能文件复制到 Cursor 技能目录:
36
-
37
36
  **Windows (PowerShell):**
38
37
 
39
38
  ```powershell
40
- # Global installation (all projects) / 全局安装(所有项目生效)
39
+ # Global (all projects)
41
40
  Copy-Item -Recurse node_modules/cursor-guard "$env:USERPROFILE/.cursor/skills/cursor-guard"
42
41
 
43
- # Per-project installation / 项目级安装(仅当前项目生效)
42
+ # Per-project (current project only)
44
43
  Copy-Item -Recurse node_modules/cursor-guard .cursor/skills/cursor-guard
45
44
  ```
46
45
 
47
46
  **macOS / Linux:**
48
47
 
49
48
  ```bash
50
- # Global installation / 全局安装
49
+ # Global
51
50
  cp -r node_modules/cursor-guard ~/.cursor/skills/cursor-guard
52
51
 
53
- # Per-project installation / 项目级安装
52
+ # Per-project
54
53
  cp -r node_modules/cursor-guard .cursor/skills/cursor-guard
55
54
  ```
56
55
 
57
56
  After copying, you can remove the npm dependency if you don't need it in `node_modules`:
58
57
 
59
- 复制完成后,如果不需要保留在 `node_modules` 中,可以卸载:
60
-
61
58
  ```bash
62
59
  npm uninstall cursor-guard
63
60
  ```
64
61
 
65
- ### Method 2: Git clone / 方式二:Git 克隆
62
+ ### Method 2: Git clone
66
63
 
67
64
  ```bash
68
- # Global installation / 全局安装
65
+ # Global
69
66
  git clone https://github.com/zhangqiang8vipp/cursor-guard.git ~/.cursor/skills/cursor-guard
70
67
 
71
- # Per-project installation / 项目级安装
68
+ # Per-project
72
69
  git clone https://github.com/zhangqiang8vipp/cursor-guard.git .cursor/skills/cursor-guard
73
70
  ```
74
71
 
75
- ### Method 3: Manual download / 方式三:手动下载
72
+ ### Method 3: Manual download
76
73
 
77
74
  Download from [GitHub Releases](https://github.com/zhangqiang8vipp/cursor-guard/releases) and extract to:
78
75
 
79
- 从 [GitHub Releases](https://github.com/zhangqiang8vipp/cursor-guard/releases) 下载并解压到:
80
-
81
76
  ```
82
- ~/.cursor/skills/cursor-guard/ # Global / 全局
83
- <project-root>/.cursor/skills/cursor-guard/ # Per-project / 项目级
77
+ ~/.cursor/skills/cursor-guard/ # Global
78
+ <project-root>/.cursor/skills/cursor-guard/ # Per-project
84
79
  ```
85
80
 
86
- ### Verify Installation / 验证安装
81
+ ### Verify Installation
87
82
 
88
- After installation, your directory structure should look like this / 安装后目录结构应如下所示:
83
+ After installation, your directory structure should look like this:
89
84
 
90
85
  ```
91
86
  .cursor/skills/cursor-guard/
92
- ├── SKILL.md # AI agent instructions / AI 代理指令
87
+ ├── SKILL.md # AI agent instructions
93
88
  ├── README.md
94
89
  ├── LICENSE
95
90
  └── references/
96
- ├── auto-backup.ps1 # Auto-backup script / 自动备份脚本
97
- ├── recovery.md # Recovery commands / 恢复命令
98
- ├── cursor-guard.example.json # Example config / 示例配置
99
- └── cursor-guard.schema.json # Config schema / 配置 Schema
91
+ ├── auto-backup.ps1 # Auto-backup script
92
+ ├── recovery.md # Recovery commands
93
+ ├── cursor-guard.example.json # Example config
94
+ └── cursor-guard.schema.json # Config schema
100
95
  ```
101
96
 
102
- The skill activates automatically when the AI agent detects risky operations (file edits, deletes, renames) or when you mention recovery-related terms.
103
-
104
- 技能会在 AI 代理检测到高风险操作(文件编辑、删除、重命名)或你提到恢复相关词汇时自动激活。无需其他设置,安装即生效。
97
+ The skill activates automatically when the AI agent detects risky operations or when you mention recovery-related terms. No extra setup needed.
105
98
 
106
99
  ---
107
100
 
108
- ## Quick Start / 快速上手
101
+ ## Quick Start
109
102
 
110
- 1. **Install the skill** using any method above / 用以上任意方式安装技能
103
+ 1. **Install the skill** using any method above
111
104
 
112
- 2. **Open Cursor** and start an Agent conversation / 打开 Cursor,开始一个 Agent 对话
105
+ 2. **Open Cursor** and start an Agent conversation
113
106
 
114
- 3. **The skill works automatically** — when the AI agent tries to edit files, it will: / 技能自动生效——当 AI 代理尝试编辑文件时,会自动:
115
- - Create a Git snapshot before writing / 写入前创建 Git 快照
116
- - Read files before overwriting / 覆写前先读取文件
117
- - Show diff previews for dangerous operations / 危险操作前展示 diff 预览
118
- - Report a status block after each protected operation / 每次受保护操作后报告状态
107
+ 3. **The skill works automatically** — when the AI agent tries to edit files, it will:
108
+ - Create a Git snapshot before writing
109
+ - Read files before overwriting
110
+ - Show diff previews for dangerous operations
111
+ - Report a status block after each protected operation
119
112
 
120
- 4. **(Optional) Add project config** to customize protection scope / (可选)添加项目配置自定义保护范围:
113
+ 4. **(Optional) Add project config** to customize protection scope:
121
114
 
122
115
  ```bash
123
116
  cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guard.json
124
117
  ```
125
118
 
126
- 5. **(Optional) Run auto-backup** in a separate terminal / (可选)在独立终端运行自动备份:
119
+ 5. **(Optional) Run auto-backup** in a separate terminal:
127
120
 
128
121
  ```powershell
129
122
  .\auto-backup.ps1 -Path "D:\MyProject"
130
123
  ```
131
124
 
132
- ### Project Configuration / 项目配置
125
+ ### Project Configuration
133
126
 
134
- Edit `.cursor-guard.json` to define which files to protect / 编辑 `.cursor-guard.json` 定义保护哪些文件:
127
+ Edit `.cursor-guard.json` to define which files to protect:
135
128
 
136
129
  ```json
137
130
  {
@@ -145,74 +138,109 @@ Edit `.cursor-guard.json` to define which files to protect / 编辑 `.cursor-gua
145
138
 
146
139
  ---
147
140
 
148
- ## Auto-Backup Script / 自动备份脚本
141
+ ## Auto-Backup Script
149
142
 
150
143
  Run in a separate terminal while working in Cursor:
151
144
 
152
- 在使用 Cursor 时,在**单独的终端窗口**中运行:
153
-
154
145
  ```powershell
155
146
  .\auto-backup.ps1 -Path "D:\MyProject"
156
147
 
157
- # Custom interval (default 60s) / 自定义间隔(默认 60 秒):
148
+ # Custom interval (default 60s):
158
149
  .\auto-backup.ps1 -Path "D:\MyProject" -IntervalSeconds 30
159
150
  ```
160
151
 
161
152
  The script uses Git plumbing commands to snapshot to `cursor-guard/auto-backup` branch — it never switches branches or touches your working index.
162
153
 
163
- 脚本使用 Git 底层命令快照到 `cursor-guard/auto-backup` 分支——不会切换分支,也不会影响你的工作索引。
164
-
165
- > **Note / 注意**: Run this script in a separate PowerShell window, NOT inside Cursor's integrated terminal. Cursor's terminal may interfere with Git plumbing commands.
166
- >
167
- > 请在独立的 PowerShell 窗口中运行此脚本,不要在 Cursor 的集成终端中运行,因为 Cursor 终端可能干扰 Git 底层命令。
154
+ > **Note**: Run this script in a separate PowerShell window, NOT inside Cursor's integrated terminal. Cursor's terminal may interfere with Git plumbing commands.
168
155
 
169
156
  ---
170
157
 
171
- ## Recovery / 恢复
158
+ ## Recovery
159
+
160
+ If something goes wrong, just tell the AI agent in natural language.
161
+
162
+ **Default behavior**: Before any restore, the agent automatically preserves your current version so you can undo the restore if needed. You don't need to ask for this — it happens by default. To skip, explicitly say "don't preserve current version" or "skip backup before restore".
172
163
 
173
- If something goes wrong, recovery follows this priority:
164
+ ### By time
174
165
 
175
- 出问题时,按以下优先级恢复:
166
+ > "restore to 5 minutes ago"
167
+ > "go back to yesterday's version"
168
+ > "restore to 3pm today"
169
+
170
+ ### By version
171
+
172
+ > "undo the last change"
173
+ > "go back 3 versions"
174
+ > "restore to the previous version"
175
+
176
+ ### By file
177
+
178
+ > "restore src/app.py to 10 minutes ago"
179
+ > "restore src/app.py to the previous version"
180
+
181
+ The agent will:
182
+ 1. **Preserve your current version** first (unless you opt out)
183
+ 2. Search Git history and auto-backup snapshots
184
+ 3. Show matching versions for you to choose
185
+ 4. Restore after your confirmation
186
+ 5. Report both the pre-restore backup ref and the restore result
187
+
188
+ If the pre-restore backup fails, the agent will **not** proceed — it will wait for your explicit confirmation before restoring without a safety net.
189
+
190
+ ### Recovery priority
176
191
 
177
192
  1. **Git** — `git restore`, `git reset`, `git reflog`
178
- 2. **Shadow copies / 影子拷贝** `.cursor-guard-backup/<timestamp>/`
179
- 3. **Conversation context / 对话上下文** Original file content captured by agent Read calls / 代理 Read 调用捕获的原始内容
180
- 4. **Editor history / 编辑器历史** VS Code/Cursor Timeline (auxiliary / 辅助)
193
+ 2. **Auto-backup branch**`cursor-guard/auto-backup`
194
+ 3. **Shadow copies**`.cursor-guard-backup/<timestamp>/`
195
+ 4. **Conversation context** Original file content captured by agent Read calls
196
+ 5. **Editor history** — VS Code/Cursor Timeline (auxiliary)
181
197
 
182
- See [references/recovery.md](references/recovery.md) for detailed commands / 详细命令见恢复文档。
198
+ See [references/recovery.md](references/recovery.md) for detailed commands.
183
199
 
184
200
  ---
185
201
 
186
- ## Trigger Keywords / 触发关键词
202
+ ## Trigger Keywords
187
203
 
188
- The skill activates on these signals / 技能在以下信号时激活:
204
+ The skill activates on these signals:
189
205
 
190
- - File edits, deletes, renames by the AI agent / AI 代理的文件编辑、删除、重命名
191
- - Recovery requests / 恢复请求:"回滚"、"误删"、"丢版本"、"rollback""undo""recover"
192
- - History issues / 历史问题:checkpoints missing、Timeline not working、save failures
206
+ - File edits, deletes, renames by the AI agent
207
+ - Recovery requests: "rollback", "undo", "recover", "restore"
208
+ - Time-based recovery: "restore to N minutes ago", "go back to yesterday"
209
+ - Version-based recovery: "previous version", "go back N versions"
210
+ - History issues: checkpoints missing, Timeline not working, save failures
193
211
 
194
212
  ---
195
213
 
196
- ## Files / 文件说明
214
+ ## Files
197
215
 
198
- | File / 文件 | Purpose / 用途 |
216
+ | File | Purpose |
199
217
  |------|---------|
200
- | `SKILL.md` | Main skill instructions for the AI agent / AI 代理的主要技能指令 |
201
- | `references/auto-backup.ps1` | PowerShell auto-backup watcher script / PowerShell 自动备份监控脚本 |
202
- | `references/recovery.md` | Recovery command templates / 恢复命令模板 |
203
- | `references/cursor-guard.example.json` | Example project configuration / 示例项目配置 |
204
- | `references/cursor-guard.schema.json` | JSON Schema for config validation / 配置文件的 JSON Schema |
218
+ | `SKILL.md` | Main skill instructions for the AI agent |
219
+ | `references/auto-backup.ps1` | PowerShell auto-backup watcher script |
220
+ | `references/recovery.md` | Recovery command templates |
221
+ | `references/cursor-guard.example.json` | Example project configuration |
222
+ | `references/cursor-guard.schema.json` | JSON Schema for config validation |
205
223
 
206
224
  ---
207
225
 
208
- ## Requirements / 环境要求
226
+ ## Known Limitations
227
+
228
+ - **Binary files**: Git diffs and snapshots work on text files. Binary files (images, compiled assets) are stored but cannot be meaningfully diffed or partially restored.
229
+ - **Untracked files**: Files never committed to Git cannot be recovered from Git history. Shadow copy (`backup_strategy: "shadow"` or `"both"`) is the only safety net for untracked files.
230
+ - **Concurrent agents**: If multiple AI agent threads write to the same file simultaneously, snapshots cannot prevent race conditions. Avoid parallel edits to the same file.
231
+ - **External tools modifying the index**: Tools that alter Git's index (e.g. other Git GUIs, IDE Git integrations) while `auto-backup.ps1` is running may conflict. The script uses a temporary index to minimize this, but edge cases exist.
232
+ - **Git worktree**: The auto-backup script supports worktree layouts (`git rev-parse --git-dir`), but has not been tested with all exotic setups (e.g. `--separate-git-dir`).
233
+ - **Cursor terminal interference**: Cursor's integrated terminal injects `--trailer` flags into `git commit` commands, which breaks plumbing commands like `commit-tree`. Always run `auto-backup.ps1` in a **separate PowerShell window**.
234
+ - **Large repos**: For very large repositories, `git add -A` in the backup loop may be slow. Use `protect` patterns in `.cursor-guard.json` to narrow scope.
235
+
236
+ ## Requirements
209
237
 
210
- - **Git** — for primary backup strategy / 主要备份策略
211
- - **PowerShell 5.1+** — for auto-backup script (Windows built-in) / 自动备份脚本(Windows 自带)
212
- - **Cursor IDE** — with Agent mode enabled / 需启用 Agent 模式
238
+ - **Git** — for primary backup strategy
239
+ - **PowerShell 5.1+** — for auto-backup script (Windows built-in)
240
+ - **Cursor IDE** — with Agent mode enabled
213
241
 
214
242
  ---
215
243
 
216
- ## License / 许可证
244
+ ## License
217
245
 
218
246
  MIT
@@ -0,0 +1,246 @@
1
+ # Cursor Guard
2
+
3
+ [![npm version](https://img.shields.io/npm/v/cursor-guard)](https://www.npmjs.com/package/cursor-guard)
4
+ [![license](https://img.shields.io/github/license/zhangqiang8vipp/cursor-guard)](LICENSE)
5
+
6
+ 保护你的代码免受 [Cursor](https://cursor.com) AI 代理意外覆写或删除。
7
+
8
+ **[English](README.md)**
9
+
10
+ ---
11
+
12
+ ## 功能介绍
13
+
14
+ 当 Cursor 的 AI 代理编辑你的文件时,可能会意外覆盖、删除或丢失代码。**Cursor Guard** 强制执行一套安全协议:
15
+
16
+ - **强制写前快照** — 在任何破坏性操作前自动 Git 提交或影子拷贝
17
+ - **先读后写** — 代理必须先读取文件内容,才能覆写
18
+ - **预览再执行** — 危险操作前展示 diff 预览并要求确认
19
+ - **确定性恢复** — 按优先级的恢复路径(Git → 影子拷贝 → 对话上下文 → 编辑器历史)
20
+ - **可配置保护范围** — 通过 `.cursor-guard.json` 配置文件只保护你关心的文件
21
+ - **敏感文件过滤** — `.env`、密钥、证书等敏感文件自动排除备份
22
+ - **自动备份脚本** — 定期快照到独立 Git 分支,不干扰工作区
23
+
24
+ ---
25
+
26
+ ## 安装
27
+
28
+ ### 方式一:npm 安装
29
+
30
+ ```bash
31
+ npm install cursor-guard
32
+ ```
33
+
34
+ 安装后,将技能文件复制到 Cursor 技能目录:
35
+
36
+ **Windows (PowerShell):**
37
+
38
+ ```powershell
39
+ # 全局安装(所有项目生效)
40
+ Copy-Item -Recurse node_modules/cursor-guard "$env:USERPROFILE/.cursor/skills/cursor-guard"
41
+
42
+ # 项目级安装(仅当前项目生效)
43
+ Copy-Item -Recurse node_modules/cursor-guard .cursor/skills/cursor-guard
44
+ ```
45
+
46
+ **macOS / Linux:**
47
+
48
+ ```bash
49
+ # 全局安装
50
+ cp -r node_modules/cursor-guard ~/.cursor/skills/cursor-guard
51
+
52
+ # 项目级安装
53
+ cp -r node_modules/cursor-guard .cursor/skills/cursor-guard
54
+ ```
55
+
56
+ 复制完成后,如果不需要保留在 `node_modules` 中,可以卸载:
57
+
58
+ ```bash
59
+ npm uninstall cursor-guard
60
+ ```
61
+
62
+ ### 方式二:Git 克隆
63
+
64
+ ```bash
65
+ # 全局安装
66
+ git clone https://github.com/zhangqiang8vipp/cursor-guard.git ~/.cursor/skills/cursor-guard
67
+
68
+ # 项目级安装
69
+ git clone https://github.com/zhangqiang8vipp/cursor-guard.git .cursor/skills/cursor-guard
70
+ ```
71
+
72
+ ### 方式三:手动下载
73
+
74
+ 从 [GitHub Releases](https://github.com/zhangqiang8vipp/cursor-guard/releases) 下载并解压到:
75
+
76
+ ```
77
+ ~/.cursor/skills/cursor-guard/ # 全局
78
+ <项目根目录>/.cursor/skills/cursor-guard/ # 项目级
79
+ ```
80
+
81
+ ### 验证安装
82
+
83
+ 安装后目录结构应如下所示:
84
+
85
+ ```
86
+ .cursor/skills/cursor-guard/
87
+ ├── SKILL.md # AI 代理指令
88
+ ├── README.md
89
+ ├── LICENSE
90
+ └── references/
91
+ ├── auto-backup.ps1 # 自动备份脚本
92
+ ├── recovery.md # 恢复命令模板
93
+ ├── cursor-guard.example.json # 示例配置
94
+ └── cursor-guard.schema.json # 配置 Schema
95
+ ```
96
+
97
+ 技能会在 AI 代理检测到高风险操作(文件编辑、删除、重命名)或你提到恢复相关词汇时自动激活。无需其他设置,安装即生效。
98
+
99
+ ---
100
+
101
+ ## 快速上手
102
+
103
+ 1. **安装技能** — 用以上任意方式安装
104
+
105
+ 2. **打开 Cursor** — 开始一个 Agent 对话
106
+
107
+ 3. **技能自动生效** — 当 AI 代理尝试编辑文件时,会自动:
108
+ - 写入前创建 Git 快照
109
+ - 覆写前先读取文件
110
+ - 危险操作前展示 diff 预览
111
+ - 每次受保护操作后报告状态
112
+
113
+ 4. **(可选)添加项目配置** — 自定义保护范围:
114
+
115
+ ```bash
116
+ cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guard.json
117
+ ```
118
+
119
+ 5. **(可选)运行自动备份** — 在独立终端运行:
120
+
121
+ ```powershell
122
+ .\auto-backup.ps1 -Path "D:\MyProject"
123
+ ```
124
+
125
+ ### 项目配置
126
+
127
+ 编辑 `.cursor-guard.json` 定义保护哪些文件:
128
+
129
+ ```json
130
+ {
131
+ "protect": ["src/**", "lib/**", "package.json"],
132
+ "ignore": ["node_modules/**", "dist/**"],
133
+ "auto_backup_interval_seconds": 60,
134
+ "secrets_patterns": [".env", ".env.*", "*.key", "*.pem"],
135
+ "retention": { "mode": "days", "days": 30 }
136
+ }
137
+ ```
138
+
139
+ ---
140
+
141
+ ## 自动备份脚本
142
+
143
+ 在使用 Cursor 时,在**单独的终端窗口**中运行:
144
+
145
+ ```powershell
146
+ .\auto-backup.ps1 -Path "D:\MyProject"
147
+
148
+ # 自定义间隔(默认 60 秒):
149
+ .\auto-backup.ps1 -Path "D:\MyProject" -IntervalSeconds 30
150
+ ```
151
+
152
+ 脚本使用 Git 底层命令快照到 `cursor-guard/auto-backup` 分支——不会切换分支,也不会影响你的工作索引。
153
+
154
+ > **注意**:请在独立的 PowerShell 窗口中运行此脚本,不要在 Cursor 的集成终端中运行,因为 Cursor 终端可能干扰 Git 底层命令。
155
+
156
+ ---
157
+
158
+ ## 恢复
159
+
160
+ 出问题时,直接用自然语言告诉 AI 代理即可。
161
+
162
+ **默认行为**:执行任何恢复操作前,代理会自动保留你的当前版本,方便恢复后反悔。无需额外请求,这是默认行为。如需跳过,请明确说"不保留当前版本"或"直接覆盖恢复"。
163
+
164
+ ### 按时间恢复
165
+
166
+ > "帮我恢复到5分钟前"
167
+ > "恢复到今天下午3点的状态"
168
+ > "回到昨天的版本"
169
+
170
+ ### 按版本恢复
171
+
172
+ > "恢复到上一个版本"
173
+ > "回到前3个版本"
174
+ > "撤销最近两次修改"
175
+
176
+ ### 指定文件恢复
177
+
178
+ > "把 src/app.py 恢复到10分钟前"
179
+ > "把 src/app.py 恢复到上一个版本"
180
+
181
+ 代理会:
182
+ 1. **先保留你的当前版本**(除非你明确选择跳过)
183
+ 2. 搜索 Git 历史和自动备份快照
184
+ 3. 列出匹配版本供你选择
185
+ 4. 确认后执行恢复
186
+ 5. 报告恢复前备份引用和恢复结果
187
+
188
+ 如果保留当前版本失败,代理**不会**继续恢复——会等你明确确认后才会在没有安全网的情况下恢复。
189
+
190
+ ### 恢复优先级
191
+
192
+ 1. **Git** — `git restore`, `git reset`, `git reflog`
193
+ 2. **自动备份分支** — `cursor-guard/auto-backup`
194
+ 3. **影子拷贝** — `.cursor-guard-backup/<时间戳>/`
195
+ 4. **对话上下文** — 代理 Read 调用捕获的原始文件内容
196
+ 5. **编辑器历史** — VS Code/Cursor Timeline(辅助)
197
+
198
+ 详细恢复命令见 [references/recovery.md](references/recovery.md)。
199
+
200
+ ---
201
+
202
+ ## 触发关键词
203
+
204
+ 技能在以下信号时激活:
205
+
206
+ - AI 代理的文件编辑、删除、重命名
207
+ - 恢复请求:"回滚"、"误删"、"丢版本"、"改不回来"
208
+ - 按时间恢复:"恢复到N分钟前"、"恢复到下午3点"、"回到昨天"
209
+ - 按版本恢复:"恢复到上一个版本"、"前N个版本"、"撤销最近N次修改"
210
+ - 历史问题:Checkpoint 丢失、Timeline 不工作、保存失败
211
+
212
+ ---
213
+
214
+ ## 文件说明
215
+
216
+ | 文件 | 用途 |
217
+ |------|------|
218
+ | `SKILL.md` | AI 代理的主要技能指令 |
219
+ | `references/auto-backup.ps1` | PowerShell 自动备份监控脚本 |
220
+ | `references/recovery.md` | 恢复命令模板 |
221
+ | `references/cursor-guard.example.json` | 示例项目配置 |
222
+ | `references/cursor-guard.schema.json` | 配置文件的 JSON Schema |
223
+
224
+ ---
225
+
226
+ ## 已知限制
227
+
228
+ - **二进制文件**:Git 快照可以存储二进制文件(图片、编译产物),但无法进行有意义的 diff 或部分恢复。
229
+ - **未跟踪文件**:从未提交到 Git 的文件无法从 Git 历史恢复。影子拷贝(`backup_strategy: "shadow"` 或 `"both"`)是未跟踪文件的唯一安全网。
230
+ - **并发 Agent**:如果多个 AI 代理线程同时写入同一文件,快照无法防止竞态条件。请避免并行编辑同一文件。
231
+ - **外部工具修改索引**:在 `auto-backup.ps1` 运行期间,其他修改 Git 索引的工具(如 Git GUI、IDE Git 集成)可能冲突。脚本使用临时索引来最小化风险,但边缘情况仍存在。
232
+ - **Git worktree**:自动备份脚本支持 worktree 布局(`git rev-parse --git-dir`),但未在所有特殊配置下测试(如 `--separate-git-dir`)。
233
+ - **Cursor 终端干扰**:Cursor 集成终端会向 `git commit` 命令注入 `--trailer` 标志,导致 `commit-tree` 等底层命令异常。请始终在**独立的 PowerShell 窗口**中运行 `auto-backup.ps1`。
234
+ - **大型仓库**:对于非常大的仓库,备份循环中的 `git add -A` 可能较慢。使用 `.cursor-guard.json` 中的 `protect` 模式缩小范围。
235
+
236
+ ## 环境要求
237
+
238
+ - **Git** — 主要备份策略
239
+ - **PowerShell 5.1+** — 自动备份脚本(Windows 自带)
240
+ - **Cursor IDE** — 需启用 Agent 模式
241
+
242
+ ---
243
+
244
+ ## 许可证
245
+
246
+ MIT