agentshield 0.0.3 → 0.0.4
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 +9 -52
- package/dist/backup.d.ts +64 -41
- package/dist/backup.js +222 -318
- package/dist/backup.js.map +1 -1
- package/dist/cli.js +114 -125
- package/dist/cli.js.map +1 -1
- package/dist/config.js +38 -13
- package/dist/config.js.map +1 -1
- package/dist/watcher.d.ts +11 -1
- package/dist/watcher.js +87 -16
- package/dist/watcher.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,9 +22,13 @@ A workspace history version management tool that protects your workspace from un
|
|
|
22
22
|
npm install -g agentshield
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
###
|
|
25
|
+
### Via Binary
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
```bash
|
|
28
|
+
curl -fsSL https://github.com/tomsun28/agentshield/raw/main/install.sh | bash
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or download the executable binary for your platform from the [Releases](https://github.com/tomsun28/agentshield/releases) page (supports Windows, macOS, Linux).
|
|
28
32
|
|
|
29
33
|
## 📖 Usage
|
|
30
34
|
|
|
@@ -54,63 +58,16 @@ shield stop ./my-project
|
|
|
54
58
|
shield status
|
|
55
59
|
```
|
|
56
60
|
|
|
57
|
-
### Exec Mode (Recommended for Agent Tasks)
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
# Snapshot workspace, run command, then allow easy restore
|
|
61
|
-
shield exec -- npm run agent-task
|
|
62
|
-
shield exec -- python ai_script.py
|
|
63
|
-
shield exec --path=./my-project -- cargo run
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
This mode:
|
|
67
|
-
1. Takes a full snapshot before the command runs
|
|
68
|
-
2. Executes your agent command
|
|
69
|
-
3. Allows you to easily restore any modified files
|
|
70
|
-
|
|
71
|
-
### One-time Snapshot
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
# Take a snapshot of current directory
|
|
75
|
-
shield snapshot
|
|
76
|
-
|
|
77
|
-
# Take a snapshot of specific directory
|
|
78
|
-
shield snapshot ./my-project
|
|
79
|
-
```
|
|
80
|
-
|
|
81
61
|
### Restore Files
|
|
82
62
|
|
|
83
63
|
```bash
|
|
84
|
-
# List all backups with
|
|
64
|
+
# List all backups with snapshot ID
|
|
85
65
|
shield list
|
|
86
|
-
# Restore all files to most recent backup
|
|
87
|
-
shield restore
|
|
88
|
-
|
|
89
|
-
# Restore only a specific file to its latest backup
|
|
90
|
-
shield restore --file=src/index.ts
|
|
91
|
-
|
|
92
|
-
# Restore all files to a specific timestamp
|
|
93
|
-
shield restore --time=1737216000000
|
|
94
|
-
|
|
95
|
-
# Restore a specific file to a specific timestamp
|
|
96
|
-
shield restore --file=src/index.ts --time=1737216000000
|
|
97
66
|
|
|
67
|
+
# Restore a specific snapshot by ID
|
|
68
|
+
shield restore --id=<snapshot_id>
|
|
98
69
|
```
|
|
99
70
|
|
|
100
|
-
### List Backups
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
# List all backups with details including timestamps
|
|
104
|
-
shield list
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
The `list` command shows:
|
|
108
|
-
- File path with event type icon (📄 changed, 🗑️ deleted, 📝 renamed)
|
|
109
|
-
- Time ago and file size
|
|
110
|
-
- Exact timestamp (for use with `--time` option)
|
|
111
|
-
- ISO date string
|
|
112
|
-
- Rename history (if applicable)
|
|
113
|
-
|
|
114
71
|
### Status and Cleanup
|
|
115
72
|
|
|
116
73
|
```bash
|
package/dist/backup.d.ts
CHANGED
|
@@ -1,78 +1,101 @@
|
|
|
1
1
|
import { ShieldConfig } from "./config.js";
|
|
2
|
-
export type FileEventType = "change" | "delete" | "rename";
|
|
3
|
-
export interface
|
|
4
|
-
|
|
2
|
+
export type FileEventType = "change" | "delete" | "rename" | "create";
|
|
3
|
+
export interface SnapshotFile {
|
|
4
|
+
path: string;
|
|
5
5
|
backupPath: string;
|
|
6
|
-
timestamp: number;
|
|
7
6
|
size: number;
|
|
8
|
-
|
|
9
|
-
eventType?: FileEventType;
|
|
10
|
-
renamedFrom?: string;
|
|
7
|
+
eventType: FileEventType;
|
|
11
8
|
renamedTo?: string;
|
|
12
9
|
}
|
|
10
|
+
export interface Snapshot {
|
|
11
|
+
id: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
files: SnapshotFile[];
|
|
14
|
+
message?: string;
|
|
15
|
+
}
|
|
13
16
|
export interface BackupIndex {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[sessionId: string]: {
|
|
17
|
-
startTime: number;
|
|
18
|
-
endTime?: number;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
17
|
+
version: number;
|
|
18
|
+
snapshots: Snapshot[];
|
|
21
19
|
}
|
|
22
20
|
export declare class BackupManager {
|
|
23
21
|
private config;
|
|
24
22
|
private snapshotsDir;
|
|
25
23
|
private indexPath;
|
|
26
24
|
private index;
|
|
27
|
-
private currentSessionId;
|
|
28
|
-
private protectedInSession;
|
|
29
25
|
constructor(config: ShieldConfig);
|
|
30
26
|
private ensureVaultExists;
|
|
31
27
|
private loadIndex;
|
|
32
28
|
private saveIndex;
|
|
33
29
|
shouldExclude(filePath: string): boolean;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Create snapshot - Package multiple file changes into one snapshot
|
|
32
|
+
*/
|
|
33
|
+
createSnapshot(files: Array<{
|
|
34
|
+
relativePath: string;
|
|
35
|
+
eventType: FileEventType;
|
|
36
|
+
content?: Buffer;
|
|
37
|
+
renamedTo?: string;
|
|
38
|
+
}>, message?: string): Snapshot | null;
|
|
39
|
+
/**
|
|
40
|
+
* Get all snapshots, sorted by time in descending order
|
|
41
|
+
*/
|
|
42
|
+
getAllSnapshots(): Snapshot[];
|
|
43
|
+
/**
|
|
44
|
+
* Get snapshot by ID
|
|
45
|
+
*/
|
|
46
|
+
getSnapshotById(snapshotId: string): Snapshot | null;
|
|
47
|
+
/**
|
|
48
|
+
* Get snapshot by timestamp
|
|
49
|
+
*/
|
|
50
|
+
getSnapshotByTimestamp(timestamp: number): Snapshot | null;
|
|
51
|
+
/**
|
|
52
|
+
* Get all backup versions of a file
|
|
53
|
+
*/
|
|
54
|
+
getFileHistory(relativePath: string): Array<{
|
|
55
|
+
snapshot: Snapshot;
|
|
56
|
+
file: SnapshotFile;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Get latest backup content of a file
|
|
60
|
+
*/
|
|
37
61
|
getLatestBackupContent(relativePath: string): {
|
|
38
62
|
content: Buffer;
|
|
39
63
|
timestamp: number;
|
|
40
64
|
} | null;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
resetSession(): void;
|
|
47
|
-
getBackupsForFile(relativePath: string): BackupEntry[];
|
|
48
|
-
getAllBackups(): BackupEntry[];
|
|
49
|
-
restoreFile(entry: BackupEntry): boolean;
|
|
50
|
-
restoreLatest(relativePath: string): boolean;
|
|
51
|
-
restoreAllLatest(): {
|
|
65
|
+
/**
|
|
66
|
+
* Restore snapshot - Batch restore all files in snapshot
|
|
67
|
+
*/
|
|
68
|
+
restoreSnapshot(snapshotId: string): {
|
|
52
69
|
restored: number;
|
|
53
70
|
failed: number;
|
|
54
71
|
deleted: number;
|
|
55
72
|
};
|
|
56
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Restore to snapshot at specified timestamp
|
|
75
|
+
*/
|
|
76
|
+
restoreToSnapshot(timestamp: number): {
|
|
57
77
|
restored: number;
|
|
58
78
|
failed: number;
|
|
59
79
|
deleted: number;
|
|
60
80
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Restore single file to latest backup
|
|
83
|
+
*/
|
|
84
|
+
restoreFile(relativePath: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Clean old snapshots
|
|
87
|
+
*/
|
|
88
|
+
cleanOldSnapshots(maxAgeDays: number): {
|
|
69
89
|
removed: number;
|
|
70
90
|
freedBytes: number;
|
|
71
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Get statistics
|
|
94
|
+
*/
|
|
72
95
|
getStats(): {
|
|
73
|
-
|
|
96
|
+
snapshots: number;
|
|
97
|
+
totalFiles: number;
|
|
74
98
|
totalSize: number;
|
|
75
99
|
uniqueFiles: number;
|
|
76
|
-
sessions: number;
|
|
77
100
|
};
|
|
78
101
|
}
|