@singularity-layer/agentvault 0.1.2 → 0.2.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/README.md +20 -3
- package/dist/client.d.ts +7 -0
- package/dist/client.js +3 -0
- package/dist/commands/backup.d.ts +2 -0
- package/dist/commands/backup.js +16 -4
- package/dist/customTarget.d.ts +24 -0
- package/dist/customTarget.js +100 -0
- package/dist/index.js +28 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,12 +32,23 @@ from **your** passphrase (scrypt). The vault stores ciphertext it cannot read.
|
|
|
32
32
|
That cuts both ways: **a lost passphrase cannot be recovered — not even by us.**
|
|
33
33
|
Write it down.
|
|
34
34
|
|
|
35
|
+
## Back up anything
|
|
36
|
+
|
|
37
|
+
Not on OpenClaw or Hermes? Any directory can be vaulted:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
agentvault backup --path ~/my-agent --name "My Agent"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Universal by design — Claude Code, Cursor, custom stacks, whatever. Restores
|
|
44
|
+
with `agentvault restore --dest` like everything else.
|
|
45
|
+
|
|
35
46
|
## Commands
|
|
36
47
|
|
|
37
48
|
| Command | What it does |
|
|
38
49
|
|---|---|
|
|
39
50
|
| `agentvault login` | Browser wallet sign-in (`--api-key` to paste a key instead) |
|
|
40
|
-
| `agentvault backup [--all]` | Encrypt + upload detected agents |
|
|
51
|
+
| `agentvault backup [--all] [--path <dir> --name <n>]` | Encrypt + upload detected agents, or ANY directory |
|
|
41
52
|
| `agentvault restore [--dest <dir>]` | Download, decrypt, safely unpack a snapshot |
|
|
42
53
|
| `agentvault list` | Agents and snapshot counts |
|
|
43
54
|
| `agentvault passphrase set\|clear` | Store the passphrase in the OS keychain (for scheduled backups) |
|
|
@@ -45,8 +56,14 @@ Write it down.
|
|
|
45
56
|
|
|
46
57
|
## Pricing
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
| | Free | Vault Pro — $3/mo |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| Snapshots | 1, rolling (new replaces old) | Unlimited, full history |
|
|
62
|
+
| Storage | 1 GiB | 5 GiB |
|
|
63
|
+
|
|
64
|
+
Vault Pro bills from your [credits](https://cloud.x402compute.cc/network/settings/credits);
|
|
65
|
+
upgrade from the dashboard. If a renewal can't be paid you drop back to free —
|
|
66
|
+
**stored backups are never deleted.** A typical agent snapshot is a few MB.
|
|
50
67
|
|
|
51
68
|
## Dashboard
|
|
52
69
|
|
package/dist/client.d.ts
CHANGED
|
@@ -16,9 +16,16 @@ export interface RequestBackupResult {
|
|
|
16
16
|
r2Key: string;
|
|
17
17
|
uploadUrl: string;
|
|
18
18
|
}
|
|
19
|
+
export interface UsageInfo {
|
|
20
|
+
plan: "free" | "pro";
|
|
21
|
+
bytesUsed: number;
|
|
22
|
+
maxBytes: number;
|
|
23
|
+
}
|
|
19
24
|
export interface ApiClient {
|
|
20
25
|
/** Cheap authenticated call — login uses it to verify an API key works. */
|
|
21
26
|
verifyKey(): Promise<void>;
|
|
27
|
+
/** Plan + usage; optional so test fakes stay small. */
|
|
28
|
+
getUsage?(): Promise<UsageInfo>;
|
|
22
29
|
listAgents(): Promise<AgentRecord[]>;
|
|
23
30
|
createAgent(name: string, framework: string): Promise<AgentRecord>;
|
|
24
31
|
requestBackup(agentId: string, sizeBytes: number): Promise<RequestBackupResult>;
|
package/dist/client.js
CHANGED
|
@@ -30,6 +30,9 @@ export function createClient(baseUrl, token, fetchImpl = fetch) {
|
|
|
30
30
|
async verifyKey() {
|
|
31
31
|
await call("/backups/agents");
|
|
32
32
|
},
|
|
33
|
+
async getUsage() {
|
|
34
|
+
return call("/backups/usage");
|
|
35
|
+
},
|
|
33
36
|
async listAgents() {
|
|
34
37
|
const { agents } = await call("/backups/agents");
|
|
35
38
|
return agents;
|
|
@@ -20,6 +20,8 @@ export interface BackupDeps {
|
|
|
20
20
|
}
|
|
21
21
|
export interface BackupOptions {
|
|
22
22
|
all: boolean;
|
|
23
|
+
/** Universal mode (`--path`): back up exactly this prebuilt target, skipping discovery. */
|
|
24
|
+
custom?: DetectedAgent;
|
|
23
25
|
}
|
|
24
26
|
/** Discover agents, choose, then back each up: pack -> reserve -> encrypt -> upload -> complete. */
|
|
25
27
|
export declare function runBackup(deps: BackupDeps, opts: BackupOptions): Promise<void>;
|
package/dist/commands/backup.js
CHANGED
|
@@ -8,13 +8,13 @@ async function ensureAgent(client, detected) {
|
|
|
8
8
|
}
|
|
9
9
|
/** Discover agents, choose, then back each up: pack -> reserve -> encrypt -> upload -> complete. */
|
|
10
10
|
export async function runBackup(deps, opts) {
|
|
11
|
-
const detected = deps.discover();
|
|
11
|
+
const detected = opts.custom ? [opts.custom] : deps.discover();
|
|
12
12
|
if (detected.length === 0) {
|
|
13
13
|
deps.logger.error("No agents found on this machine.");
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
let targets = detected;
|
|
17
|
-
if (!opts.all && detected.length > 1) {
|
|
17
|
+
if (!opts.custom && !opts.all && detected.length > 1) {
|
|
18
18
|
const chosen = await deps.prompter.select("Which agent to back up?", detected.map((d) => ({ value: d.framework, label: d.name })));
|
|
19
19
|
targets = detected.filter((d) => d.framework === chosen);
|
|
20
20
|
}
|
|
@@ -42,7 +42,19 @@ export async function runBackup(deps, opts) {
|
|
|
42
42
|
deps.logger.success(`Backed up ${target.name}.`);
|
|
43
43
|
anySucceeded = true;
|
|
44
44
|
}
|
|
45
|
-
if (anySucceeded
|
|
46
|
-
|
|
45
|
+
if (anySucceeded) {
|
|
46
|
+
// The free plan keeps ONE rolling snapshot per wallet — completing a new
|
|
47
|
+
// backup replaced any earlier one (including other agents'). Say so.
|
|
48
|
+
try {
|
|
49
|
+
const usage = await deps.client.getUsage?.();
|
|
50
|
+
if (usage?.plan === "free") {
|
|
51
|
+
deps.logger.info("Free plan: the vault keeps only your latest snapshot (across all agents). Vault Pro ($3/mo) keeps full history — upgrade in the dashboard.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// usage is informational only
|
|
56
|
+
}
|
|
57
|
+
if (deps.offerDaemon)
|
|
58
|
+
await deps.offerDaemon();
|
|
47
59
|
}
|
|
48
60
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DetectedAgent } from "@singularity-layer/agentvault-core";
|
|
2
|
+
/**
|
|
3
|
+
* Server-side framework labels must match ^[a-z0-9-]{1,32}$ and are the
|
|
4
|
+
* find-or-create identity per wallet. Custom targets are ALWAYS prefixed
|
|
5
|
+
* `custom-` (a directory named "openclaw" can never merge with the real
|
|
6
|
+
* OpenClaw lineage) and carry a 6-hex hash of the CANONICAL PATH, so two
|
|
7
|
+
* different directories with colliding names ("~/a/bot" vs "~/b/bot",
|
|
8
|
+
* "foo_bar" vs "foo bar", truncation twins) get distinct lineages.
|
|
9
|
+
*/
|
|
10
|
+
export declare function slugifyFramework(name: string, canonicalPath: string): string;
|
|
11
|
+
export interface FsProbe {
|
|
12
|
+
exists: (p: string) => boolean;
|
|
13
|
+
isDir: (p: string) => boolean;
|
|
14
|
+
isSymlink: (p: string) => boolean;
|
|
15
|
+
realpath: (p: string) => string;
|
|
16
|
+
home: () => string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build a backup target for an arbitrary directory (`backup --path`).
|
|
20
|
+
* Universal by design: any harness's state directory becomes a vaultable
|
|
21
|
+
* agent. Refuses the obvious foot-guns (missing path, files, filesystem
|
|
22
|
+
* root, the entire home directory).
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildCustomTarget(path: string, name?: string, probe?: FsProbe): DetectedAgent;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, lstatSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, resolve } from "node:path";
|
|
5
|
+
// Junk that never belongs in a backup, whatever the harness.
|
|
6
|
+
const CUSTOM_EXCLUDES = [
|
|
7
|
+
"node_modules",
|
|
8
|
+
"__pycache__",
|
|
9
|
+
"**/*.log",
|
|
10
|
+
"tmp",
|
|
11
|
+
"cache",
|
|
12
|
+
".venv",
|
|
13
|
+
".git",
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Server-side framework labels must match ^[a-z0-9-]{1,32}$ and are the
|
|
17
|
+
* find-or-create identity per wallet. Custom targets are ALWAYS prefixed
|
|
18
|
+
* `custom-` (a directory named "openclaw" can never merge with the real
|
|
19
|
+
* OpenClaw lineage) and carry a 6-hex hash of the CANONICAL PATH, so two
|
|
20
|
+
* different directories with colliding names ("~/a/bot" vs "~/b/bot",
|
|
21
|
+
* "foo_bar" vs "foo bar", truncation twins) get distinct lineages.
|
|
22
|
+
*/
|
|
23
|
+
export function slugifyFramework(name, canonicalPath) {
|
|
24
|
+
const slug = name
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
27
|
+
.replace(/-+/g, "-")
|
|
28
|
+
.replace(/^-|-$/g, "");
|
|
29
|
+
if (!slug) {
|
|
30
|
+
throw new Error(`cannot derive a framework label from "${name}" — pass --name with letters or digits`);
|
|
31
|
+
}
|
|
32
|
+
const hash = createHash("sha256").update(canonicalPath).digest("hex").slice(0, 6);
|
|
33
|
+
// custom-(7) + slug(≤18) + -(1) + hash(6) = ≤32
|
|
34
|
+
const head = `custom-${slug}`.slice(0, 25).replace(/-$/, "");
|
|
35
|
+
return `${head}-${hash}`;
|
|
36
|
+
}
|
|
37
|
+
const realProbe = {
|
|
38
|
+
exists: (p) => existsSync(p),
|
|
39
|
+
isDir: (p) => {
|
|
40
|
+
try {
|
|
41
|
+
return statSync(p).isDirectory();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
isSymlink: (p) => {
|
|
48
|
+
try {
|
|
49
|
+
return lstatSync(p).isSymbolicLink();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
realpath: (p) => realpathSync(p),
|
|
56
|
+
home: () => homedir(),
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Build a backup target for an arbitrary directory (`backup --path`).
|
|
60
|
+
* Universal by design: any harness's state directory becomes a vaultable
|
|
61
|
+
* agent. Refuses the obvious foot-guns (missing path, files, filesystem
|
|
62
|
+
* root, the entire home directory).
|
|
63
|
+
*/
|
|
64
|
+
export function buildCustomTarget(path, name, probe = realProbe) {
|
|
65
|
+
const abs = resolve(path);
|
|
66
|
+
if (!probe.exists(abs)) {
|
|
67
|
+
throw new Error(`path does not exist: ${abs}`);
|
|
68
|
+
}
|
|
69
|
+
// A symlinked ROOT would be copied as a link and silently restore nothing —
|
|
70
|
+
// require the real directory (the packager preserves inner symlinks as-is,
|
|
71
|
+
// and restore skips them by policy).
|
|
72
|
+
if (probe.isSymlink(abs)) {
|
|
73
|
+
throw new Error(`--path is a symlink — point it at the real directory: ${probe.realpath(abs)}`);
|
|
74
|
+
}
|
|
75
|
+
if (!probe.isDir(abs)) {
|
|
76
|
+
throw new Error(`--path must be a directory: ${abs}`);
|
|
77
|
+
}
|
|
78
|
+
const canonical = probe.realpath(abs);
|
|
79
|
+
let canonicalHome;
|
|
80
|
+
try {
|
|
81
|
+
canonicalHome = probe.realpath(resolve(probe.home()));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
canonicalHome = resolve(probe.home());
|
|
85
|
+
}
|
|
86
|
+
if (canonical === "/" || canonical === canonicalHome) {
|
|
87
|
+
throw new Error("refusing to back up the filesystem root or your entire home directory — point --path at the agent's own folder");
|
|
88
|
+
}
|
|
89
|
+
const displayName = (name ?? basename(abs)).trim();
|
|
90
|
+
if (!displayName) {
|
|
91
|
+
throw new Error("agent name is empty — pass --name");
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
name: displayName,
|
|
95
|
+
framework: slugifyFramework(displayName, canonical),
|
|
96
|
+
paths: [abs],
|
|
97
|
+
exclude: [...CUSTOM_EXCLUDES],
|
|
98
|
+
version: null,
|
|
99
|
+
};
|
|
100
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { openBrowser } from "./deps.js";
|
|
|
14
14
|
import { keychainPassphraseOrThrow, runPassphraseClear, runPassphraseSet, } from "./commands/passphrase.js";
|
|
15
15
|
import { runRestore } from "./commands/restore.js";
|
|
16
16
|
import { createConfigStore } from "./config.js";
|
|
17
|
+
import { buildCustomTarget } from "./customTarget.js";
|
|
17
18
|
import { authedClient, downloadBlob, homedir, realCore, realDaemonFs, realExec, realIo, resolveBinPath, } from "./deps.js";
|
|
18
19
|
import { createKeychain } from "./keychain.js";
|
|
19
20
|
export function buildProgram() {
|
|
@@ -54,10 +55,35 @@ export function buildProgram() {
|
|
|
54
55
|
});
|
|
55
56
|
program
|
|
56
57
|
.command("backup")
|
|
57
|
-
.description("Back up local agents")
|
|
58
|
+
.description("Back up local agents (or ANY directory via --path)")
|
|
58
59
|
.option("--all", "back up all detected agents", false)
|
|
60
|
+
.option("--path <dir>", "back up this directory as an agent (universal mode)")
|
|
61
|
+
.option("--name <name>", "display name for --path (defaults to the folder name)")
|
|
59
62
|
.option("--non-interactive", "use the stored passphrase (no prompts)", false)
|
|
60
63
|
.action(async (opts) => {
|
|
64
|
+
// Validate flags BEFORE auth so a bad invocation gets the right error
|
|
65
|
+
// even when logged out.
|
|
66
|
+
let custom;
|
|
67
|
+
if (opts.path) {
|
|
68
|
+
if (opts.all) {
|
|
69
|
+
realIo.logger.error("--all and --path are mutually exclusive — pick one");
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
custom = buildCustomTarget(String(opts.path), opts.name ? String(opts.name) : undefined);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
realIo.logger.error(e instanceof Error ? e.message : String(e));
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (opts.name) {
|
|
83
|
+
realIo.logger.error("--name only makes sense together with --path");
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
61
87
|
const { client } = authedClient();
|
|
62
88
|
const keychain = createKeychain();
|
|
63
89
|
const nonInteractive = Boolean(opts.nonInteractive);
|
|
@@ -83,7 +109,7 @@ export function buildProgram() {
|
|
|
83
109
|
prompter: realIo.prompter,
|
|
84
110
|
nonInteractive,
|
|
85
111
|
}),
|
|
86
|
-
}, { all: Boolean(opts.all) || nonInteractive });
|
|
112
|
+
}, { all: Boolean(opts.all) || nonInteractive, custom });
|
|
87
113
|
});
|
|
88
114
|
program
|
|
89
115
|
.command("restore")
|