@madarco/agentbox 0.18.0 → 0.19.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/CHANGELOG.md +56 -0
- package/README.md +4 -3
- package/dist/{_cloud-attach-3UC3IL62.js → _cloud-attach-YM2KOWHO.js} +4 -4
- package/dist/{chunk-6QFPYU4Z.js → chunk-7K2A3NLE.js} +8 -5
- package/dist/chunk-7K2A3NLE.js.map +1 -0
- package/dist/{chunk-U7IZS2ZP.js → chunk-A5OFRJDI.js} +1313 -213
- package/dist/chunk-A5OFRJDI.js.map +1 -0
- package/dist/{chunk-5BO6SGMI.js → chunk-JK5V4OLT.js} +7 -7
- package/dist/{chunk-IA6YHH52.js → chunk-MODNW54N.js} +6 -3
- package/dist/{chunk-IA6YHH52.js.map → chunk-MODNW54N.js.map} +1 -1
- package/dist/{chunk-46NXCJ6Z.js → chunk-NXX3KQZ6.js} +2 -2
- package/dist/{chunk-3JXSW6PN.js → chunk-P6UT5XGE.js} +2 -2
- package/dist/{chunk-OG4KMYOJ.js → chunk-SPUUOEW2.js} +273 -54
- package/dist/chunk-SPUUOEW2.js.map +1 -0
- package/dist/{chunk-XWBFWUY2.js → chunk-Y6PUCLOE.js} +2 -2
- package/dist/{dist-CFSKUAS5.js → dist-EKSNZHDY.js} +13 -3
- package/dist/{dist-7BS2JS27.js → dist-FTCDWRAL.js} +18 -7
- package/dist/dist-FTCDWRAL.js.map +1 -0
- package/dist/{dist-4BHW7DCO.js → dist-PRDYMXCX.js} +10 -5
- package/dist/dist-PRDYMXCX.js.map +1 -0
- package/dist/{dist-3UYQZOAO.js → dist-U2BHTWG4.js} +17 -5
- package/dist/dist-U2BHTWG4.js.map +1 -0
- package/dist/{dist-T7ESSBCZ.js → dist-VQSZVBT3.js} +20 -6
- package/dist/dist-VQSZVBT3.js.map +1 -0
- package/dist/index.js +471 -311
- package/dist/index.js.map +1 -1
- package/dist/{prepared-state-MQHD3M5F-OVABNV66.js → prepared-state-MQHD3M5F-5ZMCNY43.js} +2 -2
- package/package.json +5 -5
- package/runtime/docker/apps/cli/share/agentbox-setup/SKILL.md +1 -1
- package/runtime/docker/packages/ctl/dist/bin.cjs +133 -107
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +13 -0
- package/runtime/e2b/agentbox-setup-skill.md +1 -1
- package/runtime/e2b/ctl.cjs +133 -107
- package/runtime/hetzner/agentbox-dockerd-start +13 -0
- package/runtime/hetzner/agentbox-setup-skill.md +1 -1
- package/runtime/hetzner/ctl.cjs +133 -107
- package/runtime/relay/bin.cjs +261 -63
- package/runtime/vercel/agentbox-dockerd-start +145 -0
- package/runtime/vercel/agentbox-setup-skill.md +1 -1
- package/runtime/vercel/ctl.cjs +133 -107
- package/runtime/vercel/custom-system-CLAUDE.md +5 -4
- package/runtime/vercel/scripts/provision.sh +20 -5
- package/share/agentbox-setup/SKILL.md +1 -1
- package/share/host-skills/agentbox/SKILL.md +2 -2
- package/share/host-skills/codex/agentbox.md +10 -2
- package/dist/chunk-6QFPYU4Z.js.map +0 -1
- package/dist/chunk-OG4KMYOJ.js.map +0 -1
- package/dist/chunk-U7IZS2ZP.js.map +0 -1
- package/dist/dist-3UYQZOAO.js.map +0 -1
- package/dist/dist-4BHW7DCO.js.map +0 -1
- package/dist/dist-7BS2JS27.js.map +0 -1
- package/dist/dist-T7ESSBCZ.js.map +0 -1
- /package/dist/{_cloud-attach-3UC3IL62.js.map → _cloud-attach-YM2KOWHO.js.map} +0 -0
- /package/dist/{chunk-5BO6SGMI.js.map → chunk-JK5V4OLT.js.map} +0 -0
- /package/dist/{chunk-46NXCJ6Z.js.map → chunk-NXX3KQZ6.js.map} +0 -0
- /package/dist/{chunk-3JXSW6PN.js.map → chunk-P6UT5XGE.js.map} +0 -0
- /package/dist/{chunk-XWBFWUY2.js.map → chunk-Y6PUCLOE.js.map} +0 -0
- /package/dist/{dist-CFSKUAS5.js.map → dist-EKSNZHDY.js.map} +0 -0
- /package/dist/{prepared-state-MQHD3M5F-OVABNV66.js.map → prepared-state-MQHD3M5F-5ZMCNY43.js.map} +0 -0
package/runtime/relay/bin.cjs
CHANGED
|
@@ -3130,12 +3130,12 @@ var require_isexe = __commonJS({
|
|
|
3130
3130
|
if (typeof Promise !== "function") {
|
|
3131
3131
|
throw new TypeError("callback not provided");
|
|
3132
3132
|
}
|
|
3133
|
-
return new Promise(function(
|
|
3133
|
+
return new Promise(function(resolve3, reject) {
|
|
3134
3134
|
isexe(path6, options || {}, function(er, is) {
|
|
3135
3135
|
if (er) {
|
|
3136
3136
|
reject(er);
|
|
3137
3137
|
} else {
|
|
3138
|
-
|
|
3138
|
+
resolve3(is);
|
|
3139
3139
|
}
|
|
3140
3140
|
});
|
|
3141
3141
|
});
|
|
@@ -3202,27 +3202,27 @@ var require_which = __commonJS({
|
|
|
3202
3202
|
opt = {};
|
|
3203
3203
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
3204
3204
|
const found = [];
|
|
3205
|
-
const step = (i2) => new Promise((
|
|
3205
|
+
const step = (i2) => new Promise((resolve3, reject) => {
|
|
3206
3206
|
if (i2 === pathEnv.length)
|
|
3207
|
-
return opt.all && found.length ?
|
|
3207
|
+
return opt.all && found.length ? resolve3(found) : reject(getNotFoundError(cmd));
|
|
3208
3208
|
const ppRaw = pathEnv[i2];
|
|
3209
3209
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
3210
3210
|
const pCmd = path6.join(pathPart, cmd);
|
|
3211
3211
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
3212
|
-
|
|
3212
|
+
resolve3(subStep(p, i2, 0));
|
|
3213
3213
|
});
|
|
3214
|
-
const subStep = (p, i2, ii) => new Promise((
|
|
3214
|
+
const subStep = (p, i2, ii) => new Promise((resolve3, reject) => {
|
|
3215
3215
|
if (ii === pathExt.length)
|
|
3216
|
-
return
|
|
3216
|
+
return resolve3(step(i2 + 1));
|
|
3217
3217
|
const ext = pathExt[ii];
|
|
3218
3218
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
3219
3219
|
if (!er && is) {
|
|
3220
3220
|
if (opt.all)
|
|
3221
3221
|
found.push(p + ext);
|
|
3222
3222
|
else
|
|
3223
|
-
return
|
|
3223
|
+
return resolve3(p + ext);
|
|
3224
3224
|
}
|
|
3225
|
-
return
|
|
3225
|
+
return resolve3(subStep(p, i2, ii + 1));
|
|
3226
3226
|
});
|
|
3227
3227
|
});
|
|
3228
3228
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -10947,7 +10947,7 @@ var init_cloud_poller = __esm({
|
|
|
10947
10947
|
stderr: result.stderr
|
|
10948
10948
|
};
|
|
10949
10949
|
const payload = JSON.stringify(body);
|
|
10950
|
-
await new Promise((
|
|
10950
|
+
await new Promise((resolve3, reject) => {
|
|
10951
10951
|
const headers = {
|
|
10952
10952
|
"Content-Type": "application/json",
|
|
10953
10953
|
"Content-Length": Buffer.byteLength(payload).toString(),
|
|
@@ -10967,7 +10967,7 @@ var init_cloud_poller = __esm({
|
|
|
10967
10967
|
},
|
|
10968
10968
|
(res) => {
|
|
10969
10969
|
res.resume();
|
|
10970
|
-
if ((res.statusCode ?? 0) >= 200 && (res.statusCode ?? 0) < 300)
|
|
10970
|
+
if ((res.statusCode ?? 0) >= 200 && (res.statusCode ?? 0) < 300) resolve3();
|
|
10971
10971
|
else reject(new Error(`bridge/action-result \u2192 ${String(res.statusCode)}`));
|
|
10972
10972
|
}
|
|
10973
10973
|
);
|
|
@@ -11072,7 +11072,7 @@ var init_cloud_poller = __esm({
|
|
|
11072
11072
|
const transport = isHttps ? import_node_https.request : import_node_http.request;
|
|
11073
11073
|
const port = url.port.length > 0 ? Number.parseInt(url.port, 10) : isHttps ? 443 : 80;
|
|
11074
11074
|
const timeoutMs = this.fastModePolls > 0 ? FAST_REQUEST_TIMEOUT_MS : REQUEST_TIMEOUT_MS;
|
|
11075
|
-
return new Promise((
|
|
11075
|
+
return new Promise((resolve3, reject) => {
|
|
11076
11076
|
const headers = {
|
|
11077
11077
|
Authorization: `Bearer ${this.deps.bridgeToken}`,
|
|
11078
11078
|
Accept: "application/json"
|
|
@@ -11101,7 +11101,7 @@ var init_cloud_poller = __esm({
|
|
|
11101
11101
|
}
|
|
11102
11102
|
try {
|
|
11103
11103
|
const parsed = JSON.parse(text);
|
|
11104
|
-
|
|
11104
|
+
resolve3({
|
|
11105
11105
|
actions: Array.isArray(parsed.actions) ? parsed.actions : [],
|
|
11106
11106
|
events: Array.isArray(parsed.events) ? parsed.events : [],
|
|
11107
11107
|
status: parsed.status ?? null,
|
|
@@ -12730,8 +12730,8 @@ var disconnect = (anyProcess) => {
|
|
|
12730
12730
|
// ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/utils/deferred.js
|
|
12731
12731
|
var createDeferred = () => {
|
|
12732
12732
|
const methods = {};
|
|
12733
|
-
const promise = new Promise((
|
|
12734
|
-
Object.assign(methods, { resolve:
|
|
12733
|
+
const promise = new Promise((resolve3, reject) => {
|
|
12734
|
+
Object.assign(methods, { resolve: resolve3, reject });
|
|
12735
12735
|
});
|
|
12736
12736
|
return Object.assign(promise, methods);
|
|
12737
12737
|
};
|
|
@@ -17368,11 +17368,11 @@ var addConcurrentStream = (concurrentStreams, stream, waitName) => {
|
|
|
17368
17368
|
const promises = weakMap.get(stream);
|
|
17369
17369
|
const promise = createDeferred();
|
|
17370
17370
|
promises.push(promise);
|
|
17371
|
-
const
|
|
17372
|
-
return { resolve:
|
|
17371
|
+
const resolve3 = promise.resolve.bind(promise);
|
|
17372
|
+
return { resolve: resolve3, promises };
|
|
17373
17373
|
};
|
|
17374
|
-
var waitForConcurrentStreams = async ({ resolve:
|
|
17375
|
-
|
|
17374
|
+
var waitForConcurrentStreams = async ({ resolve: resolve3, promises }, subprocess) => {
|
|
17375
|
+
resolve3();
|
|
17376
17376
|
const [isSubprocessExit] = await Promise.race([
|
|
17377
17377
|
Promise.allSettled([true, subprocess]),
|
|
17378
17378
|
Promise.all([false, ...promises])
|
|
@@ -17974,8 +17974,11 @@ var PLACEHOLDER_KEYS = [
|
|
|
17974
17974
|
"AGENTBOX_BOX_KIND",
|
|
17975
17975
|
"AGENTBOX_HOST_WORKSPACE",
|
|
17976
17976
|
"AGENTBOX_PROJECT_ROOT",
|
|
17977
|
-
// Convenience: the
|
|
17978
|
-
//
|
|
17977
|
+
// Convenience: the host this box is reachable at. Derived from
|
|
17978
|
+
// AGENTBOX_BOX_NAME as `<box-name>.localhost` when not set explicitly (the
|
|
17979
|
+
// portless host for docker/hetzner). Public-URL cloud providers
|
|
17980
|
+
// (vercel/daytona/e2b) set it explicitly at boot to the real preview host
|
|
17981
|
+
// (e.g. `<sub>.vercel.run`), which then wins over the derived fallback.
|
|
17979
17982
|
"AGENTBOX_BOX_HOST"
|
|
17980
17983
|
];
|
|
17981
17984
|
var PLACEHOLDER_SET = new Set(PLACEHOLDER_KEYS);
|
|
@@ -18197,7 +18200,7 @@ async function probeGh() {
|
|
|
18197
18200
|
return null;
|
|
18198
18201
|
}
|
|
18199
18202
|
function runHostGh(args, cwd, timeoutMs = GH_RPC_TIMEOUT_MS) {
|
|
18200
|
-
return new Promise((
|
|
18203
|
+
return new Promise((resolve3) => {
|
|
18201
18204
|
const child = (0, import_node_child_process6.spawn)("gh", args, {
|
|
18202
18205
|
cwd,
|
|
18203
18206
|
env: process.env,
|
|
@@ -18209,7 +18212,7 @@ function runHostGh(args, cwd, timeoutMs = GH_RPC_TIMEOUT_MS) {
|
|
|
18209
18212
|
const finish = (exitCode) => {
|
|
18210
18213
|
if (settled) return;
|
|
18211
18214
|
settled = true;
|
|
18212
|
-
|
|
18215
|
+
resolve3({ exitCode, stdout, stderr });
|
|
18213
18216
|
};
|
|
18214
18217
|
const timer = setTimeout(() => {
|
|
18215
18218
|
child.kill("SIGTERM");
|
|
@@ -18273,7 +18276,7 @@ async function checkoutGuards(hostMainRepo, registeredBranches) {
|
|
|
18273
18276
|
return null;
|
|
18274
18277
|
}
|
|
18275
18278
|
function runGitProbe(args) {
|
|
18276
|
-
return new Promise((
|
|
18279
|
+
return new Promise((resolve3) => {
|
|
18277
18280
|
const child = (0, import_node_child_process6.spawn)("git", args, { env: process.env, stdio: ["ignore", "pipe", "pipe"] });
|
|
18278
18281
|
let stdout = "";
|
|
18279
18282
|
let stderr = "";
|
|
@@ -18284,10 +18287,10 @@ function runGitProbe(args) {
|
|
|
18284
18287
|
stderr += c3.toString("utf8");
|
|
18285
18288
|
});
|
|
18286
18289
|
child.on("error", (err) => {
|
|
18287
|
-
|
|
18290
|
+
resolve3({ exitCode: 127, stdout, stderr: stderr + String(err.message ?? err) });
|
|
18288
18291
|
});
|
|
18289
18292
|
child.on("close", (code) => {
|
|
18290
|
-
|
|
18293
|
+
resolve3({ exitCode: code ?? -1, stdout, stderr });
|
|
18291
18294
|
});
|
|
18292
18295
|
});
|
|
18293
18296
|
}
|
|
@@ -19296,7 +19299,7 @@ function runHostBinary(connector, argv, cwd, timeoutMs) {
|
|
|
19296
19299
|
`
|
|
19297
19300
|
});
|
|
19298
19301
|
}
|
|
19299
|
-
return new Promise((
|
|
19302
|
+
return new Promise((resolve3) => {
|
|
19300
19303
|
const child = (0, import_node_child_process7.spawn)(connector.hostBin, [...argv], {
|
|
19301
19304
|
cwd,
|
|
19302
19305
|
env,
|
|
@@ -19308,7 +19311,7 @@ function runHostBinary(connector, argv, cwd, timeoutMs) {
|
|
|
19308
19311
|
const finish = (exitCode) => {
|
|
19309
19312
|
if (settled) return;
|
|
19310
19313
|
settled = true;
|
|
19311
|
-
|
|
19314
|
+
resolve3({ exitCode, stdout, stderr });
|
|
19312
19315
|
};
|
|
19313
19316
|
const timer = setTimeout(() => {
|
|
19314
19317
|
child.kill("SIGTERM");
|
|
@@ -19384,11 +19387,11 @@ var PendingPrompts = class {
|
|
|
19384
19387
|
return true;
|
|
19385
19388
|
}
|
|
19386
19389
|
add(boxId, ev) {
|
|
19387
|
-
return new Promise((
|
|
19390
|
+
return new Promise((resolve3) => {
|
|
19388
19391
|
this.entries.set(ev.id, {
|
|
19389
19392
|
ev,
|
|
19390
19393
|
boxId,
|
|
19391
|
-
resolve:
|
|
19394
|
+
resolve: resolve3,
|
|
19392
19395
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
19393
19396
|
});
|
|
19394
19397
|
});
|
|
@@ -20132,6 +20135,17 @@ async function lookupCloudBox(boxId) {
|
|
|
20132
20135
|
}
|
|
20133
20136
|
return { workspacePath: hit.box.workspacePath, cloudSandboxId: sid };
|
|
20134
20137
|
}
|
|
20138
|
+
async function boxWorkspacePath(boxId) {
|
|
20139
|
+
const state = await readState();
|
|
20140
|
+
const hit = findBox(boxId, state);
|
|
20141
|
+
return hit.kind === "ok" ? hit.box.workspacePath : void 0;
|
|
20142
|
+
}
|
|
20143
|
+
function resolveHostPath(workspacePath, hostPath) {
|
|
20144
|
+
if ((0, import_node_path6.isAbsolute)(hostPath)) return hostPath;
|
|
20145
|
+
if (hostPath === "~") return (0, import_node_os4.homedir)();
|
|
20146
|
+
if (hostPath.startsWith("~/")) return (0, import_node_path6.join)((0, import_node_os4.homedir)(), hostPath.slice(2));
|
|
20147
|
+
return workspacePath ? (0, import_node_path6.resolve)(workspacePath, hostPath) : (0, import_node_path6.resolve)(hostPath);
|
|
20148
|
+
}
|
|
20135
20149
|
var cloudCpModule;
|
|
20136
20150
|
async function loadCloudCp() {
|
|
20137
20151
|
if (cloudCpModule) return cloudCpModule;
|
|
@@ -20160,27 +20174,28 @@ async function runCpRpc(action, deps) {
|
|
|
20160
20174
|
};
|
|
20161
20175
|
}
|
|
20162
20176
|
const direction = action.method === "cp.toHost" ? "box -> host" : "host -> box";
|
|
20177
|
+
const lookup = await lookupCloudBox(deps.boxId);
|
|
20178
|
+
const hostAbs = resolveHostPath(lookup.workspacePath, params.hostPath);
|
|
20163
20179
|
if (deps.prompts && deps.subscribers) {
|
|
20164
20180
|
const verdict = await askPrompt(deps.prompts, deps.subscribers, deps.boxId, {
|
|
20165
20181
|
kind: "confirm",
|
|
20166
20182
|
message: `Allow cp (${direction}) on ${deps.boxName ?? deps.boxId}?`,
|
|
20167
|
-
detail: action.method === "cp.toHost" ? `${params.boxPath} -> ${
|
|
20183
|
+
detail: action.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`,
|
|
20168
20184
|
defaultAnswer: "n",
|
|
20169
20185
|
context: {
|
|
20170
20186
|
command: action.method,
|
|
20171
|
-
argv: [params.boxPath,
|
|
20187
|
+
argv: [params.boxPath, hostAbs]
|
|
20172
20188
|
}
|
|
20173
20189
|
});
|
|
20174
20190
|
if (verdict.answer !== "y") {
|
|
20175
20191
|
return { exitCode: 10, stdout: "", stderr: "denied by user\n" };
|
|
20176
20192
|
}
|
|
20177
20193
|
}
|
|
20178
|
-
const lookup = await lookupCloudBox(deps.boxId);
|
|
20179
20194
|
const backend = await resolveCloudBackend(deps.backendName);
|
|
20180
20195
|
const handle = { sandboxId: lookup.cloudSandboxId };
|
|
20181
20196
|
const cp = await loadCloudCp();
|
|
20182
20197
|
try {
|
|
20183
|
-
const result = action.method === "cp.toHost" ? await cp.downloadFromCloudBox(backend, handle, params.boxPath,
|
|
20198
|
+
const result = action.method === "cp.toHost" ? await cp.downloadFromCloudBox(backend, handle, params.boxPath, hostAbs) : await cp.uploadToCloudBox(backend, handle, hostAbs, params.boxPath);
|
|
20184
20199
|
return { exitCode: 0, stdout: `${result.finalPath}
|
|
20185
20200
|
`, stderr: "" };
|
|
20186
20201
|
} catch (err) {
|
|
@@ -20256,7 +20271,7 @@ async function runDownloadRpc(action, deps) {
|
|
|
20256
20271
|
const backend = await resolveCloudBackend(deps.backendName);
|
|
20257
20272
|
const handle = { sandboxId: lookup.cloudSandboxId };
|
|
20258
20273
|
const cp = await loadCloudCp();
|
|
20259
|
-
const hostDst = typeof params.hostPath === "string" && params.hostPath.length > 0 ? params.hostPath : lookup.workspacePath;
|
|
20274
|
+
const hostDst = typeof params.hostPath === "string" && params.hostPath.length > 0 ? resolveHostPath(lookup.workspacePath, params.hostPath) : lookup.workspacePath;
|
|
20260
20275
|
try {
|
|
20261
20276
|
const result = await cp.pullCloudDirContents(backend, handle, "/workspace", hostDst);
|
|
20262
20277
|
return { exitCode: 0, stdout: `${result.finalPath}
|
|
@@ -20497,8 +20512,8 @@ var HostActionQueue = class {
|
|
|
20497
20512
|
params,
|
|
20498
20513
|
createdAt: new Date(this.now()).toISOString()
|
|
20499
20514
|
};
|
|
20500
|
-
return new Promise((
|
|
20501
|
-
this.map.set(id, { action, resolve:
|
|
20515
|
+
return new Promise((resolve3) => {
|
|
20516
|
+
this.map.set(id, { action, resolve: resolve3, delivered: false });
|
|
20502
20517
|
});
|
|
20503
20518
|
}
|
|
20504
20519
|
/**
|
|
@@ -20750,7 +20765,7 @@ function send(res, status, body, contentType = "application/json") {
|
|
|
20750
20765
|
}
|
|
20751
20766
|
}
|
|
20752
20767
|
async function readJsonBody(req) {
|
|
20753
|
-
return new Promise((
|
|
20768
|
+
return new Promise((resolve3, reject) => {
|
|
20754
20769
|
let total = 0;
|
|
20755
20770
|
const chunks = [];
|
|
20756
20771
|
req.on("data", (chunk) => {
|
|
@@ -20765,11 +20780,11 @@ async function readJsonBody(req) {
|
|
|
20765
20780
|
req.on("end", () => {
|
|
20766
20781
|
const text = Buffer.concat(chunks).toString("utf8");
|
|
20767
20782
|
if (text.length === 0) {
|
|
20768
|
-
|
|
20783
|
+
resolve3({});
|
|
20769
20784
|
return;
|
|
20770
20785
|
}
|
|
20771
20786
|
try {
|
|
20772
|
-
|
|
20787
|
+
resolve3(JSON.parse(text));
|
|
20773
20788
|
} catch (err) {
|
|
20774
20789
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
20775
20790
|
}
|
|
@@ -21003,7 +21018,9 @@ function createRelayServer(opts) {
|
|
|
21003
21018
|
return;
|
|
21004
21019
|
}
|
|
21005
21020
|
const direction = body.method === "cp.toHost" ? "box -> host" : "host -> box";
|
|
21006
|
-
const
|
|
21021
|
+
const workspacePath = await boxWorkspacePath(reg.boxId);
|
|
21022
|
+
const hostAbs = resolveHostPath(workspacePath, params.hostPath);
|
|
21023
|
+
const pathDetail = body.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`;
|
|
21007
21024
|
const detailParts = [pathDetail];
|
|
21008
21025
|
if (params.exclude && params.exclude.length > 0) {
|
|
21009
21026
|
detailParts.push(`exclude: ${params.exclude.join(", ")}`);
|
|
@@ -21017,14 +21034,17 @@ function createRelayServer(opts) {
|
|
|
21017
21034
|
defaultAnswer: "n",
|
|
21018
21035
|
context: {
|
|
21019
21036
|
command: body.method,
|
|
21020
|
-
argv: [params.boxPath,
|
|
21037
|
+
argv: [params.boxPath, hostAbs]
|
|
21021
21038
|
}
|
|
21022
21039
|
});
|
|
21023
21040
|
if (verdict.answer !== "y") {
|
|
21024
21041
|
send(res, 500, { exitCode: 10, stdout: "", stderr: "denied by user\n" });
|
|
21025
21042
|
return;
|
|
21026
21043
|
}
|
|
21027
|
-
const result = await handleCpRpc(reg, body.method, params
|
|
21044
|
+
const result = await handleCpRpc(reg, body.method, params, {
|
|
21045
|
+
hostPath: hostAbs,
|
|
21046
|
+
cwd: workspacePath
|
|
21047
|
+
});
|
|
21028
21048
|
const status = result.exitCode === 0 ? 200 : 500;
|
|
21029
21049
|
send(res, status, result);
|
|
21030
21050
|
return;
|
|
@@ -21455,10 +21475,10 @@ data: {"ts":"${(/* @__PURE__ */ new Date()).toISOString()}"}
|
|
|
21455
21475
|
},
|
|
21456
21476
|
close: async () => {
|
|
21457
21477
|
if (pollers) await pollers.stopAll();
|
|
21458
|
-
await new Promise((
|
|
21478
|
+
await new Promise((resolve3, reject) => {
|
|
21459
21479
|
server.close((err) => {
|
|
21460
21480
|
if (err) reject(err);
|
|
21461
|
-
else
|
|
21481
|
+
else resolve3();
|
|
21462
21482
|
});
|
|
21463
21483
|
});
|
|
21464
21484
|
}
|
|
@@ -21695,7 +21715,7 @@ async function handleIntegrationRpc(method, reg, params, prompts, subscribers, h
|
|
|
21695
21715
|
}
|
|
21696
21716
|
return runHostIntegration(connector, opDesc, args, worktree.hostMainRepo);
|
|
21697
21717
|
}
|
|
21698
|
-
async function handleCpRpc(reg, method, params) {
|
|
21718
|
+
async function handleCpRpc(reg, method, params, opts) {
|
|
21699
21719
|
const entry = process.env.AGENTBOX_CLI_ENTRY;
|
|
21700
21720
|
if (!entry) {
|
|
21701
21721
|
return {
|
|
@@ -21709,8 +21729,8 @@ async function handleCpRpc(reg, method, params) {
|
|
|
21709
21729
|
for (const pat of params.exclude ?? []) flags.push("--exclude", pat);
|
|
21710
21730
|
if (params.defaultExcludes === false) flags.push("--no-default-excludes");
|
|
21711
21731
|
if (params.yes) flags.push("--yes");
|
|
21712
|
-
const argv = method === "cp.toHost" ? [process.execPath, entry, "cp", boxRef,
|
|
21713
|
-
return runHostCommand(argv, CP_RPC_TIMEOUT_MS);
|
|
21732
|
+
const argv = method === "cp.toHost" ? [process.execPath, entry, "cp", boxRef, opts.hostPath, ...flags] : [process.execPath, entry, "cp", opts.hostPath, boxRef, ...flags];
|
|
21733
|
+
return runHostCommand(argv, CP_RPC_TIMEOUT_MS, opts.cwd);
|
|
21714
21734
|
}
|
|
21715
21735
|
async function handleDownloadRpc(reg, kind) {
|
|
21716
21736
|
const entry = process.env.AGENTBOX_CLI_ENTRY;
|
|
@@ -21724,7 +21744,8 @@ async function handleDownloadRpc(reg, kind) {
|
|
|
21724
21744
|
const argv = [process.execPath, entry, "download"];
|
|
21725
21745
|
if (kind !== "workspace") argv.push(kind);
|
|
21726
21746
|
argv.push(reg.name, "-y");
|
|
21727
|
-
|
|
21747
|
+
const cwd = await boxWorkspacePath(reg.boxId);
|
|
21748
|
+
return runHostCommand(argv, DOWNLOAD_RPC_TIMEOUT_MS, cwd);
|
|
21728
21749
|
}
|
|
21729
21750
|
async function handleCheckpointRpc(reg, params) {
|
|
21730
21751
|
const entry = process.env.AGENTBOX_CLI_ENTRY;
|
|
@@ -21751,16 +21772,20 @@ function isOpenableUrl(value) {
|
|
|
21751
21772
|
}
|
|
21752
21773
|
return url.protocol === "http:" || url.protocol === "https:";
|
|
21753
21774
|
}
|
|
21754
|
-
function runHostCommand(argv, timeoutMs = GIT_RPC_TIMEOUT_MS) {
|
|
21755
|
-
return new Promise((
|
|
21775
|
+
function runHostCommand(argv, timeoutMs = GIT_RPC_TIMEOUT_MS, cwd) {
|
|
21776
|
+
return new Promise((resolve3) => {
|
|
21756
21777
|
const [cmd, ...rest] = argv;
|
|
21757
21778
|
if (!cmd) {
|
|
21758
|
-
|
|
21779
|
+
resolve3({ exitCode: 64, stdout: "", stderr: "empty command" });
|
|
21759
21780
|
return;
|
|
21760
21781
|
}
|
|
21761
21782
|
const child = (0, import_node_child_process8.spawn)(cmd, rest, {
|
|
21762
21783
|
env: process.env,
|
|
21763
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
21784
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
21785
|
+
// Default to the relay daemon's CWD when unset (legacy behaviour); callers
|
|
21786
|
+
// that know the box pass its workspace so relative host paths + project
|
|
21787
|
+
// config resolve against the box, not whatever dir launched the relay.
|
|
21788
|
+
...cwd ? { cwd } : {}
|
|
21764
21789
|
});
|
|
21765
21790
|
let stdout = "";
|
|
21766
21791
|
let stderr = "";
|
|
@@ -21768,7 +21793,7 @@ function runHostCommand(argv, timeoutMs = GIT_RPC_TIMEOUT_MS) {
|
|
|
21768
21793
|
const finish = (exitCode) => {
|
|
21769
21794
|
if (settled) return;
|
|
21770
21795
|
settled = true;
|
|
21771
|
-
|
|
21796
|
+
resolve3({ exitCode, stdout, stderr });
|
|
21772
21797
|
};
|
|
21773
21798
|
const timer = setTimeout(() => {
|
|
21774
21799
|
child.kill("SIGTERM");
|
|
@@ -21796,11 +21821,11 @@ relay: command timed out after ${String(timeoutMs)}ms
|
|
|
21796
21821
|
}
|
|
21797
21822
|
async function startRelayServer(opts) {
|
|
21798
21823
|
const handle = createRelayServer(opts);
|
|
21799
|
-
await new Promise((
|
|
21824
|
+
await new Promise((resolve3, reject) => {
|
|
21800
21825
|
handle.server.once("error", reject);
|
|
21801
21826
|
handle.server.listen(opts.port, opts.host ?? "0.0.0.0", () => {
|
|
21802
21827
|
handle.server.removeListener("error", reject);
|
|
21803
|
-
|
|
21828
|
+
resolve3();
|
|
21804
21829
|
});
|
|
21805
21830
|
});
|
|
21806
21831
|
return handle;
|
|
@@ -22377,7 +22402,7 @@ function toEpoch(iso) {
|
|
|
22377
22402
|
var INSPECT_TIMEOUT_MS = 15e3;
|
|
22378
22403
|
var PAUSE_TIMEOUT_MS = 3e4;
|
|
22379
22404
|
function runDocker(args, timeoutMs) {
|
|
22380
|
-
return new Promise((
|
|
22405
|
+
return new Promise((resolve3) => {
|
|
22381
22406
|
const child = (0, import_node_child_process10.spawn)("docker", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
22382
22407
|
let stdout = "";
|
|
22383
22408
|
let stderr = "";
|
|
@@ -22385,7 +22410,7 @@ function runDocker(args, timeoutMs) {
|
|
|
22385
22410
|
const finish = (exitCode) => {
|
|
22386
22411
|
if (settled) return;
|
|
22387
22412
|
settled = true;
|
|
22388
|
-
|
|
22413
|
+
resolve3({ exitCode, stdout, stderr });
|
|
22389
22414
|
};
|
|
22390
22415
|
const timer = setTimeout(() => {
|
|
22391
22416
|
child.kill("SIGTERM");
|
|
@@ -22436,6 +22461,173 @@ async function pauseContainer(name) {
|
|
|
22436
22461
|
}
|
|
22437
22462
|
}
|
|
22438
22463
|
|
|
22464
|
+
// src/cloud-keepalive.ts
|
|
22465
|
+
var import_promises21 = require("fs/promises");
|
|
22466
|
+
function selectBoxesToRenew(entries, windowMs, now) {
|
|
22467
|
+
const out = [];
|
|
22468
|
+
for (const e of entries) {
|
|
22469
|
+
if (e.agentState == null) continue;
|
|
22470
|
+
let target = null;
|
|
22471
|
+
if (e.agentState === "active") {
|
|
22472
|
+
target = now + windowMs;
|
|
22473
|
+
} else if (e.agentState === "idle" && e.lastActivityMs != null && now - e.lastActivityMs < windowMs) {
|
|
22474
|
+
target = e.lastActivityMs + windowMs;
|
|
22475
|
+
}
|
|
22476
|
+
if (target != null) {
|
|
22477
|
+
out.push({ boxId: e.boxId, backend: e.backend, targetDeadlineEpochMs: target });
|
|
22478
|
+
}
|
|
22479
|
+
}
|
|
22480
|
+
return out;
|
|
22481
|
+
}
|
|
22482
|
+
function coarseKeepaliveState(s) {
|
|
22483
|
+
switch (s) {
|
|
22484
|
+
case "working":
|
|
22485
|
+
case "compacting":
|
|
22486
|
+
case "waiting":
|
|
22487
|
+
case "question":
|
|
22488
|
+
case "end-plan":
|
|
22489
|
+
return "active";
|
|
22490
|
+
case "idle":
|
|
22491
|
+
return "idle";
|
|
22492
|
+
default:
|
|
22493
|
+
return null;
|
|
22494
|
+
}
|
|
22495
|
+
}
|
|
22496
|
+
var DEFAULT_INTERVAL_MS3 = 6e4;
|
|
22497
|
+
var FAILURE_BACKOFF_MS = 5 * 6e4;
|
|
22498
|
+
function startCloudKeepaliveLoop(deps) {
|
|
22499
|
+
const loadConfig = deps.loadConfig ?? loadAutopauseConfig;
|
|
22500
|
+
const resolveBackend = deps.resolveBackend ?? resolveCloudBackend;
|
|
22501
|
+
const lookupBox = deps.lookupBox ?? defaultLookupBox;
|
|
22502
|
+
const fallbackCreateTimeoutMs = deps.fallbackCreateTimeoutMs ?? defaultFallbackCreateTimeoutMs;
|
|
22503
|
+
const nowFn = deps.now ?? Date.now;
|
|
22504
|
+
const intervalMs = deps.intervalMs ?? DEFAULT_INTERVAL_MS3;
|
|
22505
|
+
const { registry, statusStore, log } = deps;
|
|
22506
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
22507
|
+
const backoffUntil = /* @__PURE__ */ new Map();
|
|
22508
|
+
const backendCache = /* @__PURE__ */ new Map();
|
|
22509
|
+
let ticking = false;
|
|
22510
|
+
let stopped = false;
|
|
22511
|
+
let inFlight = Promise.resolve();
|
|
22512
|
+
async function resolveCached(name) {
|
|
22513
|
+
if (backendCache.has(name)) return backendCache.get(name) ?? null;
|
|
22514
|
+
let backend = null;
|
|
22515
|
+
try {
|
|
22516
|
+
backend = await resolveBackend(name);
|
|
22517
|
+
} catch {
|
|
22518
|
+
backend = null;
|
|
22519
|
+
}
|
|
22520
|
+
backendCache.set(name, backend);
|
|
22521
|
+
return backend;
|
|
22522
|
+
}
|
|
22523
|
+
async function tick() {
|
|
22524
|
+
if (ticking) return;
|
|
22525
|
+
ticking = true;
|
|
22526
|
+
try {
|
|
22527
|
+
const cfg = await loadConfig();
|
|
22528
|
+
if (!cfg.enabled) return;
|
|
22529
|
+
const windowMs = cfg.idleMinutes * 6e4;
|
|
22530
|
+
const now = nowFn();
|
|
22531
|
+
const live = /* @__PURE__ */ new Set();
|
|
22532
|
+
const entries = [];
|
|
22533
|
+
for (const reg of registry.list()) {
|
|
22534
|
+
if (reg.kind !== "cloud" || !reg.backend) continue;
|
|
22535
|
+
const backend = await resolveCached(reg.backend);
|
|
22536
|
+
if (!backend || typeof backend.renewTimeout !== "function") continue;
|
|
22537
|
+
live.add(reg.boxId);
|
|
22538
|
+
const active = readActiveAgent(statusStore.get(reg.boxId));
|
|
22539
|
+
entries.push({
|
|
22540
|
+
boxId: reg.boxId,
|
|
22541
|
+
backend: reg.backend,
|
|
22542
|
+
agentState: coarseKeepaliveState(active.state),
|
|
22543
|
+
lastActivityMs: active.updatedAt ? toEpoch2(active.updatedAt) : null
|
|
22544
|
+
});
|
|
22545
|
+
}
|
|
22546
|
+
for (const id of [...tracked.keys()]) if (!live.has(id)) tracked.delete(id);
|
|
22547
|
+
for (const id of [...backoffUntil.keys()]) if (!live.has(id)) backoffUntil.delete(id);
|
|
22548
|
+
const decisions = selectBoxesToRenew(entries, windowMs, now);
|
|
22549
|
+
for (const d of decisions) {
|
|
22550
|
+
const until = backoffUntil.get(d.boxId);
|
|
22551
|
+
if (until != null && now < until) continue;
|
|
22552
|
+
const lookup = await lookupBox(d.boxId);
|
|
22553
|
+
if (!lookup) continue;
|
|
22554
|
+
let current = tracked.get(d.boxId);
|
|
22555
|
+
if (current == null) {
|
|
22556
|
+
const createMs = lookup.createdAtMs ?? now;
|
|
22557
|
+
const createTimeoutMs = lookup.createTimeoutMs ?? await fallbackCreateTimeoutMs(d.backend);
|
|
22558
|
+
current = createMs + createTimeoutMs;
|
|
22559
|
+
tracked.set(d.boxId, current);
|
|
22560
|
+
}
|
|
22561
|
+
if (d.targetDeadlineEpochMs <= current + intervalMs) continue;
|
|
22562
|
+
try {
|
|
22563
|
+
const backend = await resolveCached(d.backend);
|
|
22564
|
+
if (!backend?.renewTimeout) continue;
|
|
22565
|
+
await backend.renewTimeout({ sandboxId: lookup.sandboxId }, d.targetDeadlineEpochMs, current);
|
|
22566
|
+
tracked.set(d.boxId, d.targetDeadlineEpochMs);
|
|
22567
|
+
backoffUntil.delete(d.boxId);
|
|
22568
|
+
log(
|
|
22569
|
+
`cloud-keepalive: renewed box ${d.boxId} (${d.backend}) +${String(Math.round((d.targetDeadlineEpochMs - now) / 6e4))}m`
|
|
22570
|
+
);
|
|
22571
|
+
} catch (err) {
|
|
22572
|
+
backoffUntil.set(d.boxId, now + FAILURE_BACKOFF_MS);
|
|
22573
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
22574
|
+
log(`cloud-keepalive: renew box ${d.boxId} (${d.backend}) failed: ${msg}`);
|
|
22575
|
+
}
|
|
22576
|
+
}
|
|
22577
|
+
} catch (err) {
|
|
22578
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
22579
|
+
log(`cloud-keepalive: tick error: ${msg}`);
|
|
22580
|
+
} finally {
|
|
22581
|
+
ticking = false;
|
|
22582
|
+
}
|
|
22583
|
+
}
|
|
22584
|
+
const timer = setInterval(() => {
|
|
22585
|
+
if (stopped) return;
|
|
22586
|
+
inFlight = tick();
|
|
22587
|
+
}, intervalMs);
|
|
22588
|
+
timer.unref();
|
|
22589
|
+
return {
|
|
22590
|
+
stop: async () => {
|
|
22591
|
+
stopped = true;
|
|
22592
|
+
clearInterval(timer);
|
|
22593
|
+
await inFlight.catch(() => {
|
|
22594
|
+
});
|
|
22595
|
+
}
|
|
22596
|
+
};
|
|
22597
|
+
}
|
|
22598
|
+
function toEpoch2(iso) {
|
|
22599
|
+
if (!iso) return null;
|
|
22600
|
+
const t = Date.parse(iso);
|
|
22601
|
+
return Number.isNaN(t) ? null : t;
|
|
22602
|
+
}
|
|
22603
|
+
async function defaultLookupBox(boxId) {
|
|
22604
|
+
const state = await readState();
|
|
22605
|
+
const hit = findBox(boxId, state);
|
|
22606
|
+
if (hit.kind !== "ok") return null;
|
|
22607
|
+
const sandboxId = hit.box.cloud?.sandboxId;
|
|
22608
|
+
if (!sandboxId) return null;
|
|
22609
|
+
return {
|
|
22610
|
+
sandboxId,
|
|
22611
|
+
createdAtMs: toEpoch2(hit.box.createdAt),
|
|
22612
|
+
createTimeoutMs: hit.box.cloud?.sessionTimeoutMs ?? null
|
|
22613
|
+
};
|
|
22614
|
+
}
|
|
22615
|
+
async function defaultFallbackCreateTimeoutMs(backend) {
|
|
22616
|
+
const generic = 45 * 6e4;
|
|
22617
|
+
if (backend !== "vercel") return generic;
|
|
22618
|
+
const fallback = BUILT_IN_DEFAULTS.box.vercelTimeoutMs;
|
|
22619
|
+
try {
|
|
22620
|
+
const global3 = parseUserConfig(
|
|
22621
|
+
await (0, import_promises21.readFile)(GLOBAL_CONFIG_FILE, "utf8"),
|
|
22622
|
+
GLOBAL_CONFIG_FILE
|
|
22623
|
+
);
|
|
22624
|
+
const v = global3.box?.vercelTimeoutMs;
|
|
22625
|
+
return typeof v === "number" && v > 0 ? v : fallback;
|
|
22626
|
+
} catch {
|
|
22627
|
+
return fallback;
|
|
22628
|
+
}
|
|
22629
|
+
}
|
|
22630
|
+
|
|
22439
22631
|
// src/bin.ts
|
|
22440
22632
|
var program2 = new Command();
|
|
22441
22633
|
program2.name("agentbox-relay").description("Host-side HTTP relay for box\u2192host events and RPCs").version("0.0.0");
|
|
@@ -22459,6 +22651,12 @@ program2.command("serve").description("Run the HTTP relay in the foreground").op
|
|
|
22459
22651
|
statusStore: handle.statusStore,
|
|
22460
22652
|
events: handle.events,
|
|
22461
22653
|
log: (line) => process.stdout.write(`agentbox-relay: ${line}
|
|
22654
|
+
`)
|
|
22655
|
+
});
|
|
22656
|
+
const cloudKeepalive = startCloudKeepaliveLoop({
|
|
22657
|
+
registry: handle.registry,
|
|
22658
|
+
statusStore: handle.statusStore,
|
|
22659
|
+
log: (line) => process.stdout.write(`agentbox-relay: ${line}
|
|
22462
22660
|
`)
|
|
22463
22661
|
});
|
|
22464
22662
|
const queue = startQueueLoop({
|
|
@@ -22473,7 +22671,7 @@ program2.command("serve").description("Run the HTTP relay in the foreground").op
|
|
|
22473
22671
|
const shutdown = (signal) => {
|
|
22474
22672
|
process.stdout.write(`agentbox-relay: ${signal} \u2014 shutting down
|
|
22475
22673
|
`);
|
|
22476
|
-
Promise.allSettled([autopause.stop(), queue.stop()]).finally(() => handle.close()).finally(() => process.exit(0));
|
|
22674
|
+
Promise.allSettled([autopause.stop(), cloudKeepalive.stop(), queue.stop()]).finally(() => handle.close()).finally(() => process.exit(0));
|
|
22477
22675
|
};
|
|
22478
22676
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
22479
22677
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
@@ -22494,7 +22692,7 @@ program2.command("tail").description("Print recent events (in-container shim; GE
|
|
|
22494
22692
|
async function adminPost(path6, body, portStr) {
|
|
22495
22693
|
const port = Number.parseInt(portStr, 10);
|
|
22496
22694
|
const json = JSON.stringify(body);
|
|
22497
|
-
await new Promise((
|
|
22695
|
+
await new Promise((resolve3, reject) => {
|
|
22498
22696
|
const req = (0, import_node_http3.request)(
|
|
22499
22697
|
{
|
|
22500
22698
|
host: "127.0.0.1",
|
|
@@ -22512,7 +22710,7 @@ async function adminPost(path6, body, portStr) {
|
|
|
22512
22710
|
res.on("end", () => {
|
|
22513
22711
|
const status = res.statusCode ?? 0;
|
|
22514
22712
|
if (status >= 200 && status < 300) {
|
|
22515
|
-
|
|
22713
|
+
resolve3();
|
|
22516
22714
|
} else {
|
|
22517
22715
|
const text = Buffer.concat(chunks).toString("utf8");
|
|
22518
22716
|
reject(new Error(`relay ${path6} \u2192 ${String(status)}: ${text}`));
|
|
@@ -22527,7 +22725,7 @@ async function adminPost(path6, body, portStr) {
|
|
|
22527
22725
|
}
|
|
22528
22726
|
async function adminGet(path6, portStr) {
|
|
22529
22727
|
const port = Number.parseInt(portStr, 10);
|
|
22530
|
-
return new Promise((
|
|
22728
|
+
return new Promise((resolve3, reject) => {
|
|
22531
22729
|
const req = (0, import_node_http3.request)(
|
|
22532
22730
|
{ host: "127.0.0.1", port, method: "GET", path: path6 },
|
|
22533
22731
|
(res) => {
|
|
@@ -22536,7 +22734,7 @@ async function adminGet(path6, portStr) {
|
|
|
22536
22734
|
res.on("end", () => {
|
|
22537
22735
|
const text = Buffer.concat(chunks).toString("utf8");
|
|
22538
22736
|
const status = res.statusCode ?? 0;
|
|
22539
|
-
if (status >= 200 && status < 300)
|
|
22737
|
+
if (status >= 200 && status < 300) resolve3(text);
|
|
22540
22738
|
else reject(new Error(`relay ${path6} \u2192 ${String(status)}: ${text}`));
|
|
22541
22739
|
});
|
|
22542
22740
|
}
|