@madarco/agentbox 0.20.1 → 0.21.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 (62) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/dist/{_cloud-attach-MH7NKIZY.js → _cloud-attach-U3QJO7IF.js} +4 -4
  3. package/dist/{chunk-52LKNUY7.js → chunk-6JJIKCMY.js} +2 -2
  4. package/dist/{chunk-P6UT5XGE.js → chunk-DBMLOY3T.js} +11 -3
  5. package/dist/{chunk-P6UT5XGE.js.map → chunk-DBMLOY3T.js.map} +1 -1
  6. package/dist/{chunk-NXX3KQZ6.js → chunk-IXQTUXWV.js} +2 -2
  7. package/dist/{chunk-MODNW54N.js → chunk-KTEDFUKM.js} +2 -2
  8. package/dist/{chunk-4ATVA3RM.js → chunk-PX7G4PSI.js} +78 -23
  9. package/dist/chunk-PX7G4PSI.js.map +1 -0
  10. package/dist/{chunk-3465NDRZ.js → chunk-QKL7PCXQ.js} +127 -11
  11. package/dist/chunk-QKL7PCXQ.js.map +1 -0
  12. package/dist/{chunk-7K2A3NLE.js → chunk-X2DWS4KS.js} +14 -6
  13. package/dist/chunk-X2DWS4KS.js.map +1 -0
  14. package/dist/{chunk-5N7GA2X7.js → chunk-YZVFGFYQ.js} +263 -881
  15. package/dist/chunk-YZVFGFYQ.js.map +1 -0
  16. package/dist/{dist-G5PDFWKH.js → dist-FMA5Y25B.js} +5 -5
  17. package/dist/{dist-T3JIYHCA.js → dist-NWKOEWUJ.js} +120 -26
  18. package/dist/dist-NWKOEWUJ.js.map +1 -0
  19. package/dist/{dist-AJWL4WLW.js → dist-SAS4PIHA.js} +13 -3
  20. package/dist/{dist-CTTTHG6U.js → dist-U76JL6HI.js} +5 -5
  21. package/dist/{dist-LUEH7MER.js → dist-UVQJ2BZJ.js} +5 -5
  22. package/dist/index.js +1236 -561
  23. package/dist/index.js.map +1 -1
  24. package/dist/{prepared-state-MQHD3M5F-5ZMCNY43.js → prepared-state-MQHD3M5F-YYVVMTNJ.js} +2 -2
  25. package/package.json +6 -5
  26. package/runtime/daytona/custom-system-CLAUDE.md +13 -3
  27. package/runtime/docker/Dockerfile.box +44 -10
  28. package/runtime/docker/apps/cli/share/agentbox-setup/SKILL.md +6 -5
  29. package/runtime/docker/packages/ctl/dist/bin.cjs +324 -109
  30. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-portless-trust +82 -0
  31. package/runtime/docker/packages/sandbox-docker/scripts/custom-system-CLAUDE.md +12 -3
  32. package/runtime/e2b/agentbox-setup-skill.md +6 -5
  33. package/runtime/e2b/ctl.cjs +324 -109
  34. package/runtime/e2b/custom-system-CLAUDE.md +12 -3
  35. package/runtime/e2b/scripts/build-template.sh +44 -2
  36. package/runtime/hetzner/agentbox-portless-trust +82 -0
  37. package/runtime/hetzner/agentbox-setup-skill.md +6 -5
  38. package/runtime/hetzner/ctl.cjs +324 -109
  39. package/runtime/hetzner/custom-system-CLAUDE.md +12 -3
  40. package/runtime/hetzner/scripts/install-box.sh +51 -7
  41. package/runtime/relay/bin.cjs +187 -43
  42. package/runtime/vercel/agentbox-setup-skill.md +6 -5
  43. package/runtime/vercel/ctl.cjs +324 -109
  44. package/runtime/vercel/custom-system-CLAUDE.md +12 -3
  45. package/runtime/vercel/scripts/provision.sh +44 -2
  46. package/share/agentbox-setup/SKILL.md +6 -5
  47. package/share/host-skills/agentbox/SKILL.md +14 -0
  48. package/share/host-skills/agentbox-info/SKILL.md +30 -1
  49. package/dist/chunk-3465NDRZ.js.map +0 -1
  50. package/dist/chunk-4ATVA3RM.js.map +0 -1
  51. package/dist/chunk-5N7GA2X7.js.map +0 -1
  52. package/dist/chunk-7K2A3NLE.js.map +0 -1
  53. package/dist/dist-T3JIYHCA.js.map +0 -1
  54. /package/dist/{_cloud-attach-MH7NKIZY.js.map → _cloud-attach-U3QJO7IF.js.map} +0 -0
  55. /package/dist/{chunk-52LKNUY7.js.map → chunk-6JJIKCMY.js.map} +0 -0
  56. /package/dist/{chunk-NXX3KQZ6.js.map → chunk-IXQTUXWV.js.map} +0 -0
  57. /package/dist/{chunk-MODNW54N.js.map → chunk-KTEDFUKM.js.map} +0 -0
  58. /package/dist/{dist-G5PDFWKH.js.map → dist-FMA5Y25B.js.map} +0 -0
  59. /package/dist/{dist-AJWL4WLW.js.map → dist-SAS4PIHA.js.map} +0 -0
  60. /package/dist/{dist-CTTTHG6U.js.map → dist-U76JL6HI.js.map} +0 -0
  61. /package/dist/{dist-LUEH7MER.js.map → dist-UVQJ2BZJ.js.map} +0 -0
  62. /package/dist/{prepared-state-MQHD3M5F-5ZMCNY43.js.map → prepared-state-MQHD3M5F-YYVVMTNJ.js.map} +0 -0
@@ -6,6 +6,7 @@ import {
6
6
  CLAUDE_FORWARDED_ENV_KEYS,
7
7
  CODEX_CREDENTIALS_BACKUP_FILE,
8
8
  CODEX_FORWARDED_ENV_KEYS,
9
+ CODEX_OVERRIDE_WROTE_MARKER,
9
10
  CREDENTIALS_BACKUP_FILE,
10
11
  OPENCODE_CREDENTIALS_BACKUP_FILE,
11
12
  OPENCODE_FORWARDED_ENV_KEYS,
@@ -13,6 +14,7 @@ import {
13
14
  SHARED_CODEX_VOLUME,
14
15
  SHARED_OPENCODE_VOLUME,
15
16
  TERM_FALLBACK_SNIPPET,
17
+ buildCodexAgentsOverrideScript,
16
18
  buildHostEnvFindArgs,
17
19
  buildHostSyncManifest,
18
20
  buildTmuxConfigShellSnippet,
@@ -43,7 +45,7 @@ import {
43
45
  stageOpencodeStateForUpload,
44
46
  stageOpencodeStaticForUpload,
45
47
  syncClaudeCredentials
46
- } from "./chunk-5N7GA2X7.js";
48
+ } from "./chunk-YZVFGFYQ.js";
47
49
  import {
48
50
  DEFAULT_BOX_IMAGE,
49
51
  allocateProjectIndex,
@@ -55,7 +57,7 @@ import {
55
57
  recordBox,
56
58
  removeBoxRecord,
57
59
  renderCarryEntries
58
- } from "./chunk-7K2A3NLE.js";
60
+ } from "./chunk-X2DWS4KS.js";
59
61
 
60
62
  // ../../packages/sandbox-cloud/dist/index.js
61
63
  import { basename as basename2, resolve } from "path";
@@ -179,6 +181,21 @@ async function seedAgentVolumesIfFresh(backend, handle, opts = {}) {
179
181
  )
180
182
  );
181
183
  }
184
+ async function ensureAgentHomeDirsOwned(backend, handle, opts = {}) {
185
+ const log = opts.onLog ?? (() => {
186
+ });
187
+ const paths = AGENT_SPECS.map((s) => s.staticMountPath).join(" ");
188
+ try {
189
+ await backend.exec(
190
+ handle,
191
+ `sudo -n chown -R vscode:vscode ${paths} 2>/dev/null || true`
192
+ );
193
+ } catch (err) {
194
+ log(
195
+ `agent home-dir ownership normalize failed (continuing): ${err instanceof Error ? err.message : String(err)}`
196
+ );
197
+ }
198
+ }
182
199
  async function refreshAgentCredentialsBackup(opts = {}) {
183
200
  const log = opts.onLog ?? (() => {
184
201
  });
@@ -415,6 +432,28 @@ async function seedDynamicConfig(backend, handle, opts) {
415
432
  );
416
433
  }
417
434
  }
435
+ var BOX_CODEX_HOME = "/home/vscode/.codex";
436
+ async function ensureCodexAgentsOverride(backend, handle, opts = {}) {
437
+ const log = opts.onLog ?? (() => {
438
+ });
439
+ const script = buildCodexAgentsOverrideScript(BOX_CODEX_HOME) + `
440
+ chown vscode:vscode "$OVR" 2>/dev/null || true
441
+ chmod 0644 "$OVR" 2>/dev/null || true`;
442
+ try {
443
+ const res = await backend.exec(handle, script);
444
+ if (res.exitCode !== 0)
445
+ log(
446
+ `codex AGENTS.override seed failed (continuing): exit ${res.exitCode}${res.stderr.trim() ? `: ${res.stderr.trim()}` : ""}`
447
+ );
448
+ else if (res.stdout.includes(CODEX_OVERRIDE_WROTE_MARKER))
449
+ log("seeded Codex AGENTS.override.md");
450
+ else log("codex AGENTS.override skipped: box-facts file absent");
451
+ } catch (err) {
452
+ log(
453
+ `codex AGENTS.override seed failed (continuing): ${err instanceof Error ? err.message : String(err)}`
454
+ );
455
+ }
456
+ }
418
457
  var REMOTE_TAR2 = "/tmp/agentbox-claude-json.tar.gz";
419
458
  var BOX_CLAUDE_DIR = "/home/vscode/.claude";
420
459
  async function seedClaudeJsonAtCreate(backend, handle, opts = {}) {
@@ -774,7 +813,8 @@ function isPlainObject(v) {
774
813
  }
775
814
  var REMOTE_UP_TAR = "/tmp/agentbox-cp-up.tar.gz";
776
815
  var REMOTE_DOWN_TAR = "/tmp/agentbox-cp-down.tar.gz";
777
- async function uploadToCloudBox(backend, handle, hostSrc, boxDst, exclude) {
816
+ var BOX_HOME2 = "/home/vscode";
817
+ async function uploadOneToCloudBox(backend, handle, hostSrc, boxDst, exclude) {
778
818
  const srcAbs = hostResolve(hostSrc);
779
819
  if (!existsSync(srcAbs)) throw new Error(`source not found: ${hostSrc}`);
780
820
  const srcBasename = hostBasename(srcAbs);
@@ -799,6 +839,8 @@ async function uploadToCloudBox(backend, handle, hostSrc, boxDst, exclude) {
799
839
  await backend.uploadFile(handle, localTar, REMOTE_UP_TAR);
800
840
  const initialPath = boxParent === "/" ? `/${srcBasename}` : `${boxParent}/${srcBasename}`;
801
841
  const renameStep = finalName !== srcBasename ? `$SUDO cp -f ${quoteShellArg(initialPath)} ${quoteShellArg(finalPath)} && $SUDO rm -f ${quoteShellArg(initialPath)}` : ": # no rename";
842
+ const underHome = finalPath.startsWith(BOX_HOME2 + "/");
843
+ const parentWalk = underHome ? `parent=$(dirname ${quoteShellArg(finalPath)}); while [ "$parent" != ${quoteShellArg(BOX_HOME2)} ] && [ "$parent" != "/" ]; do $SUDO chown "$(id -un):$(id -gn)" "$parent" || true; parent=$(dirname "$parent"); done` : `: # dest outside ${BOX_HOME2}; leave parent ownership untouched`;
802
844
  const script = [
803
845
  `set -euo pipefail`,
804
846
  `if command -v sudo >/dev/null 2>&1; then SUDO='sudo -n'; else SUDO=''; fi`,
@@ -809,9 +851,10 @@ async function uploadToCloudBox(backend, handle, hostSrc, boxDst, exclude) {
809
851
  // sandbox's regular disk. Same flags as the credential-seed extract.
810
852
  `$SUDO tar -xzf ${quoteShellArg(REMOTE_UP_TAR)} -C ${quoteShellArg(boxParent)} --no-same-permissions --no-same-owner -m`,
811
853
  renameStep,
812
- // chown only the landed path — anything we mkdir'd through stays at
813
- // its existing ownership. Tolerate failure (chown bad on read-only mounts).
854
+ // chown the landed subtree, then the parent chain back up to $HOME.
855
+ // Tolerate failure (chown bad on read-only / FUSE mounts).
814
856
  `$SUDO chown -R "$(id -un):$(id -gn)" ${quoteShellArg(finalPath)} || true`,
857
+ parentWalk,
815
858
  `rm -f ${quoteShellArg(REMOTE_UP_TAR)}`
816
859
  ].join("\n");
817
860
  const r = await backend.exec(handle, bashScript(script));
@@ -847,7 +890,7 @@ async function pullCloudDirContents(backend, handle, boxSrcDir, hostDstDir) {
847
890
  }
848
891
  return { finalPath: dstAbs };
849
892
  }
850
- async function downloadFromCloudBox(backend, handle, boxSrc, hostDst, exclude) {
893
+ async function downloadOneFromCloudBox(backend, handle, boxSrc, hostDst, exclude) {
851
894
  const srcBasename = posix.basename(boxSrc);
852
895
  const srcParent = posix.dirname(boxSrc);
853
896
  const dstAbs = hostResolve(hostDst);
@@ -888,6 +931,37 @@ async function downloadFromCloudBox(backend, handle, boxSrc, hostDst, exclude) {
888
931
  }
889
932
  return { finalPath };
890
933
  }
934
+ async function uploadToCloudBox(backend, handle, hostSrcs, boxDst, exclude) {
935
+ if (hostSrcs.length === 1) {
936
+ return uploadOneToCloudBox(backend, handle, hostSrcs[0], boxDst, exclude);
937
+ }
938
+ if (!boxDst.endsWith("/")) {
939
+ throw new Error(
940
+ `cannot copy multiple sources to '${boxDst}': destination is not a directory (add a trailing slash, e.g. ${boxDst}/)`
941
+ );
942
+ }
943
+ for (const src of hostSrcs) {
944
+ await uploadOneToCloudBox(backend, handle, src, boxDst, exclude);
945
+ }
946
+ return { finalPath: boxDst };
947
+ }
948
+ async function downloadFromCloudBox(backend, handle, boxSrcs, hostDst, exclude) {
949
+ if (boxSrcs.length === 1) {
950
+ return downloadOneFromCloudBox(backend, handle, boxSrcs[0], hostDst, exclude);
951
+ }
952
+ const dstAbs = hostResolve(hostDst);
953
+ const dstExists = existsSync(dstAbs);
954
+ if (!hostDst.endsWith("/") && !(dstExists && statSync(dstAbs).isDirectory())) {
955
+ throw new Error(
956
+ `cannot copy multiple sources to '${hostDst}': destination is not a directory (add a trailing slash, e.g. ${hostDst}/)`
957
+ );
958
+ }
959
+ mkdirSync(dstAbs, { recursive: true });
960
+ for (const src of boxSrcs) {
961
+ await downloadOneFromCloudBox(backend, handle, src, dstAbs, exclude);
962
+ }
963
+ return { finalPath: dstAbs };
964
+ }
891
965
  async function launchCloudCtlDaemon(args) {
892
966
  const env = [
893
967
  `AGENTBOX_BOX_ID=${quoteShellArgv([args.boxId])}`,
@@ -908,8 +982,29 @@ async function launchCloudCtlDaemon(args) {
908
982
  if (args.webProxyPort !== void 0)
909
983
  boxEnvFile.push(`AGENTBOX_WEB_PROXY_PORT=${quoteShellArgv([String(args.webProxyPort)])}`);
910
984
  if (args.boxHost) boxEnvFile.push(`AGENTBOX_BOX_HOST=${quoteShellArgv([args.boxHost])}`);
985
+ const boxRelayPort = (() => {
986
+ if (args.relayUrl) {
987
+ try {
988
+ const p = new URL(args.relayUrl).port;
989
+ if (p) return Number.parseInt(p, 10);
990
+ } catch {
991
+ }
992
+ }
993
+ return 8788;
994
+ })();
911
995
  const script = [
912
996
  `set -e`,
997
+ // Idempotent: if a healthy ctl daemon is already serving the box relay,
998
+ // leave it — it already has the right env (relayUrl/token are stable across
999
+ // a host-only reconnect), and a fresh spawn would just fail to bind :PORT
1000
+ // and linger as an orphan. Only a real sandbox restart kills the daemon, in
1001
+ // which case the probe fails and we (re)launch. Without this, every
1002
+ // start/resume/recover leaked another idle daemon. node is guaranteed
1003
+ // present (it runs agentbox-ctl); curl may not be.
1004
+ `if node -e 'require("http").get("http://127.0.0.1:${String(boxRelayPort)}/healthz",r=>process.exit(r.statusCode===200?0:1)).on("error",()=>process.exit(1))' 2>/dev/null; then`,
1005
+ ` echo "agentbox-ctl daemon already healthy on :${String(boxRelayPort)}; skipping launch"`,
1006
+ ` exit 0`,
1007
+ `fi`,
913
1008
  `if command -v sudo >/dev/null 2>&1; then SUDO='sudo -n'; else SUDO=''; fi`,
914
1009
  `$SUDO mkdir -p /run/agentbox /var/log/agentbox /etc/agentbox`,
915
1010
  `$SUDO chown "$(id -un):$(id -gn)" /run/agentbox /var/log/agentbox`,
@@ -1862,6 +1957,8 @@ function createCloudProvider(backend, opts = {}) {
1862
1957
  onLog: log
1863
1958
  });
1864
1959
  }
1960
+ await ensureAgentHomeDirsOwned(backend, handle, { onLog: log });
1961
+ await ensureCodexAgentsOverride(backend, handle, { onLog: log });
1865
1962
  await seedOpencodeModelState(backend, handle, { onLog: log });
1866
1963
  await seedClaudeJsonAtCreate(backend, handle, {
1867
1964
  hostWorkspace: req.workspacePath,
@@ -2094,6 +2191,25 @@ function createCloudProvider(backend, opts = {}) {
2094
2191
  await backend.start(h);
2095
2192
  return reEnsureCloudBox(box, h);
2096
2193
  },
2194
+ async reconnect(box) {
2195
+ const h = handleFor(box);
2196
+ const state = await probe(box);
2197
+ if (state === "running") return reEnsureCloudBox(box, h);
2198
+ if (state === "paused") {
2199
+ await backend.resume(h);
2200
+ return reEnsureCloudBox(box, h);
2201
+ }
2202
+ if (state === "stopped") {
2203
+ await backend.start(h);
2204
+ return reEnsureCloudBox(box, h);
2205
+ }
2206
+ throw new Error(
2207
+ `cannot recover ${box.name}: sandbox ${box.cloud?.sandboxId ?? box.id} is ${state}`
2208
+ );
2209
+ },
2210
+ async repairReachability(box) {
2211
+ return await backend.repairReachability?.(handleFor(box)) ?? { changed: false };
2212
+ },
2097
2213
  async pause(box) {
2098
2214
  await backend.pause(handleFor(box));
2099
2215
  await persistLastState(box, "paused");
@@ -2197,11 +2313,11 @@ function createCloudProvider(backend, opts = {}) {
2197
2313
  } : void 0;
2198
2314
  return { argv: fullArgv, cleanup };
2199
2315
  },
2200
- async uploadPath(box, hostSrc, boxDst, exclude) {
2201
- return uploadToCloudBox(backend, handleFor(box), hostSrc, boxDst, exclude);
2316
+ async uploadPath(box, hostSrcs, boxDst, exclude) {
2317
+ return uploadToCloudBox(backend, handleFor(box), hostSrcs, boxDst, exclude);
2202
2318
  },
2203
- async downloadPath(box, boxSrc, hostDst, exclude) {
2204
- return downloadFromCloudBox(backend, handleFor(box), boxSrc, hostDst, exclude);
2319
+ async downloadPath(box, boxSrcs, hostDst, exclude) {
2320
+ return downloadFromCloudBox(backend, handleFor(box), boxSrcs, hostDst, exclude);
2205
2321
  },
2206
2322
  async downloadDirContents(box, boxSrc, hostDst) {
2207
2323
  return pullCloudDirContents(backend, handleFor(box), boxSrc, hostDst);
@@ -2385,4 +2501,4 @@ export {
2385
2501
  hostTermForCloud,
2386
2502
  renderInnerCommand
2387
2503
  };
2388
- //# sourceMappingURL=chunk-3465NDRZ.js.map
2504
+ //# sourceMappingURL=chunk-QKL7PCXQ.js.map