@dennisonbertram/agent-drive 0.1.0 → 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 +9 -2
- package/dist/SKILL.md +10 -2
- package/dist/account-seal.d.ts +124 -0
- package/dist/account-seal.js +575 -0
- package/dist/account-seal.js.map +1 -0
- package/dist/backup.d.ts +8 -0
- package/dist/backup.js +285 -35
- package/dist/backup.js.map +1 -1
- package/dist/capture-spool.d.ts +10 -4
- package/dist/capture-spool.js +124 -41
- package/dist/capture-spool.js.map +1 -1
- package/dist/capture.js +13 -0
- package/dist/capture.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +232 -11
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +18 -1
- package/dist/client.js +36 -6
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -1
- package/dist/credentials.js +3 -0
- package/dist/credentials.js.map +1 -1
- package/dist/mcp.js +25 -5
- package/dist/mcp.js.map +1 -1
- package/dist/seal.d.ts +7 -2
- package/dist/seal.js +12 -8
- package/dist/seal.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
// Auto-seals held drive keys to the owner's account public key (docs/keys-and-recovery.md). The
|
|
2
|
+
// console's passphrase unlock then opens every sealed drive with no recovery file. Everything here
|
|
3
|
+
// is best-effort for the calling command: failures surface as one warning, never a thrown error.
|
|
4
|
+
//
|
|
5
|
+
// Private state (pins, throttle timestamps, agent-only drive ids) lives in `<config>.state/`,
|
|
6
|
+
// the same per-config directory backup.ts and capture.ts use, guarded by
|
|
7
|
+
// ensurePrivateStateDirectory — never in config.json, so an AGENT_DRIVE_CREDENTIALS bundle's
|
|
8
|
+
// secrets are never persisted and a sibling config's state can never be shared or redirected.
|
|
9
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
10
|
+
import { constants } from 'node:fs';
|
|
11
|
+
import { mkdir, open, readFile, rename, rm, rmdir } from 'node:fs/promises';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { AgentDriveApiError, AgentDriveClient } from './client.js';
|
|
14
|
+
import { configPath, driveKeyEnvironmentName, keysForOrigin, } from './config.js';
|
|
15
|
+
import { sealDriveKey } from './seal.js';
|
|
16
|
+
import { ensurePrivateStateDirectory } from './sync.js';
|
|
17
|
+
export const SEAL_THROTTLE_MS = 24 * 60 * 60 * 1000;
|
|
18
|
+
/** Background (automatic) sealing must never hold a command; the whole attempt gets this budget. */
|
|
19
|
+
export const SEAL_DEADLINE_MS = 5_000;
|
|
20
|
+
const ACCOUNT_SEAL_SALT = 'agent-drive-account-v1';
|
|
21
|
+
const NO_ACCOUNT_KEY_WARNING = 'Your account has no account key yet, so the console cannot open this drive. ' +
|
|
22
|
+
'Set a passphrase in the console under Settings; agents will add the drive then.';
|
|
23
|
+
const UNREADABLE_PIN_FILE = 'The account-key pin file is unreadable, so sealing is refused. Confirm the account key ' +
|
|
24
|
+
'fingerprint in the console, then repair the file with `agent-drive account seal --repin`.';
|
|
25
|
+
export const UNKNOWN_TYPE_HINT = "unknown drive type: run 'agent-drive account seal --drive ID' with a key that can read drives";
|
|
26
|
+
/** The same fingerprint the console prints on Settings: SHA-256(raw key), first 8 bytes, grouped. */
|
|
27
|
+
export function accountKeyFingerprint(publicKey) {
|
|
28
|
+
const hex = createHash('sha256')
|
|
29
|
+
.update(Buffer.from(publicKey, 'base64url'))
|
|
30
|
+
.digest('hex')
|
|
31
|
+
.slice(0, 16);
|
|
32
|
+
return hex.match(/.{4}/g).join(' ');
|
|
33
|
+
}
|
|
34
|
+
export class AccountKeyPinMismatch extends Error {
|
|
35
|
+
constructor(expected, actual) {
|
|
36
|
+
super(`The account public key changed (pinned fingerprint ${expected}, server returned ${actual}). ` +
|
|
37
|
+
'If the owner reset the passphrase in the console, run `agent-drive account seal --repin` to pin the new key.');
|
|
38
|
+
this.name = 'AccountKeyPinMismatch';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class AccountSealStateUnreadable extends Error {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(UNREADABLE_PIN_FILE);
|
|
44
|
+
this.name = 'AccountSealStateUnreadable';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function accountSealStatePath() {
|
|
48
|
+
return join(`${configPath()}.state`, 'account-seal.json');
|
|
49
|
+
}
|
|
50
|
+
function emptyState() {
|
|
51
|
+
return { pins: {}, checked: {}, agentOnly: [], pendingAgentOnly: [] };
|
|
52
|
+
}
|
|
53
|
+
/** Marks are origin-scoped: cloned APIs sharing a drive id must not share outcomes. */
|
|
54
|
+
const scoped = (origin, id) => `${origin}\n${id}`;
|
|
55
|
+
const isStringMap = (value) => Boolean(value) &&
|
|
56
|
+
typeof value === 'object' &&
|
|
57
|
+
!Array.isArray(value) &&
|
|
58
|
+
Object.values(value).every((item) => typeof item === 'string');
|
|
59
|
+
const isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
60
|
+
/** The exact shape accountKeyFingerprint produces: 'a1b2 c3d4 e5f6 7890'. */
|
|
61
|
+
const isFingerprint = (value) => /^[0-9a-f]{4}( [0-9a-f]{4}){3}$/u.test(value);
|
|
62
|
+
/**
|
|
63
|
+
* Reads the pin/state file, refusing a symlink outright (O_NOFOLLOW). Distinguishes "no file
|
|
64
|
+
* yet" from "exists but unusable": a truncated write, an invalid `pins`, or a symlink all make
|
|
65
|
+
* the file 'unreadable' so callers fail closed instead of resetting pin protection.
|
|
66
|
+
*/
|
|
67
|
+
async function readSealStateFile() {
|
|
68
|
+
let serialized;
|
|
69
|
+
try {
|
|
70
|
+
const handle = await open(accountSealStatePath(), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
71
|
+
try {
|
|
72
|
+
serialized = await handle.readFile('utf8');
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
await handle.close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (isCode(error, 'ENOENT'))
|
|
80
|
+
return { kind: 'missing' };
|
|
81
|
+
return { kind: 'unreadable' };
|
|
82
|
+
}
|
|
83
|
+
let parsed;
|
|
84
|
+
try {
|
|
85
|
+
parsed = JSON.parse(serialized);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return { kind: 'unreadable' };
|
|
89
|
+
}
|
|
90
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
91
|
+
return { kind: 'unreadable' };
|
|
92
|
+
const record = parsed;
|
|
93
|
+
// The first version of this file was a flat {driveId: timestamp} map.
|
|
94
|
+
const legacy = record.pins === undefined &&
|
|
95
|
+
record.checked === undefined &&
|
|
96
|
+
record.agentOnly === undefined &&
|
|
97
|
+
record.pendingAgentOnly === undefined;
|
|
98
|
+
if (legacy && isStringMap(record))
|
|
99
|
+
return { kind: 'ok', state: { ...emptyState(), checked: record } };
|
|
100
|
+
// A current-format file is damaged when `pins` is absent or not a map, or any pin is not a
|
|
101
|
+
// real fingerprint: an empty or hand-edited value is corruption, not "no pin". Fail closed.
|
|
102
|
+
if (!isStringMap(record.pins) ||
|
|
103
|
+
Object.values(record.pins).some((pin) => !isFingerprint(pin)) ||
|
|
104
|
+
(record.checked !== undefined && !isStringMap(record.checked)) ||
|
|
105
|
+
(record.agentOnly !== undefined && !isStringList(record.agentOnly)) ||
|
|
106
|
+
(record.pendingAgentOnly !== undefined && !isStringList(record.pendingAgentOnly)))
|
|
107
|
+
return { kind: 'unreadable' };
|
|
108
|
+
return {
|
|
109
|
+
kind: 'ok',
|
|
110
|
+
state: {
|
|
111
|
+
pins: record.pins,
|
|
112
|
+
checked: record.checked ?? {},
|
|
113
|
+
agentOnly: record.agentOnly ?? [],
|
|
114
|
+
pendingAgentOnly: record.pendingAgentOnly ?? [],
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Atomic write: a unique temp file in the same private directory, fsynced, then renamed over
|
|
120
|
+
* `account-seal.json` — an interrupted write can never leave a half-written pin file, and a
|
|
121
|
+
* symlink at the target path is replaced rather than followed.
|
|
122
|
+
*/
|
|
123
|
+
async function writeSealState(state) {
|
|
124
|
+
const directory = `${configPath()}.state`;
|
|
125
|
+
await ensurePrivateStateDirectory(directory);
|
|
126
|
+
const path = accountSealStatePath();
|
|
127
|
+
const temporary = join(directory, `account-seal.json.${process.pid}.${randomUUID()}.tmp`);
|
|
128
|
+
let created = false;
|
|
129
|
+
try {
|
|
130
|
+
const handle = await open(temporary, 'wx', 0o600);
|
|
131
|
+
created = true;
|
|
132
|
+
try {
|
|
133
|
+
await handle.chmod(0o600);
|
|
134
|
+
await handle.writeFile(`${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
|
135
|
+
await handle.sync();
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
await handle.close();
|
|
139
|
+
}
|
|
140
|
+
await rename(temporary, path);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
if (created)
|
|
144
|
+
await rm(temporary, { force: true });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function isCode(error, code) {
|
|
148
|
+
return typeof error === 'object' && error !== null && 'code' in error && error.code === code;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Reads then writes the seal state under an advisory lock, so a second process compares (and
|
|
152
|
+
* merges) against what the first one committed. `update` mutates the fresh state and reports
|
|
153
|
+
* whether it changed; a throw still releases the lock. An unreadable file throws
|
|
154
|
+
* AccountSealStateUnreadable unless `replaceIfUnreadable` (--repin repairing the pin), in
|
|
155
|
+
* which case the state starts empty and `onReset` fires once — every other origin's pin is
|
|
156
|
+
* gone and the caller must say so. The lock wait is unref'd and bounded by `timeoutAt` (the
|
|
157
|
+
* automatic path's overall 5s budget).
|
|
158
|
+
*/
|
|
159
|
+
async function withSealState(update, opts = {}) {
|
|
160
|
+
const directory = `${configPath()}.state`;
|
|
161
|
+
await ensurePrivateStateDirectory(directory);
|
|
162
|
+
const lockPath = join(directory, 'account-seal.lock');
|
|
163
|
+
const timeoutAt = opts.timeoutAt ?? Date.now() + 10_000;
|
|
164
|
+
for (;;) {
|
|
165
|
+
try {
|
|
166
|
+
await mkdir(lockPath, { mode: 0o700 });
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (!isCode(error, 'EEXIST')) {
|
|
171
|
+
throw new Error(`Unable to acquire the account-seal state lock at ${lockPath}.`);
|
|
172
|
+
}
|
|
173
|
+
if (Date.now() >= timeoutAt) {
|
|
174
|
+
throw new Error(`Timed out waiting for the account-seal state lock at ${lockPath}. If no Agent Drive command is running, remove the stale lock directory manually.`);
|
|
175
|
+
}
|
|
176
|
+
await new Promise((resolveDelay) => {
|
|
177
|
+
const timer = setTimeout(resolveDelay, 50);
|
|
178
|
+
timer.unref();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const read = await readSealStateFile();
|
|
184
|
+
let state;
|
|
185
|
+
if (read.kind === 'unreadable') {
|
|
186
|
+
if (!opts.replaceIfUnreadable)
|
|
187
|
+
throw new AccountSealStateUnreadable();
|
|
188
|
+
state = emptyState();
|
|
189
|
+
opts.onReset?.();
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
state = read.kind === 'ok' ? read.state : emptyState();
|
|
193
|
+
}
|
|
194
|
+
if ((await update(state)).changed)
|
|
195
|
+
await writeSealState(state);
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
try {
|
|
199
|
+
await rmdir(lockPath);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (!isCode(error, 'ENOENT')) {
|
|
203
|
+
throw new Error(`Unable to release the account-seal state lock at ${lockPath}.`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Remembers a drive as agent-only locally, so later seals skip it regardless of the listing. */
|
|
209
|
+
export async function recordAgentOnlyDrive(driveId, origin) {
|
|
210
|
+
await withSealState((state) => {
|
|
211
|
+
const mark = scoped(origin, driveId);
|
|
212
|
+
if (state.agentOnly.includes(mark))
|
|
213
|
+
return { changed: false };
|
|
214
|
+
state.agentOnly.push(mark);
|
|
215
|
+
return { changed: true };
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Records a `--agent-only` choice by drive NAME before the remote drive exists: if this write
|
|
220
|
+
* fails the command must stop so a state failure never strands a remote drive. Once creation
|
|
221
|
+
* returns an id, recordAgentOnlyDrive takes over and clearAgentOnlyIntent retires the intent.
|
|
222
|
+
*/
|
|
223
|
+
export async function recordAgentOnlyIntent(name, origin) {
|
|
224
|
+
const mark = scoped(origin, name);
|
|
225
|
+
await withSealState((state) => {
|
|
226
|
+
if (state.pendingAgentOnly.includes(mark))
|
|
227
|
+
return { changed: false };
|
|
228
|
+
state.pendingAgentOnly.push(mark);
|
|
229
|
+
return { changed: true };
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
export async function clearAgentOnlyIntent(name, origin) {
|
|
233
|
+
const mark = scoped(origin, name);
|
|
234
|
+
await withSealState((state) => {
|
|
235
|
+
const at = state.pendingAgentOnly.indexOf(mark);
|
|
236
|
+
if (at < 0)
|
|
237
|
+
return { changed: false };
|
|
238
|
+
state.pendingAgentOnly.splice(at, 1);
|
|
239
|
+
return { changed: true };
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/** Drive names with a pending --agent-only intent for `origin`; matched through a listing. */
|
|
243
|
+
export async function pendingAgentOnlyNames(origin) {
|
|
244
|
+
const read = await readSealStateFile();
|
|
245
|
+
const prefix = `${origin}\n`;
|
|
246
|
+
if (read.kind !== 'ok')
|
|
247
|
+
return new Set();
|
|
248
|
+
return new Set(read.state.pendingAgentOnly
|
|
249
|
+
.filter((mark) => mark.startsWith(prefix))
|
|
250
|
+
.map((mark) => mark.slice(prefix.length)));
|
|
251
|
+
}
|
|
252
|
+
function recentlyChecked(checked, origin, driveId, now) {
|
|
253
|
+
const at = Date.parse(checked[scoped(origin, driveId)] ?? '');
|
|
254
|
+
return Number.isFinite(at) && now - at < SEAL_THROTTLE_MS;
|
|
255
|
+
}
|
|
256
|
+
/** The slot endpoint's rejection of an agent-only drive; the local list learns from it. */
|
|
257
|
+
function isAgentOnlyRejection(error) {
|
|
258
|
+
return (error instanceof AgentDriveApiError &&
|
|
259
|
+
error.code === 'conflict' &&
|
|
260
|
+
error.message.includes('agent-only'));
|
|
261
|
+
}
|
|
262
|
+
/** One-line summary for automatic sealing; the explicit command prints a status per drive. */
|
|
263
|
+
function describeFailure(failed, failures) {
|
|
264
|
+
const first = failures.get(failed[0]);
|
|
265
|
+
const message = first instanceof Error ? first.message : String(first);
|
|
266
|
+
return `Drive key sealing skipped for ${failed.length === 1 ? `drive ${failed[0]}` : `${failed.length} drives`}: ${message}`;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Seals every held key in `targets` to the account public key, keyed by the client's effective
|
|
270
|
+
* API origin. Returns one status per drive attempted; drives skipped by the 24h throttle are
|
|
271
|
+
* absent from the map. A failing drive marks 'failed' and does not stop the rest. Throws
|
|
272
|
+
* AccountKeyPinMismatch when the pinned fingerprint does not match and `repin` is false, and
|
|
273
|
+
* AccountSealStateUnreadable when the pin file cannot be read (fail closed).
|
|
274
|
+
*/
|
|
275
|
+
export async function sealDrivesToAccount(opts) {
|
|
276
|
+
const { client, config, targets } = opts;
|
|
277
|
+
const result = new Map();
|
|
278
|
+
const origin = client.apiOrigin;
|
|
279
|
+
let repaired = false;
|
|
280
|
+
const stateOpts = {
|
|
281
|
+
timeoutAt: opts.stateDeadlineAt,
|
|
282
|
+
replaceIfUnreadable: opts.repin === true,
|
|
283
|
+
onReset: () => {
|
|
284
|
+
if (repaired)
|
|
285
|
+
return;
|
|
286
|
+
repaired = true;
|
|
287
|
+
opts.onRepair?.();
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
// Fail closed before any key can be posted: the pin cannot be compared.
|
|
291
|
+
const initial = await readSealStateFile();
|
|
292
|
+
if (initial.kind === 'unreadable' && !opts.repin)
|
|
293
|
+
throw new AccountSealStateUnreadable();
|
|
294
|
+
const prefix = `${origin}\n`;
|
|
295
|
+
// Bare ids are pre-origin marks; they apply to every origin (fail closed). Scoped marks
|
|
296
|
+
// apply only to their own origin.
|
|
297
|
+
const localOnly = new Set((initial.kind === 'ok' ? initial.state.agentOnly : []).flatMap((mark) => mark.includes('\n') ? (mark.startsWith(prefix) ? [mark.slice(prefix.length)] : []) : [mark]));
|
|
298
|
+
const pending = targets.filter((target) => {
|
|
299
|
+
// A target key identical to the saved one IS the saved key — it may only seal to the API
|
|
300
|
+
// origin it was saved for, whatever path (keys, resolveKey, env fallback) supplied it.
|
|
301
|
+
// Explicitly supplied keys (env/--key-file, a just-created drive key) differ from the
|
|
302
|
+
// saved value, so they stay allowed. No network call happens for a refused key.
|
|
303
|
+
const saved = config.driveKeys?.[target.driveId];
|
|
304
|
+
if (saved !== undefined &&
|
|
305
|
+
saved === target.driveKey &&
|
|
306
|
+
config.driveKeyOrigins?.[target.driveId] !== origin) {
|
|
307
|
+
result.set(target.driveId, 'wrong origin');
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
if (target.agentOnly === true || localOnly.has(target.driveId)) {
|
|
311
|
+
result.set(target.driveId, 'agent-only');
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (opts.requireVerifiedType === true && opts.verifiedDriveIds?.has(target.driveId) !== true) {
|
|
315
|
+
result.set(target.driveId, 'unknown type');
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
return true;
|
|
319
|
+
});
|
|
320
|
+
const unknown = targets.filter((target) => result.get(target.driveId) === 'unknown type');
|
|
321
|
+
if (unknown.length) {
|
|
322
|
+
// Stamp the check so a throttled caller does not re-warn on every command.
|
|
323
|
+
const at = new Date().toISOString();
|
|
324
|
+
await withSealState((state) => {
|
|
325
|
+
for (const target of unknown)
|
|
326
|
+
state.checked[scoped(origin, target.driveId)] = at;
|
|
327
|
+
return { changed: true };
|
|
328
|
+
}, stateOpts).catch(() => { });
|
|
329
|
+
}
|
|
330
|
+
if (!pending.length)
|
|
331
|
+
return result;
|
|
332
|
+
const key = await client.accountKey();
|
|
333
|
+
if (!key || key.format !== 1) {
|
|
334
|
+
// Record the check: a throttled caller must not rediscover "no account key" every run.
|
|
335
|
+
const at = new Date().toISOString();
|
|
336
|
+
for (const target of pending)
|
|
337
|
+
result.set(target.driveId, 'no account key');
|
|
338
|
+
await withSealState((state) => {
|
|
339
|
+
for (const target of pending)
|
|
340
|
+
state.checked[scoped(origin, target.driveId)] = at;
|
|
341
|
+
return { changed: pending.length > 0 };
|
|
342
|
+
}, stateOpts).catch(() => { });
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
const fingerprint = accountKeyFingerprint(key.publicKey);
|
|
346
|
+
// The pin compare-and-set runs under the state lock, so a second concurrent process compares
|
|
347
|
+
// against the pin the first one committed rather than a stale read.
|
|
348
|
+
let checked = {};
|
|
349
|
+
await withSealState((state) => {
|
|
350
|
+
checked = { ...state.checked };
|
|
351
|
+
const pinned = state.pins[origin] ?? config.accountKeyPins?.[origin];
|
|
352
|
+
if (pinned && pinned !== fingerprint && !opts.repin)
|
|
353
|
+
throw new AccountKeyPinMismatch(pinned, fingerprint);
|
|
354
|
+
if (state.pins[origin] !== fingerprint) {
|
|
355
|
+
state.pins[origin] = fingerprint;
|
|
356
|
+
return { changed: true };
|
|
357
|
+
}
|
|
358
|
+
return { changed: false };
|
|
359
|
+
}, stateOpts);
|
|
360
|
+
const now = Date.now();
|
|
361
|
+
for (const target of pending) {
|
|
362
|
+
if (!opts.force && recentlyChecked(checked, origin, target.driveId, now))
|
|
363
|
+
continue;
|
|
364
|
+
try {
|
|
365
|
+
const sealed = await sealDriveKey(key.publicKey, target.driveId, target.driveKey, {
|
|
366
|
+
salt: ACCOUNT_SEAL_SALT,
|
|
367
|
+
label: `${key.keyId}:${target.driveId}`,
|
|
368
|
+
});
|
|
369
|
+
const uploaded = await client.addAccountKeySlot(target.driveId, {
|
|
370
|
+
keyId: key.keyId,
|
|
371
|
+
sealed,
|
|
372
|
+
});
|
|
373
|
+
result.set(target.driveId, uploaded.status === 'created' ? 'sealed' : 'already sealed');
|
|
374
|
+
const at = new Date(now).toISOString();
|
|
375
|
+
await withSealState((state) => {
|
|
376
|
+
state.checked[scoped(origin, target.driveId)] = at;
|
|
377
|
+
return { changed: true };
|
|
378
|
+
}, stateOpts);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
if (isAgentOnlyRejection(error)) {
|
|
382
|
+
result.set(target.driveId, 'agent-only');
|
|
383
|
+
await recordAgentOnlyDrive(target.driveId, origin).catch(() => { });
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
result.set(target.driveId, 'failed');
|
|
387
|
+
opts.onFailure?.(target.driveId, error);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Resolves the drive keys this machine holds for `origin` (the client's effective origin) the
|
|
395
|
+
* same way commands resolve them: an explicit `keys`/`resolveKey` answer first (the exact key
|
|
396
|
+
* the calling command used), then an `AGENT_DRIVE_KEY_<ID>` environment key, then — for the
|
|
397
|
+
* drive the calling command used — `AGENT_DRIVE_KEY` and `--key-file`, then the saved config
|
|
398
|
+
* key, but only when its recorded `driveKeyOrigins` entry matches `origin` — a key saved for
|
|
399
|
+
* another API is never sealed here. `agentOnly` flags only ever add the flag: a locally
|
|
400
|
+
* recorded agent-only drive stays agent-only even when the listing says otherwise.
|
|
401
|
+
*/
|
|
402
|
+
export async function heldSealTargets(opts) {
|
|
403
|
+
const candidates = new Set(opts.driveIds ?? [
|
|
404
|
+
...Object.keys(keysForOrigin(opts.config, opts.origin)),
|
|
405
|
+
...(opts.selectedDriveId ? [opts.selectedDriveId] : []),
|
|
406
|
+
...(opts.agentOnly?.keys() ?? []),
|
|
407
|
+
]);
|
|
408
|
+
const targets = [];
|
|
409
|
+
for (const driveId of candidates) {
|
|
410
|
+
let driveKey = opts.keys?.[driveId] ?? opts.resolveKey?.(driveId);
|
|
411
|
+
if (!driveKey) {
|
|
412
|
+
const envKey = process.env[driveKeyEnvironmentName(driveId)]?.trim();
|
|
413
|
+
if (envKey) {
|
|
414
|
+
driveKey = envKey;
|
|
415
|
+
}
|
|
416
|
+
else if (driveId === opts.selectedDriveId) {
|
|
417
|
+
// Identical to the command's own resolution — env-per-drive, AGENT_DRIVE_KEY, key
|
|
418
|
+
// file — except the saved-key fallback must be bound to this origin.
|
|
419
|
+
driveKey =
|
|
420
|
+
process.env.AGENT_DRIVE_KEY?.trim() ||
|
|
421
|
+
(opts.keyFile ? (await readFile(opts.keyFile, 'utf8')).trim() : undefined) ||
|
|
422
|
+
keysForOrigin(opts.config, opts.origin)[driveId];
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
driveKey = keysForOrigin(opts.config, opts.origin)[driveId];
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (!driveKey)
|
|
429
|
+
continue;
|
|
430
|
+
targets.push({ driveId, driveKey, agentOnly: opts.agentOnly?.get(driveId) === true });
|
|
431
|
+
}
|
|
432
|
+
return targets;
|
|
433
|
+
}
|
|
434
|
+
export { NO_ACCOUNT_KEY_WARNING };
|
|
435
|
+
/**
|
|
436
|
+
* A sealing client whose requests share an overall deadline, so automatic sealing can never
|
|
437
|
+
* hold the calling command. The returned signal marks the budget: an aborted run stays silent.
|
|
438
|
+
* `deadlineAt` is the same budget as epoch ms, for work that does not take an AbortSignal.
|
|
439
|
+
*/
|
|
440
|
+
export function sealClientWithDeadline(apiUrl, apiKey, machine) {
|
|
441
|
+
const deadline = AbortSignal.timeout(SEAL_DEADLINE_MS);
|
|
442
|
+
const deadlineAt = Date.now() + SEAL_DEADLINE_MS;
|
|
443
|
+
const client = new AgentDriveClient({
|
|
444
|
+
apiUrl,
|
|
445
|
+
apiKey,
|
|
446
|
+
...(machine ? { machine } : {}),
|
|
447
|
+
fetch: (input, init) => globalThis.fetch(input, {
|
|
448
|
+
...init,
|
|
449
|
+
signal: init?.signal ? AbortSignal.any([init.signal, deadline]) : deadline,
|
|
450
|
+
}),
|
|
451
|
+
});
|
|
452
|
+
return { client, deadline, deadlineAt };
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Best-effort seal for held keys, called after commands that put or use drive keys on this
|
|
456
|
+
* machine. `force` seals regardless of the throttle (create/login/import/mcp); otherwise drives
|
|
457
|
+
* checked in the last 24h are skipped before any network call. The drive listing is paginated
|
|
458
|
+
* fully; a key without `read` cannot list (403), and a drive whose type is then unproven — not
|
|
459
|
+
* in the listing and without a local mark — is skipped as 'unknown type' rather than being
|
|
460
|
+
* sent a key that could belong to an agent-only drive. Errors become one `warn` line, and
|
|
461
|
+
* nothing is reported once `deadline` aborts the attempt.
|
|
462
|
+
*/
|
|
463
|
+
export async function autoSealHeldKeys(opts) {
|
|
464
|
+
try {
|
|
465
|
+
const origin = opts.client.apiOrigin;
|
|
466
|
+
const held = Object.keys(keysForOrigin(opts.config, origin));
|
|
467
|
+
const early = new Set(opts.driveIds ?? held);
|
|
468
|
+
if (opts.selectedDriveId)
|
|
469
|
+
early.add(opts.selectedDriveId);
|
|
470
|
+
if (opts.keys)
|
|
471
|
+
for (const id of Object.keys(opts.keys))
|
|
472
|
+
early.add(id);
|
|
473
|
+
if (!early.size)
|
|
474
|
+
return;
|
|
475
|
+
if (!opts.force) {
|
|
476
|
+
const read = await readSealStateFile();
|
|
477
|
+
if (read.kind === 'unreadable')
|
|
478
|
+
throw new AccountSealStateUnreadable();
|
|
479
|
+
const checked = read.kind === 'ok' ? read.state.checked : {};
|
|
480
|
+
const now = Date.now();
|
|
481
|
+
if (![...early].some((id) => !recentlyChecked(checked, origin, id, now)))
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
// The full listing tells bulk sealing which held drives still exist and which are
|
|
485
|
+
// agent-only; recorded --agent-only create intents join in by name. A key without `read`
|
|
486
|
+
// cannot list (403): with no listing and no local mark a drive's type is unproven, so it
|
|
487
|
+
// is skipped rather than sent a key that could belong to an agent-only drive.
|
|
488
|
+
const flags = new Map();
|
|
489
|
+
const listed = new Set();
|
|
490
|
+
let listingOk = true;
|
|
491
|
+
const pendingNames = await pendingAgentOnlyNames(origin);
|
|
492
|
+
try {
|
|
493
|
+
let cursor;
|
|
494
|
+
for (let page = 0; page < 50; page += 1) {
|
|
495
|
+
const res = await opts.client.listDrives(undefined, cursor);
|
|
496
|
+
for (const drive of res.items ?? []) {
|
|
497
|
+
listed.add(drive.id);
|
|
498
|
+
flags.set(drive.id, drive.agentOnly === true || pendingNames.has(drive.name));
|
|
499
|
+
}
|
|
500
|
+
if (!res.nextCursor)
|
|
501
|
+
break;
|
|
502
|
+
cursor = res.nextCursor;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
if (!(error instanceof AgentDriveApiError && error.status === 403))
|
|
507
|
+
throw error;
|
|
508
|
+
listingOk = false;
|
|
509
|
+
}
|
|
510
|
+
const candidates = new Set();
|
|
511
|
+
if (opts.driveIds) {
|
|
512
|
+
for (const id of opts.driveIds)
|
|
513
|
+
candidates.add(id);
|
|
514
|
+
if (opts.selectedDriveId)
|
|
515
|
+
candidates.add(opts.selectedDriveId);
|
|
516
|
+
}
|
|
517
|
+
else if (listingOk) {
|
|
518
|
+
// Only listed drives seal: a slot POST for a deleted drive would fail noisily every day.
|
|
519
|
+
for (const id of listed)
|
|
520
|
+
candidates.add(id);
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
for (const id of held)
|
|
524
|
+
candidates.add(id);
|
|
525
|
+
if (opts.selectedDriveId)
|
|
526
|
+
candidates.add(opts.selectedDriveId);
|
|
527
|
+
}
|
|
528
|
+
const targets = await heldSealTargets({
|
|
529
|
+
config: opts.config,
|
|
530
|
+
origin,
|
|
531
|
+
driveIds: [...candidates],
|
|
532
|
+
agentOnly: flags,
|
|
533
|
+
...(opts.selectedDriveId ? { selectedDriveId: opts.selectedDriveId } : {}),
|
|
534
|
+
...(opts.keyFile ? { keyFile: opts.keyFile } : {}),
|
|
535
|
+
...(opts.keys ? { keys: opts.keys } : {}),
|
|
536
|
+
...(opts.resolveKey ? { resolveKey: opts.resolveKey } : {}),
|
|
537
|
+
});
|
|
538
|
+
if (!targets.length)
|
|
539
|
+
return;
|
|
540
|
+
const failures = new Map();
|
|
541
|
+
// Drives explicitly named by the caller (a just-created drive) are known to exist even
|
|
542
|
+
// when the listing is denied; every other drive needs the listing or a local mark.
|
|
543
|
+
const verified = new Set([...listed, ...(opts.driveIds ?? [])]);
|
|
544
|
+
const result = await sealDrivesToAccount({
|
|
545
|
+
client: opts.client,
|
|
546
|
+
config: opts.config,
|
|
547
|
+
targets,
|
|
548
|
+
force: opts.force === true,
|
|
549
|
+
requireVerifiedType: true,
|
|
550
|
+
verifiedDriveIds: verified,
|
|
551
|
+
stateDeadlineAt: opts.deadlineAt,
|
|
552
|
+
onFailure: (driveId, error) => failures.set(driveId, error),
|
|
553
|
+
});
|
|
554
|
+
if (opts.deadline?.aborted)
|
|
555
|
+
return;
|
|
556
|
+
// Only the named events (create/login/import/mcp) warn: an account with no key would
|
|
557
|
+
// otherwise print the same line on every throttled command.
|
|
558
|
+
if (opts.force && [...result.values()].some((status) => status === 'no account key'))
|
|
559
|
+
opts.warn(NO_ACCOUNT_KEY_WARNING);
|
|
560
|
+
const unknown = targets
|
|
561
|
+
.filter((target) => result.get(target.driveId) === 'unknown type')
|
|
562
|
+
.map((target) => target.driveId);
|
|
563
|
+
if (unknown.length)
|
|
564
|
+
opts.warn(`Drive key sealing skipped for ${unknown.length === 1 ? `drive ${unknown[0]}` : `${unknown.length} drives`}: ${UNKNOWN_TYPE_HINT}.`);
|
|
565
|
+
const failed = [...failures.keys()];
|
|
566
|
+
if (failed.length)
|
|
567
|
+
opts.warn(describeFailure(failed, failures));
|
|
568
|
+
}
|
|
569
|
+
catch (error) {
|
|
570
|
+
if (opts.deadline?.aborted)
|
|
571
|
+
return;
|
|
572
|
+
opts.warn(`Drive key sealing skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
//# sourceMappingURL=account-seal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-seal.js","sourceRoot":"","sources":["../src/account-seal.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,mGAAmG;AACnG,iGAAiG;AACjG,EAAE;AACF,8FAA8F;AAC9F,yEAAyE;AACzE,6FAA6F;AAC7F,8FAA8F;AAE9F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,aAAa,GAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACpD,oGAAoG;AACpG,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AACtC,MAAM,iBAAiB,GAAG,wBAAwB,CAA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C,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QACpC,IAAI,MAAM,CAAC,MAAM;YAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,QAAQ,EAAE,OAAO;YAAE,OAAO;QACnC,IAAI,CAAC,IAAI,CACP,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACvF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/backup.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { Stats } from 'node:fs';
|
|
2
2
|
import type { AgentDriveClient } from './client.js';
|
|
3
|
+
export declare const BACKUP_MAX_FILES = 5000;
|
|
4
|
+
export declare const BACKUP_MAX_BYTES: number;
|
|
3
5
|
type BackupClient = Pick<AgentDriveClient, 'apiOrigin' | 'put'>;
|
|
4
6
|
/** Reads a regular file through a no-follow descriptor, refusing if it moved outside root. */
|
|
5
7
|
export declare function readFileInside(path: string, root: string, expected: Stats): Promise<Uint8Array<ArrayBuffer>>;
|
|
6
8
|
export declare function backupDirectory(client: BackupClient, driveId: string, localRoot: string, prefix: string, options?: {
|
|
7
9
|
dryRun?: boolean;
|
|
8
10
|
keyFile?: string;
|
|
11
|
+
yes?: boolean;
|
|
12
|
+
exclude?: string[];
|
|
13
|
+
gitignore?: boolean;
|
|
14
|
+
maxFiles?: number;
|
|
15
|
+
maxBytes?: number;
|
|
16
|
+
progressIntervalMs?: number;
|
|
9
17
|
log?: (line: string) => void;
|
|
10
18
|
}): Promise<{
|
|
11
19
|
uploaded: number;
|