Skip to content

Commit 4e073ed

Browse files
authored
feat: use snapshot design (#9)
* docs: remove snapshot command from README and refactor backup system to snapshot-based architecture - Remove "One-time Snapshot" section from both English and Chinese READMEs - Rename "Download Binary" to "Via Binary" in installation sections - Refactor backup system from entry-based to snapshot-based architecture: - Replace BackupEntry with Snapshot and SnapshotFile interfaces - Add "create" event type to FileEventType - Change BackupIndex structure to use snapshots array instead of entries - Replace * feat: add defensive null checks for snapshot data structures - Add files array initialization when loading backup index to ensure all snapshots have files property - Add null-safe array access with fallback to empty arrays in getAllSnapshots(), getFileHistory(), restoreSnapshot(), cleanupOldSnapshots(), and getBackupStats() - Add null-safe size access with fallback to 0 in getBackupStats() - Prevent potential runtime errors when accessing snapshots or files arrays that may be undefined * feat: auto-load .gitignore patterns and expand default exclude patterns - Add automatic .gitignore file reading and pattern merging in getDefaultConfig() - Expand default exclude patterns to cover more system and build artifacts: - Change .git pattern to **/.*/** for all hidden files/directories - Add database files (*.db, *.sqlite, *.sqlite3) - Add lock and process files (*.lock, *.lck, *.pid) - Add system log and trace files (*.idx, *.etl, *.evtx, *.evt, *.trace, *.out, *.asl) - Add Windows * update fix * update fix * update fix * update fix * update fix * refactor: simplify restore command to use positional argument instead of flags - Replace --id and --time flags with single positional argument accepting snapshot ID or timestamp - Auto-detect input type: snap_* prefix for snapshot ID, numeric for timestamp - Update help text and examples to show new usage: `shield restore <id>` - Update interactive mode hints to reflect simplified command syntax - Improve error message to show expected input formats
1 parent 3606cb4 commit 4e073ed

File tree

7 files changed

+522
-625
lines changed

7 files changed

+522
-625
lines changed

README.md

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A workspace history version management tool that protects your workspace from un
2222
npm install -g agentshield
2323
```
2424

25-
### Download Binary
25+
### Via Binary
2626

2727
```bash
2828
curl -fsSL https://github.com/tomsun28/agentshield/raw/main/install.sh | bash
@@ -58,63 +58,16 @@ shield stop ./my-project
5858
shield status
5959
```
6060

61-
### Exec Mode (Recommended for Agent Tasks)
62-
63-
```bash
64-
# Snapshot workspace, run command, then allow easy restore
65-
shield exec -- npm run agent-task
66-
shield exec -- python ai_script.py
67-
shield exec --path=./my-project -- cargo run
68-
```
69-
70-
This mode:
71-
1. Takes a full snapshot before the command runs
72-
2. Executes your agent command
73-
3. Allows you to easily restore any modified files
74-
75-
### One-time Snapshot
76-
77-
```bash
78-
# Take a snapshot of current directory
79-
shield snapshot
80-
81-
# Take a snapshot of specific directory
82-
shield snapshot ./my-project
83-
```
84-
8561
### Restore Files
8662

8763
```bash
88-
# List all backups with timestamps (use for --time option)
64+
# List all backups with snapshot ID
8965
shield list
90-
# Restore all files to most recent backup
91-
shield restore
92-
93-
# Restore only a specific file to its latest backup
94-
shield restore --file=src/index.ts
95-
96-
# Restore all files to a specific timestamp
97-
shield restore --time=1737216000000
98-
99-
# Restore a specific file to a specific timestamp
100-
shield restore --file=src/index.ts --time=1737216000000
10166

67+
# Restore a specific snapshot by ID
68+
shield restore --id=<snapshot_id>
10269
```
10370

104-
### List Backups
105-
106-
```bash
107-
# List all backups with details including timestamps
108-
shield list
109-
```
110-
111-
The `list` command shows:
112-
- File path with event type icon (📄 changed, 🗑️ deleted, 📝 renamed)
113-
- Time ago and file size
114-
- Exact timestamp (for use with `--time` option)
115-
- ISO date string
116-
- Rename history (if applicable)
117-
11871
### Status and Cleanup
11972

12073
```bash

README_CN.md

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
npm install -g agentshield
2323
```
2424

25-
### 二进制文件安装
25+
### 二进制安装
2626

2727
```bash
2828
curl -fsSL https://github.com/tomsun28/agentshield/raw/main/install.sh | bash
@@ -57,63 +57,16 @@ shield stop ./my-project
5757
shield status
5858
```
5959

60-
### Exec 模式(推荐用于代理任务)
61-
62-
```bash
63-
# 快照工作区,运行命令,然后允许轻松恢复
64-
shield exec -- npm run agent-task
65-
shield exec -- python ai_script.py
66-
shield exec --path=./my-project -- cargo run
67-
```
68-
69-
此模式会:
70-
1. 在命令运行前创建完整快照
71-
2. 执行你的代理命令
72-
3. 允许你轻松恢复任何修改过的文件
73-
74-
### 一次性快照
75-
76-
```bash
77-
# 创建当前目录的快照
78-
shield snapshot
79-
80-
# 创建指定目录的快照
81-
shield snapshot ./my-project
82-
```
83-
8460
### 恢复文件
8561

8662
```bash
87-
# 列出所有备份及时间戳(用于 --time 选项)
63+
# 列出所有变更及快照点
8864
shield list
8965

90-
# 恢复所有文件到最近的备份
91-
shield restore
92-
93-
# 仅恢复特定文件到其最新备份
94-
shield restore --file=src/index.ts
95-
96-
# 恢复所有文件到特定时间戳
97-
shield restore --time=1737216000000
98-
99-
# 恢复特定文件到特定时间戳
100-
shield restore --file=src/index.ts --time=1737216000000
66+
# 恢复文件到特定快照点
67+
shield restore --id=<snapshot_id>
10168
```
10269

103-
### 列出备份
104-
105-
```bash
106-
# 列出所有备份详情,包括时间戳
107-
shield list
108-
```
109-
110-
`list` 命令显示:
111-
- 文件路径及事件类型图标(📄 修改、🗑️ 删除、📝 重命名)
112-
- 相对时间和文件大小
113-
- 精确时间戳(用于 `--time` 选项)
114-
- ISO 日期字符串
115-
- 重命名历史(如适用)
116-
11770
### 状态和清理
11871

11972
```bash
@@ -133,4 +86,4 @@ shield clean --days=3
13386

13487
## 📄 开源协议
13588

136-
[Apache License 2.0](./LICENSE)
89+
[Apache License 2.0](./LICENSE)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agentshield",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "Instant file protection for AI agent operations - hardlink-based zero-copy backup system",
55
"type": "module",
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)