@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
@@ -11529,13 +11529,49 @@ var codexStateCommand = new Command("codex-state").description("Report Codex act
11529
11529
  // src/relay-rpc.ts
11530
11530
  var import_node_http = require("http");
11531
11531
  var import_node_https = require("https");
11532
+
11533
+ // src/relay-env.ts
11534
+ var import_node_fs3 = require("fs");
11535
+ var import_node_path2 = require("path");
11536
+ var DEFAULT_RELAY_ENV_FILE = "/run/agentbox/relay.env";
11537
+ function relayEnvFilePath() {
11538
+ return process.env.AGENTBOX_RELAY_ENV_FILE ?? DEFAULT_RELAY_ENV_FILE;
11539
+ }
11540
+ function resolveRelayEnv(env = process.env) {
11541
+ let url = env.AGENTBOX_RELAY_URL;
11542
+ let token = env.AGENTBOX_RELAY_TOKEN;
11543
+ if (url && token) return { url, token };
11544
+ try {
11545
+ const text = (0, import_node_fs3.readFileSync)(relayEnvFilePath(), "utf8");
11546
+ for (const line of text.split("\n")) {
11547
+ const eq = line.indexOf("=");
11548
+ if (eq === -1) continue;
11549
+ const key = line.slice(0, eq).trim();
11550
+ const value = line.slice(eq + 1).trim();
11551
+ if (key === "AGENTBOX_RELAY_URL") url ??= value;
11552
+ else if (key === "AGENTBOX_RELAY_TOKEN") token ??= value;
11553
+ }
11554
+ } catch {
11555
+ }
11556
+ return { url, token };
11557
+ }
11558
+ function writeRelayEnvFile(url, token) {
11559
+ const path6 = relayEnvFilePath();
11560
+ (0, import_node_fs3.mkdirSync)((0, import_node_path2.dirname)(path6), { recursive: true });
11561
+ const body = `AGENTBOX_RELAY_URL=${url}
11562
+ AGENTBOX_RELAY_TOKEN=${token}
11563
+ `;
11564
+ (0, import_node_fs3.writeFileSync)(path6, body, { mode: 384 });
11565
+ (0, import_node_fs3.chmodSync)(path6, 384);
11566
+ }
11567
+
11568
+ // src/relay-rpc.ts
11532
11569
  function postRpc(method, params, opts = {}) {
11533
11570
  const prefix = opts.errorPrefix ?? "agentbox-ctl rpc";
11534
- const urlStr = process.env.AGENTBOX_RELAY_URL;
11535
- const token = process.env.AGENTBOX_RELAY_TOKEN;
11571
+ const { url: urlStr, token } = resolveRelayEnv();
11536
11572
  if (!urlStr || !token) {
11537
11573
  process.stderr.write(
11538
- `${prefix}: AGENTBOX_RELAY_URL / AGENTBOX_RELAY_TOKEN not set; no relay configured for this box.
11574
+ `${prefix}: AGENTBOX_RELAY_URL / AGENTBOX_RELAY_TOKEN not set (and ${relayEnvFilePath()} absent); no relay configured for this box.
11539
11575
  `
11540
11576
  );
11541
11577
  return Promise.resolve({ status: 0, parsed: null, raw: "", internalExitCode: 65 });
@@ -11612,26 +11648,43 @@ function collectExclude(val, acc) {
11612
11648
  acc.push(val);
11613
11649
  return acc;
11614
11650
  }
11615
- function buildCpParams(boxPath, hostPath, opts) {
11616
- const params = { boxPath, hostPath };
11651
+ function buildCpParams(paths, opts) {
11652
+ if (paths.length < 2) {
11653
+ throw new Error("needs at least one source and a destination, e.g. `cp toHost /workspace/foo ./out/`.");
11654
+ }
11655
+ const sources = paths.slice(0, -1);
11656
+ const dest = paths[paths.length - 1];
11657
+ const params = { sources, dest };
11617
11658
  if (opts.recursive === false) params.recursive = false;
11618
11659
  if (opts.exclude.length > 0) params.exclude = opts.exclude;
11619
11660
  if (opts.defaultExcludes === false) params.defaultExcludes = false;
11620
11661
  if (opts.yes) params.yes = true;
11621
11662
  return params;
11622
11663
  }
11623
- var cpCommand = new Command("cp").description("Copy a file/dir between this box and the host (gated by user prompt on the host wrapper)").addCommand(
11624
- new Command("toHost").description("Copy box:<boxPath> -> host:<hostPath>").argument("<boxPath>", "source path inside the container").argument("<hostPath>", "destination on the host (relative resolves against the box workspace)").option("--no-recursive", "reserved; current implementation is always recursive (docker cp -a)").option("--exclude <pattern>", "exclude paths matching <pattern> (repeatable)", collectExclude, []).option("--no-default-excludes", "keep heavy dirs the host drops by default (.git, node_modules, ...)").option("-y, --yes", "copy even if the source is over the host size limit").action(async (boxPath, hostPath, opts) => {
11625
- const code = await postRpcAndExit("cp.toHost", buildCpParams(boxPath, hostPath, opts), {
11626
- errorPrefix: "agentbox-ctl cp"
11627
- });
11664
+ var cpCommand = new Command("cp").description("Copy file(s)/dir(s) between this box and the host (gated by user prompt on the host wrapper)").addCommand(
11665
+ new Command("toHost").description("Copy box source(s) -> host destination (last path is the dest)").argument("<paths...>", "box source path(s) inside the container, then the host destination").option("--no-recursive", "reserved; current implementation is always recursive (docker cp -a)").option("--exclude <pattern>", "exclude paths matching <pattern> (repeatable)", collectExclude, []).option("--no-default-excludes", "keep heavy dirs the host drops by default (.git, node_modules, ...)").option("-y, --yes", "copy even if a source is over the host size limit").action(async (paths, opts) => {
11666
+ let params;
11667
+ try {
11668
+ params = buildCpParams(paths, opts);
11669
+ } catch (err) {
11670
+ process.stderr.write(`agentbox-ctl cp: ${err instanceof Error ? err.message : String(err)}
11671
+ `);
11672
+ process.exit(64);
11673
+ }
11674
+ const code = await postRpcAndExit("cp.toHost", params, { errorPrefix: "agentbox-ctl cp" });
11628
11675
  process.exit(code);
11629
11676
  })
11630
11677
  ).addCommand(
11631
- new Command("fromHost").description("Copy host:<hostPath> -> box:<boxPath>").argument("<hostPath>", "source on the host (relative resolves against the box workspace)").argument("<boxPath>", "destination path inside the container").option("--no-recursive", "reserved; current implementation is always recursive (docker cp -a)").option("--exclude <pattern>", "exclude paths matching <pattern> (repeatable)", collectExclude, []).option("--no-default-excludes", "keep heavy dirs the host drops by default (.git, node_modules, ...)").option("-y, --yes", "copy even if the source is over the host size limit").action(async (hostPath, boxPath, opts) => {
11632
- const code = await postRpcAndExit("cp.fromHost", buildCpParams(boxPath, hostPath, opts), {
11633
- errorPrefix: "agentbox-ctl cp"
11634
- });
11678
+ new Command("fromHost").description("Copy host source(s) -> box destination (last path is the dest)").argument("<paths...>", "host source path(s) (relative resolves against the box workspace), then the box destination").option("--no-recursive", "reserved; current implementation is always recursive (docker cp -a)").option("--exclude <pattern>", "exclude paths matching <pattern> (repeatable)", collectExclude, []).option("--no-default-excludes", "keep heavy dirs the host drops by default (.git, node_modules, ...)").option("-y, --yes", "copy even if a source is over the host size limit").action(async (paths, opts) => {
11679
+ let params;
11680
+ try {
11681
+ params = buildCpParams(paths, opts);
11682
+ } catch (err) {
11683
+ process.stderr.write(`agentbox-ctl cp: ${err instanceof Error ? err.message : String(err)}
11684
+ `);
11685
+ process.exit(64);
11686
+ }
11687
+ const code = await postRpcAndExit("cp.fromHost", params, { errorPrefix: "agentbox-ctl cp" });
11635
11688
  process.exit(code);
11636
11689
  })
11637
11690
  );
@@ -13353,13 +13406,13 @@ var handleCommand = (filePath, rawArguments, rawOptions) => {
13353
13406
  };
13354
13407
 
13355
13408
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/arguments/options.js
13356
- var import_node_path6 = __toESM(require("path"), 1);
13409
+ var import_node_path7 = __toESM(require("path"), 1);
13357
13410
  var import_node_process8 = __toESM(require("process"), 1);
13358
13411
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
13359
13412
 
13360
13413
  // ../../node_modules/.pnpm/npm-run-path@6.0.0/node_modules/npm-run-path/index.js
13361
13414
  var import_node_process5 = __toESM(require("process"), 1);
13362
- var import_node_path3 = __toESM(require("path"), 1);
13415
+ var import_node_path4 = __toESM(require("path"), 1);
13363
13416
 
13364
13417
  // ../../node_modules/.pnpm/path-key@4.0.0/node_modules/path-key/index.js
13365
13418
  function pathKey(options = {}) {
@@ -13376,7 +13429,7 @@ function pathKey(options = {}) {
13376
13429
  // ../../node_modules/.pnpm/unicorn-magic@0.3.0/node_modules/unicorn-magic/node.js
13377
13430
  var import_node_util4 = require("util");
13378
13431
  var import_node_child_process3 = require("child_process");
13379
- var import_node_path2 = __toESM(require("path"), 1);
13432
+ var import_node_path3 = __toESM(require("path"), 1);
13380
13433
  var import_node_url2 = require("url");
13381
13434
  var execFileOriginal = (0, import_node_util4.promisify)(import_node_child_process3.execFile);
13382
13435
  function toPath(urlOrPath) {
@@ -13385,12 +13438,12 @@ function toPath(urlOrPath) {
13385
13438
  function traversePathUp(startPath) {
13386
13439
  return {
13387
13440
  *[Symbol.iterator]() {
13388
- let currentPath = import_node_path2.default.resolve(toPath(startPath));
13441
+ let currentPath = import_node_path3.default.resolve(toPath(startPath));
13389
13442
  let previousPath;
13390
13443
  while (previousPath !== currentPath) {
13391
13444
  yield currentPath;
13392
13445
  previousPath = currentPath;
13393
- currentPath = import_node_path2.default.resolve(currentPath, "..");
13446
+ currentPath = import_node_path3.default.resolve(currentPath, "..");
13394
13447
  }
13395
13448
  }
13396
13449
  };
@@ -13405,27 +13458,27 @@ var npmRunPath = ({
13405
13458
  execPath: execPath2 = import_node_process5.default.execPath,
13406
13459
  addExecPath = true
13407
13460
  } = {}) => {
13408
- const cwdPath = import_node_path3.default.resolve(toPath(cwd));
13461
+ const cwdPath = import_node_path4.default.resolve(toPath(cwd));
13409
13462
  const result = [];
13410
- const pathParts = pathOption.split(import_node_path3.default.delimiter);
13463
+ const pathParts = pathOption.split(import_node_path4.default.delimiter);
13411
13464
  if (preferLocal) {
13412
13465
  applyPreferLocal(result, pathParts, cwdPath);
13413
13466
  }
13414
13467
  if (addExecPath) {
13415
13468
  applyExecPath(result, pathParts, execPath2, cwdPath);
13416
13469
  }
13417
- return pathOption === "" || pathOption === import_node_path3.default.delimiter ? `${result.join(import_node_path3.default.delimiter)}${pathOption}` : [...result, pathOption].join(import_node_path3.default.delimiter);
13470
+ return pathOption === "" || pathOption === import_node_path4.default.delimiter ? `${result.join(import_node_path4.default.delimiter)}${pathOption}` : [...result, pathOption].join(import_node_path4.default.delimiter);
13418
13471
  };
13419
13472
  var applyPreferLocal = (result, pathParts, cwdPath) => {
13420
13473
  for (const directory of traversePathUp(cwdPath)) {
13421
- const pathPart = import_node_path3.default.join(directory, "node_modules/.bin");
13474
+ const pathPart = import_node_path4.default.join(directory, "node_modules/.bin");
13422
13475
  if (!pathParts.includes(pathPart)) {
13423
13476
  result.push(pathPart);
13424
13477
  }
13425
13478
  }
13426
13479
  };
13427
13480
  var applyExecPath = (result, pathParts, execPath2, cwdPath) => {
13428
- const pathPart = import_node_path3.default.resolve(cwdPath, toPath(execPath2), "..");
13481
+ const pathPart = import_node_path4.default.resolve(cwdPath, toPath(execPath2), "..");
13429
13482
  if (!pathParts.includes(pathPart)) {
13430
13483
  result.push(pathPart);
13431
13484
  }
@@ -14580,7 +14633,7 @@ var killAfterTimeout = async (subprocess, timeout, context, { signal }) => {
14580
14633
 
14581
14634
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/methods/node.js
14582
14635
  var import_node_process6 = require("process");
14583
- var import_node_path4 = __toESM(require("path"), 1);
14636
+ var import_node_path5 = __toESM(require("path"), 1);
14584
14637
  var mapNode = ({ options }) => {
14585
14638
  if (options.node === false) {
14586
14639
  throw new TypeError('The "node" option cannot be false with `execaNode()`.');
@@ -14599,7 +14652,7 @@ var handleNodeOption = (file, commandArguments, {
14599
14652
  throw new TypeError('The "execPath" option has been removed. Please use the "nodePath" option instead.');
14600
14653
  }
14601
14654
  const normalizedNodePath = safeNormalizeFileUrl(nodePath, 'The "nodePath" option');
14602
- const resolvedNodePath = import_node_path4.default.resolve(cwd, normalizedNodePath);
14655
+ const resolvedNodePath = import_node_path5.default.resolve(cwd, normalizedNodePath);
14603
14656
  const newOptions = {
14604
14657
  ...options,
14605
14658
  nodePath: resolvedNodePath,
@@ -14609,7 +14662,7 @@ var handleNodeOption = (file, commandArguments, {
14609
14662
  if (!shouldHandleNode) {
14610
14663
  return [file, commandArguments, newOptions];
14611
14664
  }
14612
- if (import_node_path4.default.basename(file, ".exe") === "node") {
14665
+ if (import_node_path5.default.basename(file, ".exe") === "node") {
14613
14666
  throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');
14614
14667
  }
14615
14668
  return [
@@ -14698,12 +14751,12 @@ var ENCODING_ALIASES = {
14698
14751
  var serializeEncoding = (encoding) => typeof encoding === "string" ? `"${encoding}"` : String(encoding);
14699
14752
 
14700
14753
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/arguments/cwd.js
14701
- var import_node_fs3 = require("fs");
14702
- var import_node_path5 = __toESM(require("path"), 1);
14754
+ var import_node_fs4 = require("fs");
14755
+ var import_node_path6 = __toESM(require("path"), 1);
14703
14756
  var import_node_process7 = __toESM(require("process"), 1);
14704
14757
  var normalizeCwd = (cwd = getDefaultCwd()) => {
14705
14758
  const cwdString = safeNormalizeFileUrl(cwd, 'The "cwd" option');
14706
- return import_node_path5.default.resolve(cwdString);
14759
+ return import_node_path6.default.resolve(cwdString);
14707
14760
  };
14708
14761
  var getDefaultCwd = () => {
14709
14762
  try {
@@ -14720,7 +14773,7 @@ var fixCwdError = (originalMessage, cwd) => {
14720
14773
  }
14721
14774
  let cwdStat;
14722
14775
  try {
14723
- cwdStat = (0, import_node_fs3.statSync)(cwd);
14776
+ cwdStat = (0, import_node_fs4.statSync)(cwd);
14724
14777
  } catch (error) {
14725
14778
  return `The "cwd" option is invalid: ${cwd}.
14726
14779
  ${error.message}
@@ -14750,7 +14803,7 @@ var normalizeOptions = (filePath, rawArguments, rawOptions) => {
14750
14803
  options.killSignal = normalizeKillSignal(options.killSignal);
14751
14804
  options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
14752
14805
  options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);
14753
- if (import_node_process8.default.platform === "win32" && import_node_path6.default.basename(file, ".exe") === "cmd") {
14806
+ if (import_node_process8.default.platform === "win32" && import_node_path7.default.basename(file, ".exe") === "cmd") {
14754
14807
  commandArguments.unshift("/q");
14755
14808
  }
14756
14809
  return { file, commandArguments, options };
@@ -15725,7 +15778,7 @@ var handleResult = (result, verboseInfo, { reject }) => {
15725
15778
  };
15726
15779
 
15727
15780
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/stdio/handle-sync.js
15728
- var import_node_fs5 = require("fs");
15781
+ var import_node_fs6 = require("fs");
15729
15782
 
15730
15783
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/stdio/type.js
15731
15784
  var getStdioItemType = (value, optionName) => {
@@ -16055,7 +16108,7 @@ var normalizeStdioSync = (stdioArray, buffer, verboseInfo) => stdioArray.map((st
16055
16108
  var isOutputPipeOnly = (stdioOption) => stdioOption === "pipe" || Array.isArray(stdioOption) && stdioOption.every((item) => item === "pipe");
16056
16109
 
16057
16110
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/stdio/native.js
16058
- var import_node_fs4 = require("fs");
16111
+ var import_node_fs5 = require("fs");
16059
16112
  var import_node_tty2 = __toESM(require("tty"), 1);
16060
16113
  var handleNativeStream = ({ stdioItem, stdioItem: { type }, isStdioArray, fdNumber, direction, isSync }) => {
16061
16114
  if (!isStdioArray || type !== "native") {
@@ -16089,7 +16142,7 @@ var getTargetFd = ({ value, optionName, fdNumber, direction }) => {
16089
16142
  if (import_node_tty2.default.isatty(targetFdNumber)) {
16090
16143
  throw new TypeError(`The \`${optionName}: ${serializeOptionValue(value)}\` option is invalid: it cannot be a TTY with synchronous methods.`);
16091
16144
  }
16092
- return { type: "uint8Array", value: bufferToUint8Array((0, import_node_fs4.readFileSync)(targetFdNumber)), optionName };
16145
+ return { type: "uint8Array", value: bufferToUint8Array((0, import_node_fs5.readFileSync)(targetFdNumber)), optionName };
16093
16146
  };
16094
16147
  var getTargetFdNumber = (value, fdNumber) => {
16095
16148
  if (value === "inherit") {
@@ -16422,8 +16475,8 @@ var addProperties = {
16422
16475
  var addPropertiesSync = {
16423
16476
  input: {
16424
16477
  ...addProperties,
16425
- fileUrl: ({ value }) => ({ contents: [bufferToUint8Array((0, import_node_fs5.readFileSync)(value))] }),
16426
- filePath: ({ value: { file } }) => ({ contents: [bufferToUint8Array((0, import_node_fs5.readFileSync)(file))] }),
16478
+ fileUrl: ({ value }) => ({ contents: [bufferToUint8Array((0, import_node_fs6.readFileSync)(value))] }),
16479
+ filePath: ({ value: { file } }) => ({ contents: [bufferToUint8Array((0, import_node_fs6.readFileSync)(file))] }),
16427
16480
  fileNumber: forbiddenIfSync,
16428
16481
  iterable: ({ value }) => ({ contents: [...value] }),
16429
16482
  string: ({ value }) => ({ contents: [value] }),
@@ -16769,7 +16822,7 @@ var validateSerializable = (newContents) => {
16769
16822
  };
16770
16823
 
16771
16824
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/io/output-sync.js
16772
- var import_node_fs6 = require("fs");
16825
+ var import_node_fs7 = require("fs");
16773
16826
 
16774
16827
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/verbose/output.js
16775
16828
  var shouldLogOutput = ({ stdioItems, encoding, verboseInfo, fdNumber }) => fdNumber !== "all" && isFullVerbose(verboseInfo, fdNumber) && !BINARY_ENCODINGS.has(encoding) && fdUsesVerbose(fdNumber) && (stdioItems.some(({ type, value }) => type === "native" && PIPED_STDIO_VALUES.has(value)) || stdioItems.every(({ type }) => TRANSFORM_TYPES.has(type)));
@@ -16893,10 +16946,10 @@ var writeToFiles = (serializedResult, stdioItems, outputFiles) => {
16893
16946
  for (const { path: path6, append } of stdioItems.filter(({ type }) => FILE_TYPES.has(type))) {
16894
16947
  const pathString = typeof path6 === "string" ? path6 : path6.toString();
16895
16948
  if (append || outputFiles.has(pathString)) {
16896
- (0, import_node_fs6.appendFileSync)(path6, serializedResult);
16949
+ (0, import_node_fs7.appendFileSync)(path6, serializedResult);
16897
16950
  } else {
16898
16951
  outputFiles.add(pathString);
16899
- (0, import_node_fs6.writeFileSync)(path6, serializedResult);
16952
+ (0, import_node_fs7.writeFileSync)(path6, serializedResult);
16900
16953
  }
16901
16954
  }
16902
16955
  };
@@ -17340,7 +17393,7 @@ var duplex = () => new import_node_stream2.Duplex({ read() {
17340
17393
  var handleDummyPromise = async (error, verboseInfo, options) => handleResult(error, verboseInfo, options);
17341
17394
 
17342
17395
  // ../../node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/stdio/handle-async.js
17343
- var import_node_fs7 = require("fs");
17396
+ var import_node_fs8 = require("fs");
17344
17397
  var import_node_buffer3 = require("buffer");
17345
17398
  var import_node_stream3 = require("stream");
17346
17399
  var handleStdioAsync = (options, verboseInfo) => handleStdio(addPropertiesAsync, options, verboseInfo, false);
@@ -17364,8 +17417,8 @@ var addProperties2 = {
17364
17417
  var addPropertiesAsync = {
17365
17418
  input: {
17366
17419
  ...addProperties2,
17367
- fileUrl: ({ value }) => ({ stream: (0, import_node_fs7.createReadStream)(value) }),
17368
- filePath: ({ value: { file } }) => ({ stream: (0, import_node_fs7.createReadStream)(file) }),
17420
+ fileUrl: ({ value }) => ({ stream: (0, import_node_fs8.createReadStream)(value) }),
17421
+ filePath: ({ value: { file } }) => ({ stream: (0, import_node_fs8.createReadStream)(file) }),
17369
17422
  webStream: ({ value }) => ({ stream: import_node_stream3.Readable.fromWeb(value) }),
17370
17423
  iterable: ({ value }) => ({ stream: import_node_stream3.Readable.from(value) }),
17371
17424
  asyncIterable: ({ value }) => ({ stream: import_node_stream3.Readable.from(value) }),
@@ -17374,8 +17427,8 @@ var addPropertiesAsync = {
17374
17427
  },
17375
17428
  output: {
17376
17429
  ...addProperties2,
17377
- fileUrl: ({ value }) => ({ stream: (0, import_node_fs7.createWriteStream)(value) }),
17378
- filePath: ({ value: { file, append } }) => ({ stream: (0, import_node_fs7.createWriteStream)(file, append ? { flags: "a" } : {}) }),
17430
+ fileUrl: ({ value }) => ({ stream: (0, import_node_fs8.createWriteStream)(value) }),
17431
+ filePath: ({ value: { file, append } }) => ({ stream: (0, import_node_fs8.createWriteStream)(file, append ? { flags: "a" } : {}) }),
17379
17432
  webStream: ({ value }) => ({ stream: import_node_stream3.Writable.fromWeb(value) }),
17380
17433
  iterable: forbiddenIfAsync,
17381
17434
  asyncIterable: forbiddenIfAsync,
@@ -20636,6 +20689,54 @@ var BoxStatusStore = class {
20636
20689
  this.map.delete(boxId);
20637
20690
  }
20638
20691
  };
20692
+ function normalizeCpParams(method, params) {
20693
+ if (!params) throw new Error("cp.* requires params");
20694
+ let sources = params.sources;
20695
+ let dest = params.dest;
20696
+ if (!Array.isArray(sources) || sources.length === 0 || typeof dest !== "string") {
20697
+ if (typeof params.boxPath === "string" && typeof params.hostPath === "string") {
20698
+ if (method === "cp.toHost") {
20699
+ sources = [params.boxPath];
20700
+ dest = params.hostPath;
20701
+ } else {
20702
+ sources = [params.hostPath];
20703
+ dest = params.boxPath;
20704
+ }
20705
+ }
20706
+ }
20707
+ if (!Array.isArray(sources) || sources.length === 0 || sources.some((s) => typeof s !== "string")) {
20708
+ throw new Error("cp.* requires a non-empty {sources} string array (or legacy {boxPath, hostPath})");
20709
+ }
20710
+ if (typeof dest !== "string") {
20711
+ throw new Error("cp.* requires a {dest} string (or legacy {boxPath, hostPath})");
20712
+ }
20713
+ return { sources, dest };
20714
+ }
20715
+ function cpFlags(params) {
20716
+ const flags = [];
20717
+ for (const pat of params.exclude ?? []) flags.push("--exclude", pat);
20718
+ if (params.defaultExcludes === false) flags.push("--no-default-excludes");
20719
+ if (params.yes) flags.push("--yes");
20720
+ return flags;
20721
+ }
20722
+ function buildCpArgv(opts) {
20723
+ const { method, boxName, sources, dest, resolveHost, flags } = opts;
20724
+ if (method === "cp.toHost") {
20725
+ const hostAbs = resolveHost(dest);
20726
+ const boxArgs = sources.map((s) => `${boxName}:${s}`);
20727
+ return {
20728
+ argv: ["cp", ...boxArgs, hostAbs, ...flags],
20729
+ detail: `${sources.join(", ")} -> ${hostAbs}`,
20730
+ contextArgv: [...sources, hostAbs]
20731
+ };
20732
+ }
20733
+ const hostAbsSrcs = sources.map(resolveHost);
20734
+ return {
20735
+ argv: ["cp", ...hostAbsSrcs, `${boxName}:${dest}`, ...flags],
20736
+ detail: `${hostAbsSrcs.join(", ")} -> ${dest}`,
20737
+ contextArgv: [...hostAbsSrcs, dest]
20738
+ };
20739
+ }
20639
20740
  async function resolveCloudBackend(name) {
20640
20741
  if (name === "daytona") {
20641
20742
  const pkg = "@agentbox/sandbox-daytona";
@@ -21024,47 +21125,56 @@ async function loadCloudCp() {
21024
21125
  }
21025
21126
  }
21026
21127
  async function runCpRpc(action, deps) {
21128
+ const method = action.method;
21027
21129
  const params = action.params ?? {};
21028
- if (typeof params.boxPath !== "string" || typeof params.hostPath !== "string") {
21130
+ let norm;
21131
+ try {
21132
+ norm = normalizeCpParams(method, params);
21133
+ } catch (err) {
21134
+ return { exitCode: 64, stdout: "", stderr: `${err instanceof Error ? err.message : String(err)}
21135
+ ` };
21136
+ }
21137
+ const entry = process.env["AGENTBOX_CLI_ENTRY"];
21138
+ if (!entry) {
21029
21139
  return {
21030
21140
  exitCode: 64,
21031
21141
  stdout: "",
21032
- stderr: "cp.* requires {boxPath, hostPath} strings\n"
21142
+ stderr: "relay: AGENTBOX_CLI_ENTRY not set; cannot run cp host-side\n"
21033
21143
  };
21034
21144
  }
21035
- const direction = action.method === "cp.toHost" ? "box -> host" : "host -> box";
21145
+ const direction = method === "cp.toHost" ? "box -> host" : "host -> box";
21036
21146
  const lookup = await lookupCloudBox(deps.boxId);
21037
- const hostAbs = resolveHostPath(lookup.workspacePath, params.hostPath);
21147
+ const boxName = deps.boxName ?? deps.boxId;
21148
+ const { argv: cpArgs, detail, contextArgv } = buildCpArgv({
21149
+ method,
21150
+ boxName,
21151
+ sources: norm.sources,
21152
+ dest: norm.dest,
21153
+ resolveHost: (p) => resolveHostPath(lookup.workspacePath, p),
21154
+ flags: cpFlags(params)
21155
+ });
21038
21156
  if (deps.prompts && deps.subscribers) {
21039
21157
  const verdict = await askPrompt(deps.prompts, deps.subscribers, deps.boxId, {
21040
21158
  kind: "confirm",
21041
- message: `Allow cp (${direction}) on ${deps.boxName ?? deps.boxId}?`,
21042
- detail: action.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`,
21159
+ message: `Allow cp (${direction}) on ${boxName}?`,
21160
+ detail,
21043
21161
  defaultAnswer: "n",
21044
- context: {
21045
- command: action.method,
21046
- argv: [params.boxPath, hostAbs]
21047
- }
21162
+ context: { command: method, argv: contextArgv }
21048
21163
  });
21049
21164
  if (verdict.answer !== "y") {
21050
21165
  return { exitCode: 10, stdout: "", stderr: "denied by user\n" };
21051
21166
  }
21052
21167
  }
21053
- const backend = await resolveCloudBackend(deps.backendName);
21054
- const handle = { sandboxId: lookup.cloudSandboxId };
21055
- const cp = await loadCloudCp();
21056
- try {
21057
- const result = action.method === "cp.toHost" ? await cp.downloadFromCloudBox(backend, handle, params.boxPath, hostAbs) : await cp.uploadToCloudBox(backend, handle, hostAbs, params.boxPath);
21058
- return { exitCode: 0, stdout: `${result.finalPath}
21059
- `, stderr: "" };
21060
- } catch (err) {
21061
- return {
21062
- exitCode: 1,
21063
- stdout: "",
21064
- stderr: `cp failed: ${err instanceof Error ? err.message : String(err)}
21065
- `
21066
- };
21067
- }
21168
+ const argv = [process.execPath, entry, ...cpArgs];
21169
+ const result = await execa(argv[0], argv.slice(1), {
21170
+ reject: false,
21171
+ cwd: lookup.workspacePath
21172
+ });
21173
+ return {
21174
+ exitCode: result.exitCode ?? 1,
21175
+ stdout: result.stdout ?? "",
21176
+ stderr: result.stderr ?? ""
21177
+ };
21068
21178
  }
21069
21179
  async function runCheckpointRpc(action, deps) {
21070
21180
  const params = action.params ?? {};
@@ -21169,6 +21279,45 @@ async function runGitRpc(action, deps) {
21169
21279
  stderr: `failed to resolve branch in sandbox ${containerPath}: ${branchProbe.stderr || branch}`
21170
21280
  };
21171
21281
  }
21282
+ if (params.hostOnly) {
21283
+ const dest = params.as && params.as.length > 0 ? params.as : branch;
21284
+ const stageSave = await (0, import_promises17.mkdtemp)((0, import_path5.join)((0, import_os4.tmpdir)(), "agentbox-git-save-"));
21285
+ const hostBundleSave = (0, import_path5.join)(stageSave, "op.bundle");
21286
+ const remoteBundleSave = "/tmp/agentbox-rpc-save.bundle";
21287
+ try {
21288
+ const make = await backend.exec(
21289
+ handle,
21290
+ `git -C ${shellQuote(containerPath)} bundle create ${shellQuote(remoteBundleSave)} ${shellQuote(branch)}`
21291
+ );
21292
+ if (make.exitCode !== 0) {
21293
+ return { exitCode: make.exitCode, stdout: "", stderr: `bundle create failed: ${make.stderr || make.stdout}` };
21294
+ }
21295
+ await backend.downloadFile(handle, remoteBundleSave, hostBundleSave);
21296
+ const refspec = `${params.force ? "+" : ""}${branch}:refs/heads/${dest}`;
21297
+ const landed = await execa(
21298
+ "git",
21299
+ ["-C", lookup.workspacePath, "fetch", hostBundleSave, refspec],
21300
+ { reject: false }
21301
+ );
21302
+ if ((landed.exitCode ?? 1) !== 0) {
21303
+ return {
21304
+ exitCode: landed.exitCode ?? 1,
21305
+ stdout: landed.stdout ?? "",
21306
+ stderr: `host git fetch from bundle failed: ${landed.stderr ?? ""}`
21307
+ };
21308
+ }
21309
+ return {
21310
+ exitCode: 0,
21311
+ stdout: `branch ${dest} available in ${lookup.workspacePath}
21312
+ ${landed.stdout ?? ""}`,
21313
+ stderr: landed.stderr ?? ""
21314
+ };
21315
+ } finally {
21316
+ await (0, import_promises17.rm)(stageSave, { recursive: true, force: true });
21317
+ await backend.exec(handle, `rm -f ${shellQuote(remoteBundleSave)}`).catch(() => {
21318
+ });
21319
+ }
21320
+ }
21172
21321
  const isAgentboxBranch = branch.startsWith("agentbox/");
21173
21322
  const tokenClaimedGit = typeof params.hostInitiated === "string";
21174
21323
  const incomingHashGit = hashRpcParams(params);
@@ -21569,6 +21718,12 @@ function createRelayServer(opts) {
21569
21718
  }
21570
21719
  if (body.method === "git.push" || body.method === "git.fetch") {
21571
21720
  if (body.method === "git.push") {
21721
+ const hostOnlyParams = body.params;
21722
+ if (hostOnlyParams?.hostOnly) {
21723
+ const saveResult = await handleGitSaveToHost(reg, hostOnlyParams);
21724
+ send(res, saveResult.exitCode === 0 ? 200 : 500, saveResult);
21725
+ return;
21726
+ }
21572
21727
  const params = body.params;
21573
21728
  const worktree = resolveWorktree(reg, params?.path ?? "/workspace");
21574
21729
  const isAgentboxBranch = worktree?.branch.startsWith("agentbox/") ?? false;
@@ -21608,8 +21763,11 @@ function createRelayServer(opts) {
21608
21763
  }
21609
21764
  if (body.method === "cp.toHost" || body.method === "cp.fromHost") {
21610
21765
  const params = body.params;
21611
- if (!params || typeof params.boxPath !== "string" || typeof params.hostPath !== "string") {
21612
- send(res, 400, { error: "cp.* requires {boxPath, hostPath} strings" });
21766
+ let norm;
21767
+ try {
21768
+ norm = normalizeCpParams(body.method, params);
21769
+ } catch (err) {
21770
+ send(res, 400, { error: err instanceof Error ? err.message : String(err) });
21613
21771
  return;
21614
21772
  }
21615
21773
  if (params.exclude !== void 0 && (!Array.isArray(params.exclude) || params.exclude.some((p) => typeof p !== "string"))) {
@@ -21618,9 +21776,15 @@ function createRelayServer(opts) {
21618
21776
  }
21619
21777
  const direction = body.method === "cp.toHost" ? "box -> host" : "host -> box";
21620
21778
  const workspacePath = await boxWorkspacePath(reg.boxId);
21621
- const hostAbs = resolveHostPath(workspacePath, params.hostPath);
21622
- const pathDetail = body.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`;
21623
- const detailParts = [pathDetail];
21779
+ const { argv: cpArgs, detail, contextArgv } = buildCpArgv({
21780
+ method: body.method,
21781
+ boxName: reg.name,
21782
+ sources: norm.sources,
21783
+ dest: norm.dest,
21784
+ resolveHost: (p) => resolveHostPath(workspacePath, p),
21785
+ flags: cpFlags(params)
21786
+ });
21787
+ const detailParts = [detail];
21624
21788
  if (params.exclude && params.exclude.length > 0) {
21625
21789
  detailParts.push(`exclude: ${params.exclude.join(", ")}`);
21626
21790
  }
@@ -21633,17 +21797,14 @@ function createRelayServer(opts) {
21633
21797
  defaultAnswer: "n",
21634
21798
  context: {
21635
21799
  command: body.method,
21636
- argv: [params.boxPath, hostAbs]
21800
+ argv: contextArgv
21637
21801
  }
21638
21802
  });
21639
21803
  if (verdict.answer !== "y") {
21640
21804
  send(res, 500, { exitCode: 10, stdout: "", stderr: "denied by user\n" });
21641
21805
  return;
21642
21806
  }
21643
- const result = await handleCpRpc(reg, body.method, params, {
21644
- hostPath: hostAbs,
21645
- cwd: workspacePath
21646
- });
21807
+ const result = await handleCpRpc(cpArgs, workspacePath);
21647
21808
  const status2 = result.exitCode === 0 ? 200 : 500;
21648
21809
  send(res, status2, result);
21649
21810
  return;
@@ -22105,6 +22266,45 @@ function resolveWorktree(reg, containerPath) {
22105
22266
  const prefixMatches = trees.filter((w) => containerPath === w.containerPath || containerPath.startsWith(w.containerPath + "/")).sort((a2, b) => b.containerPath.length - a2.containerPath.length);
22106
22267
  return prefixMatches[0] ?? trees.find((w) => w.containerPath === "/workspace") ?? null;
22107
22268
  }
22269
+ async function handleGitSaveToHost(reg, params) {
22270
+ const containerPath = params?.path ?? "/workspace";
22271
+ const worktree = resolveWorktree(reg, containerPath);
22272
+ if (!worktree) {
22273
+ return {
22274
+ exitCode: 64,
22275
+ stdout: "",
22276
+ stderr: `no worktree registered for box ${reg.boxId} matching ${containerPath}`
22277
+ };
22278
+ }
22279
+ const src = worktree.branch;
22280
+ const dest = params?.as && params.as.length > 0 ? params.as : src;
22281
+ if (dest === src) {
22282
+ return {
22283
+ exitCode: 0,
22284
+ stdout: `branch ${dest} already available in ${worktree.hostMainRepo}
22285
+ `,
22286
+ stderr: ""
22287
+ };
22288
+ }
22289
+ const refspec = `${params?.force ? "+" : ""}${src}:refs/heads/${dest}`;
22290
+ const result = await runHostCommand([
22291
+ "git",
22292
+ "-C",
22293
+ worktree.hostMainRepo,
22294
+ "fetch",
22295
+ ".",
22296
+ refspec
22297
+ ]);
22298
+ if (result.exitCode === 0) {
22299
+ return {
22300
+ exitCode: 0,
22301
+ stdout: `branch ${dest} available in ${worktree.hostMainRepo}
22302
+ ${result.stdout}`,
22303
+ stderr: result.stderr
22304
+ };
22305
+ }
22306
+ return result;
22307
+ }
22108
22308
  async function handleGitRpc(reg, method, params) {
22109
22309
  const containerPath = params?.path ?? "/workspace";
22110
22310
  const worktree = resolveWorktree(reg, containerPath);
@@ -22314,7 +22514,7 @@ async function handleIntegrationRpc(method, reg, params, prompts, subscribers, h
22314
22514
  }
22315
22515
  return runHostIntegration(connector, opDesc, args, worktree.hostMainRepo);
22316
22516
  }
22317
- async function handleCpRpc(reg, method, params, opts) {
22517
+ async function handleCpRpc(cpArgs, cwd) {
22318
22518
  const entry = process.env.AGENTBOX_CLI_ENTRY;
22319
22519
  if (!entry) {
22320
22520
  return {
@@ -22323,13 +22523,8 @@ async function handleCpRpc(reg, method, params, opts) {
22323
22523
  stderr: "relay: AGENTBOX_CLI_ENTRY not set; cannot run cp host-side"
22324
22524
  };
22325
22525
  }
22326
- const boxRef = `${reg.name}:${params.boxPath}`;
22327
- const flags = [];
22328
- for (const pat of params.exclude ?? []) flags.push("--exclude", pat);
22329
- if (params.defaultExcludes === false) flags.push("--no-default-excludes");
22330
- if (params.yes) flags.push("--yes");
22331
- const argv = method === "cp.toHost" ? [process.execPath, entry, "cp", boxRef, opts.hostPath, ...flags] : [process.execPath, entry, "cp", opts.hostPath, boxRef, ...flags];
22332
- return runHostCommand(argv, CP_RPC_TIMEOUT_MS, opts.cwd);
22526
+ const argv = [process.execPath, entry, ...cpArgs];
22527
+ return runHostCommand(argv, CP_RPC_TIMEOUT_MS, cwd);
22333
22528
  }
22334
22529
  async function handleDownloadRpc(reg, kind) {
22335
22530
  const entry = process.env.AGENTBOX_CLI_ENTRY;
@@ -23189,21 +23384,21 @@ function defaultCapturePane2(sessionName) {
23189
23384
  var import_node_child_process9 = require("child_process");
23190
23385
  var import_node_crypto = require("crypto");
23191
23386
  var import_node_events15 = require("events");
23192
- var import_node_fs8 = require("fs");
23387
+ var import_node_fs9 = require("fs");
23193
23388
  var import_promises22 = require("fs/promises");
23194
- var import_node_path8 = require("path");
23389
+ var import_node_path9 = require("path");
23195
23390
 
23196
23391
  // src/state-dir.ts
23197
23392
  var import_promises20 = require("fs/promises");
23198
- var import_node_path7 = require("path");
23393
+ var import_node_path8 = require("path");
23199
23394
  async function resolveWritableStateDir(want = DEFAULT_STATE_DIR, logDir = DEFAULT_LOG_DIR, ensureSubdir = "tasks", onNotice) {
23200
23395
  try {
23201
- await (0, import_promises20.mkdir)((0, import_node_path7.join)(want, ensureSubdir), { recursive: true });
23396
+ await (0, import_promises20.mkdir)((0, import_node_path8.join)(want, ensureSubdir), { recursive: true });
23202
23397
  return want;
23203
23398
  } catch {
23204
- const fallback = (0, import_node_path7.join)(logDir, "state");
23399
+ const fallback = (0, import_node_path8.join)(logDir, "state");
23205
23400
  try {
23206
- await (0, import_promises20.mkdir)((0, import_node_path7.join)(fallback, ensureSubdir), { recursive: true });
23401
+ await (0, import_promises20.mkdir)((0, import_node_path8.join)(fallback, ensureSubdir), { recursive: true });
23207
23402
  onNotice?.(`${want} not writable, using ${fallback}`);
23208
23403
  return fallback;
23209
23404
  } catch {
@@ -23325,8 +23520,9 @@ var RelayClient = class {
23325
23520
  url;
23326
23521
  token;
23327
23522
  constructor(env = process.env) {
23328
- const rawUrl = env.AGENTBOX_RELAY_URL;
23329
- const token = env.AGENTBOX_RELAY_TOKEN ?? "";
23523
+ const resolved = resolveRelayEnv(env);
23524
+ const rawUrl = resolved.url;
23525
+ const token = resolved.token ?? "";
23330
23526
  let url = null;
23331
23527
  if (rawUrl && token.length > 0) {
23332
23528
  try {
@@ -23462,7 +23658,7 @@ var Ring = class {
23462
23658
  };
23463
23659
  function resolveCwd(unitCwd, baseCwd) {
23464
23660
  if (!unitCwd) return baseCwd;
23465
- return unitCwd.startsWith("/") ? unitCwd : (0, import_node_path8.join)(baseCwd, unitCwd);
23661
+ return unitCwd.startsWith("/") ? unitCwd : (0, import_node_path9.join)(baseCwd, unitCwd);
23466
23662
  }
23467
23663
  function spawnArgs(cmd) {
23468
23664
  if (typeof cmd === "string") return { bin: "bash", args: ["-c", cmd] };
@@ -23584,7 +23780,7 @@ var ServiceRunner = class extends import_node_events15.EventEmitter {
23584
23780
  const spec = this.spec;
23585
23781
  const cwd = resolveCwd(spec.cwd, this.opts.cwd);
23586
23782
  if (!this.logStream) {
23587
- this.logStream = (0, import_node_fs8.createWriteStream)((0, import_node_path8.join)(this.opts.logDir, `${spec.name}.log`), {
23783
+ this.logStream = (0, import_node_fs9.createWriteStream)((0, import_node_path9.join)(this.opts.logDir, `${spec.name}.log`), {
23588
23784
  flags: "a"
23589
23785
  });
23590
23786
  this.logStream.on("error", (err) => {
@@ -23788,7 +23984,7 @@ var TaskRunner = class extends import_node_events15.EventEmitter {
23788
23984
  }
23789
23985
  ensureLogStream() {
23790
23986
  if (this.logStream) return;
23791
- this.logStream = (0, import_node_fs8.createWriteStream)((0, import_node_path8.join)(this.opts.logDir, `${this.spec.name}.log`), {
23987
+ this.logStream = (0, import_node_fs9.createWriteStream)((0, import_node_path9.join)(this.opts.logDir, `${this.spec.name}.log`), {
23792
23988
  flags: "a"
23793
23989
  });
23794
23990
  this.logStream.on("error", (err) => {
@@ -23801,7 +23997,7 @@ var TaskRunner = class extends import_node_events15.EventEmitter {
23801
23997
  return (0, import_node_crypto.createHash)("sha256").update(payload).digest("hex");
23802
23998
  }
23803
23999
  markerPath() {
23804
- return (0, import_node_path8.join)(this.opts.stateDir, "tasks", this.spec.name);
24000
+ return (0, import_node_path9.join)(this.opts.stateDir, "tasks", this.spec.name);
23805
24001
  }
23806
24002
  /** Run the `run_once.check` probe. Resolves true when it exits 0. */
23807
24003
  runCheck(command, cwd) {
@@ -23849,7 +24045,7 @@ var TaskRunner = class extends import_node_events15.EventEmitter {
23849
24045
  async writeMarker(cwd) {
23850
24046
  const marker = this.markerPath();
23851
24047
  try {
23852
- await (0, import_promises22.mkdir)((0, import_node_path8.join)(this.opts.stateDir, "tasks"), { recursive: true });
24048
+ await (0, import_promises22.mkdir)((0, import_node_path9.join)(this.opts.stateDir, "tasks"), { recursive: true });
23853
24049
  await (0, import_promises22.writeFile)(marker, `${this.commandHash(cwd)}
23854
24050
  `, "utf8");
23855
24051
  } catch (err) {
@@ -24377,7 +24573,7 @@ function normalizeTask(t) {
24377
24573
  };
24378
24574
  }
24379
24575
  async function readLogFile(logDir, service, tail) {
24380
- const path6 = (0, import_node_path8.join)(logDir, `${service}.log`);
24576
+ const path6 = (0, import_node_path9.join)(logDir, `${service}.log`);
24381
24577
  let text;
24382
24578
  try {
24383
24579
  text = await (0, import_promises22.readFile)(path6, "utf8");
@@ -24399,7 +24595,7 @@ async function readLogFile(logDir, service, tail) {
24399
24595
  // src/socket.ts
24400
24596
  var import_node_net4 = require("net");
24401
24597
  var import_promises23 = require("fs/promises");
24402
- var import_node_path9 = require("path");
24598
+ var import_node_path10 = require("path");
24403
24599
 
24404
24600
  // src/status-reporter.ts
24405
24601
  var import_node_child_process11 = require("child_process");
@@ -24674,7 +24870,7 @@ async function discoverListeningPorts() {
24674
24870
 
24675
24871
  // src/socket.ts
24676
24872
  async function startServer(opts) {
24677
- await (0, import_promises23.mkdir)((0, import_node_path9.dirname)(opts.socketPath), { recursive: true });
24873
+ await (0, import_promises23.mkdir)((0, import_node_path10.dirname)(opts.socketPath), { recursive: true });
24678
24874
  await (0, import_promises23.unlink)(opts.socketPath).catch(() => {
24679
24875
  });
24680
24876
  const server = (0, import_node_net4.createServer)((sock) => {
@@ -25038,6 +25234,13 @@ var daemonCommand = new Command("daemon").description("Run the agentbox-ctl supe
25038
25234
  kind: "cloud",
25039
25235
  registeredAt: (/* @__PURE__ */ new Date()).toISOString()
25040
25236
  });
25237
+ try {
25238
+ writeRelayEnvFile(`http://127.0.0.1:${String(boxRelayPort)}`, boxToken);
25239
+ } catch (err) {
25240
+ const msg = err instanceof Error ? err.message : String(err);
25241
+ process.stderr.write(`agentbox-ctl: failed to write relay env file: ${msg}
25242
+ `);
25243
+ }
25041
25244
  process.stdout.write(
25042
25245
  `agentbox-ctl: in-sandbox relay (mode=box) listening on :${String(boxRelayPort)}
25043
25246
  `
@@ -25241,9 +25444,17 @@ function hostInitiatedOption() {
25241
25444
  ).hideHelp();
25242
25445
  }
25243
25446
  function buildParams(opts, extra) {
25447
+ const args = [...extra];
25244
25448
  const params = { path: opts.cwd ?? process.cwd() };
25245
25449
  if (opts.remote) params.remote = opts.remote;
25246
- if (extra.length > 0) params.args = extra;
25450
+ if (opts.hostOnly) {
25451
+ params.hostOnly = true;
25452
+ if (opts.as) params.as = opts.as;
25453
+ if (opts.force) params.force = true;
25454
+ } else if (opts.force) {
25455
+ args.push("--force");
25456
+ }
25457
+ if (args.length > 0) params.args = args;
25247
25458
  if (opts.hostInitiatedToken) params.hostInitiated = opts.hostInitiatedToken;
25248
25459
  return params;
25249
25460
  }
@@ -25271,10 +25482,14 @@ function hasGitIdentity(cwd) {
25271
25482
  });
25272
25483
  }
25273
25484
  var gitCommand = new Command("git").description("Git operations that need host credentials (routed through the agentbox relay)").addCommand(
25274
- new Command("push").description("Run `git push` on the host main repo against this box's branch (user is prompted on the host wrapper to confirm)").option("--remote <name>", "remote name (default: origin)").option("--cwd <path>", "container path identifying which registered worktree to use").addOption(hostInitiatedOption()).allowExcessArguments(true).allowUnknownOption(true).argument(
25485
+ new Command("push").description("Run `git push` on the host main repo against this box's branch (user is prompted on the host wrapper to confirm)").option("--remote <name>", "remote name (default: origin)").option("--cwd <path>", "container path identifying which registered worktree to use").option("--host-only", "land the branch in the host's local repo only; do NOT push to the remote (nothing is published online)").option("--as <branch>", "with --host-only: destination branch name in the host repo (default: this box's branch name)").option("--force", "with --host-only: allow a non-fast-forward overwrite of the destination branch").addOption(hostInitiatedOption()).allowExcessArguments(true).allowUnknownOption(true).argument(
25275
25486
  "[args...]",
25276
25487
  "extra flags appended to the host-built `git push <remote> <branch>` (e.g. `--force-with-lease`, `--tags`). Do NOT re-pass the remote or branch \u2014 they are taken from --remote and the registered worktree; appending them as positionals makes git treat them as refspecs and fail with `refs/remotes/origin/HEAD cannot be resolved to branch`. Use --remote to change the remote."
25277
25488
  ).action(async (args, opts) => {
25489
+ if (opts.hostOnly && opts.remote) {
25490
+ process.stderr.write("agentbox-ctl git push: --host-only does not use a remote; drop --remote\n");
25491
+ process.exit(64);
25492
+ }
25278
25493
  const code = await postRpcAndExit("git.push", buildParams(opts, args), {
25279
25494
  errorPrefix: "agentbox-ctl git"
25280
25495
  });
@@ -25447,7 +25662,7 @@ var import_promises25 = require("fs/promises");
25447
25662
  // src/secret.ts
25448
25663
  var import_node_crypto2 = require("crypto");
25449
25664
  var import_promises24 = require("fs/promises");
25450
- var import_node_path10 = require("path");
25665
+ var import_node_path11 = require("path");
25451
25666
  var SECRET_RE = /\{\{\s*AGENTBOX_AUTO_SECRET(?::([A-Za-z0-9_-]+))?\s*\}\}/g;
25452
25667
  var SECRET_BYTES = 32;
25453
25668
  function generateSecret() {
@@ -25466,7 +25681,7 @@ async function resolveAutoSecrets(content, opts = {}) {
25466
25681
  "secrets",
25467
25682
  (msg) => opts.onLog?.(msg)
25468
25683
  );
25469
- const dir = (0, import_node_path10.join)(base, "secrets");
25684
+ const dir = (0, import_node_path11.join)(base, "secrets");
25470
25685
  for (const name of names) named.set(name, await loadOrCreateSecret(dir, name, opts.onLog));
25471
25686
  }
25472
25687
  return content.replace(
@@ -25475,7 +25690,7 @@ async function resolveAutoSecrets(content, opts = {}) {
25475
25690
  );
25476
25691
  }
25477
25692
  async function loadOrCreateSecret(dir, name, onLog) {
25478
- const file = (0, import_node_path10.join)(dir, name);
25693
+ const file = (0, import_node_path11.join)(dir, name);
25479
25694
  try {
25480
25695
  const existing = (await (0, import_promises24.readFile)(file, "utf8")).trim();
25481
25696
  if (existing.length > 0) return existing;