@dambrogia/openclaw-agents-backup 0.1.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/.eslintrc.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "parser": "@typescript-eslint/parser",
3
+ "extends": ["plugin:@typescript-eslint/recommended"],
4
+ "plugins": ["@typescript-eslint"],
5
+ "parserOptions": {
6
+ "ecmaVersion": 2020,
7
+ "sourceType": "module"
8
+ },
9
+ "rules": {
10
+ "@typescript-eslint/explicit-function-return-types": "off",
11
+ "@typescript-eslint/no-explicit-any": "error",
12
+ "@typescript-eslint/no-unused-vars": [
13
+ "error",
14
+ {
15
+ "argsIgnorePattern": "^_",
16
+ "varsIgnorePattern": "^_"
17
+ }
18
+ ],
19
+ "@typescript-eslint/no-var-requires": "off",
20
+ "semi": ["error", "always"],
21
+ "quotes": ["error", "single", { "avoidEscape": true }],
22
+ "no-console": ["warn", { "allow": ["log", "warn", "error"] }]
23
+ }
24
+ }
@@ -0,0 +1,40 @@
1
+ name: Tests and Linting
2
+
3
+ on:
4
+ push:
5
+ branches: [master, develop]
6
+ pull_request:
7
+ branches: [master, develop]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Use Node.js 24.x
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: '24.x'
20
+ cache: 'npm'
21
+
22
+ - name: Install dependencies
23
+ run: npm ci
24
+
25
+ - name: Build
26
+ run: npm run build
27
+
28
+ - name: Run linting
29
+ run: npm run lint
30
+
31
+ - name: Run tests with coverage
32
+ run: npm run test:coverage
33
+
34
+ - name: Upload coverage reports
35
+ uses: codecov/codecov-action@v3
36
+ with:
37
+ files: ./coverage/coverage-final.json
38
+ flags: unittests
39
+ name: codecov-umbrella
40
+ fail_ci_if_error: false
@@ -0,0 +1,51 @@
1
+ # This file should be copied to your backup repository as .gitignore
2
+ # It ensures that secrets and temporary files are never committed
3
+
4
+ # Environment and secrets
5
+ .env
6
+ .env.local
7
+ .env.*.local
8
+ .env.production.local
9
+
10
+ # Authentication profiles (sensitive)
11
+ auth-profiles.json
12
+ auth-profiles.*
13
+
14
+ # Dependencies and build artifacts
15
+ node_modules/
16
+ package-lock.json
17
+ yarn.lock
18
+ dist/
19
+ build/
20
+ *.js
21
+ *.js.map
22
+ *.d.ts
23
+ .next/
24
+ .nuxt/
25
+
26
+ # IDE and editor files
27
+ .vscode/
28
+ .idea/
29
+ *.swp
30
+ *.swo
31
+ *~
32
+ .DS_Store
33
+ .sublime-project
34
+ .sublime-workspace
35
+
36
+ # Logs and temporary files
37
+ *.log
38
+ logs/
39
+ *.tmp
40
+ .cache/
41
+ .parcel-cache/
42
+
43
+ # OS files
44
+ Thumbs.db
45
+ .AppleDouble
46
+ .LSOverride
47
+
48
+ # Local development
49
+ .local/
50
+ tmp/
51
+ temp/
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dambrogia-ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,342 @@
1
+ # @dambrogia/openclaw-agents-backup
2
+
3
+ Backup and restore OpenClaw multi-agent workspaces. Automated hourly snapshots with full disaster recovery capabilities.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@dambrogia/openclaw-agents-backup)](https://www.npmjs.com/package/@dambrogia/openclaw-agents-backup)
6
+ [![Tests](https://github.com/dambrogia-ai/openclaw-agents-backup/actions/workflows/test.yml/badge.svg)](https://github.com/dambrogia-ai/openclaw-agents-backup/actions)
7
+ [![Coverage](https://img.shields.io/badge/coverage->80%25-green)](./README.md)
8
+
9
+ ## Why This Exists
10
+
11
+ OpenClaw enables multiple agents to run in a single instance. Each agent has its own workspace with configuration, memory, identity files, and session history. If something goes wrong—disk corruption, accidental deletion, security incident—you lose everything.
12
+
13
+ This skill automates hourly backups of all agent workspaces and agent directories to a central Git repository. When disaster strikes, you can restore any agent to any point in history by pulling from your backup repo.
14
+
15
+ ## Agent Integration
16
+
17
+ The easiest way to use this skill is to install it and let your agent call the CLI commands.
18
+
19
+ ### Setup (One-time)
20
+
21
+ 1. **Install the skill in your agent's project:**
22
+ ```bash
23
+ npm install @dambrogia/openclaw-agents-backup
24
+ ```
25
+
26
+ That's it. You're done.
27
+
28
+ ### Usage
29
+
30
+ Your agent can now run:
31
+
32
+ ```bash
33
+ backup-agents backup # Back up all agents now
34
+ backup-agents restore # Restore to latest backup
35
+ backup-agents restore --sha abc123 # Restore to specific point in time
36
+ backup-agents history # Show recent backups
37
+ ```
38
+
39
+ Just tell your agent what you need:
40
+
41
+ - **"Back up my agents"** → Agent runs `backup-agents backup`
42
+ - **"Restore my agents"** → Agent runs `backup-agents restore`
43
+ - **"Restore agents to yesterday"** → Agent runs `backup-agents restore --sha <commit>`
44
+ - **"Show me backup history"** → Agent runs `backup-agents history`
45
+
46
+ ### Scheduled Backups
47
+
48
+ For automated hourly backups, set up a cron job in your OpenClaw instance:
49
+
50
+ ```javascript
51
+ // Runs every hour at :00
52
+ cron.add({
53
+ name: 'agents-backup-hourly',
54
+ schedule: { kind: 'cron', expr: '0 * * * *' },
55
+ payload: {
56
+ kind: 'agentTurn',
57
+ message: 'Back up all agents: backup-agents backup',
58
+ timeoutSeconds: 300
59
+ },
60
+ sessionTarget: 'isolated',
61
+ notify: false
62
+ });
63
+ ```
64
+
65
+ Or just tell your agent: **"Schedule hourly backups of my agents"**
66
+
67
+ ---
68
+
69
+ ## Quick Start
70
+
71
+ ### 1. Initialize Backup Repository
72
+
73
+ ```bash
74
+ mkdir my-agents-backup
75
+ cd my-agents-backup
76
+ git init
77
+ git config user.email "backup@example.com"
78
+ git config user.name "Backup Bot"
79
+ git commit --allow-empty -m "Initial commit"
80
+ ```
81
+
82
+ ### 2. Create Backup Config
83
+
84
+ In your OpenClaw workspace (`~/.openclaw/workspace`), create `.backupconfig.json`:
85
+
86
+ ```json
87
+ {
88
+ "backupRepoPath": "/path/to/my-agents-backup"
89
+ }
90
+ ```
91
+
92
+ ### 3. Install the Library
93
+
94
+ ```bash
95
+ npm install @dambrogia/openclaw-agents-backup
96
+ ```
97
+
98
+ ### 4. Schedule Hourly Backups
99
+
100
+ Use OpenClaw's cron system or call the backup function hourly.
101
+
102
+ ```javascript
103
+ const { performBackup } = require('@dambrogia/openclaw-agents-backup');
104
+
105
+ // Run every hour
106
+ await performBackup('/root/.openclaw/workspace');
107
+ ```
108
+
109
+ ### 5. Disaster Recovery
110
+
111
+ When you need to restore:
112
+
113
+ ```bash
114
+ # Wipe the VPS, reinstall OpenClaw
115
+ openclaw init
116
+
117
+ # Clone your backup
118
+ git clone <backup-repo-url> /path/to/my-agents-backup
119
+
120
+ # Create config pointing to backup repo
121
+ echo '{"backupRepoPath": "/path/to/my-agents-backup"}' > ~/.openclaw/workspace/.backupconfig.json
122
+
123
+ # Restore all agents to current state
124
+ node -e "require('@dambrogia/openclaw-agents-backup').performRestore(...)"
125
+ ```
126
+
127
+ ## Features
128
+
129
+ ✅ **Multi-agent support** — Back up all agents in one command
130
+ ✅ **Hourly snapshots** — Automated backup schedule
131
+ ✅ **Git history** — Full point-in-time recovery via Git commits
132
+ ✅ **Selective ignore** — `.env`, secrets, and temporary files never committed
133
+ ✅ **Minimal disk usage** — Only changed files are stored in Git
134
+ ✅ **Simple restore** — One command to restore any agent to any point
135
+ ✅ **Test coverage** — >80% covered, production-ready
136
+
137
+ ## What Gets Backed Up
138
+
139
+ For each agent, the skill backs up:
140
+
141
+ - **Workspace** — Identity files (SOUL.md, USER.md, IDENTITY.md), memory (MEMORY.md, memory/), configuration, tools
142
+ - **Agent directory** — Session files, auth profiles, history (when available)
143
+
144
+ What's **not** backed up (by design):
145
+
146
+ - `.env*` files (use these for secrets)
147
+ - `auth-profiles.json` (sensitive auth data)
148
+ - `node_modules/`, build artifacts, logs
149
+
150
+ ## API Reference
151
+
152
+ Agents call these functions directly. Most users don't need to interact with the API — just tell your agent what you need.
153
+
154
+ ### Backup
155
+
156
+ ```typescript
157
+ import { performBackup } from '@dambrogia/openclaw-agents-backup';
158
+
159
+ const result = await performBackup('/root/.openclaw/workspace');
160
+
161
+ /*
162
+ {
163
+ success: true,
164
+ message: "Backed up 3 agents. Changes: 2",
165
+ agentsProcessed: 3,
166
+ changes: [
167
+ { agentId: 'main', workspaceChanged: true, agentDirChanged: false },
168
+ { agentId: 'worker-1', workspaceChanged: false, agentDirChanged: true },
169
+ { agentId: 'worker-2', workspaceChanged: false, agentDirChanged: false }
170
+ ]
171
+ }
172
+ */
173
+ ```
174
+
175
+ ### Restore
176
+
177
+ ```typescript
178
+ import { performRestore } from '@dambrogia/openclaw-agents-backup';
179
+
180
+ // Restore latest backup
181
+ const result = await performRestore(
182
+ '/path/to/backup-repo',
183
+ null,
184
+ '/root/.openclaw/workspace'
185
+ );
186
+
187
+ // Or restore to specific point in time (git SHA)
188
+ const result = await performRestore(
189
+ '/path/to/backup-repo',
190
+ 'abc123def456',
191
+ '/root/.openclaw/workspace'
192
+ );
193
+
194
+ /*
195
+ {
196
+ success: true,
197
+ message: "Successfully restored 3 agents",
198
+ agentsRestored: 3
199
+ }
200
+ */
201
+ ```
202
+
203
+ ## Backup Structure
204
+
205
+ ```
206
+ my-agents-backup/
207
+ ├── .git/ # Full Git history
208
+ ├── archives/
209
+ │ ├── main/
210
+ │ │ ├── agent.json # Metadata: paths, timestamp, identity
211
+ │ │ ├── workspace/ # Synced workspace directory
212
+ │ │ └── agentDir/ # Synced agent directory
213
+ │ ├── worker-1/
214
+ │ │ ├── agent.json
215
+ │ │ ├── workspace/
216
+ │ │ └── agentDir/
217
+ │ └── ...
218
+ └── .gitignore
219
+ ```
220
+
221
+ Each backup run creates one Git commit. You can browse history:
222
+
223
+ ```bash
224
+ cd my-agents-backup
225
+ git log --oneline
226
+ # Restore to a specific commit
227
+ git checkout abc123def456
228
+ ```
229
+
230
+ ## Testing
231
+
232
+ ```bash
233
+ npm test # Run tests
234
+ npm run test:coverage # Check coverage (>80% required)
235
+ npm run lint # ESLint check
236
+ npm run build # TypeScript compilation
237
+ ```
238
+
239
+ ## Common Scenarios
240
+
241
+ ### Restore an Agent After Accidental Changes
242
+
243
+ ```bash
244
+ # Find the commit before the change
245
+ cd my-agents-backup
246
+ git log --oneline | head -10
247
+
248
+ # Restore that state
249
+ git checkout <commit-hash>
250
+ node -e "require('@dambrogia/openclaw-agents-backup').performRestore(...)"
251
+ ```
252
+
253
+ ### Back Up Before Major Changes
254
+
255
+ Run backup manually before modifying agent code or identity:
256
+
257
+ ```javascript
258
+ const { performBackup } = require('@dambrogia/openclaw-agents-backup');
259
+ await performBackup('/root/.openclaw/workspace');
260
+ ```
261
+
262
+ Check that files were committed in Git.
263
+
264
+ ### Migrate Agents to New VPS
265
+
266
+ 1. Set up new VPS with OpenClaw
267
+ 2. Clone your backup repo
268
+ 3. Point `.backupconfig.json` to it
269
+ 4. Run restore — agents are back online
270
+
271
+ ## Size Considerations
272
+
273
+ Each backup cycle syncs full agent workspaces and agent directories. Disk usage:
274
+
275
+ - **`archives/` directory** — Full copy of workspace + agentDir per agent (updated hourly, size stays constant)
276
+ - **Git repository** — Only changed files are committed; grows incrementally with actual changes
277
+
278
+ ### Realistic Example
279
+
280
+ **1 agent with 100MB workspace:**
281
+ - `archives/main/workspace/` — 100MB (constant, updated each sync)
282
+ - Git growth — 500KB-1MB per day (memory files + config changes) = ~15MB/month
283
+ - Total after 30 days — ~115MB
284
+
285
+ **3 agents with 100MB each:**
286
+ - `archives/` total — ~300MB (constant)
287
+ - Git growth — ~45MB/month (3 agents × 15MB/month)
288
+ - Total after 30 days — ~345MB
289
+
290
+ **Note:** If agents have cloned git repos in their workspace, those don't inflate Git (stored in `archives/` only, not committed to backup Git). Backup repo itself grows only by actual edits to memory, config, and metadata files — typically small daily changes.
291
+
292
+ Recommendation: For typical setups, monthly growth is 10-50MB. A 35GB disk is more than sufficient for years of backups.
293
+
294
+ **⚠️ Warning:** If agents accidentally save large files (binaries, datasets, etc.) to their workspace, Git history will grow quickly. Use `.gitignore` in agent workspaces to prevent committing large artifacts.
295
+
296
+ ## Limitations
297
+
298
+ - **Point-in-time restore via Git SHA** — Requires manual `git checkout` before calling restore
299
+ - **No encryption** — Backup repo should be private and secure
300
+ - **No compression** — Backups stored as full directory syncs in Git
301
+ - **Single backup location** — Multi-region replication not supported
302
+ - **Large files bloat Git** — If agents accidentally save large files (binaries, datasets, etc.) to workspace, Git history will balloon. Recommend using `.gitignore` in agent workspaces to prevent this
303
+
304
+ ## Troubleshooting
305
+
306
+ **Q: Backup runs but doesn't commit?**
307
+ A: Check Git configuration in the backup repo:
308
+ ```bash
309
+ cd /path/to/backup-repo
310
+ git config user.email "test@example.com"
311
+ git config user.name "Test"
312
+ git log --oneline # Verify commits are created
313
+ ```
314
+
315
+ **Q: Restore says "Archives directory not found"?**
316
+ A: Run backup at least once to create the archives directory structure.
317
+
318
+ **Q: Can I back up to a remote server?**
319
+ A: Yes! `backupRepoPath` can be a local clone of a remote repo. Configure a Git remote and push after backups:
320
+ ```bash
321
+ cd /path/to/backup-repo
322
+ git remote add origin <repo-url>
323
+ git push origin main
324
+ ```
325
+
326
+ ## Performance
327
+
328
+ - **Backup time** — Depends on agent size and disk speed. Typical: 30s–2min per agent
329
+ - **Restore time** — Similar to backup time
330
+ - **Cron interval** — Hourly recommended; can run more/less frequently
331
+
332
+ ## License
333
+
334
+ MIT — Use freely in your projects.
335
+
336
+ ## Contributing
337
+
338
+ Issues, PRs, and questions welcome! Please include test cases for any changes.
339
+
340
+ ---
341
+
342
+ **Made for OpenClaw multi-agent setups. Disaster recovery, made simple.**