@singularity-layer/agentvault 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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.js +68 -0
- package/dist/commands/backup.d.ts +25 -0
- package/dist/commands/backup.js +48 -0
- package/dist/commands/daemon.d.ts +37 -0
- package/dist/commands/daemon.js +95 -0
- package/dist/commands/list.d.ts +8 -0
- package/dist/commands/list.js +12 -0
- package/dist/commands/login.d.ts +32 -0
- package/dist/commands/login.js +43 -0
- package/dist/commands/logout.d.ts +8 -0
- package/dist/commands/logout.js +5 -0
- package/dist/commands/passphrase.d.ts +17 -0
- package/dist/commands/passphrase.js +20 -0
- package/dist/commands/restore.d.ts +15 -0
- package/dist/commands/restore.js +20 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +46 -0
- package/dist/daemon/descriptors.d.ts +15 -0
- package/dist/daemon/descriptors.js +52 -0
- package/dist/deps.d.ts +39 -0
- package/dist/deps.js +104 -0
- package/dist/deviceAuth.d.ts +23 -0
- package/dist/deviceAuth.js +42 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +164 -0
- package/dist/io.d.ts +32 -0
- package/dist/io.js +76 -0
- package/dist/keychain.d.ts +20 -0
- package/dist/keychain.js +135 -0
- package/dist/r2key.d.ts +6 -0
- package/dist/r2key.js +16 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Singularity Layer / EventHorizon Labs
|
|
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,58 @@
|
|
|
1
|
+
# Agent Vault
|
|
2
|
+
|
|
3
|
+
**Zero-knowledge encrypted backup, restore, and migration for AI agents.**
|
|
4
|
+
|
|
5
|
+
Snapshot an agent's entire self — memory, soul, config, skills — and bring it
|
|
6
|
+
back anywhere: a new machine, a fresh [Agent Pod](https://cloud.x402compute.cc/network/pods),
|
|
7
|
+
or the same box after a bad day.
|
|
8
|
+
|
|
9
|
+
Supports **OpenClaw** (`~/.openclaw`) and **Hermes** (`~/.hermes`).
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i -g @singularity-layer/agentvault
|
|
15
|
+
|
|
16
|
+
agentvault login # opens your browser — connect wallet, approve, done
|
|
17
|
+
agentvault backup --all # encrypt + upload every detected agent
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Restore on any machine:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
agentvault login
|
|
24
|
+
agentvault restore # pick a snapshot, enter your passphrase
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Zero-knowledge, for real
|
|
28
|
+
|
|
29
|
+
Every backup is sealed on **your** machine with AES-256-GCM under a key derived
|
|
30
|
+
from **your** passphrase (scrypt). The vault stores ciphertext it cannot read.
|
|
31
|
+
|
|
32
|
+
That cuts both ways: **a lost passphrase cannot be recovered — not even by us.**
|
|
33
|
+
Write it down.
|
|
34
|
+
|
|
35
|
+
## Commands
|
|
36
|
+
|
|
37
|
+
| Command | What it does |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `agentvault login` | Browser wallet sign-in (`--api-key` to paste a key instead) |
|
|
40
|
+
| `agentvault backup [--all]` | Encrypt + upload detected agents |
|
|
41
|
+
| `agentvault restore [--dest <dir>]` | Download, decrypt, safely unpack a snapshot |
|
|
42
|
+
| `agentvault list` | Agents and snapshot counts |
|
|
43
|
+
| `agentvault passphrase set\|clear` | Store the passphrase in the OS keychain (for scheduled backups) |
|
|
44
|
+
| `agentvault daemon install [--frequency weekly\|daily]` | Automatic backups (launchd/systemd) |
|
|
45
|
+
|
|
46
|
+
## Pricing
|
|
47
|
+
|
|
48
|
+
Storage is metered at **$0.15 per GiB-month**, pro-rated daily from your
|
|
49
|
+
[Singularity Layer credits](https://cloud.x402compute.cc/network/settings/credits).
|
|
50
|
+
A typical agent snapshot is a few MB — fractions of a cent per month.
|
|
51
|
+
Your data is never deleted for non-payment; new backups just pause.
|
|
52
|
+
|
|
53
|
+
## Dashboard
|
|
54
|
+
|
|
55
|
+
Manage everything at [cloud.x402compute.cc/network/backups](https://cloud.x402compute.cc/network/backups) —
|
|
56
|
+
usage, snapshots, one-click pod backups, and cross-machine migration.
|
|
57
|
+
|
|
58
|
+
MIT © Singularity Layer
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
export interface AgentRecord {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
framework: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BackupRecord {
|
|
8
|
+
id: string;
|
|
9
|
+
agent_id: string;
|
|
10
|
+
size_bytes: number;
|
|
11
|
+
sha256: string | null;
|
|
12
|
+
created_at: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RequestBackupResult {
|
|
15
|
+
backupId: string;
|
|
16
|
+
r2Key: string;
|
|
17
|
+
uploadUrl: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ApiClient {
|
|
20
|
+
/** Cheap authenticated call — login uses it to verify an API key works. */
|
|
21
|
+
verifyKey(): Promise<void>;
|
|
22
|
+
listAgents(): Promise<AgentRecord[]>;
|
|
23
|
+
createAgent(name: string, framework: string): Promise<AgentRecord>;
|
|
24
|
+
requestBackup(agentId: string, sizeBytes: number): Promise<RequestBackupResult>;
|
|
25
|
+
completeBackup(backupId: string, sha256: string): Promise<void>;
|
|
26
|
+
listBackups(agentId?: string): Promise<BackupRecord[]>;
|
|
27
|
+
getRestoreUrl(backupId: string): Promise<{
|
|
28
|
+
downloadUrl: string;
|
|
29
|
+
r2Key: string;
|
|
30
|
+
}>;
|
|
31
|
+
deleteBackup(backupId: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Auth is a Singularity compute API key (dashboard → Settings → API Keys),
|
|
35
|
+
* sent as X-API-Key. Routes live under /backups on the compute worker.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createClient(baseUrl: string, token: string | null, fetchImpl?: FetchLike): ApiClient;
|
|
38
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth is a Singularity compute API key (dashboard → Settings → API Keys),
|
|
3
|
+
* sent as X-API-Key. Routes live under /backups on the compute worker.
|
|
4
|
+
*/
|
|
5
|
+
export function createClient(baseUrl, token, fetchImpl = fetch) {
|
|
6
|
+
async function call(path, init = {}) {
|
|
7
|
+
const headers = {
|
|
8
|
+
...init.headers,
|
|
9
|
+
};
|
|
10
|
+
if (init.body)
|
|
11
|
+
headers["content-type"] = "application/json";
|
|
12
|
+
if (token)
|
|
13
|
+
headers["x-api-key"] = token;
|
|
14
|
+
const res = await fetchImpl(`${baseUrl}${path}`, { ...init, headers });
|
|
15
|
+
const text = await res.text();
|
|
16
|
+
let data = {};
|
|
17
|
+
if (text) {
|
|
18
|
+
try {
|
|
19
|
+
data = JSON.parse(text);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error(`invalid response from server (status ${res.status})`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!res.ok)
|
|
26
|
+
throw new Error(data.error ?? `request failed: ${res.status}`);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
async verifyKey() {
|
|
31
|
+
await call("/backups/agents");
|
|
32
|
+
},
|
|
33
|
+
async listAgents() {
|
|
34
|
+
const { agents } = await call("/backups/agents");
|
|
35
|
+
return agents;
|
|
36
|
+
},
|
|
37
|
+
async createAgent(name, framework) {
|
|
38
|
+
const { agent } = await call("/backups/agents", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: JSON.stringify({ name, framework }),
|
|
41
|
+
});
|
|
42
|
+
return agent;
|
|
43
|
+
},
|
|
44
|
+
async requestBackup(agentId, sizeBytes) {
|
|
45
|
+
return call("/backups", {
|
|
46
|
+
method: "POST",
|
|
47
|
+
body: JSON.stringify({ agentId, sizeBytes }),
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
async completeBackup(backupId, sha256) {
|
|
51
|
+
await call(`/backups/${backupId}/complete`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
body: JSON.stringify({ sha256 }),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async listBackups(agentId) {
|
|
57
|
+
const q = agentId ? `?agentId=${encodeURIComponent(agentId)}` : "";
|
|
58
|
+
const { backups } = await call(`/backups${q}`);
|
|
59
|
+
return backups;
|
|
60
|
+
},
|
|
61
|
+
async getRestoreUrl(backupId) {
|
|
62
|
+
return call(`/backups/${backupId}/restore`);
|
|
63
|
+
},
|
|
64
|
+
async deleteBackup(backupId) {
|
|
65
|
+
await call(`/backups/${backupId}`, { method: "DELETE" });
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Aad, BackupResult, DetectedAgent, Manifest } from "@singularity-layer/agentvault-core";
|
|
2
|
+
import type { ApiClient } from "../client.js";
|
|
3
|
+
import type { Logger, Prompter } from "../io.js";
|
|
4
|
+
export interface BackupDeps {
|
|
5
|
+
client: ApiClient;
|
|
6
|
+
discover: () => DetectedAgent[];
|
|
7
|
+
packAgent: (input: {
|
|
8
|
+
paths: string[];
|
|
9
|
+
exclude: string[];
|
|
10
|
+
manifest: Manifest;
|
|
11
|
+
}) => Promise<Buffer>;
|
|
12
|
+
encrypt: (tarball: Buffer, passphrase: string, aad: Aad) => Promise<Buffer>;
|
|
13
|
+
uploadBlob: (blob: Buffer, url: string) => Promise<BackupResult>;
|
|
14
|
+
/** Resolve the backup passphrase (interactive prompt or keychain). */
|
|
15
|
+
resolvePassphrase: () => Promise<string>;
|
|
16
|
+
prompter: Prompter;
|
|
17
|
+
logger: Logger;
|
|
18
|
+
/** Optional: invoked once after a successful backup to offer daemon install. */
|
|
19
|
+
offerDaemon?: () => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface BackupOptions {
|
|
22
|
+
all: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Discover agents, choose, then back each up: pack -> reserve -> encrypt -> upload -> complete. */
|
|
25
|
+
export declare function runBackup(deps: BackupDeps, opts: BackupOptions): Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { parseAad } from "../r2key.js";
|
|
2
|
+
async function ensureAgent(client, detected) {
|
|
3
|
+
const remote = await client.listAgents();
|
|
4
|
+
const match = remote.find((a) => a.framework === detected.framework);
|
|
5
|
+
if (match)
|
|
6
|
+
return match;
|
|
7
|
+
return client.createAgent(detected.name, detected.framework);
|
|
8
|
+
}
|
|
9
|
+
/** Discover agents, choose, then back each up: pack -> reserve -> encrypt -> upload -> complete. */
|
|
10
|
+
export async function runBackup(deps, opts) {
|
|
11
|
+
const detected = deps.discover();
|
|
12
|
+
if (detected.length === 0) {
|
|
13
|
+
deps.logger.error("No agents found on this machine.");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
let targets = detected;
|
|
17
|
+
if (!opts.all && detected.length > 1) {
|
|
18
|
+
const chosen = await deps.prompter.select("Which agent to back up?", detected.map((d) => ({ value: d.framework, label: d.name })));
|
|
19
|
+
targets = detected.filter((d) => d.framework === chosen);
|
|
20
|
+
}
|
|
21
|
+
const passphrase = await deps.resolvePassphrase();
|
|
22
|
+
let anySucceeded = false;
|
|
23
|
+
for (const target of targets) {
|
|
24
|
+
const agent = await ensureAgent(deps.client, target);
|
|
25
|
+
const manifest = {
|
|
26
|
+
agentName: target.name,
|
|
27
|
+
framework: target.framework,
|
|
28
|
+
frameworkVersion: target.version,
|
|
29
|
+
createdAt: new Date().toISOString(),
|
|
30
|
+
formatVersion: 1,
|
|
31
|
+
};
|
|
32
|
+
const tarball = await deps.packAgent({
|
|
33
|
+
paths: target.paths,
|
|
34
|
+
exclude: target.exclude,
|
|
35
|
+
manifest,
|
|
36
|
+
});
|
|
37
|
+
const { backupId, r2Key, uploadUrl } = await deps.client.requestBackup(agent.id, tarball.length);
|
|
38
|
+
const aad = parseAad(r2Key);
|
|
39
|
+
const blob = await deps.encrypt(tarball, passphrase, aad);
|
|
40
|
+
const { sha256 } = await deps.uploadBlob(blob, uploadUrl);
|
|
41
|
+
await deps.client.completeBackup(backupId, sha256);
|
|
42
|
+
deps.logger.success(`Backed up ${target.name}.`);
|
|
43
|
+
anySucceeded = true;
|
|
44
|
+
}
|
|
45
|
+
if (anySucceeded && deps.offerDaemon) {
|
|
46
|
+
await deps.offerDaemon();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Frequency } from "../daemon/descriptors.js";
|
|
2
|
+
import type { Logger, Prompter } from "../io.js";
|
|
3
|
+
export interface DaemonFs {
|
|
4
|
+
writeFile(path: string, content: string): void;
|
|
5
|
+
removeFile(path: string): void;
|
|
6
|
+
exists(path: string): boolean;
|
|
7
|
+
}
|
|
8
|
+
export type DaemonExec = (cmd: string, args: string[]) => Promise<{
|
|
9
|
+
code: number;
|
|
10
|
+
stdout: string;
|
|
11
|
+
}>;
|
|
12
|
+
export interface DaemonDeps {
|
|
13
|
+
platform: NodeJS.Platform;
|
|
14
|
+
home: string;
|
|
15
|
+
binPath: string;
|
|
16
|
+
fs: DaemonFs;
|
|
17
|
+
exec: DaemonExec;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
}
|
|
20
|
+
export interface DaemonInstallOptions {
|
|
21
|
+
frequency: Frequency;
|
|
22
|
+
}
|
|
23
|
+
/** Install the scheduled backup daemon for the current platform. */
|
|
24
|
+
export declare function runDaemonInstall(deps: DaemonDeps, opts: DaemonInstallOptions): Promise<void>;
|
|
25
|
+
/** Remove the scheduled backup daemon. */
|
|
26
|
+
export declare function runDaemonUninstall(deps: DaemonDeps): Promise<void>;
|
|
27
|
+
export interface OfferDaemonDeps extends DaemonDeps {
|
|
28
|
+
prompter: Prompter;
|
|
29
|
+
nonInteractive: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* After a backup, offer to install automatic backups — unless running
|
|
33
|
+
* non-interactively or already installed. Installs weekly if the user accepts.
|
|
34
|
+
*/
|
|
35
|
+
export declare function runOfferDaemon(deps: OfferDaemonDeps): Promise<void>;
|
|
36
|
+
/** Report whether the daemon is installed. */
|
|
37
|
+
export declare function runDaemonStatus(deps: DaemonDeps): Promise<void>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { LABEL, launchdPlist, systemdService, systemdTimer, } from "../daemon/descriptors.js";
|
|
3
|
+
function darwinPlistPath(home) {
|
|
4
|
+
return join(home, "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
5
|
+
}
|
|
6
|
+
function linuxServicePath(home) {
|
|
7
|
+
return join(home, ".config", "systemd", "user", "agentvault.service");
|
|
8
|
+
}
|
|
9
|
+
function linuxTimerPath(home) {
|
|
10
|
+
return join(home, ".config", "systemd", "user", "agentvault.timer");
|
|
11
|
+
}
|
|
12
|
+
/** Install the scheduled backup daemon for the current platform. */
|
|
13
|
+
export async function runDaemonInstall(deps, opts) {
|
|
14
|
+
if (deps.platform === "darwin") {
|
|
15
|
+
const path = darwinPlistPath(deps.home);
|
|
16
|
+
deps.fs.writeFile(path, launchdPlist({ binPath: deps.binPath, frequency: opts.frequency }));
|
|
17
|
+
const load = await deps.exec("launchctl", ["load", path]);
|
|
18
|
+
if (load.code !== 0) {
|
|
19
|
+
deps.fs.removeFile(path);
|
|
20
|
+
throw new Error("launchctl load failed - automatic backups are NOT installed");
|
|
21
|
+
}
|
|
22
|
+
deps.logger.success(`Automatic ${opts.frequency} backups installed.`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (deps.platform === "linux") {
|
|
26
|
+
deps.fs.writeFile(linuxServicePath(deps.home), systemdService({ binPath: deps.binPath }));
|
|
27
|
+
deps.fs.writeFile(linuxTimerPath(deps.home), systemdTimer(opts.frequency));
|
|
28
|
+
const enable = await deps.exec("systemctl", [
|
|
29
|
+
"--user",
|
|
30
|
+
"enable",
|
|
31
|
+
"--now",
|
|
32
|
+
"agentvault.timer",
|
|
33
|
+
]);
|
|
34
|
+
if (enable.code !== 0) {
|
|
35
|
+
throw new Error("systemctl enable failed (no user systemd session?) - automatic backups are NOT installed");
|
|
36
|
+
}
|
|
37
|
+
deps.logger.success(`Automatic ${opts.frequency} backups installed.`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
deps.logger.error(`Automatic backups are not supported on ${deps.platform} yet.`);
|
|
41
|
+
}
|
|
42
|
+
/** Remove the scheduled backup daemon. */
|
|
43
|
+
export async function runDaemonUninstall(deps) {
|
|
44
|
+
if (deps.platform === "darwin") {
|
|
45
|
+
const path = darwinPlistPath(deps.home);
|
|
46
|
+
const unload = await deps.exec("launchctl", ["unload", path]);
|
|
47
|
+
if (unload.code !== 0 && deps.fs.exists(path)) {
|
|
48
|
+
deps.logger.info("launchctl unload reported an error; removing the plist anyway.");
|
|
49
|
+
}
|
|
50
|
+
if (deps.fs.exists(path))
|
|
51
|
+
deps.fs.removeFile(path);
|
|
52
|
+
deps.logger.success("Automatic backups removed.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (deps.platform === "linux") {
|
|
56
|
+
await deps.exec("systemctl", [
|
|
57
|
+
"--user",
|
|
58
|
+
"disable",
|
|
59
|
+
"--now",
|
|
60
|
+
"agentvault.timer",
|
|
61
|
+
]);
|
|
62
|
+
for (const p of [linuxServicePath(deps.home), linuxTimerPath(deps.home)]) {
|
|
63
|
+
if (deps.fs.exists(p))
|
|
64
|
+
deps.fs.removeFile(p);
|
|
65
|
+
}
|
|
66
|
+
deps.logger.success("Automatic backups removed.");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
deps.logger.error(`Automatic backups are not supported on ${deps.platform} yet.`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* After a backup, offer to install automatic backups — unless running
|
|
73
|
+
* non-interactively or already installed. Installs weekly if the user accepts.
|
|
74
|
+
*/
|
|
75
|
+
export async function runOfferDaemon(deps) {
|
|
76
|
+
if (deps.nonInteractive)
|
|
77
|
+
return;
|
|
78
|
+
const path = deps.platform === "darwin"
|
|
79
|
+
? darwinPlistPath(deps.home)
|
|
80
|
+
: linuxTimerPath(deps.home);
|
|
81
|
+
if (deps.fs.exists(path))
|
|
82
|
+
return; // already installed
|
|
83
|
+
const yes = await deps.prompter.confirm("Set up automatic weekly backups?");
|
|
84
|
+
if (yes)
|
|
85
|
+
await runDaemonInstall(deps, { frequency: "weekly" });
|
|
86
|
+
}
|
|
87
|
+
/** Report whether the daemon is installed. */
|
|
88
|
+
export async function runDaemonStatus(deps) {
|
|
89
|
+
const path = deps.platform === "darwin"
|
|
90
|
+
? darwinPlistPath(deps.home)
|
|
91
|
+
: linuxTimerPath(deps.home);
|
|
92
|
+
deps.logger.info(deps.fs.exists(path)
|
|
93
|
+
? "Automatic backups: installed."
|
|
94
|
+
: "Automatic backups: not installed.");
|
|
95
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiClient } from "../client.js";
|
|
2
|
+
import type { Logger } from "../io.js";
|
|
3
|
+
export interface ListDeps {
|
|
4
|
+
client: ApiClient;
|
|
5
|
+
logger: Logger;
|
|
6
|
+
}
|
|
7
|
+
/** Print each registered agent and how many backups it has. */
|
|
8
|
+
export declare function runList(deps: ListDeps): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Print each registered agent and how many backups it has. */
|
|
2
|
+
export async function runList(deps) {
|
|
3
|
+
const agents = await deps.client.listAgents();
|
|
4
|
+
if (agents.length === 0) {
|
|
5
|
+
deps.logger.info("No agents registered yet.");
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
for (const agent of agents) {
|
|
9
|
+
const backups = await deps.client.listBackups(agent.id);
|
|
10
|
+
deps.logger.info(`${agent.name} [${agent.framework}] — ${backups.length} backup(s)`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ConfigStore } from "../config.js";
|
|
2
|
+
import type { DeviceAuthClient } from "../deviceAuth.js";
|
|
3
|
+
import type { Logger, Prompter } from "../io.js";
|
|
4
|
+
export interface LoginDeps {
|
|
5
|
+
/** Verifies the candidate key against the backend (throws if invalid). */
|
|
6
|
+
verify: (apiKey: string) => Promise<void>;
|
|
7
|
+
store: ConfigStore;
|
|
8
|
+
prompter: Prompter;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}
|
|
11
|
+
export interface BrowserLoginDeps {
|
|
12
|
+
device: DeviceAuthClient;
|
|
13
|
+
verify: (apiKey: string) => Promise<void>;
|
|
14
|
+
store: ConfigStore;
|
|
15
|
+
logger: Logger;
|
|
16
|
+
/** Best-effort: open the approval page in the user's browser. */
|
|
17
|
+
openUrl: (url: string) => void;
|
|
18
|
+
sleep?: (ms: number) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Default sign-in: browser device flow (connect wallet → approve → done).
|
|
22
|
+
* The orchestrator mints a compute API key and delivers it to the poll
|
|
23
|
+
* exactly once; we verify it against the backend before saving, same as the
|
|
24
|
+
* paste path.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runBrowserLogin(deps: BrowserLoginDeps): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Manual sign-in (`login --api-key`): paste a Singularity compute API key.
|
|
29
|
+
* The key is verified with one cheap authenticated call BEFORE it is saved,
|
|
30
|
+
* so a typo fails here instead of on the first backup.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runLogin(deps: LoginDeps): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default sign-in: browser device flow (connect wallet → approve → done).
|
|
3
|
+
* The orchestrator mints a compute API key and delivers it to the poll
|
|
4
|
+
* exactly once; we verify it against the backend before saving, same as the
|
|
5
|
+
* paste path.
|
|
6
|
+
*/
|
|
7
|
+
export async function runBrowserLogin(deps) {
|
|
8
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
9
|
+
const session = await deps.device.start("agentvault CLI");
|
|
10
|
+
deps.logger.info(`Open this page to approve: ${session.verifyUrl}`);
|
|
11
|
+
deps.logger.info(`Confirmation code: ${session.userCode}`);
|
|
12
|
+
deps.openUrl(session.verifyUrl);
|
|
13
|
+
const deadline = Date.now() + session.expiresInSeconds * 1000;
|
|
14
|
+
while (Date.now() < deadline) {
|
|
15
|
+
await sleep(session.intervalSeconds * 1000);
|
|
16
|
+
const res = await deps.device.poll(session.deviceCode);
|
|
17
|
+
if (res.status === "pending")
|
|
18
|
+
continue;
|
|
19
|
+
if (res.status === "expired")
|
|
20
|
+
break;
|
|
21
|
+
await deps.verify(res.apiKey);
|
|
22
|
+
const cfg = deps.store.load();
|
|
23
|
+
deps.store.save({ apiUrl: cfg.apiUrl, token: res.apiKey });
|
|
24
|
+
deps.logger.success("Logged in.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Sign-in was not approved in time. Run `agentvault login` to try again, or `agentvault login --api-key` to paste a key instead.");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Manual sign-in (`login --api-key`): paste a Singularity compute API key.
|
|
31
|
+
* The key is verified with one cheap authenticated call BEFORE it is saved,
|
|
32
|
+
* so a typo fails here instead of on the first backup.
|
|
33
|
+
*/
|
|
34
|
+
export async function runLogin(deps) {
|
|
35
|
+
deps.logger.info("Create an API key in Singularity Cloud: Settings -> API Keys.");
|
|
36
|
+
const key = (await deps.prompter.password("Paste your API key")).trim();
|
|
37
|
+
if (!key)
|
|
38
|
+
throw new Error("no API key entered");
|
|
39
|
+
await deps.verify(key);
|
|
40
|
+
const cfg = deps.store.load();
|
|
41
|
+
deps.store.save({ apiUrl: cfg.apiUrl, token: key });
|
|
42
|
+
deps.logger.success("Logged in.");
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ConfigStore } from "../config.js";
|
|
2
|
+
import type { Logger } from "../io.js";
|
|
3
|
+
export interface LogoutDeps {
|
|
4
|
+
store: ConfigStore;
|
|
5
|
+
logger: Logger;
|
|
6
|
+
}
|
|
7
|
+
/** Clear the stored device token. */
|
|
8
|
+
export declare function runLogout(deps: LogoutDeps): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Logger, Prompter } from "../io.js";
|
|
2
|
+
import type { Keychain } from "../keychain.js";
|
|
3
|
+
export interface PassphraseSetDeps {
|
|
4
|
+
keychain: Keychain;
|
|
5
|
+
prompter: Prompter;
|
|
6
|
+
logger: Logger;
|
|
7
|
+
}
|
|
8
|
+
export interface PassphraseClearDeps {
|
|
9
|
+
keychain: Keychain;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
}
|
|
12
|
+
/** Prompt for a passphrase and store it in the OS keychain for non-interactive backups. */
|
|
13
|
+
export declare function runPassphraseSet(deps: PassphraseSetDeps): Promise<void>;
|
|
14
|
+
/** Remove the stored passphrase from the OS keychain. */
|
|
15
|
+
export declare function runPassphraseClear(deps: PassphraseClearDeps): Promise<void>;
|
|
16
|
+
/** Read the stored passphrase or throw a clear, actionable error. */
|
|
17
|
+
export declare function keychainPassphraseOrThrow(keychain: Keychain): Promise<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PASSPHRASE_ACCOUNT } from "../keychain.js";
|
|
2
|
+
/** Prompt for a passphrase and store it in the OS keychain for non-interactive backups. */
|
|
3
|
+
export async function runPassphraseSet(deps) {
|
|
4
|
+
const value = await deps.prompter.password("Passphrase to store for automatic backups");
|
|
5
|
+
await deps.keychain.set(PASSPHRASE_ACCOUNT, value);
|
|
6
|
+
deps.logger.success("Passphrase saved to the OS keychain (used for automatic + agent-triggered backups).");
|
|
7
|
+
}
|
|
8
|
+
/** Remove the stored passphrase from the OS keychain. */
|
|
9
|
+
export async function runPassphraseClear(deps) {
|
|
10
|
+
await deps.keychain.delete(PASSPHRASE_ACCOUNT);
|
|
11
|
+
deps.logger.success("Stored passphrase cleared.");
|
|
12
|
+
}
|
|
13
|
+
/** Read the stored passphrase or throw a clear, actionable error. */
|
|
14
|
+
export async function keychainPassphraseOrThrow(keychain) {
|
|
15
|
+
const value = await keychain.get(PASSPHRASE_ACCOUNT);
|
|
16
|
+
if (!value) {
|
|
17
|
+
throw new Error("No stored passphrase. Run `agentvault passphrase set` first to enable non-interactive backups.");
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Aad } from "@singularity-layer/agentvault-core";
|
|
2
|
+
import type { ApiClient } from "../client.js";
|
|
3
|
+
import type { Logger, Prompter } from "../io.js";
|
|
4
|
+
export interface RestoreDeps {
|
|
5
|
+
client: ApiClient;
|
|
6
|
+
downloadBlob: (url: string) => Promise<Buffer>;
|
|
7
|
+
restoreBlob: (blob: Buffer, passphrase: string, aad: Aad, destDir: string) => Promise<void>;
|
|
8
|
+
prompter: Prompter;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}
|
|
11
|
+
export interface RestoreOptions {
|
|
12
|
+
dest: string;
|
|
13
|
+
}
|
|
14
|
+
/** List backups, let the user pick one, download + decrypt + unpack to dest. */
|
|
15
|
+
export declare function runRestore(deps: RestoreDeps, opts: RestoreOptions): Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parseAad } from "../r2key.js";
|
|
2
|
+
/** List backups, let the user pick one, download + decrypt + unpack to dest. */
|
|
3
|
+
export async function runRestore(deps, opts) {
|
|
4
|
+
const backups = await deps.client.listBackups();
|
|
5
|
+
if (backups.length === 0) {
|
|
6
|
+
deps.logger.error("No backups available to restore.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const backupId = backups.length === 1
|
|
10
|
+
? backups[0].id
|
|
11
|
+
: await deps.prompter.select("Which backup to restore?", backups.map((b) => ({
|
|
12
|
+
value: b.id,
|
|
13
|
+
label: `${b.id} (${b.created_at})`,
|
|
14
|
+
})));
|
|
15
|
+
const passphrase = await deps.prompter.password("Backup passphrase");
|
|
16
|
+
const { downloadUrl, r2Key } = await deps.client.getRestoreUrl(backupId);
|
|
17
|
+
const blob = await deps.downloadBlob(downloadUrl);
|
|
18
|
+
await deps.restoreBlob(blob, passphrase, parseAad(r2Key), opts.dest);
|
|
19
|
+
deps.logger.success(`Restored to ${opts.dest}.`);
|
|
20
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CliConfig {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
token: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface ConfigStore {
|
|
6
|
+
load(): CliConfig;
|
|
7
|
+
save(config: CliConfig): void;
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
10
|
+
/** Resolve the config home: explicit arg > AGENTVAULT_HOME env > ~/.agentvault. */
|
|
11
|
+
export declare function resolveHome(explicit?: string): string;
|
|
12
|
+
export declare function createConfigStore(explicitHome?: string): ConfigStore;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
const DEFAULT_API_URL = "https://compute.x402layer.cc";
|
|
5
|
+
/** Resolve the config home: explicit arg > AGENTVAULT_HOME env > ~/.agentvault. */
|
|
6
|
+
export function resolveHome(explicit) {
|
|
7
|
+
return (explicit ?? process.env.AGENTVAULT_HOME ?? join(homedir(), ".agentvault"));
|
|
8
|
+
}
|
|
9
|
+
export function createConfigStore(explicitHome) {
|
|
10
|
+
const home = resolveHome(explicitHome);
|
|
11
|
+
const file = join(home, "config.json");
|
|
12
|
+
return {
|
|
13
|
+
load() {
|
|
14
|
+
if (!existsSync(file))
|
|
15
|
+
return { apiUrl: DEFAULT_API_URL, token: null };
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
18
|
+
return {
|
|
19
|
+
apiUrl: parsed.apiUrl ?? DEFAULT_API_URL,
|
|
20
|
+
token: parsed.token ?? null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return { apiUrl: DEFAULT_API_URL, token: null };
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
save(config) {
|
|
28
|
+
// The config holds the API key — owner-only on dir and file. The mode
|
|
29
|
+
// options only apply on CREATION, so repair pre-existing permissive
|
|
30
|
+
// paths explicitly.
|
|
31
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
32
|
+
writeFileSync(file, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
33
|
+
try {
|
|
34
|
+
chmodSync(home, 0o700);
|
|
35
|
+
chmodSync(file, 0o600);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// chmod can fail on exotic filesystems; the write itself succeeded.
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
clear() {
|
|
42
|
+
const current = this.load();
|
|
43
|
+
this.save({ apiUrl: current.apiUrl, token: null });
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const LABEL = "com.agentvault.backup";
|
|
2
|
+
export type Frequency = "weekly" | "daily";
|
|
3
|
+
export interface LaunchdOptions {
|
|
4
|
+
binPath: string;
|
|
5
|
+
frequency: Frequency;
|
|
6
|
+
}
|
|
7
|
+
/** Generate a launchd plist that runs `agentvault backup --all --non-interactive` on schedule. */
|
|
8
|
+
export declare function launchdPlist(opts: LaunchdOptions): string;
|
|
9
|
+
export interface SystemdServiceOptions {
|
|
10
|
+
binPath: string;
|
|
11
|
+
}
|
|
12
|
+
/** Generate a systemd user service unit. */
|
|
13
|
+
export declare function systemdService(opts: SystemdServiceOptions): string;
|
|
14
|
+
/** Generate a systemd user timer unit for the given frequency. */
|
|
15
|
+
export declare function systemdTimer(frequency: Frequency): string;
|