aicomputer 0.1.17 → 0.1.18
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 +8 -3
- package/dist/{chunk-5IEWKH52.js → chunk-3ZUTAUUD.js} +70 -280
- package/dist/chunk-F2U4SFJ4.js +517 -0
- package/dist/{chunk-OWK5N76S.js → chunk-JMRAYXUO.js} +3 -11
- package/dist/index.js +324 -114
- package/dist/lib/mount-config.d.ts +4 -1
- package/dist/lib/mount-host.d.ts +1 -2
- package/dist/lib/mount-host.js +1 -1
- package/dist/lib/mount-mutagen.d.ts +37 -0
- package/dist/lib/mount-mutagen.js +23 -0
- package/dist/lib/mount-reconcile.d.ts +4 -18
- package/dist/lib/mount-reconcile.js +2 -1
- package/package.json +5 -3
- package/scripts/postinstall.mjs +35 -0
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MOUNT_SERVICE_LABEL,
|
|
3
|
+
ensureHandleDirectories,
|
|
4
|
+
ensureMountDirectories
|
|
5
|
+
} from "./chunk-KXLTHWW3.js";
|
|
6
|
+
|
|
7
|
+
// src/lib/mount-mutagen.ts
|
|
8
|
+
import { chmodSync as chmodSync2, readFileSync, symlinkSync, unlinkSync, writeFileSync } from "fs";
|
|
9
|
+
import { spawn, spawnSync as spawnSync2 } from "child_process";
|
|
10
|
+
import { basename, join as join2, relative, resolve } from "path";
|
|
11
|
+
|
|
12
|
+
// src/lib/mutagen-runtime.ts
|
|
13
|
+
import { spawnSync } from "child_process";
|
|
14
|
+
import {
|
|
15
|
+
chmodSync,
|
|
16
|
+
existsSync,
|
|
17
|
+
mkdirSync,
|
|
18
|
+
renameSync,
|
|
19
|
+
rmSync
|
|
20
|
+
} from "fs";
|
|
21
|
+
import { writeFile } from "fs/promises";
|
|
22
|
+
import { homedir } from "os";
|
|
23
|
+
import { dirname, join } from "path";
|
|
24
|
+
var BUNDLED_MUTAGEN_VERSION = "0.18.1";
|
|
25
|
+
var BUNDLED_MUTAGEN_DOWNLOAD_BASE = `https://github.com/mutagen-io/mutagen/releases/download/v${BUNDLED_MUTAGEN_VERSION}`;
|
|
26
|
+
var AGENTCOMPUTER_MUTAGEN_PATH_ENV = "AGENTCOMPUTER_MUTAGEN_PATH";
|
|
27
|
+
function getBundledMutagenAsset(platform = process.platform, arch = process.arch, homeDirectory = homedir()) {
|
|
28
|
+
if (!isSupportedPlatform(platform) || !isSupportedArch(arch)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const assetName = `mutagen_${platform}_${arch}_v${BUNDLED_MUTAGEN_VERSION}.tar.gz`;
|
|
32
|
+
const installDir = join(
|
|
33
|
+
homeDirectory,
|
|
34
|
+
".agentcomputer",
|
|
35
|
+
"tools",
|
|
36
|
+
"mutagen",
|
|
37
|
+
`v${BUNDLED_MUTAGEN_VERSION}`,
|
|
38
|
+
`${platform}-${arch}`
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
platform,
|
|
42
|
+
arch,
|
|
43
|
+
version: BUNDLED_MUTAGEN_VERSION,
|
|
44
|
+
assetName,
|
|
45
|
+
downloadUrl: `${BUNDLED_MUTAGEN_DOWNLOAD_BASE}/${assetName}`,
|
|
46
|
+
installDir,
|
|
47
|
+
executablePath: join(installDir, "mutagen")
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function resolveSystemCommandPath(command) {
|
|
51
|
+
const result = spawnSync("which", [command], { encoding: "utf8" });
|
|
52
|
+
if (result.status !== 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const resolved = result.stdout.trim();
|
|
56
|
+
return resolved.length > 0 ? resolved : null;
|
|
57
|
+
}
|
|
58
|
+
async function ensureMutagenCommandPath() {
|
|
59
|
+
const asset = getBundledMutagenAsset();
|
|
60
|
+
if (asset && existsSync(asset.executablePath)) {
|
|
61
|
+
return asset.executablePath;
|
|
62
|
+
}
|
|
63
|
+
const systemPath = resolveSystemCommandPath("mutagen");
|
|
64
|
+
if (!asset) {
|
|
65
|
+
if (systemPath) {
|
|
66
|
+
return systemPath;
|
|
67
|
+
}
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}. Install Mutagen manually and rerun \`computer mount\`.`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return await installBundledMutagen(asset);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (systemPath) {
|
|
76
|
+
return systemPath;
|
|
77
|
+
}
|
|
78
|
+
const reason = error instanceof Error ? error.message : "unknown Mutagen install failure";
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Failed to install Agent Computer's bundled Mutagen (${reason}). Check your network connection and rerun \`computer mount\`.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function ensureBundledMutagenInstalled() {
|
|
85
|
+
const asset = getBundledMutagenAsset();
|
|
86
|
+
if (!asset) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}.`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return installBundledMutagen(asset);
|
|
92
|
+
}
|
|
93
|
+
function resolveMutagenCommandPath() {
|
|
94
|
+
const overridden = process.env[AGENTCOMPUTER_MUTAGEN_PATH_ENV]?.trim();
|
|
95
|
+
if (overridden) {
|
|
96
|
+
return overridden;
|
|
97
|
+
}
|
|
98
|
+
const asset = getBundledMutagenAsset();
|
|
99
|
+
if (asset && existsSync(asset.executablePath)) {
|
|
100
|
+
return asset.executablePath;
|
|
101
|
+
}
|
|
102
|
+
const systemPath = resolveSystemCommandPath("mutagen");
|
|
103
|
+
if (systemPath) {
|
|
104
|
+
return systemPath;
|
|
105
|
+
}
|
|
106
|
+
if (!asset) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}. Install Mutagen manually and rerun \`computer mount\`.`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
throw new Error(
|
|
112
|
+
"Mutagen is not installed yet. Re-run `computer mount` and Agent Computer will install its bundled copy."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
async function installBundledMutagen(asset) {
|
|
116
|
+
if (existsSync(asset.executablePath)) {
|
|
117
|
+
return asset.executablePath;
|
|
118
|
+
}
|
|
119
|
+
mkdirSync(dirname(asset.installDir), { recursive: true });
|
|
120
|
+
const stagingDir = `${asset.installDir}.staging-${process.pid}-${Date.now()}`;
|
|
121
|
+
const archivePath = join(stagingDir, asset.assetName);
|
|
122
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
123
|
+
if (existsSync(asset.installDir) && !existsSync(asset.executablePath)) {
|
|
124
|
+
rmSync(asset.installDir, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
mkdirSync(stagingDir, { recursive: true });
|
|
127
|
+
try {
|
|
128
|
+
const response = await fetch(asset.downloadUrl, {
|
|
129
|
+
headers: {
|
|
130
|
+
"User-Agent": "aicomputer-cli"
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok || !response.body) {
|
|
134
|
+
throw new Error(`download failed with status ${response.status}`);
|
|
135
|
+
}
|
|
136
|
+
await writeFile(archivePath, Buffer.from(await response.arrayBuffer()), {
|
|
137
|
+
mode: 384
|
|
138
|
+
});
|
|
139
|
+
const extract = spawnSync("tar", ["-xzf", archivePath, "-C", stagingDir], {
|
|
140
|
+
encoding: "utf8"
|
|
141
|
+
});
|
|
142
|
+
if (extract.status !== 0) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
extract.stderr.trim() || extract.stdout.trim() || `failed to extract ${asset.assetName}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (!existsSync(join(stagingDir, "mutagen"))) {
|
|
148
|
+
throw new Error("archive did not contain the Mutagen executable");
|
|
149
|
+
}
|
|
150
|
+
chmodSync(join(stagingDir, "mutagen"), 493);
|
|
151
|
+
rmSync(archivePath, { force: true });
|
|
152
|
+
try {
|
|
153
|
+
renameSync(stagingDir, asset.installDir);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!existsSync(asset.executablePath)) {
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
159
|
+
}
|
|
160
|
+
return asset.executablePath;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function isSupportedPlatform(platform) {
|
|
167
|
+
return platform === "darwin" || platform === "linux";
|
|
168
|
+
}
|
|
169
|
+
function isSupportedArch(arch) {
|
|
170
|
+
return arch === "arm64" || arch === "x64";
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/lib/mount-mutagen.ts
|
|
174
|
+
var SYNC_NAME_PREFIX = "agentcomputer-mount-";
|
|
175
|
+
var DEFAULT_IGNORE_PATHS = [
|
|
176
|
+
".codex/tmp",
|
|
177
|
+
".local",
|
|
178
|
+
".ssh/sshd.log"
|
|
179
|
+
];
|
|
180
|
+
function ensureMutagenSshEnvironment(config, paths) {
|
|
181
|
+
ensureMountDirectories(paths);
|
|
182
|
+
const sshPath = resolveCommandPath("ssh");
|
|
183
|
+
const scpPath = resolveCommandPath("scp");
|
|
184
|
+
writeExecutableLink(paths.sshToolsDir, "ssh", sshPath);
|
|
185
|
+
writeExecutableLink(paths.sshToolsDir, "scp", scpPath);
|
|
186
|
+
writeExecutableLink(paths.sshToolsDir, basename(sshPath), sshPath);
|
|
187
|
+
writeExecutableLink(paths.sshToolsDir, basename(scpPath), scpPath);
|
|
188
|
+
}
|
|
189
|
+
function getHandleSessionName(handle) {
|
|
190
|
+
return `${SYNC_NAME_PREFIX}${handle}`;
|
|
191
|
+
}
|
|
192
|
+
function getDefaultMountIgnorePaths() {
|
|
193
|
+
return [...DEFAULT_IGNORE_PATHS];
|
|
194
|
+
}
|
|
195
|
+
function createHandleSession(handle, config, paths, signal) {
|
|
196
|
+
ensureHandleDirectories(handle, config.rootPath);
|
|
197
|
+
const sessionName = getHandleSessionName(handle);
|
|
198
|
+
const args = [
|
|
199
|
+
"sync",
|
|
200
|
+
"create",
|
|
201
|
+
join2(paths.rootPath, handle),
|
|
202
|
+
`${handle}@${config.alias}:/home/node`,
|
|
203
|
+
"--name",
|
|
204
|
+
sessionName,
|
|
205
|
+
"--label",
|
|
206
|
+
`${MOUNT_SERVICE_LABEL}=true`,
|
|
207
|
+
"--label",
|
|
208
|
+
`${MOUNT_SERVICE_LABEL}.handle=${handle}`,
|
|
209
|
+
"--symlink-mode",
|
|
210
|
+
"posix-raw"
|
|
211
|
+
];
|
|
212
|
+
for (const ignorePath of DEFAULT_IGNORE_PATHS) {
|
|
213
|
+
args.push("--ignore", ignorePath);
|
|
214
|
+
}
|
|
215
|
+
return runMutagen(args, config, paths, handle, { signal }).then(async () => {
|
|
216
|
+
await runMutagen(
|
|
217
|
+
["sync", "flush", sessionName, "--skip-wait"],
|
|
218
|
+
config,
|
|
219
|
+
paths,
|
|
220
|
+
handle,
|
|
221
|
+
{ signal }
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function terminateSession(session, config, paths, signal) {
|
|
226
|
+
return runMutagen(
|
|
227
|
+
["sync", "terminate", session.identifier],
|
|
228
|
+
config,
|
|
229
|
+
paths,
|
|
230
|
+
session.handle,
|
|
231
|
+
{ ignoreFailure: true, signal }
|
|
232
|
+
).then(() => void 0);
|
|
233
|
+
}
|
|
234
|
+
function inspectHandleSession(handle, config, paths, signal) {
|
|
235
|
+
return listOwnedSessions(config, paths, signal).then((sessions) => {
|
|
236
|
+
const matching = sessions.filter((session) => session.handle === handle);
|
|
237
|
+
if (matching.length === 0) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
return selectPreferredSession(handle, matching);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
async function listOwnedSessions(config, paths, signal) {
|
|
244
|
+
const result = await runMutagen(["sync", "list", "-l"], config, paths, "mount", {
|
|
245
|
+
ignoreFailure: true,
|
|
246
|
+
signal
|
|
247
|
+
});
|
|
248
|
+
const raw = [result.stdout, result.stderr].filter(Boolean).join("\n").trim();
|
|
249
|
+
if (!raw) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
if (!result.ok && raw.includes("No synchronization sessions found")) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
const rootPath = resolve(paths.rootPath);
|
|
256
|
+
const sessions = parseMutagenSyncList(raw).filter((session) => session.alphaPath).map((session) => {
|
|
257
|
+
const alphaPath = resolve(session.alphaPath);
|
|
258
|
+
const handle = basename(alphaPath);
|
|
259
|
+
const expectedName = getHandleSessionName(handle);
|
|
260
|
+
const expectedBeta = `${handle}@${config.alias}:/home/node`;
|
|
261
|
+
const owned = alphaPath === rootPath || relative(rootPath, alphaPath) === "" || !relative(rootPath, alphaPath).startsWith("..") && !relative(rootPath, alphaPath).startsWith("../");
|
|
262
|
+
if (!owned || !session.identifier) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
identifier: session.identifier,
|
|
267
|
+
name: session.name,
|
|
268
|
+
handle,
|
|
269
|
+
alphaPath,
|
|
270
|
+
betaUrl: session.betaUrl,
|
|
271
|
+
alphaConnected: session.alphaConnected,
|
|
272
|
+
betaConnected: session.betaConnected,
|
|
273
|
+
status: session.status,
|
|
274
|
+
lastError: session.lastError,
|
|
275
|
+
scanProblemCount: session.scanProblemCount,
|
|
276
|
+
conflictCount: session.conflictCount,
|
|
277
|
+
legacy: session.name !== expectedName || session.betaUrl !== expectedBeta || alphaPath !== resolve(join2(rootPath, handle))
|
|
278
|
+
};
|
|
279
|
+
}).filter((session) => session !== null);
|
|
280
|
+
return sessions.sort((left, right) => left.handle.localeCompare(right.handle));
|
|
281
|
+
}
|
|
282
|
+
function selectPreferredSession(handle, sessions) {
|
|
283
|
+
const expectedName = getHandleSessionName(handle);
|
|
284
|
+
const exact = sessions.find((session) => session.name === expectedName);
|
|
285
|
+
return exact ?? sessions[0];
|
|
286
|
+
}
|
|
287
|
+
function parseMutagenSyncList(output) {
|
|
288
|
+
const sessions = [];
|
|
289
|
+
let current = null;
|
|
290
|
+
let section = "";
|
|
291
|
+
const finishCurrent = () => {
|
|
292
|
+
if (current?.identifier) {
|
|
293
|
+
sessions.push(current);
|
|
294
|
+
}
|
|
295
|
+
current = null;
|
|
296
|
+
section = "";
|
|
297
|
+
};
|
|
298
|
+
for (const line of output.split(/\r?\n/)) {
|
|
299
|
+
if (/^-{20,}$/.test(line.trim())) {
|
|
300
|
+
finishCurrent();
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const trimmed = line.trim();
|
|
304
|
+
if (!trimmed) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (!current) {
|
|
308
|
+
current = {
|
|
309
|
+
alphaConnected: false,
|
|
310
|
+
betaConnected: false,
|
|
311
|
+
scanProblemCount: 0,
|
|
312
|
+
conflictCount: 0
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (trimmed.endsWith(":")) {
|
|
316
|
+
switch (trimmed.slice(0, -1)) {
|
|
317
|
+
case "Alpha":
|
|
318
|
+
case "Beta":
|
|
319
|
+
case "Scan problems":
|
|
320
|
+
case "Conflicts":
|
|
321
|
+
section = trimmed.slice(0, -1);
|
|
322
|
+
continue;
|
|
323
|
+
default:
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (trimmed.startsWith("Name: ")) {
|
|
328
|
+
current.name = trimmed.slice("Name: ".length);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (trimmed.startsWith("Identifier: ")) {
|
|
332
|
+
current.identifier = trimmed.slice("Identifier: ".length);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (trimmed.startsWith("Status: ")) {
|
|
336
|
+
current.status = trimmed.slice("Status: ".length);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (trimmed.startsWith("Last error: ")) {
|
|
340
|
+
current.lastError = trimmed.slice("Last error: ".length);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (section === "Alpha") {
|
|
344
|
+
if (trimmed.startsWith("URL: ")) {
|
|
345
|
+
current.alphaPath = trimmed.slice("URL: ".length);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (trimmed.startsWith("Connected: ")) {
|
|
349
|
+
current.alphaConnected = parseConnected(trimmed);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (section === "Beta") {
|
|
354
|
+
if (trimmed.startsWith("URL: ")) {
|
|
355
|
+
current.betaUrl = trimmed.slice("URL: ".length);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (trimmed.startsWith("Connected: ")) {
|
|
359
|
+
current.betaConnected = parseConnected(trimmed);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (section === "Scan problems") {
|
|
364
|
+
current.scanProblemCount += 1;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (section === "Conflicts") {
|
|
368
|
+
if (trimmed.startsWith("(alpha)")) {
|
|
369
|
+
current.conflictCount += 1;
|
|
370
|
+
}
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
finishCurrent();
|
|
375
|
+
return sessions;
|
|
376
|
+
}
|
|
377
|
+
function parseConnected(line) {
|
|
378
|
+
return line.slice("Connected: ".length).trim().toLowerCase() === "yes";
|
|
379
|
+
}
|
|
380
|
+
function isAbortError(error) {
|
|
381
|
+
return error instanceof Error && error.name === "AbortError";
|
|
382
|
+
}
|
|
383
|
+
async function runMutagen(args, config, paths, handle, options = {}) {
|
|
384
|
+
if (options.signal?.aborted) {
|
|
385
|
+
throw createAbortError(handle);
|
|
386
|
+
}
|
|
387
|
+
return new Promise((resolve2, reject) => {
|
|
388
|
+
const child = spawn(resolveMutagenCommandPath(), args, {
|
|
389
|
+
env: {
|
|
390
|
+
...process.env,
|
|
391
|
+
MUTAGEN_SSH_PATH: paths.sshToolsDir,
|
|
392
|
+
MUTAGEN_SSH_CONNECT_TIMEOUT: String(config.connectTimeoutSeconds)
|
|
393
|
+
},
|
|
394
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
395
|
+
});
|
|
396
|
+
let stdout = "";
|
|
397
|
+
let stderr = "";
|
|
398
|
+
let settled = false;
|
|
399
|
+
let killTimer = null;
|
|
400
|
+
const finish = (callback) => {
|
|
401
|
+
if (settled) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
settled = true;
|
|
405
|
+
if (killTimer) {
|
|
406
|
+
clearTimeout(killTimer);
|
|
407
|
+
}
|
|
408
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
409
|
+
callback();
|
|
410
|
+
};
|
|
411
|
+
const onAbort = () => {
|
|
412
|
+
if (child.exitCode !== null) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
child.kill("SIGTERM");
|
|
416
|
+
killTimer = setTimeout(() => {
|
|
417
|
+
if (child.exitCode === null) {
|
|
418
|
+
child.kill("SIGKILL");
|
|
419
|
+
}
|
|
420
|
+
}, 1e3);
|
|
421
|
+
};
|
|
422
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
423
|
+
child.stdout?.setEncoding("utf8");
|
|
424
|
+
child.stdout?.on("data", (chunk) => {
|
|
425
|
+
stdout += chunk;
|
|
426
|
+
});
|
|
427
|
+
child.stderr?.setEncoding("utf8");
|
|
428
|
+
child.stderr?.on("data", (chunk) => {
|
|
429
|
+
stderr += chunk;
|
|
430
|
+
});
|
|
431
|
+
child.once("error", (error) => {
|
|
432
|
+
finish(() => {
|
|
433
|
+
reject(options.signal?.aborted ? createAbortError(handle) : error);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
child.once("close", (code) => {
|
|
437
|
+
const result = {
|
|
438
|
+
ok: code === 0,
|
|
439
|
+
stdout: stdout.trim(),
|
|
440
|
+
stderr: stderr.trim(),
|
|
441
|
+
status: code
|
|
442
|
+
};
|
|
443
|
+
finish(() => {
|
|
444
|
+
if (options.signal?.aborted) {
|
|
445
|
+
reject(createAbortError(handle));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (code !== 0 && !options.ignoreFailure) {
|
|
449
|
+
reject(
|
|
450
|
+
new Error(result.stderr || result.stdout || `mutagen failed for ${handle}`)
|
|
451
|
+
);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
resolve2(result);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
function createAbortError(handle) {
|
|
460
|
+
const error = new Error(`mutagen cancelled for ${handle}`);
|
|
461
|
+
error.name = "AbortError";
|
|
462
|
+
return error;
|
|
463
|
+
}
|
|
464
|
+
function resolveCommandPath(command) {
|
|
465
|
+
const result = spawnSync2("which", [command], { encoding: "utf8" });
|
|
466
|
+
if (result.status !== 0) {
|
|
467
|
+
throw new Error(`failed to resolve ${command}`);
|
|
468
|
+
}
|
|
469
|
+
return result.stdout.trim();
|
|
470
|
+
}
|
|
471
|
+
function writeExecutableLink(directory, name, target) {
|
|
472
|
+
const linkPath = join2(directory, name);
|
|
473
|
+
try {
|
|
474
|
+
unlinkSync(linkPath);
|
|
475
|
+
} catch {
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
symlinkSync(target, linkPath);
|
|
479
|
+
} catch {
|
|
480
|
+
const script = `#!/bin/sh
|
|
481
|
+
exec "${escapeShell(target)}" "$@"
|
|
482
|
+
`;
|
|
483
|
+
writeFileSync(linkPath, script, { mode: 493 });
|
|
484
|
+
chmodSync2(linkPath, 493);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
try {
|
|
488
|
+
const stat = readFileSync(linkPath);
|
|
489
|
+
if (!stat) {
|
|
490
|
+
throw new Error("empty");
|
|
491
|
+
}
|
|
492
|
+
} catch {
|
|
493
|
+
const script = `#!/bin/sh
|
|
494
|
+
exec "${escapeShell(target)}" "$@"
|
|
495
|
+
`;
|
|
496
|
+
writeFileSync(linkPath, script, { mode: 493 });
|
|
497
|
+
chmodSync2(linkPath, 493);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function escapeShell(value) {
|
|
501
|
+
return value.replaceAll("\\", "\\\\").replaceAll("`", "\\`").replaceAll("$", "\\$").replaceAll('"', '\\"');
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export {
|
|
505
|
+
AGENTCOMPUTER_MUTAGEN_PATH_ENV,
|
|
506
|
+
ensureMutagenCommandPath,
|
|
507
|
+
ensureBundledMutagenInstalled,
|
|
508
|
+
ensureMutagenSshEnvironment,
|
|
509
|
+
getHandleSessionName,
|
|
510
|
+
getDefaultMountIgnorePaths,
|
|
511
|
+
createHandleSession,
|
|
512
|
+
terminateSession,
|
|
513
|
+
inspectHandleSession,
|
|
514
|
+
listOwnedSessions,
|
|
515
|
+
selectPreferredSession,
|
|
516
|
+
isAbortError
|
|
517
|
+
};
|
|
@@ -3,7 +3,6 @@ import { spawnSync } from "child_process";
|
|
|
3
3
|
function getMountHostValidationIssues() {
|
|
4
4
|
return evaluateMountHostValidation({
|
|
5
5
|
platform: process.platform,
|
|
6
|
-
hasMutagen: hasCommand("mutagen"),
|
|
7
6
|
hasSsh: hasCommand("ssh"),
|
|
8
7
|
hasScp: hasCommand("scp")
|
|
9
8
|
});
|
|
@@ -13,10 +12,9 @@ function formatMountHostInstallGuidance(issues) {
|
|
|
13
12
|
for (const issue of issues) {
|
|
14
13
|
switch (issue.code) {
|
|
15
14
|
case "unsupported-platform":
|
|
16
|
-
lines.push(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
lines.push("Install Mutagen, then rerun `computer mount`.");
|
|
15
|
+
lines.push(
|
|
16
|
+
"Supported today: macOS and Linux terminals with bundled Mutagen plus OpenSSH client tools available."
|
|
17
|
+
);
|
|
20
18
|
break;
|
|
21
19
|
case "missing-ssh":
|
|
22
20
|
case "missing-scp":
|
|
@@ -38,12 +36,6 @@ function evaluateMountHostValidation(input) {
|
|
|
38
36
|
});
|
|
39
37
|
return issues;
|
|
40
38
|
}
|
|
41
|
-
if (!input.hasMutagen) {
|
|
42
|
-
issues.push({
|
|
43
|
-
code: "missing-mutagen",
|
|
44
|
-
message: "mutagen is not installed. Install Mutagen before using computer mount."
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
39
|
if (!input.hasSsh) {
|
|
48
40
|
issues.push({
|
|
49
41
|
code: "missing-ssh",
|