@madarco/agentbox 0.20.0 → 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 (64) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/dist/{_cloud-attach-THTN4CFZ.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-7RWFYLF3.js → chunk-PX7G4PSI.js} +78 -23
  9. package/dist/chunk-PX7G4PSI.js.map +1 -0
  10. package/dist/{chunk-ZX6DTA4X.js → chunk-QKL7PCXQ.js} +220 -16
  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-3VFY3N4A.js → chunk-YZVFGFYQ.js} +320 -956
  15. package/dist/chunk-YZVFGFYQ.js.map +1 -0
  16. package/dist/{dist-7ELDXBAG.js → dist-FMA5Y25B.js} +9 -6
  17. package/dist/{dist-7ELDXBAG.js.map → dist-FMA5Y25B.js.map} +1 -1
  18. package/dist/{dist-C3YRC3PP.js → dist-NWKOEWUJ.js} +120 -26
  19. package/dist/dist-NWKOEWUJ.js.map +1 -0
  20. package/dist/{dist-3PLT2EK2.js → dist-SAS4PIHA.js} +15 -3
  21. package/dist/{dist-3WFNXXPE.js → dist-U76JL6HI.js} +7 -6
  22. package/dist/{dist-3WFNXXPE.js.map → dist-U76JL6HI.js.map} +1 -1
  23. package/dist/{dist-CZ6CRADC.js → dist-UVQJ2BZJ.js} +5 -5
  24. package/dist/dist-UVQJ2BZJ.js.map +1 -0
  25. package/dist/index.js +1236 -561
  26. package/dist/index.js.map +1 -1
  27. package/dist/{prepared-state-MQHD3M5F-5ZMCNY43.js → prepared-state-MQHD3M5F-YYVVMTNJ.js} +2 -2
  28. package/package.json +4 -3
  29. package/runtime/daytona/custom-system-CLAUDE.md +13 -3
  30. package/runtime/docker/Dockerfile.box +57 -10
  31. package/runtime/docker/apps/cli/share/agentbox-setup/SKILL.md +6 -5
  32. package/runtime/docker/packages/ctl/dist/bin.cjs +324 -109
  33. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-portless-trust +82 -0
  34. package/runtime/docker/packages/sandbox-docker/scripts/custom-system-CLAUDE.md +12 -3
  35. package/runtime/e2b/agentbox-setup-skill.md +6 -5
  36. package/runtime/e2b/attach-helper.cjs +4 -1
  37. package/runtime/e2b/ctl.cjs +324 -109
  38. package/runtime/e2b/custom-system-CLAUDE.md +12 -3
  39. package/runtime/e2b/scripts/build-template.sh +54 -2
  40. package/runtime/hetzner/agentbox-portless-trust +82 -0
  41. package/runtime/hetzner/agentbox-setup-skill.md +6 -5
  42. package/runtime/hetzner/ctl.cjs +324 -109
  43. package/runtime/hetzner/custom-system-CLAUDE.md +12 -3
  44. package/runtime/hetzner/scripts/install-box.sh +60 -7
  45. package/runtime/relay/bin.cjs +187 -43
  46. package/runtime/vercel/agentbox-setup-skill.md +6 -5
  47. package/runtime/vercel/ctl.cjs +324 -109
  48. package/runtime/vercel/custom-system-CLAUDE.md +12 -3
  49. package/runtime/vercel/scripts/provision.sh +64 -2
  50. package/share/agentbox-setup/SKILL.md +6 -5
  51. package/share/host-skills/agentbox/SKILL.md +14 -0
  52. package/share/host-skills/agentbox-info/SKILL.md +30 -1
  53. package/dist/chunk-3VFY3N4A.js.map +0 -1
  54. package/dist/chunk-7K2A3NLE.js.map +0 -1
  55. package/dist/chunk-7RWFYLF3.js.map +0 -1
  56. package/dist/chunk-ZX6DTA4X.js.map +0 -1
  57. package/dist/dist-C3YRC3PP.js.map +0 -1
  58. package/dist/dist-CZ6CRADC.js.map +0 -1
  59. /package/dist/{_cloud-attach-THTN4CFZ.js.map → _cloud-attach-U3QJO7IF.js.map} +0 -0
  60. /package/dist/{chunk-52LKNUY7.js.map → chunk-6JJIKCMY.js.map} +0 -0
  61. /package/dist/{chunk-NXX3KQZ6.js.map → chunk-IXQTUXWV.js.map} +0 -0
  62. /package/dist/{chunk-MODNW54N.js.map → chunk-KTEDFUKM.js.map} +0 -0
  63. /package/dist/{dist-3PLT2EK2.js.map → dist-SAS4PIHA.js.map} +0 -0
  64. /package/dist/{prepared-state-MQHD3M5F-5ZMCNY43.js.map → prepared-state-MQHD3M5F-YYVVMTNJ.js.map} +0 -0
@@ -20,7 +20,11 @@ state. The wrapper already builds `git push <remote> <branch>` host-side from
20
20
  the registered worktree; the `-- <args>` slot is for extra flags only (e.g.
21
21
  `--force-with-lease`, `--tags`). Re-passing the remote or branch makes git
22
22
  treat them as refspecs and fails with `refs/remotes/origin/HEAD cannot be
23
- resolved to branch`.
23
+ resolved to branch`. To make the branch available on the host **without**
24
+ publishing it to the remote, add `--host-only` (e.g. `agentbox-ctl git push
25
+ --host-only`); it lands the branch in the host's local repo only. Add `--as
26
+ <branch>` to choose the host branch name (default: this box's branch), and
27
+ `--force` to allow a non-fast-forward overwrite.
24
28
 
25
29
  For GitHub PR work, use `agentbox-ctl git pr <op> [args...]` — same model,
26
30
  relay shells to host `gh`. Ops: `create`, `view`, `list`, `comment`,
@@ -29,11 +33,16 @@ read-only and run silently; everything else asks the user to confirm in
29
33
  the host wrapper (deny → exit 10).
30
34
 
31
35
  For ad-hoc file transfers between this box and the host, use
32
- `agentbox-ctl cp toHost <boxPath> <hostPath>` and
33
- `agentbox-ctl cp fromHost <hostPath> <boxPath>` or `agentbox-ctl download claude` / `download env` /
36
+ `agentbox-ctl cp toHost <boxPath...> <hostPath>` and
37
+ `agentbox-ctl cp fromHost <hostPath...> <boxPath>` (both accept multiple paths; wildcards expand in your shell) or `agentbox-ctl download claude` / `download env` /
34
38
  `download config`. They RPC to the host and
35
39
  ask the user for confirmation on the wrapper that runs `agentbox claude`;
36
40
  deny returns exit 10 (`denied by user`).
37
41
  Don't put any timeout on the command, it will run forever and the user will be notified through multiple channels.
38
42
 
43
+ If an agentbox.yaml file is present, services and docker containers will be started automatically.
44
+ Check the status with `agentbox-ctl status`.
45
+
46
+ To view any web services, open the browser to https://<AGENTBOX_BOX_HOST>. The AGENTBOX_BOX_HOST env var is available in the box and the same url will work from the host as well via a local proxy or because is a cloud provided url.
47
+
39
48
  Box identity: /etc/agentbox/box.env and the AGENTBOX_* env vars.
@@ -31,6 +31,24 @@ set -euo pipefail
31
31
  step() { printf '\n>>> BEGIN %s\n' "$1"; }
32
32
  done_() { printf '<<< END %s\n' "$1"; }
33
33
 
34
+ # Retry a command with exponential backoff. Usage: retry_backoff <max> cmd...
35
+ # Waits 60s before attempt 2, 240s before attempt 3 (~5 min total budget). Used
36
+ # for the Claude native installer, whose CDN (claude.ai / downloads.claude.ai,
37
+ # behind Cloudflare) intermittently 403s cloud-datacenter egress IPs under load.
38
+ retry_backoff() {
39
+ local max=$1; shift
40
+ local attempt=1
41
+ local -a waits=(60 240)
42
+ while true; do
43
+ if "$@"; then return 0; fi
44
+ if [ "$attempt" -ge "$max" ]; then return 1; fi
45
+ local w=${waits[$((attempt-1))]:-240}
46
+ echo "retry_backoff: attempt ${attempt}/${max} failed — backing off ${w}s" >&2
47
+ sleep "$w"
48
+ attempt=$((attempt+1))
49
+ done
50
+ }
51
+
34
52
  if [ "$(id -u)" -ne 0 ]; then
35
53
  echo "install-box.sh: must run as root (got uid $(id -u))" >&2
36
54
  exit 64
@@ -69,6 +87,7 @@ apt-get install -y --no-install-recommends \
69
87
  python3-venv \
70
88
  build-essential \
71
89
  git \
90
+ git-lfs \
72
91
  tmux \
73
92
  vim \
74
93
  libcap2-bin \
@@ -134,6 +153,14 @@ step "git system-wide safe.directory"
134
153
  git config --system --add safe.directory '*'
135
154
  done_ "git system-wide safe.directory"
136
155
 
156
+ step "git-lfs system filter"
157
+ # Register filter.lfs.* in /etc/gitconfig so an in-box checkout of an LFS repo
158
+ # smudges instead of writing pointer files. Unlike docker, cloud boxes have no
159
+ # bind-mounted ~/.gitconfig, so --system is the only place the filter lives.
160
+ # --skip-repo keeps install from touching a checkout at bake time.
161
+ git lfs install --system --skip-repo
162
+ done_ "git-lfs system filter"
163
+
137
164
  step "docker + iptables for in-VPS DinD"
138
165
  apt-get install -y --no-install-recommends \
139
166
  docker.io \
@@ -163,9 +190,10 @@ done_ "agentbox-ctl install"
163
190
  # *before* Chromium sidesteps the issue and keeps the snapshot complete.
164
191
  # Tracked as Phase-7 follow-up in docs/hertzner_backlog.md.
165
192
 
166
- step "baked helper scripts (vnc / dockerd / cleanup / xdg-open / gh + git + ntn + linear shims)"
193
+ step "baked helper scripts (vnc / dockerd / portless-trust / cleanup / xdg-open / gh + git + ntn + linear shims)"
167
194
  install -m 0755 /tmp/agentbox-vnc-start /usr/local/bin/agentbox-vnc-start
168
195
  install -m 0755 /tmp/agentbox-dockerd-start /usr/local/bin/agentbox-dockerd-start
196
+ install -m 0755 /tmp/agentbox-portless-trust /usr/local/bin/agentbox-portless-trust
169
197
  install -m 0755 /tmp/agentbox-checkpoint-cleanup /usr/local/bin/agentbox-checkpoint-cleanup
170
198
  install -m 0755 /tmp/agentbox-open /usr/local/bin/agentbox-open
171
199
  ln -sf /usr/local/bin/agentbox-open /usr/local/bin/xdg-open
@@ -182,7 +210,7 @@ install -m 0755 /tmp/agentbox-git-shim /usr/local/bin/git
182
210
  install -m 0755 /tmp/agentbox-ntn-shim /usr/local/bin/ntn
183
211
  ln -sf /usr/local/bin/ntn /usr/local/bin/notion
184
212
  install -m 0755 /tmp/agentbox-linear-shim /usr/local/bin/linear
185
- done_ "baked helper scripts (vnc / dockerd / cleanup / xdg-open / gh + git + ntn + linear shims)"
213
+ done_ "baked helper scripts (vnc / dockerd / portless-trust / cleanup / xdg-open / gh + git + ntn + linear shims)"
186
214
 
187
215
  step "baked config files (claude / codex / setup guide / tmux.conf)"
188
216
  install -m 0644 /tmp/agentbox-custom-CLAUDE.md /etc/claude-code/CLAUDE.md
@@ -262,6 +290,18 @@ export LC_ALL=${LC_ALL:-en_US.UTF-8}
262
290
  export DISPLAY=${DISPLAY:-:1}
263
291
  export AGENT_BROWSER_EXECUTABLE_PATH=${AGENT_BROWSER_EXECUTABLE_PATH:-/usr/local/bin/chromium}
264
292
  export BROWSER=${BROWSER:-/usr/local/bin/agentbox-open}
293
+ # Land interactive login shells in the workspace, so remote-host integrations
294
+ # (Codex app, VS Code Remote-SSH, plain `ssh <box>`) open in the project instead
295
+ # of $HOME. Interactive-only so scp/sftp and `ssh box <cmd>` are untouched; only
296
+ # when still at $HOME so a caller-chosen dir (e.g. agentbox's tmux `-c /workspace`)
297
+ # is never overridden.
298
+ case $- in
299
+ *i*)
300
+ if [ "$PWD" = "$HOME" ] && [ -d /workspace ]; then
301
+ cd /workspace
302
+ fi
303
+ ;;
304
+ esac
265
305
  PROFILE
266
306
  chmod 0644 /etc/profile.d/agentbox.sh
267
307
  done_ "login-shell shim (/etc/profile.d/agentbox.sh)"
@@ -325,7 +365,7 @@ done_ "VNC stack (TigerVNC + noVNC + websockify + autocutsel)"
325
365
 
326
366
  step "Chrome runtime libs"
327
367
  apt-get install -y --no-install-recommends \
328
- libnss3 libnspr4 libatk1.0-0t64 libatk-bridge2.0-0t64 libcups2t64 \
368
+ libnss3 libnss3-tools libnspr4 libatk1.0-0t64 libatk-bridge2.0-0t64 libcups2t64 \
329
369
  libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
330
370
  libgbm1 libdrm2 libpango-1.0-0 libcairo2 libasound2t64 \
331
371
  fonts-liberation xdg-utils
@@ -341,11 +381,24 @@ npm install -g @openai/codex opencode-ai
341
381
  done_ "Codex CLI prereqs (bubblewrap) + agent installs"
342
382
 
343
383
  step "Claude Code (native installer, run as vscode)"
344
- # Anthropic's native installer drops `claude` at /home/vscode/.local/bin/.
345
- # Run as vscode so the binary lands in the right home and is owned by the
346
- # user that'll execute it. DISABLE_AUTOUPDATER is set globally via
384
+ # Anthropic's native installer is the path the rest of AgentBox expects: it
385
+ # drops `claude` at /home/vscode/.local/bin/claude with installMethod=native
386
+ # (matching the host-seeded .claude.json, so the startup integrity check stays
387
+ # quiet) and ships native-only features the npm package lacks. Run as vscode so
388
+ # the binary lands in the right home; DISABLE_AUTOUPDATER is set globally via
347
389
  # /etc/profile.d/agentbox.sh below.
348
- sudo -u vscode -H bash -lc 'curl -fsSL https://claude.ai/install.sh | bash -s stable'
390
+ #
391
+ # Its CDN (claude.ai / downloads.claude.ai) sits behind Cloudflare, which
392
+ # intermittently 403s cloud-datacenter egress IPs (Hetzner among them) under
393
+ # load. Retry with backoff rather than falling back to npm. A bare `curl | bash`
394
+ # would hide a 403 (curl -f exits non-zero but the pipe's status is bash's 0),
395
+ # so keep pipefail and fold the PATH check in so a "succeeded but absent" result
396
+ # also retries. A failed prepare is better than a claude-less snapshot.
397
+ if ! retry_backoff 3 sudo -u vscode -H bash -lc \
398
+ 'set -o pipefail; curl -fsSL https://claude.ai/install.sh | bash -s stable && command -v claude >/dev/null'; then
399
+ echo "install-box.sh: Claude native installer failed after 3 attempts (Cloudflare 403?) — aborting bake" >&2
400
+ exit 71
401
+ fi
349
402
  done_ "Claude Code (native installer, run as vscode)"
350
403
 
351
404
  step "Chromium download via Playwright (as vscode)"
@@ -18381,6 +18381,56 @@ var HostInitiatedTokens = class {
18381
18381
  }
18382
18382
  };
18383
18383
 
18384
+ // src/cp-rpc.ts
18385
+ function normalizeCpParams(method, params) {
18386
+ if (!params) throw new Error("cp.* requires params");
18387
+ let sources = params.sources;
18388
+ let dest = params.dest;
18389
+ if (!Array.isArray(sources) || sources.length === 0 || typeof dest !== "string") {
18390
+ if (typeof params.boxPath === "string" && typeof params.hostPath === "string") {
18391
+ if (method === "cp.toHost") {
18392
+ sources = [params.boxPath];
18393
+ dest = params.hostPath;
18394
+ } else {
18395
+ sources = [params.hostPath];
18396
+ dest = params.boxPath;
18397
+ }
18398
+ }
18399
+ }
18400
+ if (!Array.isArray(sources) || sources.length === 0 || sources.some((s) => typeof s !== "string")) {
18401
+ throw new Error("cp.* requires a non-empty {sources} string array (or legacy {boxPath, hostPath})");
18402
+ }
18403
+ if (typeof dest !== "string") {
18404
+ throw new Error("cp.* requires a {dest} string (or legacy {boxPath, hostPath})");
18405
+ }
18406
+ return { sources, dest };
18407
+ }
18408
+ function cpFlags(params) {
18409
+ const flags = [];
18410
+ for (const pat of params.exclude ?? []) flags.push("--exclude", pat);
18411
+ if (params.defaultExcludes === false) flags.push("--no-default-excludes");
18412
+ if (params.yes) flags.push("--yes");
18413
+ return flags;
18414
+ }
18415
+ function buildCpArgv(opts) {
18416
+ const { method, boxName, sources, dest, resolveHost, flags } = opts;
18417
+ if (method === "cp.toHost") {
18418
+ const hostAbs = resolveHost(dest);
18419
+ const boxArgs = sources.map((s) => `${boxName}:${s}`);
18420
+ return {
18421
+ argv: ["cp", ...boxArgs, hostAbs, ...flags],
18422
+ detail: `${sources.join(", ")} -> ${hostAbs}`,
18423
+ contextArgv: [...sources, hostAbs]
18424
+ };
18425
+ }
18426
+ const hostAbsSrcs = sources.map(resolveHost);
18427
+ return {
18428
+ argv: ["cp", ...hostAbsSrcs, `${boxName}:${dest}`, ...flags],
18429
+ detail: `${hostAbsSrcs.join(", ")} -> ${dest}`,
18430
+ contextArgv: [...hostAbsSrcs, dest]
18431
+ };
18432
+ }
18433
+
18384
18434
  // src/integrations.ts
18385
18435
  var import_node_child_process7 = require("child_process");
18386
18436
 
@@ -20171,47 +20221,56 @@ async function loadCloudCp() {
20171
20221
  }
20172
20222
  }
20173
20223
  async function runCpRpc(action, deps) {
20224
+ const method = action.method;
20174
20225
  const params = action.params ?? {};
20175
- if (typeof params.boxPath !== "string" || typeof params.hostPath !== "string") {
20226
+ let norm;
20227
+ try {
20228
+ norm = normalizeCpParams(method, params);
20229
+ } catch (err) {
20230
+ return { exitCode: 64, stdout: "", stderr: `${err instanceof Error ? err.message : String(err)}
20231
+ ` };
20232
+ }
20233
+ const entry = process.env["AGENTBOX_CLI_ENTRY"];
20234
+ if (!entry) {
20176
20235
  return {
20177
20236
  exitCode: 64,
20178
20237
  stdout: "",
20179
- stderr: "cp.* requires {boxPath, hostPath} strings\n"
20238
+ stderr: "relay: AGENTBOX_CLI_ENTRY not set; cannot run cp host-side\n"
20180
20239
  };
20181
20240
  }
20182
- const direction = action.method === "cp.toHost" ? "box -> host" : "host -> box";
20241
+ const direction = method === "cp.toHost" ? "box -> host" : "host -> box";
20183
20242
  const lookup = await lookupCloudBox(deps.boxId);
20184
- const hostAbs = resolveHostPath(lookup.workspacePath, params.hostPath);
20243
+ const boxName = deps.boxName ?? deps.boxId;
20244
+ const { argv: cpArgs, detail, contextArgv } = buildCpArgv({
20245
+ method,
20246
+ boxName,
20247
+ sources: norm.sources,
20248
+ dest: norm.dest,
20249
+ resolveHost: (p) => resolveHostPath(lookup.workspacePath, p),
20250
+ flags: cpFlags(params)
20251
+ });
20185
20252
  if (deps.prompts && deps.subscribers) {
20186
20253
  const verdict = await askPrompt(deps.prompts, deps.subscribers, deps.boxId, {
20187
20254
  kind: "confirm",
20188
- message: `Allow cp (${direction}) on ${deps.boxName ?? deps.boxId}?`,
20189
- detail: action.method === "cp.toHost" ? `${params.boxPath} -> ${hostAbs}` : `${hostAbs} -> ${params.boxPath}`,
20255
+ message: `Allow cp (${direction}) on ${boxName}?`,
20256
+ detail,
20190
20257
  defaultAnswer: "n",
20191
- context: {
20192
- command: action.method,
20193
- argv: [params.boxPath, hostAbs]
20194
- }
20258
+ context: { command: method, argv: contextArgv }
20195
20259
  });
20196
20260
  if (verdict.answer !== "y") {
20197
20261
  return { exitCode: 10, stdout: "", stderr: "denied by user\n" };
20198
20262
  }
20199
20263
  }
20200
- const backend = await resolveCloudBackend(deps.backendName);
20201
- const handle = { sandboxId: lookup.cloudSandboxId };
20202
- const cp = await loadCloudCp();
20203
- try {
20204
- const result = action.method === "cp.toHost" ? await cp.downloadFromCloudBox(backend, handle, params.boxPath, hostAbs) : await cp.uploadToCloudBox(backend, handle, hostAbs, params.boxPath);
20205
- return { exitCode: 0, stdout: `${result.finalPath}
20206
- `, stderr: "" };
20207
- } catch (err) {
20208
- return {
20209
- exitCode: 1,
20210
- stdout: "",
20211
- stderr: `cp failed: ${err instanceof Error ? err.message : String(err)}
20212
- `
20213
- };
20214
- }
20264
+ const argv = [process.execPath, entry, ...cpArgs];
20265
+ const result = await execa(argv[0], argv.slice(1), {
20266
+ reject: false,
20267
+ cwd: lookup.workspacePath
20268
+ });
20269
+ return {
20270
+ exitCode: result.exitCode ?? 1,
20271
+ stdout: result.stdout ?? "",
20272
+ stderr: result.stderr ?? ""
20273
+ };
20215
20274
  }
20216
20275
  async function runCheckpointRpc(action, deps) {
20217
20276
  const params = action.params ?? {};
@@ -20316,6 +20375,45 @@ async function runGitRpc(action, deps) {
20316
20375
  stderr: `failed to resolve branch in sandbox ${containerPath}: ${branchProbe.stderr || branch}`
20317
20376
  };
20318
20377
  }
20378
+ if (params.hostOnly) {
20379
+ const dest = params.as && params.as.length > 0 ? params.as : branch;
20380
+ const stageSave = await (0, import_promises15.mkdtemp)((0, import_node_path6.join)((0, import_node_os4.tmpdir)(), "agentbox-git-save-"));
20381
+ const hostBundleSave = (0, import_node_path6.join)(stageSave, "op.bundle");
20382
+ const remoteBundleSave = "/tmp/agentbox-rpc-save.bundle";
20383
+ try {
20384
+ const make = await backend.exec(
20385
+ handle,
20386
+ `git -C ${shellQuote(containerPath)} bundle create ${shellQuote(remoteBundleSave)} ${shellQuote(branch)}`
20387
+ );
20388
+ if (make.exitCode !== 0) {
20389
+ return { exitCode: make.exitCode, stdout: "", stderr: `bundle create failed: ${make.stderr || make.stdout}` };
20390
+ }
20391
+ await backend.downloadFile(handle, remoteBundleSave, hostBundleSave);
20392
+ const refspec = `${params.force ? "+" : ""}${branch}:refs/heads/${dest}`;
20393
+ const landed = await execa(
20394
+ "git",
20395
+ ["-C", lookup.workspacePath, "fetch", hostBundleSave, refspec],
20396
+ { reject: false }
20397
+ );
20398
+ if ((landed.exitCode ?? 1) !== 0) {
20399
+ return {
20400
+ exitCode: landed.exitCode ?? 1,
20401
+ stdout: landed.stdout ?? "",
20402
+ stderr: `host git fetch from bundle failed: ${landed.stderr ?? ""}`
20403
+ };
20404
+ }
20405
+ return {
20406
+ exitCode: 0,
20407
+ stdout: `branch ${dest} available in ${lookup.workspacePath}
20408
+ ${landed.stdout ?? ""}`,
20409
+ stderr: landed.stderr ?? ""
20410
+ };
20411
+ } finally {
20412
+ await (0, import_promises15.rm)(stageSave, { recursive: true, force: true });
20413
+ await backend.exec(handle, `rm -f ${shellQuote(remoteBundleSave)}`).catch(() => {
20414
+ });
20415
+ }
20416
+ }
20319
20417
  const isAgentboxBranch = branch.startsWith("agentbox/");
20320
20418
  const tokenClaimedGit = typeof params.hostInitiated === "string";
20321
20419
  const incomingHashGit = hashRpcParams(params);
@@ -20976,6 +21074,12 @@ function createRelayServer(opts) {
20976
21074
  }
20977
21075
  if (body.method === "git.push" || body.method === "git.fetch") {
20978
21076
  if (body.method === "git.push") {
21077
+ const hostOnlyParams = body.params;
21078
+ if (hostOnlyParams?.hostOnly) {
21079
+ const saveResult = await handleGitSaveToHost(reg, hostOnlyParams);
21080
+ send(res, saveResult.exitCode === 0 ? 200 : 500, saveResult);
21081
+ return;
21082
+ }
20979
21083
  const params = body.params;
20980
21084
  const worktree = resolveWorktree(reg, params?.path ?? "/workspace");
20981
21085
  const isAgentboxBranch = worktree?.branch.startsWith("agentbox/") ?? false;
@@ -21015,8 +21119,11 @@ function createRelayServer(opts) {
21015
21119
  }
21016
21120
  if (body.method === "cp.toHost" || body.method === "cp.fromHost") {
21017
21121
  const params = body.params;
21018
- if (!params || typeof params.boxPath !== "string" || typeof params.hostPath !== "string") {
21019
- send(res, 400, { error: "cp.* requires {boxPath, hostPath} strings" });
21122
+ let norm;
21123
+ try {
21124
+ norm = normalizeCpParams(body.method, params);
21125
+ } catch (err) {
21126
+ send(res, 400, { error: err instanceof Error ? err.message : String(err) });
21020
21127
  return;
21021
21128
  }
21022
21129
  if (params.exclude !== void 0 && (!Array.isArray(params.exclude) || params.exclude.some((p) => typeof p !== "string"))) {
@@ -21025,9 +21132,15 @@ function createRelayServer(opts) {
21025
21132
  }
21026
21133
  const direction = body.method === "cp.toHost" ? "box -> host" : "host -> box";
21027
21134
  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}`;
21030
- const detailParts = [pathDetail];
21135
+ const { argv: cpArgs, detail, contextArgv } = buildCpArgv({
21136
+ method: body.method,
21137
+ boxName: reg.name,
21138
+ sources: norm.sources,
21139
+ dest: norm.dest,
21140
+ resolveHost: (p) => resolveHostPath(workspacePath, p),
21141
+ flags: cpFlags(params)
21142
+ });
21143
+ const detailParts = [detail];
21031
21144
  if (params.exclude && params.exclude.length > 0) {
21032
21145
  detailParts.push(`exclude: ${params.exclude.join(", ")}`);
21033
21146
  }
@@ -21040,17 +21153,14 @@ function createRelayServer(opts) {
21040
21153
  defaultAnswer: "n",
21041
21154
  context: {
21042
21155
  command: body.method,
21043
- argv: [params.boxPath, hostAbs]
21156
+ argv: contextArgv
21044
21157
  }
21045
21158
  });
21046
21159
  if (verdict.answer !== "y") {
21047
21160
  send(res, 500, { exitCode: 10, stdout: "", stderr: "denied by user\n" });
21048
21161
  return;
21049
21162
  }
21050
- const result = await handleCpRpc(reg, body.method, params, {
21051
- hostPath: hostAbs,
21052
- cwd: workspacePath
21053
- });
21163
+ const result = await handleCpRpc(cpArgs, workspacePath);
21054
21164
  const status = result.exitCode === 0 ? 200 : 500;
21055
21165
  send(res, status, result);
21056
21166
  return;
@@ -21512,6 +21622,45 @@ function resolveWorktree(reg, containerPath) {
21512
21622
  const prefixMatches = trees.filter((w) => containerPath === w.containerPath || containerPath.startsWith(w.containerPath + "/")).sort((a2, b) => b.containerPath.length - a2.containerPath.length);
21513
21623
  return prefixMatches[0] ?? trees.find((w) => w.containerPath === "/workspace") ?? null;
21514
21624
  }
21625
+ async function handleGitSaveToHost(reg, params) {
21626
+ const containerPath = params?.path ?? "/workspace";
21627
+ const worktree = resolveWorktree(reg, containerPath);
21628
+ if (!worktree) {
21629
+ return {
21630
+ exitCode: 64,
21631
+ stdout: "",
21632
+ stderr: `no worktree registered for box ${reg.boxId} matching ${containerPath}`
21633
+ };
21634
+ }
21635
+ const src = worktree.branch;
21636
+ const dest = params?.as && params.as.length > 0 ? params.as : src;
21637
+ if (dest === src) {
21638
+ return {
21639
+ exitCode: 0,
21640
+ stdout: `branch ${dest} already available in ${worktree.hostMainRepo}
21641
+ `,
21642
+ stderr: ""
21643
+ };
21644
+ }
21645
+ const refspec = `${params?.force ? "+" : ""}${src}:refs/heads/${dest}`;
21646
+ const result = await runHostCommand([
21647
+ "git",
21648
+ "-C",
21649
+ worktree.hostMainRepo,
21650
+ "fetch",
21651
+ ".",
21652
+ refspec
21653
+ ]);
21654
+ if (result.exitCode === 0) {
21655
+ return {
21656
+ exitCode: 0,
21657
+ stdout: `branch ${dest} available in ${worktree.hostMainRepo}
21658
+ ${result.stdout}`,
21659
+ stderr: result.stderr
21660
+ };
21661
+ }
21662
+ return result;
21663
+ }
21515
21664
  async function handleGitRpc(reg, method, params) {
21516
21665
  const containerPath = params?.path ?? "/workspace";
21517
21666
  const worktree = resolveWorktree(reg, containerPath);
@@ -21721,7 +21870,7 @@ async function handleIntegrationRpc(method, reg, params, prompts, subscribers, h
21721
21870
  }
21722
21871
  return runHostIntegration(connector, opDesc, args, worktree.hostMainRepo);
21723
21872
  }
21724
- async function handleCpRpc(reg, method, params, opts) {
21873
+ async function handleCpRpc(cpArgs, cwd) {
21725
21874
  const entry = process.env.AGENTBOX_CLI_ENTRY;
21726
21875
  if (!entry) {
21727
21876
  return {
@@ -21730,13 +21879,8 @@ async function handleCpRpc(reg, method, params, opts) {
21730
21879
  stderr: "relay: AGENTBOX_CLI_ENTRY not set; cannot run cp host-side"
21731
21880
  };
21732
21881
  }
21733
- const boxRef = `${reg.name}:${params.boxPath}`;
21734
- const flags = [];
21735
- for (const pat of params.exclude ?? []) flags.push("--exclude", pat);
21736
- if (params.defaultExcludes === false) flags.push("--no-default-excludes");
21737
- if (params.yes) flags.push("--yes");
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);
21882
+ const argv = [process.execPath, entry, ...cpArgs];
21883
+ return runHostCommand(argv, CP_RPC_TIMEOUT_MS, cwd);
21740
21884
  }
21741
21885
  async function handleDownloadRpc(reg, kind) {
21742
21886
  const entry = process.env.AGENTBOX_CLI_ENTRY;
@@ -222,8 +222,9 @@ write back to the host):
222
222
  `obj`, `packages`, `dist`, `.next`, `target`) are dropped by default; `exclude:`
223
223
  is additive. Each carry entry is capped at `box.cpMaxBytes` (default 100 MiB
224
224
  after excludes) — the same limit `agentbox cp` enforces.
225
- - **`agentbox-ctl cp fromHost <hostPath> <boxPath>`** (ad-hoc, from inside the box)
226
- — for a one-off copy. Prompts the user on the host to approve.
225
+ - **`agentbox-ctl cp fromHost <hostPath...> <boxPath>`** (ad-hoc, from inside the box)
226
+ — for a one-off copy. Takes several sources in one call (last path is the dest,
227
+ which must be a directory). Prompts the user on the host to approve.
227
228
 
228
229
  **The per-copy size limit (important for large/legacy folders).** A single copy is
229
230
  blocked above `box.cpMaxBytes` (default **100 MB**) *after* default excludes, so it
@@ -236,9 +237,9 @@ the biggest remaining folders/subfolders. To get under the limit, EITHER:
236
237
  - pass `--yes` to copy the whole thing anyway (only when you really need it all).
237
238
 
238
239
  Example: a 2.4 GB legacy folder is mostly `packages/` (NuGet) + `.git`; those are
239
- excluded by default, and what's left can be split:
240
- `agentbox-ctl cp fromHost ../legacy/src /workspace/legacy/src` then
241
- `... cp fromHost ../legacy/Database /workspace/legacy/Database`.
240
+ excluded by default, and what's left can be copied in one call by listing the
241
+ sub-folders into a destination directory:
242
+ `agentbox-ctl cp fromHost ../legacy/src ../legacy/Database /workspace/legacy/`.
242
243
 
243
244
  ## 7. Validate before handing off
244
245