cursor-guard 4.9.1 → 4.9.6
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 +94 -28
- package/README.zh-CN.md +91 -25
- package/ROADMAP.md +45 -9
- package/SKILL.md +32 -22
- package/package.json +1 -1
- package/references/config-reference.md +68 -7
- package/references/config-reference.zh-CN.md +68 -7
- package/references/cursor-guard.example.json +11 -7
- package/references/cursor-guard.schema.json +30 -7
- package/references/dashboard/public/app.js +73 -27
- package/references/dashboard/public/index.html +8 -7
- package/references/lib/auto-backup.js +40 -2
- package/references/lib/core/backups.js +46 -16
- package/references/lib/core/core.test.js +101 -22
- package/references/lib/core/dashboard.js +37 -23
- package/references/lib/core/doctor.js +19 -13
- package/references/lib/core/pre-warning.js +296 -0
- package/references/lib/core/snapshot.js +24 -2
- package/references/lib/core/status.js +15 -7
- package/references/lib/utils.js +46 -20
- package/references/mcp/mcp.test.js +60 -12
- package/references/mcp/server.js +72 -60
- package/references/quickstart.zh-CN.md +46 -21
- package/references/vscode-extension/build-vsix.js +4 -3
- package/references/vscode-extension/dist/LICENSE +65 -0
- package/references/vscode-extension/dist/{cursor-guard-ide-4.9.1.vsix → cursor-guard-ide-4.9.6.vsix} +0 -0
- package/references/vscode-extension/dist/dashboard/public/app.js +73 -27
- package/references/vscode-extension/dist/dashboard/public/index.html +8 -7
- package/references/vscode-extension/dist/extension.js +498 -296
- package/references/vscode-extension/dist/guard-version.json +1 -1
- package/references/vscode-extension/dist/lib/auto-backup.js +40 -2
- package/references/vscode-extension/dist/lib/core/backups.js +46 -16
- package/references/vscode-extension/dist/lib/core/dashboard.js +37 -23
- package/references/vscode-extension/dist/lib/core/doctor.js +19 -13
- package/references/vscode-extension/dist/lib/core/pre-warning.js +296 -0
- package/references/vscode-extension/dist/lib/core/snapshot.js +24 -2
- package/references/vscode-extension/dist/lib/core/status.js +15 -7
- package/references/vscode-extension/dist/lib/sidebar-webview.js +502 -447
- package/references/vscode-extension/dist/lib/status-bar.js +95 -68
- package/references/vscode-extension/dist/lib/tree-view.js +174 -114
- package/references/vscode-extension/dist/lib/utils.js +46 -20
- package/references/vscode-extension/dist/mcp/server.js +393 -30
- package/references/vscode-extension/dist/package.json +1 -1
- package/references/vscode-extension/dist/skill/ROADMAP.md +45 -9
- package/references/vscode-extension/dist/skill/SKILL.md +32 -22
- package/references/vscode-extension/dist/skill/config-reference.md +68 -7
- package/references/vscode-extension/dist/skill/config-reference.zh-CN.md +68 -7
- package/references/vscode-extension/dist/skill/cursor-guard.example.json +11 -7
- package/references/vscode-extension/dist/skill/cursor-guard.schema.json +30 -7
- package/references/vscode-extension/extension.js +498 -296
- package/references/vscode-extension/lib/sidebar-webview.js +502 -447
- package/references/vscode-extension/lib/status-bar.js +95 -68
- package/references/vscode-extension/lib/tree-view.js +174 -114
- package/references/vscode-extension/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,11 +21,17 @@ When Cursor's AI agent edits your files, there's a risk of accidental overwrites
|
|
|
21
21
|
- **Secrets filtering** — Sensitive files (`.env`, keys, certificates) are auto-excluded from backups
|
|
22
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
|
- **MCP tool calls (optional)** — 9 structured tools (diagnostics, snapshot, restore, status, dashboard, alerts, etc.) with JSON responses and lower token cost
|
|
24
|
-
- **Auto-fix diagnostics** — `doctor_fix` automatically patches missing configs, uninitialized Git repos, gitignore gaps, and stale locks
|
|
25
|
-
- **Proactive change-velocity alerts (V4)** — Auto-detects abnormal file change patterns and raises risk warnings
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
24
|
+
- **Auto-fix diagnostics** — `doctor_fix` automatically patches missing configs, uninitialized Git repos, gitignore gaps, and stale locks
|
|
25
|
+
- **Proactive change-velocity alerts (V4)** — Auto-detects abnormal file change patterns and raises risk warnings
|
|
26
|
+
- **Pre-warning destructive edit guard (V4.9.6)** — Detects risky partial deletions before they quietly stick, with `popup` / `dashboard` / `silent` modes in the IDE
|
|
27
|
+
- **Backup health dashboard (V4)** — One-call comprehensive view: strategy, counts, disk usage, protection scope, health status
|
|
28
|
+
- **Web dashboard (V4.2)** — Local read-only web UI at `http://127.0.0.1:3120` — see health, backups, restore points, diagnostics, protection scope at a glance. Dual-language (zh-CN / en-US), auto-refresh, multi-project support
|
|
28
29
|
- **IDE extension (V4.7)** — Full dashboard embedded in VSCode/Cursor/Windsurf as a WebView tab + status bar alert indicator + sidebar project tree. No browser needed
|
|
30
|
+
- **Event-driven watching (V4.9)** — `fs.watch` + debounce replaces blind polling. Backup latency < 500ms, zero CPU when idle. Automatic fallback to polling on unsupported platforms
|
|
31
|
+
- **Right-click context menus (V4.7.7)** — Add files/folders to `protect` or `ignore` lists via Explorer/Editor right-click menu with pattern picker
|
|
32
|
+
- **Real-time sidebar (V4.9.1)** — "Last backup Xs ago" and alert countdown tick every second in the sidebar dashboard
|
|
33
|
+
- **Smart restore for deleted files (V4.8.4)** — Restore commands auto-point to parent commit (`hash~1`) when file was deleted in the snapshot, preventing "file not found" errors
|
|
34
|
+
- **Self-contained VSIX (V4.8.1)** — MCP server bundled as a single file via esbuild, zero npm dependencies needed for IDE extension
|
|
29
35
|
- **One-click hot restart (V4.5.8)** — Dashboard detects new versions and offers in-place server restart without losing state
|
|
30
36
|
- **Shadow incremental hard links (V4.5.4)** — Unchanged files are hard-linked to save disk space and I/O
|
|
31
37
|
- **Strong protection mode (V4.5.4)** — `always_watch: true` auto-starts watcher with MCP server, ensuring zero protection gaps
|
|
@@ -118,8 +124,9 @@ After installation, your directory structure should look like this:
|
|
|
118
124
|
│ ├── backups.js # Backup listing + retention
|
|
119
125
|
│ ├── restore.js # Single file / project restore
|
|
120
126
|
│ ├── status.js # Backup system status
|
|
121
|
-
│ ├── anomaly.js # V4: Change-velocity detection
|
|
122
|
-
│
|
|
127
|
+
│ ├── anomaly.js # V4: Change-velocity detection
|
|
128
|
+
│ ├── pre-warning.js # V4.9.6: destructive edit risk scoring + persistence
|
|
129
|
+
│ └── dashboard.js # V4: Health dashboard aggregation
|
|
123
130
|
├── dashboard/
|
|
124
131
|
│ ├── server.js # Dashboard HTTP server + API
|
|
125
132
|
│ └── public/ # Web UI (HTML/CSS/JS)
|
|
@@ -194,15 +201,21 @@ npx cursor-guard-backup --path /my/project
|
|
|
194
201
|
Edit `.cursor-guard.json` to define which files to protect:
|
|
195
202
|
|
|
196
203
|
```json
|
|
197
|
-
{
|
|
198
|
-
"protect": ["src/**", "lib/**", "package.json"],
|
|
199
|
-
"ignore": ["node_modules/**", "dist/**"],
|
|
200
|
-
"auto_backup_interval_seconds": 60,
|
|
201
|
-
"secrets_patterns": [".env", ".env.*", "*.key", "*.pem"],
|
|
202
|
-
"pre_restore_backup": "always",
|
|
203
|
-
"
|
|
204
|
-
}
|
|
205
|
-
|
|
204
|
+
{
|
|
205
|
+
"protect": ["src/**", "lib/**", "package.json"],
|
|
206
|
+
"ignore": ["node_modules/**", "dist/**"],
|
|
207
|
+
"auto_backup_interval_seconds": 60,
|
|
208
|
+
"secrets_patterns": [".env", ".env.*", "*.key", "*.pem"],
|
|
209
|
+
"pre_restore_backup": "always",
|
|
210
|
+
"proactive_alert": true,
|
|
211
|
+
"alert_thresholds": { "files_per_window": 20, "window_seconds": 10, "cooldown_seconds": 60 },
|
|
212
|
+
"enable_pre_warning": true,
|
|
213
|
+
"pre_warning_threshold": 30,
|
|
214
|
+
"pre_warning_mode": "popup",
|
|
215
|
+
"pre_warning_exclude_patterns": ["generated/**"],
|
|
216
|
+
"retention": { "mode": "days", "days": 30 }
|
|
217
|
+
}
|
|
218
|
+
```
|
|
206
219
|
|
|
207
220
|
#### `pre_restore_backup` — restore behavior control
|
|
208
221
|
|
|
@@ -212,9 +225,22 @@ Edit `.cursor-guard.json` to define which files to protect:
|
|
|
212
225
|
| `"ask"` | Prompt you each time: "Preserve current version before restore? (Y/n)" — you decide per restore. |
|
|
213
226
|
| `"never"` | Never preserve current version before restore (not recommended). |
|
|
214
227
|
|
|
215
|
-
Regardless of config, you can always override per-request:
|
|
216
|
-
- Say "don't preserve current version" to skip even when config is `"always"`
|
|
217
|
-
- Say "preserve current first" to force even when config is `"never"`
|
|
228
|
+
Regardless of config, you can always override per-request:
|
|
229
|
+
- Say "don't preserve current version" to skip even when config is `"always"`
|
|
230
|
+
- Say "preserve current first" to force even when config is `"never"`
|
|
231
|
+
|
|
232
|
+
#### `enable_pre_warning` — destructive partial-delete pre-warning
|
|
233
|
+
|
|
234
|
+
When enabled, the IDE extension evaluates edits that remove lines or whole methods/functions before they slip by unnoticed.
|
|
235
|
+
|
|
236
|
+
| Field | Default | Meaning |
|
|
237
|
+
|-------|---------|---------|
|
|
238
|
+
| `enable_pre_warning` | `false` | Turn pre-warning on without affecting existing projects |
|
|
239
|
+
| `pre_warning_threshold` | `30` | Warn when deletion risk reaches this percent |
|
|
240
|
+
| `pre_warning_mode` | `"popup"` | `popup` = interrupt with actions, `dashboard` = highlight only, `silent` = log/status only |
|
|
241
|
+
| `pre_warning_exclude_patterns` | `[]` | Skip generated files, migrations, vendored code, etc. |
|
|
242
|
+
|
|
243
|
+
Method/function removal is treated as high risk and can still trigger a warning even when the deleted-line percentage is below the threshold.
|
|
218
244
|
|
|
219
245
|
---
|
|
220
246
|
|
|
@@ -309,8 +335,8 @@ node build-vsix.js
|
|
|
309
335
|
cd dist
|
|
310
336
|
npx vsce package
|
|
311
337
|
|
|
312
|
-
# Install the generated .vsix file
|
|
313
|
-
code --install-extension cursor-guard-ide-4.
|
|
338
|
+
# Install the generated .vsix file (or download from GitHub Releases)
|
|
339
|
+
code --install-extension cursor-guard-ide-4.9.6.vsix
|
|
314
340
|
```
|
|
315
341
|
|
|
316
342
|
On first activation, the extension automatically:
|
|
@@ -330,9 +356,13 @@ Features:
|
|
|
330
356
|
- **WebView Dashboard** — full dashboard embedded as an editor tab, identical to the browser version
|
|
331
357
|
- **Status Bar Indicator** — shows `Guard: OK` (green) or `Guard: 22 files!` (yellow) in real-time
|
|
332
358
|
- **Sidebar TreeView** — activity bar icon with project list, watcher status, backup stats, alerts, health
|
|
333
|
-
- **Visual Sidebar** — graphical dashboard with
|
|
334
|
-
- **
|
|
359
|
+
- **Visual Sidebar** — graphical dashboard with live-ticking backup age, alert countdown, protection scope, quick stats
|
|
360
|
+
- **Pre-warning delete guard** — flags risky partial deletions, removed methods, and suspicious line drops before they quietly stick
|
|
361
|
+
- **Command Palette** — `Open Dashboard`, `Snapshot Now`, `Start/Stop Watcher`, `Quick Restore`, `Doctor`, `Refresh`
|
|
362
|
+
- **Right-click menus** — add files/folders to `protect` or `ignore` via Explorer/Editor context menu
|
|
363
|
+
- **Event-driven refresh** — `FileSystemWatcher` pushes UI updates on file changes (< 1.5s latency), 30s heartbeat fallback
|
|
335
364
|
- **Auto-setup (V4.7.5)** — auto-detects IDE type, installs Skill, registers MCP, creates config on first run
|
|
365
|
+
- **Self-contained (V4.8.1)** — MCP server bundled via esbuild, zero npm dependencies
|
|
336
366
|
- **Multi-project** — hot-loads all workspace folders with `.cursor-guard.json`
|
|
337
367
|
- **Compatible** — works with VSCode ^1.74.0, Cursor, Windsurf, Trae, and all VSCode-based IDEs
|
|
338
368
|
|
|
@@ -405,7 +435,7 @@ The skill activates on these signals:
|
|
|
405
435
|
|------|---------|
|
|
406
436
|
| `SKILL.md` | Main skill instructions for the AI agent (with MCP dual-path) |
|
|
407
437
|
| `ROADMAP.md` | Version evolution roadmap (V2-V7) |
|
|
408
|
-
| `references/lib/core/` | Core layer:
|
|
438
|
+
| `references/lib/core/` | Core layer: 9 pure-logic modules (doctor / doctor-fix / snapshot / backups / restore / status / anomaly / pre-warning / dashboard) |
|
|
409
439
|
| `references/mcp/server.js` | MCP Server: 9 structured tools (optional) |
|
|
410
440
|
| `references/lib/auto-backup.js` | Auto-backup watcher (calls Core) |
|
|
411
441
|
| `references/lib/guard-doctor.js` | Health check CLI shell (calls Core) |
|
|
@@ -425,7 +455,42 @@ The skill activates on these signals:
|
|
|
425
455
|
|
|
426
456
|
---
|
|
427
457
|
|
|
428
|
-
## Changelog
|
|
458
|
+
## Changelog
|
|
459
|
+
|
|
460
|
+
### v4.9.6 — Pre-Warning for Destructive Partial Deletes
|
|
461
|
+
|
|
462
|
+
- **Feature**: Added configurable `pre_warning` support in `.cursor-guard.json` — `enable_pre_warning`, `pre_warning_threshold`, `pre_warning_mode`, `pre_warning_exclude_patterns`
|
|
463
|
+
- **Feature**: IDE extension now detects risky line/method removals and can react in `popup`, `dashboard`, or `silent` mode
|
|
464
|
+
- **Feature**: `backup_status`, `dashboard`, sidebar, status bar, and browser dashboard surface active delete-risk warnings
|
|
465
|
+
- **Improve**: New `pre-warning.js` core module centralizes deletion-risk scoring, active-warning persistence, and warning history
|
|
466
|
+
- **Docs**: README, skill guide, roadmap, and config references now document the pre-warning flow end-to-end
|
|
467
|
+
|
|
468
|
+
### v4.9.0–v4.9.1 — Event-Driven Architecture
|
|
469
|
+
|
|
470
|
+
- **Architecture**: Watcher (`auto-backup.js`) rewritten from `while+sleep` polling to `fs.watch` event-driven with 500ms debounce. Zero CPU when idle, backup latency < 500ms
|
|
471
|
+
- **Fallback**: Automatic degradation to polling mode if `fs.watch` is unavailable (e.g. older Linux kernels)
|
|
472
|
+
- **Config hot-reload**: `.cursor-guard.json` changes trigger instant config reload via `fs.watch` event (no more waiting 10 polling cycles)
|
|
473
|
+
- **IDE FileSystemWatcher**: Extension uses VSCode built-in `createFileSystemWatcher` to push UI updates on file changes (1.5s debounce)
|
|
474
|
+
- **Poller heartbeat**: Reduced from 5s fixed interval to 30s heartbeat; UI updates are now event-driven
|
|
475
|
+
- **Live sidebar counters**: "Last backup Xs ago" ticks every second in real-time (v4.9.1)
|
|
476
|
+
|
|
477
|
+
### v4.8.0–v4.8.5 — Bundling, Doctor Fixes, Restore UX
|
|
478
|
+
|
|
479
|
+
- **Fix**: MCP server bundled as single self-contained file via esbuild — eliminates all transitive dependency issues (`zod-to-json-schema`, `ajv`, etc.) (v4.8.1)
|
|
480
|
+
- **Fix**: `doctor` MCP check no longer false-warns when cursor-guard is configured in `.cursor/mcp.json` (v4.8.2)
|
|
481
|
+
- **Fix**: Skill directory `references/` now auto-creates junction link to extension runtime files on every activation (v4.8.2)
|
|
482
|
+
- **Fix**: Deleted file restore commands auto-point to parent commit (`hash~1`), preventing "file not found" errors. Button shows "Restore pre-delete" with orange styling (v4.8.4)
|
|
483
|
+
- **Fix**: Files outside `protect` scope no longer appear as phantom "deleted" in change summaries (v4.8.5)
|
|
484
|
+
- **Improve**: VSIX package reduced from 3.18 MB to 1.27 MB thanks to esbuild bundling
|
|
485
|
+
|
|
486
|
+
### v4.7.6–v4.7.9 — Sidebar Redesign, Context Menus, Protection Scope
|
|
487
|
+
|
|
488
|
+
- **Feature**: Right-click context menus — add files/folders to `protect` or `ignore` via Explorer/Editor menus with pattern picker (v4.7.7)
|
|
489
|
+
- **Feature**: Protection scope card in sidebar — shows protected/excluded file counts, actual protect/ignore patterns (v4.7.8)
|
|
490
|
+
- **Feature**: Alert countdown ticks live every second in sidebar (v4.7.8)
|
|
491
|
+
- **Fix**: Open Dashboard CORS/CSP issues — added `Access-Control-Allow-Origin`, relaxed CSP, fallback to browser on WebView failure (v4.7.8)
|
|
492
|
+
- **Fix**: `protect` patterns now use strict matching (full path only, no basename fallback) for consistency (v4.7.8)
|
|
493
|
+
- **Redesign**: Sidebar dashboard simplified — single status indicator, 2x2 action button grid, streamlined Quick Stats, removed clutter (v4.7.6)
|
|
429
494
|
|
|
430
495
|
### v4.7.5 — VSIX Self-Contained Build + Auto-Setup
|
|
431
496
|
|
|
@@ -462,7 +527,7 @@ The skill activates on these signals:
|
|
|
462
527
|
- **Feature**: Dashboard version detection + one-click hot restart (`/api/restart` endpoint)
|
|
463
528
|
- **Feature**: File detail modal with per-file restore command copy buttons
|
|
464
529
|
- **Feature**: `cursor-guard-init` auto-creates `.cursor-guard.json`; `backup_interval_seconds` alias supported
|
|
465
|
-
- **License**: Changed
|
|
530
|
+
- **License**: Changed to BSL 1.1
|
|
466
531
|
|
|
467
532
|
### v4.4.0 — V4 Final
|
|
468
533
|
|
|
@@ -541,8 +606,9 @@ The skill activates on these signals:
|
|
|
541
606
|
- **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.
|
|
542
607
|
- **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.
|
|
543
608
|
- **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.
|
|
544
|
-
- **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`).
|
|
545
|
-
- **
|
|
609
|
+
- **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`).
|
|
610
|
+
- **Pre-warning scope**: `pre_warning` is currently an editor/extension-side "last brake", not a universal cross-process write blocker. Headless shell / MCP flows surface it through status and dashboard after detection rather than hard-blocking writes.
|
|
611
|
+
- **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**.
|
|
546
612
|
- **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.
|
|
547
613
|
|
|
548
614
|
## Requirements
|
|
@@ -565,4 +631,4 @@ This is an independent open-source project maintained by a solo developer. If Cu
|
|
|
565
631
|
|
|
566
632
|
## License
|
|
567
633
|
|
|
568
|
-
[BSL 1.1
|
|
634
|
+
[BSL 1.1](LICENSE)
|
package/README.zh-CN.md
CHANGED
|
@@ -22,10 +22,16 @@
|
|
|
22
22
|
- **自动备份脚本** — 跨平台 (Node.js) 定期快照到独立 Git 分支,不干扰工作区
|
|
23
23
|
- **MCP 工具调用(可选)** — 9 个标准化工具(诊断、快照、恢复、状态、看板、告警等),结构化 JSON 返回,低 token 消耗
|
|
24
24
|
- **自动诊断修复** — `doctor_fix` 一键修补缺失配置、未初始化 Git、gitignore 遗漏等常见问题
|
|
25
|
-
- **主动变更频率告警(V4)** — 自动检测异常文件变更模式并发出风险预警
|
|
26
|
-
-
|
|
27
|
-
-
|
|
25
|
+
- **主动变更频率告警(V4)** — 自动检测异常文件变更模式并发出风险预警
|
|
26
|
+
- **事先预警删除风险(V4.9.6)** — 在危险的局部删除真正“悄悄生效”前先提醒你,支持 `popup` / `dashboard` / `silent` 三种模式
|
|
27
|
+
- **备份健康看板(V4)** — 一次调用全面查看:策略、数量、磁盘占用、保护范围、健康状态
|
|
28
|
+
- **Web 仪表盘(V4.2)** — 本地只读 Web 页面 `http://127.0.0.1:3120`——健康状态、备份、恢复点、诊断、保护范围一目了然。中英双语、自动刷新、支持多项目监控
|
|
28
29
|
- **IDE 扩展(V4.7)** — 完整仪表盘嵌入 VSCode/Cursor/Windsurf,WebView 标签页 + 状态栏告警指示器 + 侧边栏项目树。无需打开浏览器
|
|
30
|
+
- **事件驱动监听(V4.9)** — `fs.watch` + 防抖替代盲轮询。备份延迟 < 500ms,空闲时零 CPU。不支持的平台自动降级为轮询
|
|
31
|
+
- **右键上下文菜单(V4.7.7)** — 在资源管理器/编辑器右键菜单中将文件或文件夹添加到 `protect` 或 `ignore` 列表
|
|
32
|
+
- **实时侧边栏(V4.9.1)** — "上次备份 Xs 前"和告警倒计时每秒跳动更新
|
|
33
|
+
- **删除文件智能恢复(V4.8.4)** — 恢复命令自动指向父提交(`hash~1`),避免"文件不存在"错误
|
|
34
|
+
- **自包含 VSIX(V4.8.1)** — MCP server 通过 esbuild 打包为单文件,IDE 扩展零 npm 依赖
|
|
29
35
|
- **一键热重启(V4.5.8)** — 仪表盘检测到新版本时可原地重启服务,不丢失状态
|
|
30
36
|
- **Shadow 增量硬链接(V4.5.4)** — 未变更文件硬链接到上次快照,节省磁盘空间和 I/O
|
|
31
37
|
- **强保护模式(V4.5.4)** — `always_watch: true` 让 watcher 随 MCP server 自动启动,确保零保护缺口
|
|
@@ -118,8 +124,9 @@ git clone https://github.com/zhangqiang8vipp/cursor-guard.git .cursor/skills/cur
|
|
|
118
124
|
│ ├── backups.js # 备份列表 + 留存清理
|
|
119
125
|
│ ├── restore.js # 单文件/全项目恢复
|
|
120
126
|
│ ├── status.js # 备份系统状态
|
|
121
|
-
│ ├── anomaly.js # V4:变更频率检测
|
|
122
|
-
│
|
|
127
|
+
│ ├── anomaly.js # V4:变更频率检测
|
|
128
|
+
│ ├── pre-warning.js # V4.9.6:删除风险评分 + 持久化
|
|
129
|
+
│ └── dashboard.js # V4:健康看板聚合
|
|
123
130
|
├── dashboard/
|
|
124
131
|
│ ├── server.js # 仪表盘 HTTP 服务 + API
|
|
125
132
|
│ └── public/ # Web UI(HTML/CSS/JS)
|
|
@@ -196,13 +203,19 @@ npx cursor-guard-backup --path /my/project
|
|
|
196
203
|
```json
|
|
197
204
|
{
|
|
198
205
|
"protect": ["src/**", "lib/**", "package.json"],
|
|
199
|
-
"ignore": ["node_modules/**", "dist/**"],
|
|
200
|
-
"auto_backup_interval_seconds": 60,
|
|
201
|
-
"secrets_patterns": [".env", ".env.*", "*.key", "*.pem"],
|
|
202
|
-
"pre_restore_backup": "always",
|
|
203
|
-
"
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
+
"ignore": ["node_modules/**", "dist/**"],
|
|
207
|
+
"auto_backup_interval_seconds": 60,
|
|
208
|
+
"secrets_patterns": [".env", ".env.*", "*.key", "*.pem"],
|
|
209
|
+
"pre_restore_backup": "always",
|
|
210
|
+
"proactive_alert": true,
|
|
211
|
+
"alert_thresholds": { "files_per_window": 20, "window_seconds": 10, "cooldown_seconds": 60 },
|
|
212
|
+
"enable_pre_warning": true,
|
|
213
|
+
"pre_warning_threshold": 30,
|
|
214
|
+
"pre_warning_mode": "popup",
|
|
215
|
+
"pre_warning_exclude_patterns": ["generated/**"],
|
|
216
|
+
"retention": { "mode": "days", "days": 30 }
|
|
217
|
+
}
|
|
218
|
+
```
|
|
206
219
|
|
|
207
220
|
#### `pre_restore_backup` — 恢复前保留行为控制
|
|
208
221
|
|
|
@@ -212,9 +225,22 @@ npx cursor-guard-backup --path /my/project
|
|
|
212
225
|
| `"ask"` | 每次恢复前询问你:"恢复前是否保留当前版本?(Y/n)"——由你逐次决定。 |
|
|
213
226
|
| `"never"` | 恢复前不保留当前版本(不推荐)。 |
|
|
214
227
|
|
|
215
|
-
无论配置如何,你始终可以在单次请求中覆盖:
|
|
216
|
-
- 说"不保留当前版本"可跳过保留(即使配置为 `"always"`)
|
|
217
|
-
- 说"先保留当前版本"可强制保留(即使配置为 `"never"`)
|
|
228
|
+
无论配置如何,你始终可以在单次请求中覆盖:
|
|
229
|
+
- 说"不保留当前版本"可跳过保留(即使配置为 `"always"`)
|
|
230
|
+
- 说"先保留当前版本"可强制保留(即使配置为 `"never"`)
|
|
231
|
+
|
|
232
|
+
#### `enable_pre_warning` — 局部破坏性删除的事先预警
|
|
233
|
+
|
|
234
|
+
开启后,IDE 扩展会在“删行很多”或“直接删掉方法/函数”这类高风险编辑发生时,先给出最后一道提醒。
|
|
235
|
+
|
|
236
|
+
| 字段 | 默认值 | 说明 |
|
|
237
|
+
|------|--------|------|
|
|
238
|
+
| `enable_pre_warning` | `false` | 默认关闭,兼容旧项目 |
|
|
239
|
+
| `pre_warning_threshold` | `30` | 删除风险达到这个百分比时触发预警 |
|
|
240
|
+
| `pre_warning_mode` | `"popup"` | `popup` 弹窗拦一下,`dashboard` 仅高亮看板,`silent` 只记日志/状态 |
|
|
241
|
+
| `pre_warning_exclude_patterns` | `[]` | 跳过生成文件、迁移脚本、第三方代码等 |
|
|
242
|
+
|
|
243
|
+
如果检测到方法/函数被移除,即使删行比例没到阈值,也会按高风险处理并触发提醒。
|
|
218
244
|
|
|
219
245
|
---
|
|
220
246
|
|
|
@@ -309,8 +335,8 @@ node build-vsix.js
|
|
|
309
335
|
cd dist
|
|
310
336
|
npx vsce package
|
|
311
337
|
|
|
312
|
-
# 安装生成的 .vsix
|
|
313
|
-
code --install-extension cursor-guard-ide-4.
|
|
338
|
+
# 安装生成的 .vsix 文件(或从 GitHub Releases 下载)
|
|
339
|
+
code --install-extension cursor-guard-ide-4.9.6.vsix
|
|
314
340
|
```
|
|
315
341
|
|
|
316
342
|
首次激活时,扩展自动:
|
|
@@ -330,9 +356,13 @@ code --install-extension .
|
|
|
330
356
|
- **WebView 仪表盘** — 完整仪表盘作为编辑器标签页嵌入,与浏览器版本完全一致
|
|
331
357
|
- **状态栏指示器** — 实时显示 `Guard: OK`(绿色)或 `Guard: 22 files!`(黄色告警)
|
|
332
358
|
- **侧边栏 TreeView** — Activity Bar 图标,树形展示项目列表、Watcher 状态、备份统计、告警、健康评估
|
|
333
|
-
- **可视化图表侧边栏** —
|
|
334
|
-
-
|
|
359
|
+
- **可视化图表侧边栏** — 备份时间实时跳动、告警倒计时、保护范围、Quick Stats
|
|
360
|
+
- **事先预警删除保护** — 在局部删代码、删方法、可疑大段删行时提前亮警报
|
|
361
|
+
- **命令面板** — `Open Dashboard`、`Snapshot Now`、`Start/Stop Watcher`、`Quick Restore`、`Doctor`、`Refresh`
|
|
362
|
+
- **右键菜单** — 在资源管理器/编辑器右键菜单中将文件或文件夹添加到 `protect` 或 `ignore`
|
|
363
|
+
- **事件驱动刷新** — `FileSystemWatcher` 监听文件变化推送 UI 更新(< 1.5s 延迟),30s 心跳兜底
|
|
335
364
|
- **自动配置(V4.7.5)** — 首次运行自动检测 IDE 类型、安装 Skill、注册 MCP、创建配置
|
|
365
|
+
- **自包含(V4.8.1)** — MCP server 通过 esbuild 打包,零 npm 依赖
|
|
336
366
|
- **多项目** — 热加载所有包含 `.cursor-guard.json` 的工作区文件夹
|
|
337
367
|
- **兼容性** — 支持 VSCode ^1.74.0、Cursor、Windsurf、Trae 及所有基于 VSCode 的 IDE
|
|
338
368
|
|
|
@@ -405,7 +435,7 @@ code --install-extension .
|
|
|
405
435
|
|------|------|
|
|
406
436
|
| `SKILL.md` | AI 代理的主要技能指令(含 MCP 双路径逻辑) |
|
|
407
437
|
| `ROADMAP.md` | 版本演进规划书(V2-V7) |
|
|
408
|
-
| `references/lib/core/` | Core 层:
|
|
438
|
+
| `references/lib/core/` | Core 层:9 个纯逻辑模块(doctor / doctor-fix / snapshot / backups / restore / status / anomaly / pre-warning / dashboard) |
|
|
409
439
|
| `references/mcp/server.js` | MCP Server:9 个标准化工具(可选) |
|
|
410
440
|
| `references/lib/auto-backup.js` | 自动备份 watcher(调用 Core) |
|
|
411
441
|
| `references/lib/guard-doctor.js` | 健康检查 CLI 壳(调用 Core) |
|
|
@@ -425,7 +455,42 @@ code --install-extension .
|
|
|
425
455
|
|
|
426
456
|
---
|
|
427
457
|
|
|
428
|
-
## 更新日志
|
|
458
|
+
## 更新日志
|
|
459
|
+
|
|
460
|
+
### v4.9.6 — 事先预警局部破坏性删除
|
|
461
|
+
|
|
462
|
+
- **新功能**:`.cursor-guard.json` 新增 `enable_pre_warning`、`pre_warning_threshold`、`pre_warning_mode`、`pre_warning_exclude_patterns`
|
|
463
|
+
- **新功能**:IDE 扩展现在会检测高风险删行 / 删方法,并支持 `popup`、`dashboard`、`silent` 三种预警模式
|
|
464
|
+
- **新功能**:`backup_status`、`dashboard`、侧边栏、状态栏、浏览器仪表盘都会展示活跃的删除风险预警
|
|
465
|
+
- **增强**:新增 `pre-warning.js` Core 模块,统一负责删除风险评分、活跃预警持久化和历史记录
|
|
466
|
+
- **文档**:README、SKILL、ROADMAP 与配置说明已补齐预警功能说明
|
|
467
|
+
|
|
468
|
+
### v4.9.0–v4.9.1 — 事件驱动架构
|
|
469
|
+
|
|
470
|
+
- **架构重构**:Watcher(`auto-backup.js`)从 `while+sleep` 轮询重写为 `fs.watch` 事件驱动 + 500ms 防抖。空闲时零 CPU,备份延迟 < 500ms
|
|
471
|
+
- **自动降级**:`fs.watch` 不可用时自动回退到轮询模式
|
|
472
|
+
- **配置即时响应**:`.cursor-guard.json` 变化通过 `fs.watch` 事件直接触发热加载(不再等待 10 个轮询周期)
|
|
473
|
+
- **IDE FileSystemWatcher**:扩展使用 VSCode 内置 `createFileSystemWatcher` 推送文件变化事件(1.5s 防抖)
|
|
474
|
+
- **Poller 心跳**:从 5s 固定轮询改为 30s 心跳;UI 更新由事件驱动
|
|
475
|
+
- **实时侧边栏计时**:"上次备份 Xs 前"每秒跳动更新(v4.9.1)
|
|
476
|
+
|
|
477
|
+
### v4.8.0–v4.8.5 — 打包修复、Doctor 优化、恢复 UX
|
|
478
|
+
|
|
479
|
+
- **修复**:MCP server 通过 esbuild 打包为单个自包含文件——彻底解决传递依赖缺失问题(`zod-to-json-schema`、`ajv` 等)(v4.8.1)
|
|
480
|
+
- **修复**:`doctor` MCP 检查不再在 `.cursor/mcp.json` 已配置 cursor-guard 时误报 WARN(v4.8.2)
|
|
481
|
+
- **修复**:Skill 目录 `references/` 每次激活时自动创建 junction 链接到扩展运行时文件(v4.8.2)
|
|
482
|
+
- **修复**:删除文件的恢复命令自动指向父提交(`hash~1`),避免"文件不存在"错误。按钮显示"恢复删除前"橙色样式(v4.8.4)
|
|
483
|
+
- **修复**:`protect` 范围外的文件不再在变更摘要中被误标为"删除"(v4.8.5)
|
|
484
|
+
- **优化**:VSIX 包从 3.18 MB 缩减至 1.27 MB
|
|
485
|
+
|
|
486
|
+
### v4.7.6–v4.7.9 — 侧边栏重设计、右键菜单、保护范围
|
|
487
|
+
|
|
488
|
+
- **新功能**:右键上下文菜单——在资源管理器/编辑器右键添加文件到 `protect` 或 `ignore`,含模式选择器(v4.7.7)
|
|
489
|
+
- **新功能**:侧边栏保护范围卡片——显示受保护/排除文件数、protect/ignore 模式列表(v4.7.8)
|
|
490
|
+
- **新功能**:告警倒计时每秒实时跳动(v4.7.8)
|
|
491
|
+
- **修复**:Open Dashboard CORS/CSP 问题——添加 CORS 头、放宽 CSP、WebView 失败时回退到浏览器(v4.7.8)
|
|
492
|
+
- **修复**:`protect` 模式改为严格匹配(仅完整路径,不回退到 basename)(v4.7.8)
|
|
493
|
+
- **重设计**:侧边栏仪表盘简化——单一状态指示器、2×2 操作按钮网格、精简 Quick Stats(v4.7.6)
|
|
429
494
|
|
|
430
495
|
### v4.7.5 — VSIX 独立打包 + 自动配置
|
|
431
496
|
|
|
@@ -461,7 +526,7 @@ code --install-extension .
|
|
|
461
526
|
- **功能**:Dashboard 版本检测 + 一键热重启(`/api/restart` 端点)
|
|
462
527
|
- **功能**:文件详情弹窗 + 每文件恢复命令复制按钮
|
|
463
528
|
- **功能**:`cursor-guard-init` 自动创建 `.cursor-guard.json`;支持 `backup_interval_seconds` 别名
|
|
464
|
-
-
|
|
529
|
+
- **许可证**:变更为 BSL 1.1
|
|
465
530
|
|
|
466
531
|
### v4.4.0 — V4 收官版
|
|
467
532
|
|
|
@@ -540,8 +605,9 @@ code --install-extension .
|
|
|
540
605
|
- **未跟踪文件**:从未提交到 Git 的文件无法从 Git 历史恢复。影子拷贝(`backup_strategy: "shadow"` 或 `"both"`)是未跟踪文件的唯一安全网。
|
|
541
606
|
- **并发 Agent**:如果多个 AI 代理线程同时写入同一文件,快照无法防止竞态条件。请避免并行编辑同一文件。
|
|
542
607
|
- **外部工具修改索引**:在自动备份运行期间,其他修改 Git 索引的工具(如 Git GUI、IDE Git 集成)可能冲突。脚本使用临时索引来最小化风险,但边缘情况仍存在。
|
|
543
|
-
- **Git worktree**:自动备份脚本支持 worktree 布局(`git rev-parse --git-dir`),但未在所有特殊配置下测试(如 `--separate-git-dir`)。
|
|
544
|
-
-
|
|
608
|
+
- **Git worktree**:自动备份脚本支持 worktree 布局(`git rev-parse --git-dir`),但未在所有特殊配置下测试(如 `--separate-git-dir`)。
|
|
609
|
+
- **预警边界**:`pre_warning` 目前属于编辑器/扩展侧的“最后一道刹车”,还不是跨进程、全场景的硬拦截。纯 shell / 纯 MCP 无界面场景下,主要通过状态和看板暴露风险。
|
|
610
|
+
- **Cursor 终端干扰**:Cursor 集成终端会向 `git commit` 命令注入 `--trailer` 标志,导致 `commit-tree` 等底层命令异常。请始终在**独立的终端窗口**中运行自动备份脚本。
|
|
545
611
|
- **大型仓库**:对于非常大的仓库,备份循环中的 `git add -A` 可能较慢。使用 `.cursor-guard.json` 中的 `protect` 模式缩小范围。
|
|
546
612
|
|
|
547
613
|
## 环境要求
|
|
@@ -564,4 +630,4 @@ code --install-extension .
|
|
|
564
630
|
|
|
565
631
|
## 许可证
|
|
566
632
|
|
|
567
|
-
[BSL 1.1
|
|
633
|
+
[BSL 1.1](LICENSE)
|
package/ROADMAP.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
> 本文档描述 cursor-guard 从 V2 到 V7 的长期演进方向。
|
|
4
4
|
> 每一代向下兼容,低版本功能永远不废弃。
|
|
5
5
|
>
|
|
6
|
-
> **当前版本**:`V4.9.
|
|
7
|
-
> **文档状态**:`V2` ~ `V4.9.
|
|
6
|
+
> **当前版本**:`V4.9.6`
|
|
7
|
+
> **文档状态**:`V2` ~ `V4.9.6` 已完成交付(含 V5 intent/audit 基础),`V5` 主体规划中
|
|
8
8
|
|
|
9
9
|
## 阅读导航
|
|
10
10
|
|
|
@@ -193,7 +193,7 @@ cursor-guard 的安全,不靠“模型自己小心一点”,而是靠**规
|
|
|
193
193
|
|
|
194
194
|
---
|
|
195
195
|
|
|
196
|
-
## V2 — Skill + Script
|
|
196
|
+
## V2 — Skill + Script(基础能力起点)
|
|
197
197
|
|
|
198
198
|
| 项目 | 内容 |
|
|
199
199
|
|---|---|
|
|
@@ -560,7 +560,7 @@ V4 经过 4 轮系统性代码审查,修复了以下关键问题:
|
|
|
560
560
|
|
|
561
561
|
| 层 | 改动 | 说明 |
|
|
562
562
|
|----|------|------|
|
|
563
|
-
| Core | `backups.js` 新增 `getBackupFiles(projectDir, commitHash)` | 对指定 commit 运行 `diff
|
|
563
|
+
| Core | `backups.js` 新增 `getBackupFiles(projectDir, commitHash)` | 对指定 commit 运行 `git diff --numstat` + `git diff --name-status`(与终端一致;V4.9.3+)。无 parent 时对 Git 空树 `4b825dc…`。返回 `[{path, action, added, deleted}]`,按变化量降序;`R`/`C` 前缀解析 rename/copy |
|
|
564
564
|
| Server | `GET /api/backup-files?id=<project>&hash=<commit>` | 懒加载端点,不在 `list_backups` 中批量计算(50 条备份×`diff-tree` 会很慢)。400 校验 `hash` 必填 |
|
|
565
565
|
| Dashboard | `parseSummaryToFiles(summary)` | 解析 summary 文本格式 `"Modified 3: a.js (+2 -1), b.js (+0 -5), ...; Added 2: c.js (+10 -0)"` → `[{path, action, added, deleted}]`。正则匹配 `(Modified|Added|Deleted|Renamed) N:` 段头,逐文件解析 `filename (+N -M)`,自动跳过 `...` 截断标记 |
|
|
566
566
|
| Dashboard | `fetchBackupFiles(hash)` | 调用 `/api/backup-files` 端点,返回完整文件数组。网络失败静默降级(返回空数组) |
|
|
@@ -734,6 +734,39 @@ V4 经过 4 轮系统性代码审查,修复了以下关键问题:
|
|
|
734
734
|
}
|
|
735
735
|
```
|
|
736
736
|
|
|
737
|
+
### V4.9.6:新增可开关的 `pre_warning` 事先预警 MVP ✅
|
|
738
|
+
|
|
739
|
+
| 能力 | 说明 |
|
|
740
|
+
|------|------|
|
|
741
|
+
| **配置开关** | `.cursor-guard.json` 新增 `enable_pre_warning`、`pre_warning_threshold`、`pre_warning_mode`、`pre_warning_exclude_patterns`,默认关闭,兼容旧项目 |
|
|
742
|
+
| **风险模型** | 基于删行比例 + 方法/函数移除检测进行评分;删方法/函数即使未达到删行阈值,也会按高风险处理 |
|
|
743
|
+
| **IDE 交互** | VSCode / Cursor / Windsurf 扩展支持 `popup` / `dashboard` / `silent` 三种模式;`popup` 提供 `Undo Change` 与 `View Diff` 作为最后一道刹车 |
|
|
744
|
+
| **状态面整合** | `backup_status`、`dashboard`、状态栏、侧边栏、浏览器仪表盘统一展示活跃 pre-warning;风险摘要进入 health issues |
|
|
745
|
+
| **架构定位** | 这是 V5「变更控制层」前的一步 MVP:先做编辑器侧的“最后一道提醒”,不是跨进程硬拦截;后续仍由 V5 的 `begin_edit` / embedded watcher 承接更强的事前控制 |
|
|
746
|
+
|
|
747
|
+
### V4.9.5 / V4.9.4:修复事件驱动 Watcher 因 `.git` 写入导致的疯狂自触发备份 ✅
|
|
748
|
+
|
|
749
|
+
| 修复 | 说明 |
|
|
750
|
+
|------|------|
|
|
751
|
+
| **根因** | v4.9.0 起 `fs.watch(recursive)` 监听整个仓库。每次快照会写 `.git/objects`、`refs/guard/…` 等,触发 watch → debounce 后又跑备份。Windows 下 `filename` 常为 `HEAD`、`objects/…` 等**不带** `.git/` 前缀 → **反馈环路** |
|
|
752
|
+
| **完全避免(不靠延时)** | `shouldIgnoreFsWatchEvent`:凡可判定为「落在 Git 目录内」的事件一律不触发备份。**不用**快照后冷却计时;路径语义正确即可从根上断开环路 |
|
|
753
|
+
| **真实 Git 目录** | 传入 `git rev-parse --git-dir` 解析后的路径(worktree / 子模块等下 `.git` 可能是文件),避免误用 `项目/.git` 字符串 |
|
|
754
|
+
| **路径规则** | `.git/` 前缀、`.cursor-guard-backup`、多段路径在 `git-dir` 下存在、`path.relative(gitDir, resolve(项目,filename))` 落在仓库内 → 忽略 |
|
|
755
|
+
| **V4.9.5** | 移除曾加入的 **3.5s 冷却**(用户要求:应全量避免,而非靠时间窗口兜底) |
|
|
756
|
+
|
|
757
|
+
### V4.9.3:备份文件 +/- 与终端 `git diff` 完全一致 ✅
|
|
758
|
+
|
|
759
|
+
| 变更 | 说明 |
|
|
760
|
+
|------|------|
|
|
761
|
+
| **唯一数据源** | `getBackupFiles` 只使用 `git diff --numstat <parent> <commit>` + `git diff --name-status <parent> <commit>`,与你在终端执行的 diff 统计一致(含 rename 检测、CRLF、二进制 `- -` 等) |
|
|
762
|
+
| **根/orphan 提交** | 无父提交时 `parent` 使用 Git 标准空树 `4b825dc642cb6eb9a060e54bf8d69288fbee4904`,不再用 `ls-tree` + 手工行数 |
|
|
763
|
+
| **移除** | 去掉 `diff-tree --numstat`、`--text` 及 `git show` 行数回退,避免与 CLI 语义分叉 |
|
|
764
|
+
| **拷贝** | `git diff --name-status` 的 `C`(copy)映射为 `action: copied` |
|
|
765
|
+
|
|
766
|
+
### V4.9.2:(已由 V4.9.3 替代)备份详情行数修复尝试
|
|
767
|
+
|
|
768
|
+
> V4.9.2 的 `--text` + `git show` 回退已废弃;以 V4.9.3「纯 git diff」为准。
|
|
769
|
+
|
|
737
770
|
### V4.9.1:侧边栏"Last backup"实时计时 ✅
|
|
738
771
|
|
|
739
772
|
| 优化 | 说明 |
|
|
@@ -1381,7 +1414,7 @@ PR Review 中展示 AI 编辑报告
|
|
|
1381
1414
|
|
|
1382
1415
|
### V6 不做的事
|
|
1383
1416
|
|
|
1384
|
-
-
|
|
1417
|
+
- **不做平台化** —— cursor-guard 专注代码安全工具
|
|
1385
1418
|
- **不做强依赖云端的服务** —— 核心能力永远是本地优先
|
|
1386
1419
|
- **不做 IDE 本体** —— 只做安全层,不越界
|
|
1387
1420
|
- **不做通用工程观测平台** —— 只围绕 AI 代码变更安全
|
|
@@ -1568,7 +1601,10 @@ V4.3.2 ───── ✅ init 自动添加 node_modules/ 到 .gitignore + doc
|
|
|
1568
1601
|
V4.3.3 ───── ✅ Intent 上下文(intent / agent / session trailer + 仪表盘展示)
|
|
1569
1602
|
V4.3.4 ───── ✅ 运维加固(日志轮转 / 锁文件时间戳 / preview 分组 / SKILL 规则)
|
|
1570
1603
|
V4.3.5 ───── ✅ Summary 增量 diff-tree 修复 + 变更列堆叠布局 + 配色优化
|
|
1571
|
-
V4.4.0 ───── ✅ V4 收官:首次快照 summary + doctor 完整性/retention 检查 + init 升级检测
|
|
1604
|
+
V4.4.0 ───── ✅ V4 收官:首次快照 summary + doctor 完整性/retention 检查 + init 升级检测
|
|
1605
|
+
V4.9.0 ───── ✅ 事件驱动 watcher + 实时侧边栏计时
|
|
1606
|
+
V4.9.5 ───── ✅ 修复 `.git` 写入导致的疯狂自触发备份
|
|
1607
|
+
V4.9.6 ───── ✅ `pre_warning` 事先预警 MVP(局部删代码风险提示) ← 当前版本
|
|
1572
1608
|
│
|
|
1573
1609
|
│ 前提:AI 编辑需要更强的追溯 / 恢复 / 查询闭环
|
|
1574
1610
|
│ 前提:多 Agent / 多工具协作成为真实场景
|
|
@@ -1647,10 +1683,10 @@ V7 的"可验证治理"是这条产品线的逻辑终点——该保护的都保
|
|
|
1647
1683
|
| 取代 Git | cursor-guard 是 Git 的增强,不是替代 |
|
|
1648
1684
|
| AI 行为限制 | cursor-guard 是安全网,不是笼子 |
|
|
1649
1685
|
| 多 IDE 全面适配 | 聚焦 Cursor,其他 IDE 由社区或 V6 协议解决 |
|
|
1650
|
-
|
|
|
1686
|
+
| 封闭化 | 保持开源,协议保持开放 |
|
|
1651
1687
|
| 中心化认证服务 | 签名和验证基于本地,不引入外部依赖 |
|
|
1652
1688
|
|
|
1653
1689
|
---
|
|
1654
1690
|
|
|
1655
|
-
*最后更新:2026-03-22*
|
|
1656
|
-
*版本:v1.
|
|
1691
|
+
*最后更新:2026-03-22*
|
|
1692
|
+
*版本:v1.6(V4.9.6,含事件驱动 watcher、自触发备份反馈环修复、`pre_warning` 事先预警 MVP)*
|
package/SKILL.md
CHANGED
|
@@ -62,17 +62,24 @@ On first trigger in a session, check if the workspace root contains `.cursor-gua
|
|
|
62
62
|
// "count": keep N newest commits. "days": keep commits from last N days.
|
|
63
63
|
"git_retention": { "enabled": false, "mode": "count", "max_count": 200 },
|
|
64
64
|
|
|
65
|
-
// V4: Proactive change-velocity detection (default: on).
|
|
66
|
-
// When enabled, the watcher monitors file change frequency and raises
|
|
67
|
-
// alerts when abnormal patterns are detected (e.g. 20+ files in 10s).
|
|
68
|
-
"proactive_alert": true,
|
|
69
|
-
"alert_thresholds": {
|
|
70
|
-
"files_per_window": 20, // trigger threshold
|
|
71
|
-
"window_seconds": 10, // sliding window
|
|
72
|
-
"cooldown_seconds": 60 // min gap between alerts
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
// V4: Proactive change-velocity detection (default: on).
|
|
66
|
+
// When enabled, the watcher monitors file change frequency and raises
|
|
67
|
+
// alerts when abnormal patterns are detected (e.g. 20+ files in 10s).
|
|
68
|
+
"proactive_alert": true,
|
|
69
|
+
"alert_thresholds": {
|
|
70
|
+
"files_per_window": 20, // trigger threshold
|
|
71
|
+
"window_seconds": 10, // sliding window
|
|
72
|
+
"cooldown_seconds": 60 // min gap between alerts
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// V4.9.6: destructive partial-delete pre-warning (default: off).
|
|
76
|
+
// Triggered when deletion risk is high or whole methods/functions disappear.
|
|
77
|
+
"enable_pre_warning": false,
|
|
78
|
+
"pre_warning_threshold": 30,
|
|
79
|
+
"pre_warning_mode": "popup",
|
|
80
|
+
"pre_warning_exclude_patterns": []
|
|
81
|
+
}
|
|
82
|
+
```
|
|
76
83
|
|
|
77
84
|
**Resolution rules:**
|
|
78
85
|
- `protect` set + `ignore` set → file must match a `protect` pattern AND not match any `ignore` pattern.
|
|
@@ -82,10 +89,12 @@ On first trigger in a session, check if the workspace root contains `.cursor-gua
|
|
|
82
89
|
|
|
83
90
|
**`secrets_patterns`**: Glob patterns for sensitive files (`.env`, keys, certificates). Matching files are **auto-excluded** from backup commits, even within `protect` scope. Built-in defaults: `.env`, `.env.*`, `*.key`, `*.pem`, `*.p12`, `*.pfx`, `credentials*`. Set this field to override.
|
|
84
91
|
|
|
85
|
-
**`retention`**: Controls automatic cleanup of old shadow-copy snapshots in `.cursor-guard-backup/`:
|
|
86
|
-
- `"days"` (default): keep snapshots from the last N days (default **30**).
|
|
87
|
-
- `"count"`: keep the N most recent snapshots (default 100).
|
|
88
|
-
- `"size"`: keep total shadow-copy folder under N MB (default 500).
|
|
92
|
+
**`retention`**: Controls automatic cleanup of old shadow-copy snapshots in `.cursor-guard-backup/`:
|
|
93
|
+
- `"days"` (default): keep snapshots from the last N days (default **30**).
|
|
94
|
+
- `"count"`: keep the N most recent snapshots (default 100).
|
|
95
|
+
- `"size"`: keep total shadow-copy folder under N MB (default 500).
|
|
96
|
+
|
|
97
|
+
**`enable_pre_warning` / `pre_warning_*`**: Optional IDE-side "last brake" for destructive partial deletions. When enabled, the extension scores deletion-heavy edits, removed methods/functions, and suspicious line drops. `popup` interrupts with quick actions, `dashboard` only surfaces the warning in UI/status, and `silent` only records it. Active warnings are exposed through `backup_status` / `dashboard` as `_activePreWarning`.
|
|
89
98
|
|
|
90
99
|
**If no config file exists**, the agent operates in "protect everything" mode (backward compatible). Mention to the user that they can create `.cursor-guard.json` to narrow scope — see [references/cursor-guard.example.json](references/cursor-guard.example.json).
|
|
91
100
|
|
|
@@ -111,12 +120,13 @@ cursor-guard provides an **MCP server** (`cursor-guard-mcp`) as an optional enha
|
|
|
111
120
|
| Change-velocity alerts | `alert_status` | manual: check alert file in .git/ or .cursor-guard-backup/ |
|
|
112
121
|
|
|
113
122
|
**Rules**:
|
|
114
|
-
- MCP results are JSON — parse `status`, `error`, and data fields; do not re-run shell to verify.
|
|
115
|
-
- If an MCP call returns an `error` field, report it to the user and fall back to the shell path for that operation.
|
|
116
|
-
- All Hard Rules (§Hard Rules) still apply regardless of execution path. MCP tools enforce them internally (e.g. `restore_file` creates a pre-restore snapshot by default).
|
|
117
|
-
- If MCP is not configured, the skill works exactly as before — **no degradation**.
|
|
118
|
-
- `
|
|
119
|
-
- `
|
|
123
|
+
- MCP results are JSON — parse `status`, `error`, and data fields; do not re-run shell to verify.
|
|
124
|
+
- If an MCP call returns an `error` field, report it to the user and fall back to the shell path for that operation.
|
|
125
|
+
- All Hard Rules (§Hard Rules) still apply regardless of execution path. MCP tools enforce them internally (e.g. `restore_file` creates a pre-restore snapshot by default).
|
|
126
|
+
- If MCP is not configured, the skill works exactly as before — **no degradation**.
|
|
127
|
+
- `backup_status` and `dashboard` may include `_activePreWarning`; when present, surface it as an active delete-risk warning before giving the rest of the health summary.
|
|
128
|
+
- `doctor_fix` is safe to call — each fix is idempotent. Use `dry_run: true` to preview changes before applying. Typical fixes: create missing config, init git repo, gitignore backup dir, remove stale lock file.
|
|
129
|
+
- `restore_project` with `preview: false` executes a full restore including pre-restore snapshot. Always call with `preview: true` first, show the result to the user, and only execute after explicit confirmation.
|
|
120
130
|
|
|
121
131
|
When the target file of an edit **falls outside the protected scope**, the agent:
|
|
122
132
|
- Still applies "Read before Write" (Hard Rule §2).
|
|
@@ -603,7 +613,7 @@ Skip the block for unrelated turns.
|
|
|
603
613
|
- Recovery commands: [references/recovery.md](references/recovery.md)
|
|
604
614
|
- Auto-backup (Node.js core): [references/lib/auto-backup.js](references/lib/auto-backup.js)
|
|
605
615
|
- Guard doctor (Node.js core): [references/lib/guard-doctor.js](references/lib/guard-doctor.js)
|
|
606
|
-
- Core modules: [references/lib/core/](references/lib/core/) (doctor, doctor-fix, snapshot, backups, restore, status, anomaly, dashboard)
|
|
616
|
+
- Core modules: [references/lib/core/](references/lib/core/) (doctor, doctor-fix, snapshot, backups, restore, status, anomaly, pre-warning, dashboard)
|
|
607
617
|
- MCP server: [references/mcp/server.js](references/mcp/server.js) (9 tools: doctor, doctor_fix, backup_status, list_backups, snapshot_now, restore_file, restore_project, dashboard, alert_status)
|
|
608
618
|
- Web dashboard: [references/dashboard/](references/dashboard/) (local read-only web UI — `node references/dashboard/server.js --path <project>`)
|
|
609
619
|
- Shared utilities: [references/lib/utils.js](references/lib/utils.js)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-guard",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.6",
|
|
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",
|