@dennisonbertram/agent-drive 0.0.0-stage → 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 +10 -2
- package/dist/SKILL.md +118 -0
- package/dist/backup-targets.d.ts +24 -0
- package/dist/backup-targets.js +104 -0
- package/dist/backup-targets.js.map +1 -0
- package/dist/backup.d.ts +16 -0
- package/dist/backup.js +151 -0
- package/dist/backup.js.map +1 -0
- package/dist/capture-codex.d.ts +5 -0
- package/dist/capture-codex.js +40 -0
- package/dist/capture-codex.js.map +1 -0
- package/dist/capture-spool.d.ts +58 -0
- package/dist/capture-spool.js +299 -0
- package/dist/capture-spool.js.map +1 -0
- package/dist/capture.d.ts +66 -0
- package/dist/capture.js +536 -0
- package/dist/capture.js.map +1 -0
- package/dist/check.d.ts +17 -0
- package/dist/check.js +119 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +584 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +259 -0
- package/dist/client.js +456 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +41 -0
- package/dist/config.js +220 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +108 -0
- package/dist/credentials.js +336 -0
- package/dist/credentials.js.map +1 -0
- package/dist/crypto-format.d.ts +8 -0
- package/dist/crypto-format.js +96 -0
- package/dist/crypto-format.js.map +1 -0
- package/dist/crypto.d.ts +20 -0
- package/dist/crypto.js +124 -0
- package/dist/crypto.js.map +1 -0
- package/dist/device.d.ts +33 -0
- package/dist/device.js +229 -0
- package/dist/device.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +7 -0
- package/dist/mcp.js +348 -0
- package/dist/mcp.js.map +1 -0
- package/dist/safe-write.d.ts +9 -0
- package/dist/safe-write.js +34 -0
- package/dist/safe-write.js.map +1 -0
- package/dist/seal.d.ts +12 -0
- package/dist/seal.js +49 -0
- package/dist/seal.js.map +1 -0
- package/dist/skill.d.ts +4 -0
- package/dist/skill.js +42 -0
- package/dist/skill.js.map +1 -0
- package/dist/sync.d.ts +13 -0
- package/dist/sync.js +301 -0
- package/dist/sync.js.map +1 -0
- package/dist/trace-inbox.d.ts +26 -0
- package/dist/trace-inbox.js +126 -0
- package/dist/trace-inbox.js.map +1 -0
- package/dist/trace-path.d.ts +10 -0
- package/dist/trace-path.js +18 -0
- package/dist/trace-path.js.map +1 -0
- package/package.json +61 -4
package/dist/check.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { driveKeyEnvironmentName } from './config.js';
|
|
3
|
+
import { BACKUP_HINT } from './credentials.js';
|
|
4
|
+
import { DriveCryptoError } from './crypto.js';
|
|
5
|
+
import { AgentDriveApiError } from './client.js';
|
|
6
|
+
export const SCOPE_HINT = 'Run `agent-drive login` again to reconnect, or ask the owner for a key with that scope.';
|
|
7
|
+
const DELEGATE_HINT = 'Run `agent-drive login` again; on the approval page, tick "Let this agent add other agents to its drives" (under "Optional") before approving.';
|
|
8
|
+
/** What a conflict loser should do next; shared by the CLI and the MCP `hint`. */
|
|
9
|
+
export function conflictHint(error) {
|
|
10
|
+
if (error.code !== 'conflict')
|
|
11
|
+
return undefined;
|
|
12
|
+
if (error.state === 'trashed')
|
|
13
|
+
return 'The file is in the trash: restore it with "restore <path>" or write with --overwrite.';
|
|
14
|
+
if (error.state === 'absent')
|
|
15
|
+
return 'There is no file at this path now; write it without --if-version.';
|
|
16
|
+
if ((error.state === 'exists' || error.state === 'changed') && error.currentVersionId)
|
|
17
|
+
return `Current version: ${error.currentVersionId}. Read the file again, merge your change, then retry with --if-version ${error.currentVersionId}.`;
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Lines to print on stderr for an API error. */
|
|
21
|
+
export function apiErrorLines(error) {
|
|
22
|
+
return [
|
|
23
|
+
error.message,
|
|
24
|
+
conflictHint(error) ?? '',
|
|
25
|
+
error.code === 'permission_denied' && /scope/iu.test(error.message)
|
|
26
|
+
? /delegate"? scope/iu.test(error.message)
|
|
27
|
+
? DELEGATE_HINT
|
|
28
|
+
: SCOPE_HINT
|
|
29
|
+
: '',
|
|
30
|
+
error.upgradeUrl ? `Upgrade: ${error.upgradeUrl}` : '',
|
|
31
|
+
error.retryAfter === undefined ? '' : `Retry after: ${error.retryAfter} seconds`,
|
|
32
|
+
].filter(Boolean);
|
|
33
|
+
}
|
|
34
|
+
export function notBackedUpMessage(driveIds) {
|
|
35
|
+
return `drive key not backed up: ${driveIds.join(', ')}\n${BACKUP_HINT}`;
|
|
36
|
+
}
|
|
37
|
+
export function createdDriveNote(configPath) {
|
|
38
|
+
return `Drive key saved to ${configPath}; back it up.`;
|
|
39
|
+
}
|
|
40
|
+
/** `{ driveId: hasKey }`; whoami returns null driveIds for manage keys, so there is nothing to map. */
|
|
41
|
+
export async function localKeyMap(driveIds, resolve) {
|
|
42
|
+
const result = {};
|
|
43
|
+
for (const id of driveIds ?? [])
|
|
44
|
+
result[id] = Boolean(await resolve(id));
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
export function pickCheckDrive(explicit, candidates, hasKey) {
|
|
48
|
+
if (explicit) {
|
|
49
|
+
if (!hasKey[explicit])
|
|
50
|
+
throw new Error(`There is no key for drive ${explicit} on this machine.`);
|
|
51
|
+
return explicit;
|
|
52
|
+
}
|
|
53
|
+
const usable = candidates.filter((id) => hasKey[id]);
|
|
54
|
+
if (!usable.length)
|
|
55
|
+
throw new Error('There is no usable drive key on this machine. Run `agent-drive login` again.');
|
|
56
|
+
if (usable.length > 1)
|
|
57
|
+
throw new Error('More than one usable drive. Pass --drive ID.');
|
|
58
|
+
return usable[0];
|
|
59
|
+
}
|
|
60
|
+
const CHECK_FILE = '/.agent-drive/check.txt';
|
|
61
|
+
/** Read-only keys cannot write a check file, so prove the drive key opens an existing live file. */
|
|
62
|
+
async function readOnlyCheck(client, driveId) {
|
|
63
|
+
let cursor;
|
|
64
|
+
do {
|
|
65
|
+
const page = await client.list(driveId, undefined, 50, cursor);
|
|
66
|
+
for (const file of page.items) {
|
|
67
|
+
if (file.path.endsWith(CHECK_FILE))
|
|
68
|
+
continue;
|
|
69
|
+
try {
|
|
70
|
+
await client.get(driveId, file.path);
|
|
71
|
+
return `check ok drive=${driveId} (read-only)`;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof DriveCryptoError)
|
|
75
|
+
throw new Error('This drive key cannot decrypt existing files.');
|
|
76
|
+
// Deleted or moved between list and get: try the next file.
|
|
77
|
+
if (!(error instanceof AgentDriveApiError && error.status === 404))
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
cursor = page.nextCursor ?? undefined;
|
|
82
|
+
} while (cursor);
|
|
83
|
+
throw new Error(`check not verified drive=${driveId}: this read-only key has nothing to decrypt yet; run check again after another agent writes a file.`);
|
|
84
|
+
}
|
|
85
|
+
export async function runCheck(client, driveId, access = { scopes: ['write'], writePaths: [] }) {
|
|
86
|
+
if (!access.scopes.includes('write'))
|
|
87
|
+
return readOnlyCheck(client, driveId);
|
|
88
|
+
const payload = randomBytes(16);
|
|
89
|
+
const path = `${access.writePaths[0] ?? ''}${CHECK_FILE}`;
|
|
90
|
+
// A wrong key would still pass the round trip below, so first prove it opens an existing file:
|
|
91
|
+
// the newest one by the recent feed (newest first), not the first page of the path-ordered list.
|
|
92
|
+
const events = (await client.recent(driveId, undefined, 50)).items;
|
|
93
|
+
const newest = events.find((event) => !event.path.endsWith(CHECK_FILE) && ['put', 'copy', 'restore'].includes(event.operation));
|
|
94
|
+
if (newest) {
|
|
95
|
+
try {
|
|
96
|
+
await client.get(driveId, newest.path);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (error instanceof DriveCryptoError)
|
|
100
|
+
throw new Error('This drive key cannot decrypt existing files.');
|
|
101
|
+
// ponytail: a file deleted or moved since is skipped, not retried with the next newest.
|
|
102
|
+
if (!(error instanceof AgentDriveApiError && error.status === 404))
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
await client.put(driveId, path, payload, { mode: 'overwrite' });
|
|
107
|
+
const back = await client.get(driveId, path);
|
|
108
|
+
if (!Buffer.from(back.bytes).equals(payload))
|
|
109
|
+
throw new Error(`Check failed: the bytes read back from drive ${driveId} do not match (mismatch).`);
|
|
110
|
+
return `check ok drive=${driveId}`;
|
|
111
|
+
}
|
|
112
|
+
/** Drives that must be backed up before check passes. Env keys and --key-file (for the checked drive only) live outside the config. */
|
|
113
|
+
export function backupCandidates(keys, driveId, keyFile, env = process.env) {
|
|
114
|
+
return Object.keys(keys).filter((id) => keys[id] &&
|
|
115
|
+
!env[driveKeyEnvironmentName(id)] &&
|
|
116
|
+
!env.AGENT_DRIVE_KEY &&
|
|
117
|
+
!(keyFile && id === driveId));
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAyB,MAAM,aAAa,CAAC;AAExE,MAAM,CAAC,MAAM,UAAU,GACrB,yFAAyF,CAAC;AAE5F,MAAM,aAAa,GACjB,gJAAgJ,CAAC;AAEnJ,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,KAAyB;IACpD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,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