cursor-guard 1.3.2 → 2.0.2

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
@@ -19,7 +19,7 @@ When Cursor's AI agent edits your files, there's a risk of accidental overwrites
19
19
  - **Deterministic recovery** — Clear priority-ordered recovery paths (Git → shadow copies → conversation context → editor history)
20
20
  - **Configurable scope** — Protect only what matters via `.cursor-guard.json`
21
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
+ - **Auto-backup script** — A cross-platform watcher (Node.js) that periodically snapshots to a dedicated Git branch without disturbing your working tree
23
23
 
24
24
  ---
25
25
 
@@ -84,14 +84,26 @@ After installation, your directory structure should look like this:
84
84
 
85
85
  ```
86
86
  .cursor/skills/cursor-guard/
87
- ├── SKILL.md # AI agent instructions
87
+ ├── SKILL.md # AI agent instructions
88
88
  ├── README.md
89
+ ├── README.zh-CN.md
89
90
  ├── LICENSE
91
+ ├── package.json
90
92
  └── references/
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
93
+ ├── lib/
94
+ ├── auto-backup.js # Backup core (Node.js)
95
+ ├── guard-doctor.js # Health check core
96
+ └── utils.js # Shared utilities
97
+ ├── bin/
98
+ │ ├── cursor-guard-backup.js # CLI entry: npx cursor-guard-backup
99
+ │ └── cursor-guard-doctor.js # CLI entry: npx cursor-guard-doctor
100
+ ├── auto-backup.ps1 / .sh # Thin wrappers
101
+ ├── guard-doctor.ps1 / .sh
102
+ ├── recovery.md # Recovery commands
103
+ ├── cursor-guard.example.json # Example config
104
+ ├── cursor-guard.schema.json # Config schema
105
+ ├── config-reference.md # Config docs (EN)
106
+ └── config-reference.zh-CN.md # Config docs (CN)
95
107
  ```
96
108
 
97
109
  The skill activates automatically when the AI agent detects risky operations or when you mention recovery-related terms. No extra setup needed.
@@ -118,8 +130,8 @@ cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guar
118
130
 
119
131
  5. **(Optional) Run auto-backup** in a separate terminal:
120
132
 
121
- ```powershell
122
- .\auto-backup.ps1 -Path "D:\MyProject"
133
+ ```bash
134
+ npx cursor-guard-backup --path /my/project
123
135
  ```
124
136
 
125
137
  ### Project Configuration
@@ -153,18 +165,32 @@ Regardless of config, you can always override per-request:
153
165
 
154
166
  ## Auto-Backup Script
155
167
 
156
- Run in a separate terminal while working in Cursor:
168
+ Run in a separate terminal while working in Cursor. Cross-platform — requires Node.js >= 18.
157
169
 
158
- ```powershell
159
- .\auto-backup.ps1 -Path "D:\MyProject"
170
+ ```bash
171
+ # Via npx (after npm install)
172
+ npx cursor-guard-backup --path /my/project
173
+ npx cursor-guard-backup --path /my/project --interval 30
174
+
175
+ # Windows PowerShell
176
+ .\references\auto-backup.ps1 -Path "D:\MyProject"
160
177
 
161
- # Custom interval (default 60s):
162
- .\auto-backup.ps1 -Path "D:\MyProject" -IntervalSeconds 30
178
+ # macOS / Linux
179
+ ./references/auto-backup.sh /my/project
163
180
  ```
164
181
 
165
- The script uses Git plumbing commands to snapshot to `cursor-guard/auto-backup` branch — it never switches branches or touches your working index.
182
+ The script uses Git plumbing commands to snapshot to `cursor-guard/auto-backup` branch — it never switches branches or touches your working index. Supports `shadow` mode for non-Git directories.
183
+
184
+ ### Health Check
185
+
186
+ ```bash
187
+ npx cursor-guard-doctor --path /my/project
188
+
189
+ # Windows: .\references\guard-doctor.ps1 -Path "D:\MyProject"
190
+ # macOS/Linux: ./references/guard-doctor.sh /my/project
191
+ ```
166
192
 
167
- > **Note**: Run this script in a separate PowerShell window, NOT inside Cursor's integrated terminal. Cursor's terminal may interfere with Git plumbing commands.
193
+ > **Note**: Run backup/doctor scripts in a separate terminal, NOT inside Cursor's integrated terminal.
168
194
 
169
195
  ---
170
196
 
@@ -229,10 +255,18 @@ The skill activates on these signals:
229
255
  | File | Purpose |
230
256
  |------|---------|
231
257
  | `SKILL.md` | Main skill instructions for the AI agent |
232
- | `references/auto-backup.ps1` | PowerShell auto-backup watcher script |
258
+ | `references/lib/auto-backup.js` | Auto-backup core logic (Node.js) |
259
+ | `references/lib/guard-doctor.js` | Health check core logic (Node.js) |
260
+ | `references/lib/utils.js` | Shared utilities (config, glob, git, manifest) |
261
+ | `references/bin/cursor-guard-backup.js` | CLI entry: `npx cursor-guard-backup` |
262
+ | `references/bin/cursor-guard-doctor.js` | CLI entry: `npx cursor-guard-doctor` |
263
+ | `references/auto-backup.ps1` / `.sh` | Thin wrappers (Windows / macOS+Linux) |
264
+ | `references/guard-doctor.ps1` / `.sh` | Thin wrappers (Windows / macOS+Linux) |
233
265
  | `references/recovery.md` | Recovery command templates |
234
266
  | `references/cursor-guard.example.json` | Example project configuration |
235
267
  | `references/cursor-guard.schema.json` | JSON Schema for config validation |
268
+ | `references/config-reference.md` | Config field docs (English) |
269
+ | `references/config-reference.zh-CN.md` | Config field docs (Chinese) |
236
270
 
237
271
  ---
238
272
 
@@ -241,15 +275,15 @@ The skill activates on these signals:
241
275
  - **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.
242
276
  - **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.
243
277
  - **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.
244
- - **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.
278
+ - **External tools modifying the index**: Tools that alter Git's index (e.g. other Git GUIs, IDE Git integrations) while auto-backup is running may conflict. The script uses a temporary index to minimize this, but edge cases exist.
245
279
  - **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`).
246
- - **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**.
280
+ - **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 in a **separate terminal window**.
247
281
  - **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.
248
282
 
249
283
  ## Requirements
250
284
 
251
- - **Git** — for primary backup strategy
252
- - **PowerShell 5.1+** — for auto-backup script (Windows built-in)
285
+ - **Node.js >= 18** — core runtime for backup and health check scripts
286
+ - **Git** — for primary backup strategy (not needed for shadow-only mode)
253
287
  - **Cursor IDE** — with Agent mode enabled
254
288
 
255
289
  ---
package/README.zh-CN.md CHANGED
@@ -19,7 +19,7 @@
19
19
  - **确定性恢复** — 按优先级的恢复路径(Git → 影子拷贝 → 对话上下文 → 编辑器历史)
20
20
  - **可配置保护范围** — 通过 `.cursor-guard.json` 配置文件只保护你关心的文件
21
21
  - **敏感文件过滤** — `.env`、密钥、证书等敏感文件自动排除备份
22
- - **自动备份脚本** — 定期快照到独立 Git 分支,不干扰工作区
22
+ - **自动备份脚本** — 跨平台 (Node.js) 定期快照到独立 Git 分支,不干扰工作区
23
23
 
24
24
  ---
25
25
 
@@ -84,14 +84,26 @@ git clone https://github.com/zhangqiang8vipp/cursor-guard.git .cursor/skills/cur
84
84
 
85
85
  ```
86
86
  .cursor/skills/cursor-guard/
87
- ├── SKILL.md # AI 代理指令
87
+ ├── SKILL.md # AI 代理指令
88
88
  ├── README.md
89
+ ├── README.zh-CN.md
89
90
  ├── LICENSE
91
+ ├── package.json
90
92
  └── references/
91
- ├── auto-backup.ps1 # 自动备份脚本
92
- ├── recovery.md # 恢复命令模板
93
- ├── cursor-guard.example.json # 示例配置
94
- └── cursor-guard.schema.json # 配置 Schema
93
+ ├── lib/
94
+ ├── auto-backup.js # 备份核心 (Node.js)
95
+ ├── guard-doctor.js # 健康检查核心
96
+ └── utils.js # 共享工具库
97
+ ├── bin/
98
+ │ ├── cursor-guard-backup.js # CLI 入口:npx cursor-guard-backup
99
+ │ └── cursor-guard-doctor.js # CLI 入口:npx cursor-guard-doctor
100
+ ├── auto-backup.ps1 / .sh # 薄封装
101
+ ├── guard-doctor.ps1 / .sh
102
+ ├── recovery.md # 恢复命令模板
103
+ ├── cursor-guard.example.json # 示例配置
104
+ ├── cursor-guard.schema.json # 配置 Schema
105
+ ├── config-reference.md # 配置说明(英文)
106
+ └── config-reference.zh-CN.md # 配置说明(中文)
95
107
  ```
96
108
 
97
109
  技能会在 AI 代理检测到高风险操作(文件编辑、删除、重命名)或你提到恢复相关词汇时自动激活。无需其他设置,安装即生效。
@@ -118,8 +130,8 @@ cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guar
118
130
 
119
131
  5. **(可选)运行自动备份** — 在独立终端运行:
120
132
 
121
- ```powershell
122
- .\auto-backup.ps1 -Path "D:\MyProject"
133
+ ```bash
134
+ npx cursor-guard-backup --path /my/project
123
135
  ```
124
136
 
125
137
  ### 项目配置
@@ -153,18 +165,32 @@ cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guar
153
165
 
154
166
  ## 自动备份脚本
155
167
 
156
- 在使用 Cursor 时,在**单独的终端窗口**中运行:
168
+ 在使用 Cursor 时,在**单独的终端窗口**中运行。跨平台——需要 Node.js >= 18。
157
169
 
158
- ```powershell
159
- .\auto-backup.ps1 -Path "D:\MyProject"
170
+ ```bash
171
+ # 通过 npx(npm 安装后)
172
+ npx cursor-guard-backup --path /my/project
173
+ npx cursor-guard-backup --path /my/project --interval 30
174
+
175
+ # Windows PowerShell
176
+ .\references\auto-backup.ps1 -Path "D:\MyProject"
160
177
 
161
- # 自定义间隔(默认 60 秒):
162
- .\auto-backup.ps1 -Path "D:\MyProject" -IntervalSeconds 30
178
+ # macOS / Linux
179
+ ./references/auto-backup.sh /my/project
163
180
  ```
164
181
 
165
- 脚本使用 Git 底层命令快照到 `cursor-guard/auto-backup` 分支——不会切换分支,也不会影响你的工作索引。
182
+ 脚本使用 Git 底层命令快照到 `cursor-guard/auto-backup` 分支——不会切换分支,也不会影响你的工作索引。支持 `shadow` 模式用于非 Git 目录。
183
+
184
+ ### 健康检查
185
+
186
+ ```bash
187
+ npx cursor-guard-doctor --path /my/project
188
+
189
+ # Windows: .\references\guard-doctor.ps1 -Path "D:\MyProject"
190
+ # macOS/Linux: ./references/guard-doctor.sh /my/project
191
+ ```
166
192
 
167
- > **注意**:请在独立的 PowerShell 窗口中运行此脚本,不要在 Cursor 的集成终端中运行,因为 Cursor 终端可能干扰 Git 底层命令。
193
+ > **注意**:请在独立终端窗口中运行备份/检查脚本,不要在 Cursor 集成终端中运行。
168
194
 
169
195
  ---
170
196
 
@@ -229,10 +255,18 @@ cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guar
229
255
  | 文件 | 用途 |
230
256
  |------|------|
231
257
  | `SKILL.md` | AI 代理的主要技能指令 |
232
- | `references/auto-backup.ps1` | PowerShell 自动备份监控脚本 |
258
+ | `references/lib/auto-backup.js` | 自动备份核心逻辑 (Node.js) |
259
+ | `references/lib/guard-doctor.js` | 健康检查核心逻辑 (Node.js) |
260
+ | `references/lib/utils.js` | 共享工具库(配置、glob、git、manifest) |
261
+ | `references/bin/cursor-guard-backup.js` | CLI 入口:`npx cursor-guard-backup` |
262
+ | `references/bin/cursor-guard-doctor.js` | CLI 入口:`npx cursor-guard-doctor` |
263
+ | `references/auto-backup.ps1` / `.sh` | 薄封装(Windows / macOS+Linux) |
264
+ | `references/guard-doctor.ps1` / `.sh` | 薄封装(Windows / macOS+Linux) |
233
265
  | `references/recovery.md` | 恢复命令模板 |
234
266
  | `references/cursor-guard.example.json` | 示例项目配置 |
235
267
  | `references/cursor-guard.schema.json` | 配置文件的 JSON Schema |
268
+ | `references/config-reference.md` | 配置字段说明(英文) |
269
+ | `references/config-reference.zh-CN.md` | 配置字段说明(中文) |
236
270
 
237
271
  ---
238
272
 
@@ -241,15 +275,15 @@ cp .cursor/skills/cursor-guard/references/cursor-guard.example.json .cursor-guar
241
275
  - **二进制文件**:Git 快照可以存储二进制文件(图片、编译产物),但无法进行有意义的 diff 或部分恢复。
242
276
  - **未跟踪文件**:从未提交到 Git 的文件无法从 Git 历史恢复。影子拷贝(`backup_strategy: "shadow"` 或 `"both"`)是未跟踪文件的唯一安全网。
243
277
  - **并发 Agent**:如果多个 AI 代理线程同时写入同一文件,快照无法防止竞态条件。请避免并行编辑同一文件。
244
- - **外部工具修改索引**:在 `auto-backup.ps1` 运行期间,其他修改 Git 索引的工具(如 Git GUI、IDE Git 集成)可能冲突。脚本使用临时索引来最小化风险,但边缘情况仍存在。
278
+ - **外部工具修改索引**:在自动备份运行期间,其他修改 Git 索引的工具(如 Git GUI、IDE Git 集成)可能冲突。脚本使用临时索引来最小化风险,但边缘情况仍存在。
245
279
  - **Git worktree**:自动备份脚本支持 worktree 布局(`git rev-parse --git-dir`),但未在所有特殊配置下测试(如 `--separate-git-dir`)。
246
- - **Cursor 终端干扰**:Cursor 集成终端会向 `git commit` 命令注入 `--trailer` 标志,导致 `commit-tree` 等底层命令异常。请始终在**独立的 PowerShell 窗口**中运行 `auto-backup.ps1`。
280
+ - **Cursor 终端干扰**:Cursor 集成终端会向 `git commit` 命令注入 `--trailer` 标志,导致 `commit-tree` 等底层命令异常。请始终在**独立的终端窗口**中运行自动备份脚本。
247
281
  - **大型仓库**:对于非常大的仓库,备份循环中的 `git add -A` 可能较慢。使用 `.cursor-guard.json` 中的 `protect` 模式缩小范围。
248
282
 
249
283
  ## 环境要求
250
284
 
251
- - **Git** — 主要备份策略
252
- - **PowerShell 5.1+** 自动备份脚本(Windows 自带)
285
+ - **Node.js >= 18** — 备份与健康检查脚本的核心运行时
286
+ - **Git**主要备份策略(仅影子拷贝模式不需要)
253
287
  - **Cursor IDE** — 需启用 Agent 模式
254
288
 
255
289
  ---
package/SKILL.md CHANGED
@@ -20,6 +20,7 @@ Use this skill when any of the following appear:
20
20
  - **Parallel context**: Multiple repos or branches; unclear which folder is the workspace root.
21
21
  - **Recovery asks**: e.g. "改不回来", "丢版本", "回滚", "reflog", "误删", or English equivalents.
22
22
  - **Time/version recovery**: e.g. "恢复到5分钟前", "恢复到前3个版本", "回到上一个版本", "restore to 10 minutes ago", "go back 2 versions", "恢复到下午3点的状态".
23
+ - **Health check**: e.g. "guard doctor", "检查备份配置", "自检", "诊断guard", "check guard setup". Run `guard-doctor.ps1` and report results.
23
24
 
24
25
  If none of the above, do not expand scope; answer normally.
25
26
 
@@ -51,7 +52,11 @@ On first trigger in a session, check if the workspace root contains `.cursor-gua
51
52
  "pre_restore_backup": "always",
52
53
 
53
54
  // Retention for shadow copies. mode: "days" | "count" | "size"
54
- "retention": { "mode": "days", "days": 30, "max_count": 100, "max_size_mb": 500 }
55
+ "retention": { "mode": "days", "days": 30, "max_count": 100, "max_size_mb": 500 },
56
+
57
+ // Retention for Git auto-backup branch. Disabled by default.
58
+ // "count": keep N newest commits. "days": keep commits from last N days.
59
+ "git_retention": { "enabled": false, "mode": "count", "max_count": 200 }
55
60
  }
56
61
  ```
57
62
 
@@ -100,19 +105,22 @@ When the target file of an edit **falls outside the protected scope**, the agent
100
105
  Use a **temporary index and dedicated ref** so the user's staged/unstaged state is never touched:
101
106
 
102
107
  ```bash
108
+ GIT_DIR=$(git rev-parse --git-dir)
109
+ GUARD_IDX="$GIT_DIR/guard-snapshot-index"
110
+
103
111
  # 1. Create temp index from HEAD
104
- GIT_INDEX_FILE=.git/guard-snapshot-index git read-tree HEAD
112
+ GIT_INDEX_FILE="$GUARD_IDX" git read-tree HEAD
105
113
 
106
114
  # 2. Stage working-tree files into temp index
107
- GIT_INDEX_FILE=.git/guard-snapshot-index git add -A
115
+ GIT_INDEX_FILE="$GUARD_IDX" git add -A
108
116
 
109
117
  # 3. Write tree and create commit on a guard ref (not on the user's branch)
110
- TREE=$(GIT_INDEX_FILE=.git/guard-snapshot-index git write-tree)
111
- COMMIT=$(git commit-tree $TREE -p HEAD -m "guard: snapshot before ai edit")
112
- git update-ref refs/guard/snapshot $COMMIT
118
+ TREE=$(GIT_INDEX_FILE="$GUARD_IDX" git write-tree)
119
+ COMMIT=$(git commit-tree "$TREE" -p HEAD -m "guard: snapshot before ai edit")
120
+ git update-ref refs/guard/snapshot "$COMMIT"
113
121
 
114
122
  # 4. Cleanup
115
- rm .git/guard-snapshot-index
123
+ rm -f "$GUARD_IDX"
116
124
  ```
117
125
 
118
126
  **PowerShell equivalent** (for agent Shell calls):
@@ -197,21 +205,24 @@ There are two distinct backup mechanisms. Do not confuse them:
197
205
  | | **Git branch snapshot** | **Shadow copy** |
198
206
  |---|---|---|
199
207
  | **What** | Commits to `cursor-guard/auto-backup` branch via plumbing | File copies to `.cursor-guard-backup/<timestamp>/` |
200
- | **Who creates** | `auto-backup.ps1` (when `backup_strategy` = `git` or `both`) | `auto-backup.ps1` (when `backup_strategy` = `shadow` or `both`); or the agent manually (§2b) |
201
- | **Who cleans up** | Manual: `git branch -D cursor-guard/auto-backup` | `auto-backup.ps1` per `retention` config; or manual |
202
- | **Restore** | `git restore --source=cursor-guard/auto-backup -- <file>` | `Copy-Item ".cursor-guard-backup/<ts>/<file>" "<path>"` |
208
+ | **Who creates** | Auto-backup script (when `backup_strategy` = `git` or `both`) | Auto-backup script (when `backup_strategy` = `shadow` or `both`); or the agent manually (§2b) |
209
+ | **Who cleans up** | `git_retention` config (auto, opt-in); or manual `git branch -D` | `retention` config (auto); or manual |
210
+ | **Restore** | `git restore --source=cursor-guard/auto-backup -- <file>` | Copy file from `.cursor-guard-backup/<ts>/<file>` to original path |
203
211
  | **Requires Git** | Yes | No (fallback for non-git repos) |
204
212
 
205
213
  **Priority order for the agent:**
206
214
 
207
215
  1. **Guard ref snapshot** (`refs/guard/snapshot`) — agent creates before each high-risk edit using temp index (§2a). Does not pollute user's branch or staging area.
208
- 2. **Git branch auto-backup** (`cursor-guard/auto-backup`) — periodic snapshots by `auto-backup.ps1`.
216
+ 2. **Git branch auto-backup** (`cursor-guard/auto-backup`) — periodic snapshots by auto-backup script.
209
217
  3. **Shadow copy** (`.cursor-guard-backup/`) — fallback for non-git repos, or as extra insurance when `backup_strategy = "both"`.
210
218
  4. **Editor habits** — Ctrl+S frequently; optional extensions are user-configured, mention only if asked.
211
219
 
212
220
  **Hard default:** Do NOT `git push` unless the user explicitly asks. Scope = **local only**.
213
221
 
214
- **Retention:** The `retention` config in `.cursor-guard.json` controls cleanup of **shadow copy directories** only. Git branch snapshots are not subject to retention; clean them manually (see [references/recovery.md](references/recovery.md)).
222
+ **Retention:**
223
+ - **Shadow copies**: controlled by `retention` in `.cursor-guard.json` (mode: days/count/size).
224
+ - **Git branch**: controlled by `git_retention` in `.cursor-guard.json` (disabled by default; enable with `"enabled": true`, mode: count/days). Safely rebuilds the backup branch as an orphan chain containing only kept snapshots — never touches user history. Run `git gc` to reclaim disk space.
225
+ - See [references/config-reference.md](references/config-reference.md) for full field docs.
215
226
 
216
227
  ---
217
228
 
@@ -359,9 +370,12 @@ Then jump to Step 5.
359
370
 
360
371
  Use the same temp-index plumbing as §2a to avoid polluting the user's staging area:
361
372
 
362
- **Git repo (preferred):**
373
+ **Git repo (preferred) — timestamped ref stack:**
374
+
375
+ Each pre-restore snapshot writes to a unique ref `refs/guard/pre-restore/<yyyyMMdd_HHmmss>` so consecutive restores never overwrite each other:
363
376
 
364
377
  ```powershell
378
+ $ts = Get-Date -Format 'yyyyMMdd_HHmmss'
365
379
  $guardIdx = Join-Path (git rev-parse --git-dir) "guard-pre-restore-index"
366
380
  $env:GIT_INDEX_FILE = $guardIdx
367
381
 
@@ -378,10 +392,16 @@ $env:GIT_INDEX_FILE = $null
378
392
  Remove-Item $guardIdx -Force -ErrorAction SilentlyContinue
379
393
 
380
394
  $commit = git commit-tree $tree -p HEAD -m "guard: preserve current before restore to <target>"
395
+ git update-ref "refs/guard/pre-restore/$ts" $commit
396
+ ```
397
+
398
+ Record the short hash and the ref path. Also update `refs/guard/pre-restore` as an alias pointing to the latest:
399
+
400
+ ```powershell
381
401
  git update-ref refs/guard/pre-restore $commit
382
402
  ```
383
403
 
384
- Record the short hash and the ref `refs/guard/pre-restore`.
404
+ To list all pre-restore snapshots: `git for-each-ref refs/guard/pre-restore/ --sort=-creatordate --format="%(refname:short) %(creatordate:short) %(objectname:short)"`
385
405
 
386
406
  **Non-Git fallback (shadow copy):**
387
407
 
@@ -404,12 +424,14 @@ If the snapshot fails (e.g. disk full, permission error):
404
424
  Before executing restore, tell the user:
405
425
  ```
406
426
  在恢复前,我已保留当前版本:
407
- - 备份引用: refs/guard/pre-restore (abc1234)
408
- - 恢复方式: git restore --source=refs/guard/pre-restore -- <file>
427
+ - 备份引用: refs/guard/pre-restore/20260321_163005 (abc1234)
428
+ - 恢复方式: git restore --source=refs/guard/pre-restore/20260321_163005 -- <file>
429
+ - 历史栈: git for-each-ref refs/guard/pre-restore/ --sort=-creatordate
409
430
 
410
431
  Current version preserved before restore:
411
- - Backup ref: refs/guard/pre-restore (abc1234)
412
- - To undo: git restore --source=refs/guard/pre-restore -- <file>
432
+ - Backup ref: refs/guard/pre-restore/20260321_163005 (abc1234)
433
+ - To undo: git restore --source=refs/guard/pre-restore/20260321_163005 -- <file>
434
+ - History: git for-each-ref refs/guard/pre-restore/ --sort=-creatordate
413
435
  ```
414
436
 
415
437
  ### Step 5: Execute Recovery
@@ -451,11 +473,12 @@ After restoring, always:
451
473
 
452
474
  ```markdown
453
475
  **Cursor Guard — restore status**
454
- - **Pre-restore backup**: `refs/guard/pre-restore` (`<short-hash>`) or `shadow copy at .cursor-guard-backup/pre-restore-<ts>/` or `skipped (user opted out)` or `skipped (no changes)`
476
+ - **Pre-restore backup**: `refs/guard/pre-restore/<ts>` (`<short-hash>`) or `shadow copy at .cursor-guard-backup/pre-restore-<ts>/` or `skipped (user opted out)` or `skipped (no changes)`
455
477
  - **Restored to**: `<target-hash>` / `<target description>`
456
478
  - **Scope**: single file `<path>` / N files / entire project
457
479
  - **Result**: success / failed
458
- - **To undo restore**: `git restore --source=refs/guard/pre-restore -- <file>`
480
+ - **To undo restore**: `git restore --source=refs/guard/pre-restore/<ts> -- <file>`
481
+ - **All pre-restore snapshots**: `git for-each-ref refs/guard/pre-restore/ --sort=-creatordate`
459
482
  ```
460
483
 
461
484
  ---
@@ -506,8 +529,29 @@ Skip the block for unrelated turns.
506
529
  ## Further Reading
507
530
 
508
531
  - Recovery commands: [references/recovery.md](references/recovery.md)
509
- - Auto-backup script: [references/auto-backup.ps1](references/auto-backup.ps1)
532
+ - Auto-backup (Node.js core): [references/lib/auto-backup.js](references/lib/auto-backup.js)
533
+ - Guard doctor (Node.js core): [references/lib/guard-doctor.js](references/lib/guard-doctor.js)
534
+ - Shared utilities: [references/lib/utils.js](references/lib/utils.js)
510
535
  - Config JSON Schema: [references/cursor-guard.schema.json](references/cursor-guard.schema.json)
511
536
  - Example config: [references/cursor-guard.example.json](references/cursor-guard.example.json)
512
537
  - Config field reference (EN): [references/config-reference.md](references/config-reference.md)
513
538
  - 配置参数说明(中文): [references/config-reference.zh-CN.md](references/config-reference.zh-CN.md)
539
+
540
+ ### Running scripts
541
+
542
+ Cross-platform (requires Node.js >= 18):
543
+
544
+ ```bash
545
+ # Via npx (if installed from npm)
546
+ npx cursor-guard-backup --path /my/project --interval 60
547
+ npx cursor-guard-doctor --path /my/project
548
+
549
+ # Via thin wrapper (from skill directory)
550
+ # Windows PowerShell:
551
+ .\references\auto-backup.ps1 -Path "D:\MyProject"
552
+ .\references\guard-doctor.ps1 -Path "D:\MyProject"
553
+
554
+ # macOS / Linux:
555
+ ./references/auto-backup.sh /my/project
556
+ ./references/guard-doctor.sh /my/project
557
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursor-guard",
3
- "version": "1.3.2",
3
+ "version": "2.0.2",
4
4
  "description": "Protects code from accidental AI overwrite or deletion in Cursor IDE — mandatory pre-write snapshots, review-before-apply, local Git safety net, and deterministic recovery. | 保护代码免受 Cursor AI 代理意外覆写或删除——强制写前快照、预览再执行、本地 Git 安全网、确定性恢复。",
5
5
  "keywords": [
6
6
  "cursor",
@@ -10,7 +10,8 @@
10
10
  "git-backup",
11
11
  "snapshot",
12
12
  "recovery",
13
- "agent-skill"
13
+ "agent-skill",
14
+ "cross-platform"
14
15
  ],
15
16
  "author": "zhangqiang8vipp",
16
17
  "license": "MIT",
@@ -19,6 +20,13 @@
19
20
  "url": "https://github.com/zhangqiang8vipp/cursor-guard.git"
20
21
  },
21
22
  "homepage": "https://github.com/zhangqiang8vipp/cursor-guard",
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "bin": {
27
+ "cursor-guard-backup": "references/bin/cursor-guard-backup.js",
28
+ "cursor-guard-doctor": "references/bin/cursor-guard-doctor.js"
29
+ },
22
30
  "files": [
23
31
  "SKILL.md",
24
32
  "README.md",