@madarco/agentbox 0.18.0 → 0.20.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +4 -3
  3. package/dist/_cloud-attach-THTN4CFZ.js +18 -0
  4. package/dist/{chunk-U7IZS2ZP.js → chunk-3VFY3N4A.js} +1388 -234
  5. package/dist/chunk-3VFY3N4A.js.map +1 -0
  6. package/dist/{chunk-XWBFWUY2.js → chunk-52LKNUY7.js} +6 -3
  7. package/dist/chunk-52LKNUY7.js.map +1 -0
  8. package/dist/{chunk-6QFPYU4Z.js → chunk-7K2A3NLE.js} +8 -5
  9. package/dist/chunk-7K2A3NLE.js.map +1 -0
  10. package/dist/{chunk-5BO6SGMI.js → chunk-7RWFYLF3.js} +194 -34
  11. package/dist/chunk-7RWFYLF3.js.map +1 -0
  12. package/dist/{chunk-IA6YHH52.js → chunk-MODNW54N.js} +6 -3
  13. package/dist/{chunk-IA6YHH52.js.map → chunk-MODNW54N.js.map} +1 -1
  14. package/dist/{chunk-46NXCJ6Z.js → chunk-NXX3KQZ6.js} +2 -2
  15. package/dist/{chunk-3JXSW6PN.js → chunk-P6UT5XGE.js} +2 -2
  16. package/dist/{chunk-OG4KMYOJ.js → chunk-ZX6DTA4X.js} +276 -56
  17. package/dist/chunk-ZX6DTA4X.js.map +1 -0
  18. package/dist/{dist-CFSKUAS5.js → dist-3PLT2EK2.js} +17 -3
  19. package/dist/{dist-T7ESSBCZ.js → dist-3WFNXXPE.js} +20 -6
  20. package/dist/dist-3WFNXXPE.js.map +1 -0
  21. package/dist/{dist-3UYQZOAO.js → dist-7ELDXBAG.js} +19 -6
  22. package/dist/dist-7ELDXBAG.js.map +1 -0
  23. package/dist/{dist-4BHW7DCO.js → dist-C3YRC3PP.js} +10 -5
  24. package/dist/dist-C3YRC3PP.js.map +1 -0
  25. package/dist/{dist-7BS2JS27.js → dist-CZ6CRADC.js} +18 -7
  26. package/dist/dist-CZ6CRADC.js.map +1 -0
  27. package/dist/index.js +1218 -560
  28. package/dist/index.js.map +1 -1
  29. package/dist/{prepared-state-MQHD3M5F-OVABNV66.js → prepared-state-MQHD3M5F-5ZMCNY43.js} +2 -2
  30. package/package.json +4 -4
  31. package/runtime/docker/apps/cli/share/agentbox-setup/SKILL.md +1 -1
  32. package/runtime/docker/packages/ctl/dist/bin.cjs +255 -169
  33. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +13 -0
  34. package/runtime/docker/packages/sandbox-docker/scripts/claude-managed-settings.json +4 -4
  35. package/runtime/e2b/agentbox-dockerd-start +145 -0
  36. package/runtime/e2b/agentbox-setup-skill.md +1 -1
  37. package/runtime/e2b/attach-helper.cjs +23 -2
  38. package/runtime/e2b/claude-managed-settings.json +4 -4
  39. package/runtime/e2b/ctl.cjs +255 -169
  40. package/runtime/e2b/scripts/build-template.sh +22 -5
  41. package/runtime/hetzner/agentbox-dockerd-start +13 -0
  42. package/runtime/hetzner/agentbox-setup-skill.md +1 -1
  43. package/runtime/hetzner/claude-managed-settings.json +4 -4
  44. package/runtime/hetzner/ctl.cjs +255 -169
  45. package/runtime/relay/bin.cjs +267 -63
  46. package/runtime/vercel/agentbox-dockerd-start +145 -0
  47. package/runtime/vercel/agentbox-setup-skill.md +1 -1
  48. package/runtime/vercel/claude-managed-settings.json +4 -4
  49. package/runtime/vercel/ctl.cjs +255 -169
  50. package/runtime/vercel/custom-system-CLAUDE.md +5 -4
  51. package/runtime/vercel/scripts/provision.sh +20 -5
  52. package/share/agentbox-setup/SKILL.md +1 -1
  53. package/share/host-skills/agentbox/SKILL.md +4 -4
  54. package/share/host-skills/agentbox-info/SKILL.md +6 -6
  55. package/share/host-skills/codex/agentbox.md +12 -4
  56. package/share/host-skills/opencode/agentbox.md +2 -2
  57. package/dist/_cloud-attach-3UC3IL62.js +0 -16
  58. package/dist/chunk-5BO6SGMI.js.map +0 -1
  59. package/dist/chunk-6QFPYU4Z.js.map +0 -1
  60. package/dist/chunk-OG4KMYOJ.js.map +0 -1
  61. package/dist/chunk-U7IZS2ZP.js.map +0 -1
  62. package/dist/chunk-XWBFWUY2.js.map +0 -1
  63. package/dist/dist-3UYQZOAO.js.map +0 -1
  64. package/dist/dist-4BHW7DCO.js.map +0 -1
  65. package/dist/dist-7BS2JS27.js.map +0 -1
  66. package/dist/dist-T7ESSBCZ.js.map +0 -1
  67. /package/dist/{_cloud-attach-3UC3IL62.js.map → _cloud-attach-THTN4CFZ.js.map} +0 -0
  68. /package/dist/{chunk-46NXCJ6Z.js.map → chunk-NXX3KQZ6.js.map} +0 -0
  69. /package/dist/{chunk-3JXSW6PN.js.map → chunk-P6UT5XGE.js.map} +0 -0
  70. /package/dist/{dist-CFSKUAS5.js.map → dist-3PLT2EK2.js.map} +0 -0
  71. /package/dist/{prepared-state-MQHD3M5F-OVABNV66.js.map → prepared-state-MQHD3M5F-5ZMCNY43.js.map} +0 -0
@@ -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(resolve2, reject) {
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
- resolve2(is);
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((resolve2, reject) => {
3205
+ const step = (i2) => new Promise((resolve3, reject) => {
3206
3206
  if (i2 === pathEnv.length)
3207
- return opt.all && found.length ? resolve2(found) : reject(getNotFoundError(cmd));
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
- resolve2(subStep(p, i2, 0));
3212
+ resolve3(subStep(p, i2, 0));
3213
3213
  });
3214
- const subStep = (p, i2, ii) => new Promise((resolve2, reject) => {
3214
+ const subStep = (p, i2, ii) => new Promise((resolve3, reject) => {
3215
3215
  if (ii === pathExt.length)
3216
- return resolve2(step(i2 + 1));
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 resolve2(p + ext);
3223
+ return resolve3(p + ext);
3224
3224
  }
3225
- return resolve2(subStep(p, i2, ii + 1));
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((resolve2, reject) => {
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) resolve2();
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((resolve2, reject) => {
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
- resolve2({
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((resolve2, reject) => {
12734
- Object.assign(methods, { resolve: resolve2, reject });
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 resolve2 = promise.resolve.bind(promise);
17372
- return { resolve: resolve2, promises };
17371
+ const resolve3 = promise.resolve.bind(promise);
17372
+ return { resolve: resolve3, promises };
17373
17373
  };
17374
- var waitForConcurrentStreams = async ({ resolve: resolve2, promises }, subprocess) => {
17375
- resolve2();
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 portless host this box publishes (`<box-name>.localhost`).
17978
- // Derived from AGENTBOX_BOX_NAME when not set explicitly.
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((resolve2) => {
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
- resolve2({ exitCode, stdout, stderr });
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((resolve2) => {
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
- resolve2({ exitCode: 127, stdout, stderr: stderr + String(err.message ?? err) });
18290
+ resolve3({ exitCode: 127, stdout, stderr: stderr + String(err.message ?? err) });
18288
18291
  });
18289
18292
  child.on("close", (code) => {
18290
- resolve2({ exitCode: code ?? -1, stdout, stderr });
18293
+ resolve3({ exitCode: code ?? -1, stdout, stderr });
18291
18294
  });
18292
18295
  });
18293
18296
  }
@@ -18433,6 +18436,7 @@ var BUILT_IN_DEFAULTS = {
18433
18436
  vercelVcpus: 2,
18434
18437
  vercelTimeoutMs: 27e5,
18435
18438
  vercelNetworkPolicy: "",
18439
+ e2bTimeoutMs: 27e5,
18436
18440
  cpMaxBytes: 100 * 1024 * 1024
18437
18441
  },
18438
18442
  checkpoint: {
@@ -18716,6 +18720,11 @@ var KEY_REGISTRY = [
18716
18720
  type: "int",
18717
18721
  description: "Max session length (ms) for new --provider vercel boxes before the VM auto-snapshots; persistent mode auto-resumes on the next call. Default 2700000 (45 min, the Hobby ceiling). Vercel-only."
18718
18722
  },
18723
+ {
18724
+ key: "box.e2bTimeoutMs",
18725
+ type: "int",
18726
+ description: "Session timeout (ms) a new --provider e2b box is created with, before E2B auto-pauses it on inactivity. The host keepalive loop pushes this forward while the agent is working. Default 2700000 (45 min); the Hobby tier caps total session at ~1 h regardless. E2B-only."
18727
+ },
18719
18728
  {
18720
18729
  key: "box.cpMaxBytes",
18721
18730
  type: "int",
@@ -19296,7 +19305,7 @@ function runHostBinary(connector, argv, cwd, timeoutMs) {
19296
19305
  `
19297
19306
  });
19298
19307
  }
19299
- return new Promise((resolve2) => {
19308
+ return new Promise((resolve3) => {
19300
19309
  const child = (0, import_node_child_process7.spawn)(connector.hostBin, [...argv], {
19301
19310
  cwd,
19302
19311
  env,
@@ -19308,7 +19317,7 @@ function runHostBinary(connector, argv, cwd, timeoutMs) {
19308
19317
  const finish = (exitCode) => {
19309
19318
  if (settled) return;
19310
19319
  settled = true;
19311
- resolve2({ exitCode, stdout, stderr });
19320
+ resolve3({ exitCode, stdout, stderr });
19312
19321
  };
19313
19322
  const timer = setTimeout(() => {
19314
19323
  child.kill("SIGTERM");
@@ -19384,11 +19393,11 @@ var PendingPrompts = class {
19384
19393
  return true;
19385
19394
  }
19386
19395
  add(boxId, ev) {
19387
- return new Promise((resolve2) => {
19396
+ return new Promise((resolve3) => {
19388
19397
  this.entries.set(ev.id, {
19389
19398
  ev,
19390
19399
  boxId,
19391
- resolve: resolve2,
19400
+ resolve: resolve3,
19392
19401
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
19393
19402
  });
19394
19403
  });
@@ -20132,6 +20141,17 @@ async function lookupCloudBox(boxId) {
20132
20141
  }
20133
20142
  return { workspacePath: hit.box.workspacePath, cloudSandboxId: sid };
20134
20143
  }
20144
+ async function boxWorkspacePath(boxId) {
20145
+ const state = await readState();
20146
+ const hit = findBox(boxId, state);
20147
+ return hit.kind === "ok" ? hit.box.workspacePath : void 0;
20148
+ }
20149
+ function resolveHostPath(workspacePath, hostPath) {
20150
+ if ((0, import_node_path6.isAbsolute)(hostPath)) return hostPath;
20151
+ if (hostPath === "~") return (0, import_node_os4.homedir)();
20152
+ if (hostPath.startsWith("~/")) return (0, import_node_path6.join)((0, import_node_os4.homedir)(), hostPath.slice(2));
20153
+ return workspacePath ? (0, import_node_path6.resolve)(workspacePath, hostPath) : (0, import_node_path6.resolve)(hostPath);
20154
+ }
20135
20155
  var cloudCpModule;
20136
20156
  async function loadCloudCp() {
20137
20157
  if (cloudCpModule) return cloudCpModule;
@@ -20160,27 +20180,28 @@ async function runCpRpc(action, deps) {
20160
20180
  };
20161
20181
  }
20162
20182
  const direction = action.method === "cp.toHost" ? "box -> host" : "host -> box";
20183
+ const lookup = await lookupCloudBox(deps.boxId);
20184
+ const hostAbs = resolveHostPath(lookup.workspacePath, params.hostPath);
20163
20185
  if (deps.prompts && deps.subscribers) {
20164
20186
  const verdict = await askPrompt(deps.prompts, deps.subscribers, deps.boxId, {
20165
20187
  kind: "confirm",
20166
20188
  message: `Allow cp (${direction}) on ${deps.boxName ?? deps.boxId}?`,
20167
- detail: action.method === "cp.toHost" ? `${params.boxPath} -> ${params.hostPath}` : `${params.hostPath} -> ${params.boxPath}`,
20189
+ detail: action.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`,
20168
20190
  defaultAnswer: "n",
20169
20191
  context: {
20170
20192
  command: action.method,
20171
- argv: [params.boxPath, params.hostPath]
20193
+ argv: [params.boxPath, hostAbs]
20172
20194
  }
20173
20195
  });
20174
20196
  if (verdict.answer !== "y") {
20175
20197
  return { exitCode: 10, stdout: "", stderr: "denied by user\n" };
20176
20198
  }
20177
20199
  }
20178
- const lookup = await lookupCloudBox(deps.boxId);
20179
20200
  const backend = await resolveCloudBackend(deps.backendName);
20180
20201
  const handle = { sandboxId: lookup.cloudSandboxId };
20181
20202
  const cp = await loadCloudCp();
20182
20203
  try {
20183
- const result = action.method === "cp.toHost" ? await cp.downloadFromCloudBox(backend, handle, params.boxPath, params.hostPath) : await cp.uploadToCloudBox(backend, handle, params.hostPath, params.boxPath);
20204
+ const result = action.method === "cp.toHost" ? await cp.downloadFromCloudBox(backend, handle, params.boxPath, hostAbs) : await cp.uploadToCloudBox(backend, handle, hostAbs, params.boxPath);
20184
20205
  return { exitCode: 0, stdout: `${result.finalPath}
20185
20206
  `, stderr: "" };
20186
20207
  } catch (err) {
@@ -20256,7 +20277,7 @@ async function runDownloadRpc(action, deps) {
20256
20277
  const backend = await resolveCloudBackend(deps.backendName);
20257
20278
  const handle = { sandboxId: lookup.cloudSandboxId };
20258
20279
  const cp = await loadCloudCp();
20259
- const hostDst = typeof params.hostPath === "string" && params.hostPath.length > 0 ? params.hostPath : lookup.workspacePath;
20280
+ const hostDst = typeof params.hostPath === "string" && params.hostPath.length > 0 ? resolveHostPath(lookup.workspacePath, params.hostPath) : lookup.workspacePath;
20260
20281
  try {
20261
20282
  const result = await cp.pullCloudDirContents(backend, handle, "/workspace", hostDst);
20262
20283
  return { exitCode: 0, stdout: `${result.finalPath}
@@ -20497,8 +20518,8 @@ var HostActionQueue = class {
20497
20518
  params,
20498
20519
  createdAt: new Date(this.now()).toISOString()
20499
20520
  };
20500
- return new Promise((resolve2) => {
20501
- this.map.set(id, { action, resolve: resolve2, delivered: false });
20521
+ return new Promise((resolve3) => {
20522
+ this.map.set(id, { action, resolve: resolve3, delivered: false });
20502
20523
  });
20503
20524
  }
20504
20525
  /**
@@ -20750,7 +20771,7 @@ function send(res, status, body, contentType = "application/json") {
20750
20771
  }
20751
20772
  }
20752
20773
  async function readJsonBody(req) {
20753
- return new Promise((resolve2, reject) => {
20774
+ return new Promise((resolve3, reject) => {
20754
20775
  let total = 0;
20755
20776
  const chunks = [];
20756
20777
  req.on("data", (chunk) => {
@@ -20765,11 +20786,11 @@ async function readJsonBody(req) {
20765
20786
  req.on("end", () => {
20766
20787
  const text = Buffer.concat(chunks).toString("utf8");
20767
20788
  if (text.length === 0) {
20768
- resolve2({});
20789
+ resolve3({});
20769
20790
  return;
20770
20791
  }
20771
20792
  try {
20772
- resolve2(JSON.parse(text));
20793
+ resolve3(JSON.parse(text));
20773
20794
  } catch (err) {
20774
20795
  reject(err instanceof Error ? err : new Error(String(err)));
20775
20796
  }
@@ -21003,7 +21024,9 @@ function createRelayServer(opts) {
21003
21024
  return;
21004
21025
  }
21005
21026
  const direction = body.method === "cp.toHost" ? "box -> host" : "host -> box";
21006
- const pathDetail = body.method === "cp.toHost" ? `${params.boxPath} -> ${params.hostPath}` : `${params.hostPath} -> ${params.boxPath}`;
21027
+ const workspacePath = await boxWorkspacePath(reg.boxId);
21028
+ const hostAbs = resolveHostPath(workspacePath, params.hostPath);
21029
+ const pathDetail = body.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`;
21007
21030
  const detailParts = [pathDetail];
21008
21031
  if (params.exclude && params.exclude.length > 0) {
21009
21032
  detailParts.push(`exclude: ${params.exclude.join(", ")}`);
@@ -21017,14 +21040,17 @@ function createRelayServer(opts) {
21017
21040
  defaultAnswer: "n",
21018
21041
  context: {
21019
21042
  command: body.method,
21020
- argv: [params.boxPath, params.hostPath]
21043
+ argv: [params.boxPath, hostAbs]
21021
21044
  }
21022
21045
  });
21023
21046
  if (verdict.answer !== "y") {
21024
21047
  send(res, 500, { exitCode: 10, stdout: "", stderr: "denied by user\n" });
21025
21048
  return;
21026
21049
  }
21027
- const result = await handleCpRpc(reg, body.method, params);
21050
+ const result = await handleCpRpc(reg, body.method, params, {
21051
+ hostPath: hostAbs,
21052
+ cwd: workspacePath
21053
+ });
21028
21054
  const status = result.exitCode === 0 ? 200 : 500;
21029
21055
  send(res, status, result);
21030
21056
  return;
@@ -21455,10 +21481,10 @@ data: {"ts":"${(/* @__PURE__ */ new Date()).toISOString()}"}
21455
21481
  },
21456
21482
  close: async () => {
21457
21483
  if (pollers) await pollers.stopAll();
21458
- await new Promise((resolve2, reject) => {
21484
+ await new Promise((resolve3, reject) => {
21459
21485
  server.close((err) => {
21460
21486
  if (err) reject(err);
21461
- else resolve2();
21487
+ else resolve3();
21462
21488
  });
21463
21489
  });
21464
21490
  }
@@ -21695,7 +21721,7 @@ async function handleIntegrationRpc(method, reg, params, prompts, subscribers, h
21695
21721
  }
21696
21722
  return runHostIntegration(connector, opDesc, args, worktree.hostMainRepo);
21697
21723
  }
21698
- async function handleCpRpc(reg, method, params) {
21724
+ async function handleCpRpc(reg, method, params, opts) {
21699
21725
  const entry = process.env.AGENTBOX_CLI_ENTRY;
21700
21726
  if (!entry) {
21701
21727
  return {
@@ -21709,8 +21735,8 @@ async function handleCpRpc(reg, method, params) {
21709
21735
  for (const pat of params.exclude ?? []) flags.push("--exclude", pat);
21710
21736
  if (params.defaultExcludes === false) flags.push("--no-default-excludes");
21711
21737
  if (params.yes) flags.push("--yes");
21712
- const argv = method === "cp.toHost" ? [process.execPath, entry, "cp", boxRef, params.hostPath, ...flags] : [process.execPath, entry, "cp", params.hostPath, boxRef, ...flags];
21713
- return runHostCommand(argv, CP_RPC_TIMEOUT_MS);
21738
+ const argv = method === "cp.toHost" ? [process.execPath, entry, "cp", boxRef, opts.hostPath, ...flags] : [process.execPath, entry, "cp", opts.hostPath, boxRef, ...flags];
21739
+ return runHostCommand(argv, CP_RPC_TIMEOUT_MS, opts.cwd);
21714
21740
  }
21715
21741
  async function handleDownloadRpc(reg, kind) {
21716
21742
  const entry = process.env.AGENTBOX_CLI_ENTRY;
@@ -21724,7 +21750,8 @@ async function handleDownloadRpc(reg, kind) {
21724
21750
  const argv = [process.execPath, entry, "download"];
21725
21751
  if (kind !== "workspace") argv.push(kind);
21726
21752
  argv.push(reg.name, "-y");
21727
- return runHostCommand(argv, DOWNLOAD_RPC_TIMEOUT_MS);
21753
+ const cwd = await boxWorkspacePath(reg.boxId);
21754
+ return runHostCommand(argv, DOWNLOAD_RPC_TIMEOUT_MS, cwd);
21728
21755
  }
21729
21756
  async function handleCheckpointRpc(reg, params) {
21730
21757
  const entry = process.env.AGENTBOX_CLI_ENTRY;
@@ -21751,16 +21778,20 @@ function isOpenableUrl(value) {
21751
21778
  }
21752
21779
  return url.protocol === "http:" || url.protocol === "https:";
21753
21780
  }
21754
- function runHostCommand(argv, timeoutMs = GIT_RPC_TIMEOUT_MS) {
21755
- return new Promise((resolve2) => {
21781
+ function runHostCommand(argv, timeoutMs = GIT_RPC_TIMEOUT_MS, cwd) {
21782
+ return new Promise((resolve3) => {
21756
21783
  const [cmd, ...rest] = argv;
21757
21784
  if (!cmd) {
21758
- resolve2({ exitCode: 64, stdout: "", stderr: "empty command" });
21785
+ resolve3({ exitCode: 64, stdout: "", stderr: "empty command" });
21759
21786
  return;
21760
21787
  }
21761
21788
  const child = (0, import_node_child_process8.spawn)(cmd, rest, {
21762
21789
  env: process.env,
21763
- stdio: ["ignore", "pipe", "pipe"]
21790
+ stdio: ["ignore", "pipe", "pipe"],
21791
+ // Default to the relay daemon's CWD when unset (legacy behaviour); callers
21792
+ // that know the box pass its workspace so relative host paths + project
21793
+ // config resolve against the box, not whatever dir launched the relay.
21794
+ ...cwd ? { cwd } : {}
21764
21795
  });
21765
21796
  let stdout = "";
21766
21797
  let stderr = "";
@@ -21768,7 +21799,7 @@ function runHostCommand(argv, timeoutMs = GIT_RPC_TIMEOUT_MS) {
21768
21799
  const finish = (exitCode) => {
21769
21800
  if (settled) return;
21770
21801
  settled = true;
21771
- resolve2({ exitCode, stdout, stderr });
21802
+ resolve3({ exitCode, stdout, stderr });
21772
21803
  };
21773
21804
  const timer = setTimeout(() => {
21774
21805
  child.kill("SIGTERM");
@@ -21796,11 +21827,11 @@ relay: command timed out after ${String(timeoutMs)}ms
21796
21827
  }
21797
21828
  async function startRelayServer(opts) {
21798
21829
  const handle = createRelayServer(opts);
21799
- await new Promise((resolve2, reject) => {
21830
+ await new Promise((resolve3, reject) => {
21800
21831
  handle.server.once("error", reject);
21801
21832
  handle.server.listen(opts.port, opts.host ?? "0.0.0.0", () => {
21802
21833
  handle.server.removeListener("error", reject);
21803
- resolve2();
21834
+ resolve3();
21804
21835
  });
21805
21836
  });
21806
21837
  return handle;
@@ -22377,7 +22408,7 @@ function toEpoch(iso) {
22377
22408
  var INSPECT_TIMEOUT_MS = 15e3;
22378
22409
  var PAUSE_TIMEOUT_MS = 3e4;
22379
22410
  function runDocker(args, timeoutMs) {
22380
- return new Promise((resolve2) => {
22411
+ return new Promise((resolve3) => {
22381
22412
  const child = (0, import_node_child_process10.spawn)("docker", args, { stdio: ["ignore", "pipe", "pipe"] });
22382
22413
  let stdout = "";
22383
22414
  let stderr = "";
@@ -22385,7 +22416,7 @@ function runDocker(args, timeoutMs) {
22385
22416
  const finish = (exitCode) => {
22386
22417
  if (settled) return;
22387
22418
  settled = true;
22388
- resolve2({ exitCode, stdout, stderr });
22419
+ resolve3({ exitCode, stdout, stderr });
22389
22420
  };
22390
22421
  const timer = setTimeout(() => {
22391
22422
  child.kill("SIGTERM");
@@ -22436,6 +22467,173 @@ async function pauseContainer(name) {
22436
22467
  }
22437
22468
  }
22438
22469
 
22470
+ // src/cloud-keepalive.ts
22471
+ var import_promises21 = require("fs/promises");
22472
+ function selectBoxesToRenew(entries, windowMs, now) {
22473
+ const out = [];
22474
+ for (const e of entries) {
22475
+ if (e.agentState == null) continue;
22476
+ let target = null;
22477
+ if (e.agentState === "active") {
22478
+ target = now + windowMs;
22479
+ } else if (e.agentState === "idle" && e.lastActivityMs != null && now - e.lastActivityMs < windowMs) {
22480
+ target = e.lastActivityMs + windowMs;
22481
+ }
22482
+ if (target != null) {
22483
+ out.push({ boxId: e.boxId, backend: e.backend, targetDeadlineEpochMs: target });
22484
+ }
22485
+ }
22486
+ return out;
22487
+ }
22488
+ function coarseKeepaliveState(s) {
22489
+ switch (s) {
22490
+ case "working":
22491
+ case "compacting":
22492
+ case "waiting":
22493
+ case "question":
22494
+ case "end-plan":
22495
+ return "active";
22496
+ case "idle":
22497
+ return "idle";
22498
+ default:
22499
+ return null;
22500
+ }
22501
+ }
22502
+ var DEFAULT_INTERVAL_MS3 = 6e4;
22503
+ var FAILURE_BACKOFF_MS = 5 * 6e4;
22504
+ function startCloudKeepaliveLoop(deps) {
22505
+ const loadConfig = deps.loadConfig ?? loadAutopauseConfig;
22506
+ const resolveBackend = deps.resolveBackend ?? resolveCloudBackend;
22507
+ const lookupBox = deps.lookupBox ?? defaultLookupBox;
22508
+ const fallbackCreateTimeoutMs = deps.fallbackCreateTimeoutMs ?? defaultFallbackCreateTimeoutMs;
22509
+ const nowFn = deps.now ?? Date.now;
22510
+ const intervalMs = deps.intervalMs ?? DEFAULT_INTERVAL_MS3;
22511
+ const { registry, statusStore, log } = deps;
22512
+ const tracked = /* @__PURE__ */ new Map();
22513
+ const backoffUntil = /* @__PURE__ */ new Map();
22514
+ const backendCache = /* @__PURE__ */ new Map();
22515
+ let ticking = false;
22516
+ let stopped = false;
22517
+ let inFlight = Promise.resolve();
22518
+ async function resolveCached(name) {
22519
+ if (backendCache.has(name)) return backendCache.get(name) ?? null;
22520
+ let backend = null;
22521
+ try {
22522
+ backend = await resolveBackend(name);
22523
+ } catch {
22524
+ backend = null;
22525
+ }
22526
+ backendCache.set(name, backend);
22527
+ return backend;
22528
+ }
22529
+ async function tick() {
22530
+ if (ticking) return;
22531
+ ticking = true;
22532
+ try {
22533
+ const cfg = await loadConfig();
22534
+ if (!cfg.enabled) return;
22535
+ const windowMs = cfg.idleMinutes * 6e4;
22536
+ const now = nowFn();
22537
+ const live = /* @__PURE__ */ new Set();
22538
+ const entries = [];
22539
+ for (const reg of registry.list()) {
22540
+ if (reg.kind !== "cloud" || !reg.backend) continue;
22541
+ const backend = await resolveCached(reg.backend);
22542
+ if (!backend || typeof backend.renewTimeout !== "function") continue;
22543
+ live.add(reg.boxId);
22544
+ const active = readActiveAgent(statusStore.get(reg.boxId));
22545
+ entries.push({
22546
+ boxId: reg.boxId,
22547
+ backend: reg.backend,
22548
+ agentState: coarseKeepaliveState(active.state),
22549
+ lastActivityMs: active.updatedAt ? toEpoch2(active.updatedAt) : null
22550
+ });
22551
+ }
22552
+ for (const id of [...tracked.keys()]) if (!live.has(id)) tracked.delete(id);
22553
+ for (const id of [...backoffUntil.keys()]) if (!live.has(id)) backoffUntil.delete(id);
22554
+ const decisions = selectBoxesToRenew(entries, windowMs, now);
22555
+ for (const d of decisions) {
22556
+ const until = backoffUntil.get(d.boxId);
22557
+ if (until != null && now < until) continue;
22558
+ const lookup = await lookupBox(d.boxId);
22559
+ if (!lookup) continue;
22560
+ let current = tracked.get(d.boxId);
22561
+ if (current == null) {
22562
+ const createMs = lookup.createdAtMs ?? now;
22563
+ const createTimeoutMs = lookup.createTimeoutMs ?? await fallbackCreateTimeoutMs(d.backend);
22564
+ current = createMs + createTimeoutMs;
22565
+ tracked.set(d.boxId, current);
22566
+ }
22567
+ if (d.targetDeadlineEpochMs <= current + intervalMs) continue;
22568
+ try {
22569
+ const backend = await resolveCached(d.backend);
22570
+ if (!backend?.renewTimeout) continue;
22571
+ await backend.renewTimeout({ sandboxId: lookup.sandboxId }, d.targetDeadlineEpochMs, current);
22572
+ tracked.set(d.boxId, d.targetDeadlineEpochMs);
22573
+ backoffUntil.delete(d.boxId);
22574
+ log(
22575
+ `cloud-keepalive: renewed box ${d.boxId} (${d.backend}) +${String(Math.round((d.targetDeadlineEpochMs - now) / 6e4))}m`
22576
+ );
22577
+ } catch (err) {
22578
+ backoffUntil.set(d.boxId, now + FAILURE_BACKOFF_MS);
22579
+ const msg = err instanceof Error ? err.message : String(err);
22580
+ log(`cloud-keepalive: renew box ${d.boxId} (${d.backend}) failed: ${msg}`);
22581
+ }
22582
+ }
22583
+ } catch (err) {
22584
+ const msg = err instanceof Error ? err.message : String(err);
22585
+ log(`cloud-keepalive: tick error: ${msg}`);
22586
+ } finally {
22587
+ ticking = false;
22588
+ }
22589
+ }
22590
+ const timer = setInterval(() => {
22591
+ if (stopped) return;
22592
+ inFlight = tick();
22593
+ }, intervalMs);
22594
+ timer.unref();
22595
+ return {
22596
+ stop: async () => {
22597
+ stopped = true;
22598
+ clearInterval(timer);
22599
+ await inFlight.catch(() => {
22600
+ });
22601
+ }
22602
+ };
22603
+ }
22604
+ function toEpoch2(iso) {
22605
+ if (!iso) return null;
22606
+ const t = Date.parse(iso);
22607
+ return Number.isNaN(t) ? null : t;
22608
+ }
22609
+ async function defaultLookupBox(boxId) {
22610
+ const state = await readState();
22611
+ const hit = findBox(boxId, state);
22612
+ if (hit.kind !== "ok") return null;
22613
+ const sandboxId = hit.box.cloud?.sandboxId;
22614
+ if (!sandboxId) return null;
22615
+ return {
22616
+ sandboxId,
22617
+ createdAtMs: toEpoch2(hit.box.createdAt),
22618
+ createTimeoutMs: hit.box.cloud?.sessionTimeoutMs ?? null
22619
+ };
22620
+ }
22621
+ async function defaultFallbackCreateTimeoutMs(backend) {
22622
+ const generic = 45 * 6e4;
22623
+ if (backend !== "vercel") return generic;
22624
+ const fallback = BUILT_IN_DEFAULTS.box.vercelTimeoutMs;
22625
+ try {
22626
+ const global3 = parseUserConfig(
22627
+ await (0, import_promises21.readFile)(GLOBAL_CONFIG_FILE, "utf8"),
22628
+ GLOBAL_CONFIG_FILE
22629
+ );
22630
+ const v = global3.box?.vercelTimeoutMs;
22631
+ return typeof v === "number" && v > 0 ? v : fallback;
22632
+ } catch {
22633
+ return fallback;
22634
+ }
22635
+ }
22636
+
22439
22637
  // src/bin.ts
22440
22638
  var program2 = new Command();
22441
22639
  program2.name("agentbox-relay").description("Host-side HTTP relay for box\u2192host events and RPCs").version("0.0.0");
@@ -22459,6 +22657,12 @@ program2.command("serve").description("Run the HTTP relay in the foreground").op
22459
22657
  statusStore: handle.statusStore,
22460
22658
  events: handle.events,
22461
22659
  log: (line) => process.stdout.write(`agentbox-relay: ${line}
22660
+ `)
22661
+ });
22662
+ const cloudKeepalive = startCloudKeepaliveLoop({
22663
+ registry: handle.registry,
22664
+ statusStore: handle.statusStore,
22665
+ log: (line) => process.stdout.write(`agentbox-relay: ${line}
22462
22666
  `)
22463
22667
  });
22464
22668
  const queue = startQueueLoop({
@@ -22473,7 +22677,7 @@ program2.command("serve").description("Run the HTTP relay in the foreground").op
22473
22677
  const shutdown = (signal) => {
22474
22678
  process.stdout.write(`agentbox-relay: ${signal} \u2014 shutting down
22475
22679
  `);
22476
- Promise.allSettled([autopause.stop(), queue.stop()]).finally(() => handle.close()).finally(() => process.exit(0));
22680
+ Promise.allSettled([autopause.stop(), cloudKeepalive.stop(), queue.stop()]).finally(() => handle.close()).finally(() => process.exit(0));
22477
22681
  };
22478
22682
  process.on("SIGTERM", () => shutdown("SIGTERM"));
22479
22683
  process.on("SIGINT", () => shutdown("SIGINT"));
@@ -22494,7 +22698,7 @@ program2.command("tail").description("Print recent events (in-container shim; GE
22494
22698
  async function adminPost(path6, body, portStr) {
22495
22699
  const port = Number.parseInt(portStr, 10);
22496
22700
  const json = JSON.stringify(body);
22497
- await new Promise((resolve2, reject) => {
22701
+ await new Promise((resolve3, reject) => {
22498
22702
  const req = (0, import_node_http3.request)(
22499
22703
  {
22500
22704
  host: "127.0.0.1",
@@ -22512,7 +22716,7 @@ async function adminPost(path6, body, portStr) {
22512
22716
  res.on("end", () => {
22513
22717
  const status = res.statusCode ?? 0;
22514
22718
  if (status >= 200 && status < 300) {
22515
- resolve2();
22719
+ resolve3();
22516
22720
  } else {
22517
22721
  const text = Buffer.concat(chunks).toString("utf8");
22518
22722
  reject(new Error(`relay ${path6} \u2192 ${String(status)}: ${text}`));
@@ -22527,7 +22731,7 @@ async function adminPost(path6, body, portStr) {
22527
22731
  }
22528
22732
  async function adminGet(path6, portStr) {
22529
22733
  const port = Number.parseInt(portStr, 10);
22530
- return new Promise((resolve2, reject) => {
22734
+ return new Promise((resolve3, reject) => {
22531
22735
  const req = (0, import_node_http3.request)(
22532
22736
  { host: "127.0.0.1", port, method: "GET", path: path6 },
22533
22737
  (res) => {
@@ -22536,7 +22740,7 @@ async function adminGet(path6, portStr) {
22536
22740
  res.on("end", () => {
22537
22741
  const text = Buffer.concat(chunks).toString("utf8");
22538
22742
  const status = res.statusCode ?? 0;
22539
- if (status >= 200 && status < 300) resolve2(text);
22743
+ if (status >= 200 && status < 300) resolve3(text);
22540
22744
  else reject(new Error(`relay ${path6} \u2192 ${String(status)}: ${text}`));
22541
22745
  });
22542
22746
  }