@madarco/agentbox 0.23.4 → 0.24.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 (193) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -2
  4. package/dist/{_cloud-attach-BQRWX3J2.js → _cloud-attach-T6GPR6LJ.js} +5 -5
  5. package/dist/{chunk-GGRZ3GZO.js → chunk-5KHEH47T.js} +91 -79
  6. package/dist/chunk-5KHEH47T.js.map +1 -0
  7. package/dist/{chunk-I6ZRWTPR.js → chunk-6U2S6QWD.js} +219 -18
  8. package/dist/chunk-6U2S6QWD.js.map +1 -0
  9. package/dist/{chunk-LK2JT2OO.js → chunk-DEDTPG2D.js} +880 -146
  10. package/dist/chunk-DEDTPG2D.js.map +1 -0
  11. package/dist/chunk-G3H2L3O2.js +0 -0
  12. package/dist/{chunk-LA4JMS27.js → chunk-I654PBHA.js} +290 -330
  13. package/dist/chunk-I654PBHA.js.map +1 -0
  14. package/dist/{chunk-W3FQPFP7.js → chunk-K2EDQGZP.js} +18 -4
  15. package/dist/chunk-K2EDQGZP.js.map +1 -0
  16. package/dist/{chunk-LSQXT5WZ.js → chunk-LC4E2EIZ.js} +3 -3
  17. package/dist/{chunk-LSQXT5WZ.js.map → chunk-LC4E2EIZ.js.map} +1 -1
  18. package/dist/{chunk-SFA57TGX.js → chunk-NACA6AM7.js} +183 -49
  19. package/dist/chunk-NACA6AM7.js.map +1 -0
  20. package/dist/{chunk-QEQFZLYR.js → chunk-RYQLFKCP.js} +20 -10
  21. package/dist/chunk-RYQLFKCP.js.map +1 -0
  22. package/dist/{chunk-QT3SHMLY.js → chunk-UIRBYL4G.js} +43 -12
  23. package/dist/chunk-UIRBYL4G.js.map +1 -0
  24. package/dist/chunk-WJFZJZIM.js +0 -0
  25. package/dist/chunk-WLHJZPFJ.js +845 -0
  26. package/dist/chunk-WLHJZPFJ.js.map +1 -0
  27. package/dist/cloud-poller-SUNA6ZQC-7M5LJHHE.js +0 -0
  28. package/dist/dist-3KIJ2KQ2.js +1437 -0
  29. package/dist/dist-3KIJ2KQ2.js.map +1 -0
  30. package/dist/{dist-V235KVEX.js → dist-7OUOHQPA.js} +196 -151
  31. package/dist/dist-7OUOHQPA.js.map +1 -0
  32. package/dist/{dist-Z2NEVV55.js → dist-B7TNWGVG.js} +8 -4
  33. package/dist/{dist-CUKBKS3N.js → dist-KYV3LEHG.js} +10 -6
  34. package/dist/{dist-FXQFTT75.js → dist-PHYCFYKH.js} +37 -17
  35. package/dist/dist-PHYCFYKH.js.map +1 -0
  36. package/dist/{dist-2BTJQUJS.js → dist-T5MXBZGP.js} +2 -2
  37. package/dist/{dist-QO4CTLAX.js → dist-Z7KEPQC7.js} +6 -6
  38. package/dist/index.js +2560 -1108
  39. package/dist/index.js.map +1 -1
  40. package/dist/{prepared-state-BUO75YLZ-CDTISC2C.js → prepared-state-BUO75YLZ-RQRFFBJW.js} +2 -2
  41. package/package.json +28 -28
  42. package/runtime/_shared/agentbox-checkpoint-cleanup +0 -0
  43. package/runtime/_shared/agentbox-codex-hooks.json +1 -1
  44. package/runtime/_shared/agentbox-dockerd-start +0 -0
  45. package/runtime/_shared/agentbox-open +0 -0
  46. package/runtime/_shared/agentbox-portless-trust +0 -0
  47. package/runtime/_shared/agentbox-vnc-start +0 -0
  48. package/runtime/_shared/ctl.cjs +468 -97
  49. package/runtime/_shared/gh-shim +0 -0
  50. package/runtime/_shared/git-shim +53 -3
  51. package/runtime/_shared/linear-shim +0 -0
  52. package/runtime/_shared/ntn-shim +0 -0
  53. package/runtime/daytona/custom-system-CLAUDE.md +1 -1
  54. package/runtime/digitalocean/agentbox-checkpoint-cleanup +55 -0
  55. package/runtime/digitalocean/agentbox-codex-hooks.json +68 -0
  56. package/runtime/digitalocean/agentbox-dockerd-start +145 -0
  57. package/runtime/digitalocean/agentbox-open +28 -0
  58. package/runtime/digitalocean/agentbox-portless-trust +82 -0
  59. package/runtime/digitalocean/agentbox-setup-skill.md +317 -0
  60. package/runtime/digitalocean/agentbox-vnc-start +102 -0
  61. package/runtime/digitalocean/claude-managed-settings.json +116 -0
  62. package/runtime/digitalocean/ctl.cjs +27852 -0
  63. package/runtime/digitalocean/custom-system-CLAUDE.md +39 -0
  64. package/runtime/digitalocean/gh-shim +344 -0
  65. package/runtime/digitalocean/git-shim +181 -0
  66. package/runtime/digitalocean/linear-shim +181 -0
  67. package/runtime/digitalocean/ntn-shim +95 -0
  68. package/runtime/digitalocean/opencode-agentbox-plugin.js +76 -0
  69. package/runtime/digitalocean/scripts/install-box.sh +462 -0
  70. package/runtime/docker/Dockerfile.box +5 -0
  71. package/runtime/docker/packages/ctl/dist/bin.cjs +468 -97
  72. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup +0 -0
  73. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-codex-hooks.json +1 -1
  74. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +0 -0
  75. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-open +0 -0
  76. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-portless-trust +0 -0
  77. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-sshd-start +0 -0
  78. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-vnc-start +0 -0
  79. package/runtime/docker/packages/sandbox-docker/scripts/chromium-resolver +0 -0
  80. package/runtime/docker/packages/sandbox-docker/scripts/custom-system-CLAUDE.md +2 -1
  81. package/runtime/docker/packages/sandbox-docker/scripts/gh-shim +0 -0
  82. package/runtime/docker/packages/sandbox-docker/scripts/git-shim +53 -3
  83. package/runtime/docker/packages/sandbox-docker/scripts/linear-shim +0 -0
  84. package/runtime/docker/packages/sandbox-docker/scripts/ntn-shim +0 -0
  85. package/runtime/e2b/agentbox-checkpoint-cleanup +0 -0
  86. package/runtime/e2b/agentbox-codex-hooks.json +1 -1
  87. package/runtime/e2b/agentbox-dockerd-start +0 -0
  88. package/runtime/e2b/agentbox-open +0 -0
  89. package/runtime/e2b/agentbox-vnc-start +0 -0
  90. package/runtime/e2b/ctl.cjs +468 -97
  91. package/runtime/e2b/custom-system-CLAUDE.md +6 -3
  92. package/runtime/e2b/gh-shim +0 -0
  93. package/runtime/e2b/git-shim +53 -3
  94. package/runtime/e2b/linear-shim +0 -0
  95. package/runtime/e2b/ntn-shim +0 -0
  96. package/runtime/e2b/scripts/build-template.sh +16 -0
  97. package/runtime/hetzner/agentbox-checkpoint-cleanup +0 -0
  98. package/runtime/hetzner/agentbox-codex-hooks.json +1 -1
  99. package/runtime/hetzner/agentbox-dockerd-start +0 -0
  100. package/runtime/hetzner/agentbox-open +0 -0
  101. package/runtime/hetzner/agentbox-portless-trust +0 -0
  102. package/runtime/hetzner/agentbox-vnc-start +0 -0
  103. package/runtime/hetzner/ctl.cjs +468 -97
  104. package/runtime/hetzner/custom-system-CLAUDE.md +1 -1
  105. package/runtime/hetzner/gh-shim +0 -0
  106. package/runtime/hetzner/git-shim +53 -3
  107. package/runtime/hetzner/linear-shim +0 -0
  108. package/runtime/hetzner/ntn-shim +0 -0
  109. package/runtime/hetzner/scripts/install-box.sh +5 -0
  110. package/runtime/hub/apps/hub/.next/BUILD_ID +1 -1
  111. package/runtime/hub/apps/hub/.next/build-manifest.json +3 -3
  112. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/boxes/[id]/page_client-reference-manifest.js +1 -1
  113. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
  114. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page_client-reference-manifest.js +1 -1
  115. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page_client-reference-manifest.js +1 -1
  116. package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
  117. package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
  118. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  119. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  120. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  121. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  122. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  123. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +12 -12
  124. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0keu6we._.js +1 -1
  125. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bqbkd5._.js +1 -1
  126. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qa4a0v._.js +1 -1
  127. package/runtime/hub/apps/hub/.next/server/chunks/_06f2faq._.js +1 -1
  128. package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +8 -8
  129. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_09gdzmo._.js +1 -1
  130. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ro6vh6._.js +1 -1
  131. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0tgpglr._.js +1 -1
  132. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_1laion6._.js +1 -1
  133. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_0b_hsjl._.js +1 -1
  134. package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
  135. package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
  136. package/runtime/hub/apps/hub/.next/static/chunks/1c5w3kqosumog.js +1 -0
  137. package/runtime/hub/apps/hub/.next/static/chunks/1o3ot_9-8jgzc.js +1 -0
  138. package/runtime/hub/apps/hub/.next/static/chunks/380qcmusmigzz.js +1 -0
  139. package/runtime/hub/apps/hub/.next/static/chunks/3uq9hf-roasav.js +1 -0
  140. package/runtime/hub/apps/hub/{auth-675P3LQS.js → auth-Q447765C.js} +2 -2
  141. package/runtime/hub/apps/hub/{auth-config-AOBEKRZQ.js → auth-config-SIL635ZD.js} +2 -2
  142. package/runtime/hub/apps/hub/{chunk-H22XP3NY.js → chunk-3VE7AYVK.js} +600 -145
  143. package/runtime/hub/apps/hub/{chunk-EXQCBM5Q.js → chunk-64WEKO34.js} +42 -11
  144. package/runtime/hub/apps/hub/{chunk-56YQBVN2.js → chunk-DZPQB2JZ.js} +1 -1
  145. package/runtime/hub/apps/hub/{chunk-2Z74R6ZT.js → chunk-FGBXEXUV.js} +351 -292
  146. package/runtime/hub/apps/hub/{chunk-AR7CEZ2G.js → chunk-YVELHPNY.js} +218 -17
  147. package/runtime/hub/apps/hub/{dist-LZNRLUYY.js → dist-33ZNVTC6.js} +183 -49
  148. package/runtime/hub/apps/hub/{dist-Q6G66Z57.js → dist-4SXAJBOC.js} +195 -150
  149. package/runtime/hub/apps/hub/{dist-SD4G36EP.js → dist-EPJFN2J3.js} +116 -86
  150. package/runtime/hub/apps/hub/{dist-STQK5XM6.js → dist-GF5EBRNG.js} +1 -1
  151. package/runtime/hub/apps/hub/{dist-LNHEG5P4.js → dist-UJVIROA4.js} +19 -5
  152. package/runtime/hub/apps/hub/dist-XULFTIMT.js +2212 -0
  153. package/runtime/hub/apps/hub/{dist-VV6Z2CQX.js → dist-YM5J25H6.js} +7 -3
  154. package/runtime/hub/apps/hub/{hub-token-2BZFBBW3.js → hub-token-UITZEWVP.js} +2 -2
  155. package/runtime/hub/apps/hub/package.json +1 -0
  156. package/runtime/hub/apps/hub/{prepared-state-BUO75YLZ-CAXQS5Y3.js → prepared-state-BUO75YLZ-O4GZMDRF.js} +1 -1
  157. package/runtime/hub/apps/hub/server.js +38 -19
  158. package/runtime/relay/bin.cjs +275 -59
  159. package/runtime/vercel/agentbox-checkpoint-cleanup +0 -0
  160. package/runtime/vercel/agentbox-codex-hooks.json +1 -1
  161. package/runtime/vercel/agentbox-dockerd-start +0 -0
  162. package/runtime/vercel/agentbox-open +0 -0
  163. package/runtime/vercel/agentbox-vnc-start +0 -0
  164. package/runtime/vercel/ctl.cjs +468 -97
  165. package/runtime/vercel/custom-system-CLAUDE.md +3 -2
  166. package/runtime/vercel/gh-shim +0 -0
  167. package/runtime/vercel/git-shim +53 -3
  168. package/runtime/vercel/linear-shim +0 -0
  169. package/runtime/vercel/ntn-shim +0 -0
  170. package/runtime/vercel/scripts/provision.sh +16 -0
  171. package/dist/chunk-GGRZ3GZO.js.map +0 -1
  172. package/dist/chunk-I6ZRWTPR.js.map +0 -1
  173. package/dist/chunk-LA4JMS27.js.map +0 -1
  174. package/dist/chunk-LK2JT2OO.js.map +0 -1
  175. package/dist/chunk-QEQFZLYR.js.map +0 -1
  176. package/dist/chunk-QT3SHMLY.js.map +0 -1
  177. package/dist/chunk-SFA57TGX.js.map +0 -1
  178. package/dist/chunk-W3FQPFP7.js.map +0 -1
  179. package/dist/dist-FXQFTT75.js.map +0 -1
  180. package/dist/dist-V235KVEX.js.map +0 -1
  181. package/runtime/hub/apps/hub/.next/static/chunks/0joh_xsiowfc4.js +0 -1
  182. package/runtime/hub/apps/hub/.next/static/chunks/20hq7-0depjid.js +0 -1
  183. package/runtime/hub/apps/hub/.next/static/chunks/3p86ecqhr_7yy.js +0 -1
  184. package/runtime/hub/apps/hub/.next/static/chunks/3qof5hg87qf5n.js +0 -1
  185. /package/dist/{_cloud-attach-BQRWX3J2.js.map → _cloud-attach-T6GPR6LJ.js.map} +0 -0
  186. /package/dist/{dist-2BTJQUJS.js.map → dist-B7TNWGVG.js.map} +0 -0
  187. /package/dist/{dist-CUKBKS3N.js.map → dist-KYV3LEHG.js.map} +0 -0
  188. /package/dist/{dist-QO4CTLAX.js.map → dist-T5MXBZGP.js.map} +0 -0
  189. /package/dist/{dist-Z2NEVV55.js.map → dist-Z7KEPQC7.js.map} +0 -0
  190. /package/dist/{prepared-state-BUO75YLZ-CDTISC2C.js.map → prepared-state-BUO75YLZ-RQRFFBJW.js.map} +0 -0
  191. /package/runtime/hub/apps/hub/.next/static/{eVq-z4zld_8DGQudbYogV → XtIjHGqvY4mQsOY2-m1Jy}/_buildManifest.js +0 -0
  192. /package/runtime/hub/apps/hub/.next/static/{eVq-z4zld_8DGQudbYogV → XtIjHGqvY4mQsOY2-m1Jy}/_clientMiddlewareManifest.js +0 -0
  193. /package/runtime/hub/apps/hub/.next/static/{eVq-z4zld_8DGQudbYogV → XtIjHGqvY4mQsOY2-m1Jy}/_ssgManifest.js +0 -0
@@ -22,8 +22,9 @@ import {
22
22
  readBoxStatus,
23
23
  registerBoxWithRelay,
24
24
  syncClaudeCredentials
25
- } from "./chunk-2Z74R6ZT.js";
25
+ } from "./chunk-FGBXEXUV.js";
26
26
  import {
27
+ AGENT_SYNC_SPECS,
27
28
  BOX_DYNAMIC_SYNC_MANIFEST,
28
29
  BOX_HOME,
29
30
  BOX_MEMORY_DIR,
@@ -31,20 +32,26 @@ import {
31
32
  DEFAULT_BOX_IMAGE,
32
33
  SEED_MARKER,
33
34
  SYNC_DRYRUN_ENV,
35
+ UserFacingError,
34
36
  allocateProjectIndex,
35
37
  buildHostSyncManifest,
36
38
  computeSyncDelta,
39
+ describeInbound,
37
40
  detectGitRepos,
38
41
  dirnameUnix,
39
42
  dryRunProviderSync,
40
43
  extractCredentials,
41
44
  generateBoxId,
42
45
  hostClaudeBackupExpired,
46
+ isRealAgentCredential,
43
47
  makeHostGitPorts,
44
48
  makeSyncContext,
49
+ parseInboundSpec,
45
50
  planCarryEntry,
51
+ pushCredentialToBox,
46
52
  pushEnvFiles,
47
53
  readCliStamp,
54
+ readCredentialBackup,
48
55
  readPreparedStateRaw,
49
56
  readState,
50
57
  recordBox,
@@ -52,6 +59,7 @@ import {
52
59
  renderCarryEntries,
53
60
  resolveSyncTopology,
54
61
  resyncWorkspace,
62
+ shouldAcceptCredentialUpdate,
55
63
  stageClaudeCredentialsForUpload,
56
64
  stageClaudeJsonOnlyForUpload,
57
65
  stageClaudeStaticForUpload,
@@ -60,8 +68,9 @@ import {
60
68
  stageDynamicSyncTarball,
61
69
  stageOpencodeCredentialsForUpload,
62
70
  stageOpencodeStateForUpload,
63
- stageOpencodeStaticForUpload
64
- } from "./chunk-H22XP3NY.js";
71
+ stageOpencodeStaticForUpload,
72
+ writeCredentialBackup
73
+ } from "./chunk-3VE7AYVK.js";
65
74
  import {
66
75
  execa
67
76
  } from "./chunk-EFW34I43.js";
@@ -71,7 +80,7 @@ import {
71
80
  projectDirSegment,
72
81
  require_dist,
73
82
  sanitizeMnemonic
74
- } from "./chunk-EXQCBM5Q.js";
83
+ } from "./chunk-64WEKO34.js";
75
84
  import {
76
85
  __toESM
77
86
  } from "./chunk-TZFWAJVB.js";
@@ -605,6 +614,44 @@ async function extractCloudAgentCredentials(backend, handle, opts = {}) {
605
614
  const transport = createCloudSyncTransport({ backend, handle });
606
615
  return extractCredentials(transport, { onLog: opts.onLog, backups: opts.backups });
607
616
  }
617
+ async function reconcileAgentCredentials(backend, handle, opts = {}) {
618
+ return reconcileAgentCredentialsViaTransport(
619
+ createCloudSyncTransport({ backend, handle }),
620
+ opts
621
+ );
622
+ }
623
+ async function reconcileAgentCredentialsViaTransport(transport, opts = {}) {
624
+ const log = opts.onLog ?? (() => {
625
+ });
626
+ for (const spec of AGENT_SYNC_SPECS) {
627
+ const backupPath = opts.backups?.[spec.id];
628
+ try {
629
+ const hostText = await readCredentialBackup(spec.id, { backupPath });
630
+ const boxText = await transport.readText(spec.credential.boxAbsPath);
631
+ const hostReal = hostText !== null && isRealAgentCredential(spec.id, hostText);
632
+ const boxReal = boxText !== null && boxText.length > 0 && isRealAgentCredential(spec.id, boxText);
633
+ if (!hostReal && !boxReal) continue;
634
+ if (!hostReal && boxReal) {
635
+ await writeCredentialBackup(spec.id, boxText, { backupPath });
636
+ log(`captured ${spec.id} credential from box (no host backup)`);
637
+ continue;
638
+ }
639
+ if (boxReal && spec.credential.realShape === "claude-oauth" && shouldAcceptCredentialUpdate(spec.id, boxText, hostText).accept) {
640
+ await writeCredentialBackup(spec.id, boxText, { backupPath });
641
+ log(`captured newer ${spec.id} credential from box`);
642
+ continue;
643
+ }
644
+ if (!boxReal || shouldAcceptCredentialUpdate(spec.id, hostText, boxText).accept) {
645
+ await pushCredentialToBox(transport, spec.id, hostText);
646
+ log(`refreshed ${spec.id} credential in box from host backup`);
647
+ }
648
+ } catch (err) {
649
+ log(
650
+ `WARN: ${spec.id} credential reconcile failed (${err instanceof Error ? err.message : String(err)}) \u2014 skipping`
651
+ );
652
+ }
653
+ }
654
+ }
608
655
  function sq(p) {
609
656
  return `'${p.replace(/'/g, `'\\''`)}'`;
610
657
  }
@@ -744,6 +791,73 @@ async function seedGitIdentity(backend, handle, opts = {}) {
744
791
  }
745
792
  log(`git: configured committer identity ${name} <${email}>`);
746
793
  }
794
+ async function seedGitCredentials(backend, handle, opts = {}) {
795
+ const log = opts.onLog ?? (() => {
796
+ });
797
+ const host = await readHostOriginHost(opts.hostRepo);
798
+ const qHost = quoteShellArg(host);
799
+ const httpsKey = quoteShellArg(`url.https://${host}/.insteadOf`);
800
+ const sshKey = quoteShellArg(`url.git@${host}:.insteadOf`);
801
+ const tokenCfg = [
802
+ `git config --global credential.helper store`,
803
+ `git config --global --unset-all ${httpsKey} 2>/dev/null || true`,
804
+ `git config --global --add ${httpsKey} ${quoteShellArg(`git@${host}:`)}`,
805
+ `git config --global --add ${httpsKey} ${quoteShellArg(`ssh://git@${host}/`)}`
806
+ ].join(" && ");
807
+ const sshCfg = [
808
+ `git config --global --replace-all ${sshKey} ${quoteShellArg(`https://${host}/`)}`,
809
+ `AGB_KEY=$(ls "$HOME"/.ssh/id_ed25519 "$HOME"/.ssh/id_rsa "$HOME"/.ssh/id_ecdsa 2>/dev/null | head -1)`,
810
+ `if [ -z "$AGB_KEY" ]; then AGB_KEY=$(find "$HOME/.ssh" -maxdepth 1 -type f ! -name '*.pub' ! -name 'config' ! -name 'known_hosts*' ! -name 'authorized_keys' 2>/dev/null | head -1); fi`,
811
+ `git config --global core.sshCommand "ssh\${AGB_KEY:+ -i $AGB_KEY} -o StrictHostKeyChecking=accept-new"`,
812
+ await buildSigningSnippet(opts.hostRepo)
813
+ ].filter(Boolean).join("; ");
814
+ const script = [
815
+ // carry chowns to a fixed uid (1000); the box user is 1001/1002 elsewhere.
816
+ // Re-own so the box can read its own 0600 creds. Provider-agnostic.
817
+ `sudo -n chown -R "$(id -u):$(id -g)" "$HOME/.git-credentials" "$HOME/.ssh" 2>/dev/null || true`,
818
+ `chmod 600 "$HOME/.git-credentials" 2>/dev/null || true`,
819
+ `chmod 700 "$HOME/.ssh" 2>/dev/null || true`,
820
+ // Any copied key (default OR custom basename) must be 0600 for ssh.
821
+ `find "$HOME/.ssh" -maxdepth 1 -type f -exec chmod 600 {} + 2>/dev/null || true`,
822
+ `HOST=${qHost}`,
823
+ // Mode comes from the explicit marker the gate wrote (so a stray `carry:`
824
+ // ~/.git-credentials can't flip an SSH-mode box to HTTPS); fall back to file
825
+ // presence for boxes created before the marker existed. SSH mode accepts ANY
826
+ // private key (default OR a custom basename from an `IdentityFile`). Whatever
827
+ // the mode, the matching credential must actually be present — if not, the
828
+ // carry dropped it, so exit non-zero and fail the create rather than stamp a
829
+ // broken direct box.
830
+ `AGB_HAS_KEY() { find "$HOME/.ssh" -maxdepth 1 -type f ! -name '*.pub' ! -name 'config' ! -name 'known_hosts*' ! -name 'authorized_keys' 2>/dev/null | grep -q .; }`,
831
+ `MODE=$(cat "$HOME/.config/agentbox/git-direct-mode" 2>/dev/null)`,
832
+ `if [ -z "$MODE" ]; then if [ -f "$HOME/.git-credentials" ]; then MODE=token; elif AGB_HAS_KEY; then MODE=ssh; fi; fi`,
833
+ `if [ "$MODE" = token ] && [ -f "$HOME/.git-credentials" ]; then ${tokenCfg}; elif [ "$MODE" = ssh ] && AGB_HAS_KEY; then ${sshCfg}; else echo "agentbox: git.pushMode=direct but the chosen credential ($MODE) did not land in the box (carry upload failed?)" >&2; exit 3; fi`
834
+ ].join("\n");
835
+ const r = await backend.exec(handle, bashScript(script));
836
+ if (r.exitCode !== 0) {
837
+ throw new Error(
838
+ `git.pushMode=direct: configuring box-held credentials failed (exit ${String(r.exitCode)}): ${(r.stderr || r.stdout).trim()}`
839
+ );
840
+ }
841
+ log("git: configured box-held credentials (direct push mode)");
842
+ }
843
+ async function buildSigningSnippet(hostRepo) {
844
+ const gpgsign = (await readHostGitConfig("commit.gpgsign", hostRepo))?.toLowerCase();
845
+ const format = (await readHostGitConfig("gpg.format", hostRepo))?.toLowerCase();
846
+ const signingKey = await readHostGitConfig("user.signingkey", hostRepo);
847
+ if (gpgsign !== "true" || !signingKey || format !== "ssh") return "";
848
+ const looksLikePath = signingKey.includes("/") && !signingKey.startsWith("key::");
849
+ const boxKey = looksLikePath ? `/home/vscode/.ssh/${signingKey.split("/").pop() ?? ""}` : signingKey;
850
+ const priv = looksLikePath ? `/home/vscode/.ssh/${(signingKey.split("/").pop() ?? "").replace(/\.pub$/, "")}` : boxKey;
851
+ return `git config --global gpg.format ssh && git config --global user.signingkey ${quoteShellArg(boxKey)} && if ssh-keygen -y -P '' -f ${quoteShellArg(priv)} >/dev/null 2>&1; then git config --global commit.gpgsign true; else git config --global --unset commit.gpgsign 2>/dev/null || true; echo "agentbox: signing key needs a passphrase \u2014 leaving commit signing OFF so in-box commits do not fail" >&2; fi`;
852
+ }
853
+ async function readHostOriginHost(hostRepo) {
854
+ const args = hostRepo ? ["-C", hostRepo, "remote", "get-url", "origin"] : ["remote", "get-url", "origin"];
855
+ const r = await execa("git", args, { reject: false });
856
+ const url = r.exitCode === 0 ? (r.stdout ?? "").trim() : "";
857
+ const m = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?([^/:]+)/i.exec(url) ?? /^(?:[^@/]+@)?([^/:]+):/i.exec(url);
858
+ const host = m?.[1];
859
+ return host && host.length > 0 ? host : "github.com";
860
+ }
747
861
  async function readHostGitConfig(key, hostRepo) {
748
862
  const args = hostRepo ? ["-C", hostRepo, "config", key] : ["config", key];
749
863
  const r = await execa("git", args, { reject: false });
@@ -810,7 +924,10 @@ async function uploadOneEntry(args) {
810
924
  const localTar = join4(args.stageDir, `carry-${String(args.index)}.tar`);
811
925
  const excludeArgs = isDir ? exclude.map((p) => `--exclude=${p}`) : [];
812
926
  const tarArgs = isDir ? ["-C", entry.absSrc, "-cf", localTar, ...excludeArgs, "."] : ["-C", dirnameUnix(entry.absSrc), "-cf", localTar, fileBase];
813
- const packed = await execa("tar", tarArgs, { reject: false });
927
+ const packed = await execa("tar", tarArgs, {
928
+ reject: false,
929
+ env: { ...process.env, COPYFILE_DISABLE: "1" }
930
+ });
814
931
  if (packed.exitCode !== 0) {
815
932
  throw new Error(`tar pack failed: ${String(packed.stderr).slice(0, 300)}`);
816
933
  }
@@ -1248,6 +1365,9 @@ function buildBootstrapEnv(args) {
1248
1365
  if (lease) {
1249
1366
  boxEnvFile.push(`AGENTBOX_GIT_LEASE=1`);
1250
1367
  }
1368
+ if (pushMode === "direct") {
1369
+ boxEnvFile.push(`AGENTBOX_GIT_DIRECT=1`);
1370
+ }
1251
1371
  return { env, boxEnvFile };
1252
1372
  }
1253
1373
  async function kickCloudBootstrap(args) {
@@ -1405,7 +1525,7 @@ function buildCarryOverSteps(opts) {
1405
1525
  }
1406
1526
  if (opts.hasUntracked) {
1407
1527
  steps.push(
1408
- opts.detectConflicts ? `if [ -f ${untracked} ]; then tar -tzf ${untracked} | while IFS= read -r p; do case "$p" in ''|*/) continue ;; esac; if [ -e ${wd}/"$p" ]; then echo "${OVERLAY_SKIP_MARKER}$p"; fi; done || true ; tar -C ${wd} --skip-old-files -xzf ${untracked} || true ; rm -f ${untracked} ; fi` : `if [ -f ${untracked} ]; then tar -C ${wd} -xzf ${untracked} && rm -f ${untracked} ; fi`
1528
+ opts.detectConflicts ? `if [ -f ${untracked} ]; then tar -tzf ${untracked} | while IFS= read -r p; do case "$p" in ''|*/) continue ;; esac; if [ -e ${wd}/"$p" ]; then echo "${OVERLAY_SKIP_MARKER}$p"; fi; done || true ; tar -C ${wd} --skip-old-files --no-same-owner -xzf ${untracked} || true ; rm -f ${untracked} ; fi` : `if [ -f ${untracked} ]; then tar -C ${wd} --no-same-owner -xzf ${untracked} && rm -f ${untracked} ; fi`
1409
1529
  );
1410
1530
  }
1411
1531
  return steps;
@@ -1488,8 +1608,7 @@ async function seedFromGitClone(args) {
1488
1608
  });
1489
1609
  const gitDir = `${args.workspaceDir}/.git`;
1490
1610
  const prepSteps = args.overlay ? [`$SUDO rm -rf ${quoteShellArgv([gitDir])}`] : [
1491
- `$SUDO rm -rf ${quoteShellArgv([args.workspaceDir])}`,
1492
- `$SUDO mkdir -p ${quoteShellArgv([args.workspaceDir])}`,
1611
+ ...wipeDirSteps(args.workspaceDir),
1493
1612
  `$SUDO chown "$(id -un):$(id -gn)" ${quoteShellArgv([args.workspaceDir])}`
1494
1613
  ];
1495
1614
  const checkoutSteps = args.overlay ? [
@@ -1514,7 +1633,12 @@ async function seedFromGitClone(args) {
1514
1633
  // `/workspace/<rel>`, so the root clone is preserved). Overlay: rm only
1515
1634
  // `<dir>/.git`, preserving the warm working tree.
1516
1635
  ...prepSteps,
1517
- `tar -C ${quoteShellArgv([args.workspaceDir])} -xzf ${quoteShellArgv([remoteTar])}`,
1636
+ // --no-same-owner (here and on every extraction in this file): clouds
1637
+ // whose exec user is root would otherwise preserve the HOST's numeric
1638
+ // uids from the tarball, and git then fails with "dubious ownership"
1639
+ // on /workspace/.git. Non-root extraction already behaves this way
1640
+ // (tar defaults to --no-same-owner unless root).
1641
+ `tar -C ${quoteShellArgv([args.workspaceDir])} --no-same-owner -xzf ${quoteShellArgv([remoteTar])}`,
1518
1642
  setOrigin,
1519
1643
  ...checkoutSteps,
1520
1644
  ...carryOverSteps,
@@ -1635,7 +1759,7 @@ async function tryReseedRepoDelta(args) {
1635
1759
  hasUntracked: untrackedSize > 0,
1636
1760
  detectConflicts: true
1637
1761
  });
1638
- const lfsStep = deltaLfsSize > 0 ? `tar -C ${quoteShellArgv([`${args.workspaceDir}/.git`])} -xzf ${quoteShellArgv([REMOTE_DELTA_LFS])}` : ": # no delta lfs objects";
1762
+ const lfsStep = deltaLfsSize > 0 ? `tar -C ${quoteShellArgv([`${args.workspaceDir}/.git`])} --no-same-owner -xzf ${quoteShellArgv([REMOTE_DELTA_LFS])}` : ": # no delta lfs objects";
1639
1763
  const SUDO = `if command -v sudo >/dev/null 2>&1; then SUDO='sudo -n'; else SUDO=''; fi`;
1640
1764
  const script = [
1641
1765
  `set -euo pipefail`,
@@ -1796,6 +1920,10 @@ async function readOriginUrl(hostRepo) {
1796
1920
  const out = (r.stdout ?? "").trim();
1797
1921
  return out.length > 0 ? out : null;
1798
1922
  }
1923
+ function wipeDirSteps(dir) {
1924
+ const q = quoteShellArgv([dir]);
1925
+ return [`$SUDO mkdir -p ${q}`, `$SUDO find ${q} -mindepth 1 -maxdepth 1 -exec rm -rf {} +`];
1926
+ }
1799
1927
  async function seedFromTar(args) {
1800
1928
  const stage = await mkdtemp6(join7(tmpdir6(), "agentbox-tar-"));
1801
1929
  const tarPath = join7(stage, "workspace.tar.gz");
@@ -1813,10 +1941,9 @@ async function seedFromTar(args) {
1813
1941
  // (index-pack) fails with "Unable to read current working directory".
1814
1942
  `cd /tmp`,
1815
1943
  SUDO,
1816
- `$SUDO rm -rf ${quoteShellArgv([args.workspaceDir])}`,
1817
- `$SUDO mkdir -p ${quoteShellArgv([args.workspaceDir])}`,
1944
+ ...wipeDirSteps(args.workspaceDir),
1818
1945
  `$SUDO chown "$(id -un):$(id -gn)" ${quoteShellArgv([args.workspaceDir])}`,
1819
- `tar -C ${quoteShellArgv([args.workspaceDir])} -xzf ${quoteShellArgv([remoteTar])}`,
1946
+ `tar -C ${quoteShellArgv([args.workspaceDir])} --no-same-owner -xzf ${quoteShellArgv([remoteTar])}`,
1820
1947
  `rm -f ${quoteShellArgv([remoteTar])}`
1821
1948
  ].join("\n");
1822
1949
  const r = await args.backend.exec(args.handle, bashScript(script));
@@ -1913,7 +2040,7 @@ function createCloudProvider(backend, opts = {}) {
1913
2040
  if (!sandboxId) {
1914
2041
  throw new Error(`cloud box ${box.name} has no sandboxId \u2014 record is malformed`);
1915
2042
  }
1916
- return { sandboxId };
2043
+ return { sandboxId, inbound: box.cloud?.inbound };
1917
2044
  }
1918
2045
  function mintBox(req) {
1919
2046
  const id = generateBoxId();
@@ -2085,6 +2212,14 @@ function createCloudProvider(backend, opts = {}) {
2085
2212
  } catch {
2086
2213
  }
2087
2214
  }
2215
+ try {
2216
+ const credentialSync = (await loadEffectiveConfig(box.workspacePath)).effective.box.credentialSync;
2217
+ if (credentialSync) {
2218
+ await reconcileAgentCredentials(backend, h, { onLog: () => {
2219
+ } });
2220
+ }
2221
+ } catch {
2222
+ }
2088
2223
  return next;
2089
2224
  }
2090
2225
  return {
@@ -2095,15 +2230,17 @@ function createCloudProvider(backend, opts = {}) {
2095
2230
  });
2096
2231
  const { id, name, branch } = mintBox(req);
2097
2232
  const image = opts.provisionImage ? await opts.provisionImage(req) : req.image ?? FALLBACK_IMAGE;
2098
- const baseResources = opts.defaultResources ?? { cpu: 2, memory: 4, disk: 8 };
2099
- const vcpuOverride = req.providerOptions?.["vcpus"];
2100
- const resources = typeof vcpuOverride === "number" && vcpuOverride > 0 ? { ...baseResources, cpu: vcpuOverride } : baseResources;
2233
+ const resources = opts.defaultResources ?? { cpu: 2, memory: 4, disk: 8 };
2101
2234
  const timeoutOverride = req.providerOptions?.["timeoutMs"];
2102
2235
  const timeoutMs = typeof timeoutOverride === "number" && timeoutOverride > 0 ? timeoutOverride : void 0;
2103
2236
  const networkPolicyOpt = req.providerOptions?.["networkPolicy"];
2104
2237
  const networkPolicy = typeof networkPolicyOpt === "string" && networkPolicyOpt.trim() !== "" ? networkPolicyOpt.trim() : void 0;
2105
2238
  const sizeOpt = req.providerOptions?.["size"];
2106
2239
  const size = typeof sizeOpt === "string" && sizeOpt.trim() !== "" ? sizeOpt.trim() : void 0;
2240
+ const locationOpt = req.providerOptions?.["location"];
2241
+ const location = typeof locationOpt === "string" && locationOpt.trim() !== "" ? locationOpt.trim() : void 0;
2242
+ const inboundOpt = req.providerOptions?.["inbound"];
2243
+ const inbound = typeof inboundOpt === "string" && inboundOpt.trim() !== "" ? inboundOpt.trim() : void 0;
2107
2244
  const relayToken = generateRelayToken();
2108
2245
  const bridgeToken = generateRelayToken();
2109
2246
  try {
@@ -2133,10 +2270,13 @@ function createCloudProvider(backend, opts = {}) {
2133
2270
  }
2134
2271
  const agentVolumes = await ensureAgentVolumesForCloud(backend, { onLog: log });
2135
2272
  const exposeServicePorts = await readExposedServicePorts(req.workspacePath);
2273
+ const credentialSyncOff = (req.credentialSync ?? (await loadEffectiveConfig(req.projectRoot ?? req.workspacePath)).effective.box.credentialSync) === false;
2136
2274
  const provisionEnv = {
2137
2275
  AGENTBOX_BOX_ID: id,
2138
2276
  AGENTBOX_BOX_NAME: name,
2139
2277
  AGENTBOX_BOX_KIND: "cloud",
2278
+ // Absent = enabled; the ctl credential watcher only checks for '0'.
2279
+ ...credentialSyncOff ? { AGENTBOX_CREDENTIAL_SYNC: "0" } : {},
2140
2280
  // In-sandbox relay is on the box's loopback at the in-box port.
2141
2281
  // 8788 is distinct from the host relay's 8787 so a nested agentbox
2142
2282
  // run inside the box can claim :8787 without colliding.
@@ -2155,6 +2295,8 @@ function createCloudProvider(backend, opts = {}) {
2155
2295
  snapshot,
2156
2296
  resources,
2157
2297
  size,
2298
+ location,
2299
+ inbound,
2158
2300
  timeoutMs,
2159
2301
  exposePorts: exposeServicePorts,
2160
2302
  networkPolicy,
@@ -2184,6 +2326,14 @@ function createCloudProvider(backend, opts = {}) {
2184
2326
  throw err;
2185
2327
  }
2186
2328
  }
2329
+ if (handle.resources) {
2330
+ const r = handle.resources;
2331
+ const parts = [];
2332
+ if (typeof r.cpu === "number") parts.push(`${String(r.cpu)} vCPU`);
2333
+ if (typeof r.memory === "number") parts.push(`${String(r.memory)} GB RAM`);
2334
+ if (typeof r.disk === "number") parts.push(`${String(r.disk)} GB disk`);
2335
+ if (parts.length > 0) log(`provisioned ${parts.join(" / ")}`);
2336
+ }
2187
2337
  const inBoxClone = req.inBoxClone ? {
2188
2338
  authedUrl: req.inBoxClone.authedUrl,
2189
2339
  originUrl: req.inBoxClone.originUrl,
@@ -2240,6 +2390,12 @@ function createCloudProvider(backend, opts = {}) {
2240
2390
  carrySummary = { count: result.applied.length, entries: result.applied };
2241
2391
  }
2242
2392
  }
2393
+ if (req.gitPushMode === "direct") {
2394
+ await seedGitCredentials(backend, handle, {
2395
+ hostRepo: req.workspacePath,
2396
+ onLog: log
2397
+ });
2398
+ }
2243
2399
  const vncEnabled = req.vnc?.enabled !== false;
2244
2400
  const vncPassword = vncEnabled ? generateVncPassword() : void 0;
2245
2401
  const wp = backend.webProxyPort ?? CLOUD_WEB_PROXY_PORT;
@@ -2433,6 +2589,12 @@ function createCloudProvider(backend, opts = {}) {
2433
2589
  snapshotRef: resolvedCheckpointRef,
2434
2590
  lastState: "running",
2435
2591
  sessionTimeoutMs: timeoutMs,
2592
+ // Real resources the backend reported (Hetzner: the plan's actual
2593
+ // cores/memory/disk). Absent → readers fall back to defaultResources.
2594
+ resources: handle.resources,
2595
+ // Inbound-access policy the backend applied to the per-box firewall
2596
+ // (VPS providers). Persisted so drift re-syncs preserve the whitelist.
2597
+ inbound: handle.inbound,
2436
2598
  // Only host-seeded boxes share a fork base with the host, so only
2437
2599
  // they can be resynced back to the host tip on session start (7.5).
2438
2600
  // inBoxClone / plane boxes clone from a leased URL — left unset.
@@ -2478,6 +2640,42 @@ function createCloudProvider(backend, opts = {}) {
2478
2640
  async repairReachability(box) {
2479
2641
  return await backend.repairReachability?.(handleFor(box)) ?? { changed: false };
2480
2642
  },
2643
+ async setInbound(box, spec, onLog) {
2644
+ if (!backend.setInbound) {
2645
+ throw new UserFacingError(
2646
+ `inbound access control isn't supported for provider '${providerName}' \u2014 it has no per-box firewall (only hetzner / digitalocean do).`
2647
+ );
2648
+ }
2649
+ const policy = parseInboundSpec(spec);
2650
+ const { sources } = await backend.setInbound(handleFor(box), policy);
2651
+ onLog?.(`${describeInbound(policy)} -> ${sources.join(", ")}`);
2652
+ const cloud = box.cloud;
2653
+ if (cloud) await recordBox({ ...box, cloud: { ...cloud, inbound: policy } });
2654
+ return policy;
2655
+ },
2656
+ async enableDirectGit(box, entries, opts2) {
2657
+ const onLog = opts2?.onLog;
2658
+ const handle = handleFor(box);
2659
+ const ctx = makeSyncContext({
2660
+ boxName: box.name,
2661
+ boxId: box.id,
2662
+ provider: "cloud",
2663
+ hostWorkspace: box.workspacePath,
2664
+ boxWorkspace: CLOUD_WORKSPACE_DIR,
2665
+ onLog
2666
+ });
2667
+ await makeCloudSync(backend, handle).applyCarry(ctx, entries);
2668
+ await seedGitCredentials(backend, handle, { hostRepo: opts2?.hostRepo, onLog });
2669
+ const flip = 'if ! sudo -n grep -q "^AGENTBOX_GIT_DIRECT=" /etc/agentbox/box.env 2>/dev/null; then echo AGENTBOX_GIT_DIRECT=1 | sudo -n tee -a /etc/agentbox/box.env >/dev/null; fi';
2670
+ const r = await backend.exec(handle, bashScript(flip));
2671
+ if (r.exitCode !== 0) {
2672
+ throw new Error(
2673
+ `enableDirectGit: failed to set AGENTBOX_GIT_DIRECT in box env: ${r.stderr || r.stdout || `exit ${String(r.exitCode)}`}`
2674
+ );
2675
+ }
2676
+ const cloud = box.cloud;
2677
+ if (cloud) await recordBox({ ...box, cloud: { ...cloud, gitPushMode: "direct" } });
2678
+ },
2481
2679
  async pause(box) {
2482
2680
  await backend.pause(handleFor(box));
2483
2681
  await persistLastState(box, "paused");
@@ -2631,6 +2829,9 @@ function createCloudProvider(backend, opts = {}) {
2631
2829
  sync(box) {
2632
2830
  return makeCloudSync(backend, handleFor(box));
2633
2831
  },
2832
+ syncTransport(box) {
2833
+ return createCloudSyncTransport({ backend, handle: handleFor(box) });
2834
+ },
2634
2835
  // Session-start live-box resync (Phase 7.5): merge the host's current state
2635
2836
  // back into the box, box-wins on conflict. Gated on `hostSeeded` so
2636
2837
  // inBoxClone / plane boxes (no host fork base) are left untouched. The box