@madarco/agentbox 0.23.5 → 0.24.1

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 (180) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -2
  4. package/dist/{_cloud-attach-D4OQO5AJ.js → _cloud-attach-T6GPR6LJ.js} +5 -5
  5. package/dist/{chunk-KY32JO6J.js → chunk-5KHEH47T.js} +91 -79
  6. package/dist/chunk-5KHEH47T.js.map +1 -0
  7. package/dist/{chunk-YRTM3KNT.js → chunk-6U2S6QWD.js} +219 -18
  8. package/dist/chunk-6U2S6QWD.js.map +1 -0
  9. package/dist/{chunk-JYEZ6Q5M.js → chunk-DEDTPG2D.js} +874 -146
  10. package/dist/chunk-DEDTPG2D.js.map +1 -0
  11. package/dist/chunk-G3H2L3O2.js +0 -0
  12. package/dist/{chunk-JNY5GPIM.js → chunk-I654PBHA.js} +290 -330
  13. package/dist/chunk-I654PBHA.js.map +1 -0
  14. package/dist/{chunk-6KOQRSHH.js → chunk-K2EDQGZP.js} +18 -4
  15. package/dist/chunk-K2EDQGZP.js.map +1 -0
  16. package/dist/{chunk-KZWJMNLP.js → chunk-LC4E2EIZ.js} +3 -3
  17. package/dist/{chunk-KZWJMNLP.js.map → chunk-LC4E2EIZ.js.map} +1 -1
  18. package/dist/{chunk-DADOEMXP.js → chunk-NACA6AM7.js} +183 -49
  19. package/dist/chunk-NACA6AM7.js.map +1 -0
  20. package/dist/{chunk-FX32NZD4.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-564EDHFF.js → dist-7OUOHQPA.js} +196 -151
  31. package/dist/dist-7OUOHQPA.js.map +1 -0
  32. package/dist/{dist-CAT2TN75.js → dist-B7TNWGVG.js} +8 -4
  33. package/dist/{dist-UDQMBWYW.js → dist-KYV3LEHG.js} +10 -6
  34. package/dist/{dist-EAR4BLL2.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-O5Y4X4C5.js → dist-Z7KEPQC7.js} +6 -6
  38. package/dist/index.js +2617 -1094
  39. package/dist/index.js.map +1 -1
  40. package/dist/{prepared-state-BUO75YLZ-PW64VQMT.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)/settings/page_client-reference-manifest.js +1 -1
  113. package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
  114. package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
  115. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  116. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  117. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  118. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  119. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  120. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +12 -12
  121. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0keu6we._.js +1 -1
  122. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bqbkd5._.js +1 -1
  123. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qa4a0v._.js +1 -1
  124. package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +8 -8
  125. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ro6vh6._.js +1 -1
  126. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_0b_hsjl._.js +1 -1
  127. package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
  128. package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
  129. package/runtime/hub/apps/hub/.next/static/chunks/380qcmusmigzz.js +1 -0
  130. package/runtime/hub/apps/hub/{auth-675P3LQS.js → auth-Q447765C.js} +2 -2
  131. package/runtime/hub/apps/hub/{auth-config-AOBEKRZQ.js → auth-config-SIL635ZD.js} +2 -2
  132. package/runtime/hub/apps/hub/{chunk-FSEPYTQ6.js → chunk-3VE7AYVK.js} +594 -145
  133. package/runtime/hub/apps/hub/{chunk-EXQCBM5Q.js → chunk-64WEKO34.js} +42 -11
  134. package/runtime/hub/apps/hub/{chunk-56YQBVN2.js → chunk-DZPQB2JZ.js} +1 -1
  135. package/runtime/hub/apps/hub/{chunk-7M6FXZIO.js → chunk-FGBXEXUV.js} +350 -292
  136. package/runtime/hub/apps/hub/{chunk-Z7ZAL24C.js → chunk-YVELHPNY.js} +218 -17
  137. package/runtime/hub/apps/hub/{dist-EKQHCXWE.js → dist-33ZNVTC6.js} +183 -49
  138. package/runtime/hub/apps/hub/{dist-V4TJ44MT.js → dist-4SXAJBOC.js} +195 -150
  139. package/runtime/hub/apps/hub/{dist-QIXUPGPP.js → dist-EPJFN2J3.js} +116 -86
  140. package/runtime/hub/apps/hub/{dist-STQK5XM6.js → dist-GF5EBRNG.js} +1 -1
  141. package/runtime/hub/apps/hub/{dist-JGZ55OIJ.js → dist-UJVIROA4.js} +19 -5
  142. package/runtime/hub/apps/hub/dist-XULFTIMT.js +2212 -0
  143. package/runtime/hub/apps/hub/{dist-GGWYKXJE.js → dist-YM5J25H6.js} +7 -3
  144. package/runtime/hub/apps/hub/{hub-token-2BZFBBW3.js → hub-token-UITZEWVP.js} +2 -2
  145. package/runtime/hub/apps/hub/package.json +1 -0
  146. package/runtime/hub/apps/hub/{prepared-state-BUO75YLZ-UICXTY25.js → prepared-state-BUO75YLZ-O4GZMDRF.js} +1 -1
  147. package/runtime/hub/apps/hub/server.js +17 -15
  148. package/runtime/relay/bin.cjs +275 -59
  149. package/runtime/vercel/agentbox-checkpoint-cleanup +0 -0
  150. package/runtime/vercel/agentbox-codex-hooks.json +1 -1
  151. package/runtime/vercel/agentbox-dockerd-start +0 -0
  152. package/runtime/vercel/agentbox-open +0 -0
  153. package/runtime/vercel/agentbox-vnc-start +0 -0
  154. package/runtime/vercel/ctl.cjs +468 -97
  155. package/runtime/vercel/custom-system-CLAUDE.md +3 -2
  156. package/runtime/vercel/gh-shim +0 -0
  157. package/runtime/vercel/git-shim +53 -3
  158. package/runtime/vercel/linear-shim +0 -0
  159. package/runtime/vercel/ntn-shim +0 -0
  160. package/runtime/vercel/scripts/provision.sh +16 -0
  161. package/dist/chunk-6KOQRSHH.js.map +0 -1
  162. package/dist/chunk-DADOEMXP.js.map +0 -1
  163. package/dist/chunk-FX32NZD4.js.map +0 -1
  164. package/dist/chunk-JNY5GPIM.js.map +0 -1
  165. package/dist/chunk-JYEZ6Q5M.js.map +0 -1
  166. package/dist/chunk-KY32JO6J.js.map +0 -1
  167. package/dist/chunk-QT3SHMLY.js.map +0 -1
  168. package/dist/chunk-YRTM3KNT.js.map +0 -1
  169. package/dist/dist-564EDHFF.js.map +0 -1
  170. package/dist/dist-EAR4BLL2.js.map +0 -1
  171. package/runtime/hub/apps/hub/.next/static/chunks/0joh_xsiowfc4.js +0 -1
  172. /package/dist/{_cloud-attach-D4OQO5AJ.js.map → _cloud-attach-T6GPR6LJ.js.map} +0 -0
  173. /package/dist/{dist-2BTJQUJS.js.map → dist-B7TNWGVG.js.map} +0 -0
  174. /package/dist/{dist-CAT2TN75.js.map → dist-KYV3LEHG.js.map} +0 -0
  175. /package/dist/{dist-O5Y4X4C5.js.map → dist-T5MXBZGP.js.map} +0 -0
  176. /package/dist/{dist-UDQMBWYW.js.map → dist-Z7KEPQC7.js.map} +0 -0
  177. /package/dist/{prepared-state-BUO75YLZ-PW64VQMT.js.map → prepared-state-BUO75YLZ-RQRFFBJW.js.map} +0 -0
  178. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → 3tBexekuTKIr_6nriQjKE}/_buildManifest.js +0 -0
  179. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → 3tBexekuTKIr_6nriQjKE}/_clientMiddlewareManifest.js +0 -0
  180. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → 3tBexekuTKIr_6nriQjKE}/_ssgManifest.js +0 -0
@@ -10873,13 +10873,13 @@ function isConnectionLevelError(err) {
10873
10873
  const msg = err instanceof Error ? err.message : String(err);
10874
10874
  return /\b(ECONNREFUSED|ENOTFOUND|EHOSTUNREACH|ECONNRESET|EPIPE)\b/.test(msg);
10875
10875
  }
10876
- var import_node_http, import_node_https, import_promises18, BACKOFF_BASE_MS, BACKOFF_MAX_MS, REQUEST_TIMEOUT_MS, FAST_REQUEST_TIMEOUT_MS, FAST_MODE_DECAY_POLLS, STOPPED_TICK_MS, CONNECTION_LEVEL_CODES, CloudBoxPoller, CloudBoxPollers;
10876
+ var import_node_http, import_node_https, import_promises19, BACKOFF_BASE_MS, BACKOFF_MAX_MS, REQUEST_TIMEOUT_MS, FAST_REQUEST_TIMEOUT_MS, FAST_MODE_DECAY_POLLS, STOPPED_TICK_MS, CONNECTION_LEVEL_CODES, CloudBoxPoller, CloudBoxPollers;
10877
10877
  var init_cloud_poller = __esm({
10878
10878
  "src/cloud-poller.ts"() {
10879
10879
  "use strict";
10880
10880
  import_node_http = require("http");
10881
10881
  import_node_https = require("https");
10882
- import_promises18 = require("timers/promises");
10882
+ import_promises19 = require("timers/promises");
10883
10883
  BACKOFF_BASE_MS = 1500;
10884
10884
  BACKOFF_MAX_MS = 3e4;
10885
10885
  REQUEST_TIMEOUT_MS = 25e3;
@@ -11033,12 +11033,12 @@ var init_cloud_poller = __esm({
11033
11033
  if (this.currentBackoffMs === 0 && this.fastModePolls > 0) {
11034
11034
  this.fastModePolls -= 1;
11035
11035
  }
11036
- if (this.currentBackoffMs === 0) await (0, import_promises18.setTimeout)(STOPPED_TICK_MS);
11036
+ if (this.currentBackoffMs === 0) await (0, import_promises19.setTimeout)(STOPPED_TICK_MS);
11037
11037
  }
11038
11038
  }
11039
11039
  async backoff() {
11040
11040
  this.currentBackoffMs = this.currentBackoffMs === 0 ? BACKOFF_BASE_MS : Math.min(this.currentBackoffMs * 2, BACKOFF_MAX_MS);
11041
- await (0, import_promises18.setTimeout)(this.currentBackoffMs);
11041
+ await (0, import_promises19.setTimeout)(this.currentBackoffMs);
11042
11042
  }
11043
11043
  async tryRecoverPreviewUrl() {
11044
11044
  if (!this.deps.recoverPreviewUrl) return;
@@ -17958,7 +17958,7 @@ var {
17958
17958
  } = getIpcExport();
17959
17959
 
17960
17960
  // src/host-actions.ts
17961
- var import_promises16 = require("fs/promises");
17961
+ var import_promises17 = require("fs/promises");
17962
17962
  var import_node_os4 = require("os");
17963
17963
  var import_node_path6 = require("path");
17964
17964
  var import_node_url3 = require("url");
@@ -18087,6 +18087,8 @@ var import_fs = require("fs");
18087
18087
  var import_os3 = require("os");
18088
18088
  var import_path4 = require("path");
18089
18089
  var import_path5 = require("path");
18090
+ var import_promises14 = require("fs/promises");
18091
+ var import_path6 = require("path");
18090
18092
  var STATE_DIR = (0, import_path3.join)((0, import_os2.homedir)(), ".agentbox");
18091
18093
  var STATE_FILE = (0, import_path3.join)(STATE_DIR, "state.json");
18092
18094
  var EMPTY = { version: 1, boxes: [] };
@@ -18251,6 +18253,17 @@ var AGENT_SYNC_SPECS = [
18251
18253
  // separately; `state_*.sqlite*` is the resume-cwd index (rebuilt in-box);
18252
18254
  // `packages`/`plugins/.plugin-appserver`/`computer-use` are heavy
18253
18255
  // macOS-only artifacts; the rest is host-only session/log/cache state.
18256
+ //
18257
+ // `.tmp` carve-in: the git-marketplace snapshots (`.tmp/marketplaces/`,
18258
+ // ~13 MB) must reach the box or in-box `codex plugin` breaks
18259
+ // ("marketplace root does not contain a supported manifest" — and the
18260
+ // box can't re-clone, the git shim blocks `clone`). The includes are
18261
+ // emitted BEFORE the excludes (first-match-wins): the root `.tmp/` dir
18262
+ // and the marketplaces subtree transfer, `/.tmp/*` drops its other
18263
+ // children (the ~200 MB desktop-app `bundled-marketplaces` + `plugins`
18264
+ // payloads), and the unanchored `.tmp` still blocks nested `.tmp` dirs
18265
+ // elsewhere in the tree.
18266
+ include: ["/.tmp/", "/.tmp/marketplaces/***"],
18254
18267
  exclude: [
18255
18268
  "auth.json",
18256
18269
  "sessions",
@@ -18264,6 +18277,7 @@ var AGENT_SYNC_SPECS = [
18264
18277
  "cache",
18265
18278
  "vendor_imports",
18266
18279
  "tmp",
18280
+ "/.tmp/*",
18267
18281
  ".tmp",
18268
18282
  ".codex-global-state.json",
18269
18283
  ".codex-global-state.json.bak",
@@ -18362,6 +18376,78 @@ function resolveAgentSpec(name) {
18362
18376
  }
18363
18377
  var BOX_CLAUDE_PROJECT_DIR = "/home/vscode/.claude/projects/-workspace";
18364
18378
  var CLAUDE_HOST_BACKUP = resolveAgentSpec("claude").credential.hostBackup;
18379
+ function isRealAgentCredential(agent, text) {
18380
+ let parsed;
18381
+ try {
18382
+ parsed = JSON.parse(text);
18383
+ } catch {
18384
+ return false;
18385
+ }
18386
+ if (typeof parsed !== "object" || parsed === null) return false;
18387
+ const spec = AGENT_SYNC_SPECS.find((s) => s.id === agent);
18388
+ if (spec?.credential.realShape === "claude-oauth") {
18389
+ const rt = parsed.claudeAiOauth?.refreshToken;
18390
+ return typeof rt === "string" && rt.length > 0;
18391
+ }
18392
+ return Object.keys(parsed).length > 0;
18393
+ }
18394
+ var MAX_CREDENTIAL_BYTES = 256 * 1024;
18395
+ function parseCredentialsUpdate(payload) {
18396
+ if (payload === null || typeof payload !== "object") return null;
18397
+ const obj = payload;
18398
+ const agent = obj["agent"];
18399
+ if (typeof agent !== "string" || !AGENT_SYNC_SPECS.some((s) => s.id === agent)) return null;
18400
+ const b64 = obj["contentBase64"];
18401
+ if (typeof b64 !== "string" || b64.length === 0 || b64.length > MAX_CREDENTIAL_BYTES) return null;
18402
+ let content;
18403
+ try {
18404
+ content = Buffer.from(b64, "base64").toString("utf8");
18405
+ } catch {
18406
+ return null;
18407
+ }
18408
+ if (!isRealAgentCredential(agent, content)) return null;
18409
+ return { agent, content };
18410
+ }
18411
+ function claudeExpiresAt(text) {
18412
+ try {
18413
+ const parsed = JSON.parse(text);
18414
+ const exp = parsed?.claudeAiOauth?.expiresAt;
18415
+ return typeof exp === "number" && Number.isFinite(exp) ? exp : null;
18416
+ } catch {
18417
+ return null;
18418
+ }
18419
+ }
18420
+ function shouldAcceptCredentialUpdate(agent, incoming, existing) {
18421
+ if (existing === null) return { accept: true, reason: "no existing backup" };
18422
+ if (existing === incoming) return { accept: false, reason: "unchanged" };
18423
+ if (resolveAgentSpec(agent).credential.realShape === "claude-oauth") {
18424
+ const incomingExp = claudeExpiresAt(incoming);
18425
+ const existingExp = claudeExpiresAt(existing);
18426
+ if (incomingExp === null) return { accept: false, reason: "incoming blob has no expiresAt" };
18427
+ if (existingExp !== null && incomingExp <= existingExp) {
18428
+ return { accept: false, reason: "not newer than backup" };
18429
+ }
18430
+ return { accept: true, reason: "newer expiresAt" };
18431
+ }
18432
+ return { accept: true, reason: "content changed" };
18433
+ }
18434
+ async function writeCredentialBackup(agent, content, opts = {}) {
18435
+ const path6 = opts.backupPath ?? resolveAgentSpec(agent).credential.hostBackup;
18436
+ await (0, import_promises14.mkdir)((0, import_path6.dirname)(path6), { recursive: true });
18437
+ const tmp = `${path6}.tmp-${String(process.pid)}`;
18438
+ await (0, import_promises14.writeFile)(tmp, content, { mode: 384 });
18439
+ await (0, import_promises14.rename)(tmp, path6);
18440
+ await (0, import_promises14.chmod)(path6, 384).catch(() => {
18441
+ });
18442
+ }
18443
+ async function readCredentialBackup(agent, opts = {}) {
18444
+ const path6 = opts.backupPath ?? resolveAgentSpec(agent).credential.hostBackup;
18445
+ try {
18446
+ return await (0, import_promises14.readFile)(path6, "utf8");
18447
+ } catch {
18448
+ return null;
18449
+ }
18450
+ }
18365
18451
  var BOX_MEMORY_DIR = `${BOX_CLAUDE_PROJECT_DIR}/memory`;
18366
18452
  var BOX_WORKSPACE2 = "/workspace";
18367
18453
  var MINIMAL_TRUSTED_CODEX_CONFIG = `[projects."${BOX_WORKSPACE2}"]
@@ -18370,6 +18456,7 @@ trust_level = "trusted"
18370
18456
  var CREDENTIALS_BACKUP_FILE = resolveAgentSpec("claude").credential.hostBackup;
18371
18457
  var CLAUDE_STATIC_EXCLUDES = resolveAgentSpec("claude").staticPaths[0]?.exclude ?? [];
18372
18458
  var CODEX_STATIC_EXCLUDES = resolveAgentSpec("codex").staticPaths[0]?.exclude ?? [];
18459
+ var CODEX_STATIC_INCLUDES = resolveAgentSpec("codex").staticPaths[0]?.include ?? [];
18373
18460
  var OPENCODE_DATA_EXCLUDES = resolveAgentSpec("opencode").staticPaths[0]?.exclude ?? [];
18374
18461
 
18375
18462
  // src/gh.ts
@@ -18768,12 +18855,12 @@ var import_node_child_process7 = require("child_process");
18768
18855
  // ../config/dist/index.js
18769
18856
  var import_yaml = __toESM(require_dist(), 1);
18770
18857
  var import_crypto = require("crypto");
18771
- var import_promises14 = require("fs/promises");
18772
- var import_os4 = require("os");
18773
- var import_path6 = require("path");
18774
18858
  var import_promises15 = require("fs/promises");
18775
- var import_yaml2 = __toESM(require_dist(), 1);
18859
+ var import_os4 = require("os");
18776
18860
  var import_path7 = require("path");
18861
+ var import_promises16 = require("fs/promises");
18862
+ var import_yaml2 = __toESM(require_dist(), 1);
18863
+ var import_path8 = require("path");
18777
18864
  var import_yaml3 = __toESM(require_dist(), 1);
18778
18865
  var PROVIDERS = [
18779
18866
  {
@@ -18793,7 +18880,7 @@ var PROVIDERS = [
18793
18880
  loginHint: "approve a browser sign-in link",
18794
18881
  rebuildMinutes: "7",
18795
18882
  blurb: "Daytona Cloud sandboxes",
18796
- sizeDesc: "Per-provider override of `box.size` for daytona. `cpu-memory-disk` GB spec (e.g. `4-8-20`). Only honored on the image/Dockerfile create path; Daytona rejects custom resources on snapshot-resume.",
18883
+ sizeDesc: "Per-provider override of `box.size` for daytona. `cpu-memory-disk` GB spec (e.g. `4-8-20`). Only honored on the image/Dockerfile create path; on the snapshot path the size is fixed at bake time (Daytona rejects custom resources on snapshot-resume).",
18797
18884
  imageDesc: "Per-provider override of `box.image` for daytona (named snapshot, e.g. `agentbox-base-<fingerprint>`). Written by `agentbox prepare --provider daytona`."
18798
18885
  },
18799
18886
  {
@@ -18813,7 +18900,7 @@ var PROVIDERS = [
18813
18900
  loginHint: "installs the Vercel sandbox CLI, then a browser sign-in",
18814
18901
  rebuildMinutes: "5-10",
18815
18902
  blurb: "Vercel Sandboxes",
18816
- sizeDesc: "Per-provider override of `box.size` for vercel. Reserved \u2014 vercel sizing is controlled via `box.vercelVcpus`.",
18903
+ sizeDesc: "Per-provider override of `box.size` for vercel. vCPU count \u2014 one of `1`, `2`, `4`, `8` (Vercel couples RAM at 2048 MB/vCPU). Default 2.",
18817
18904
  imageDesc: "Per-provider override of `box.image` for vercel (snapshot id, e.g. `snap_\u2026`). Written by `agentbox prepare --provider vercel`."
18818
18905
  },
18819
18906
  {
@@ -18823,8 +18910,18 @@ var PROVIDERS = [
18823
18910
  loginHint: "paste an API key from the E2B dashboard",
18824
18911
  rebuildMinutes: "2",
18825
18912
  blurb: "E2B microVMs",
18826
- sizeDesc: "Per-provider override of `box.size` for e2b. Reserved \u2014 e2b sizing is template-level (set at `agentbox prepare --provider e2b` time via --vcpus / --memory).",
18913
+ sizeDesc: "Per-provider override of `box.size` for e2b. `cpu-memory` GB spec (e.g. `4-8`). Template-level: baked by `agentbox prepare --provider e2b --size <spec>`; E2B rejects per-create resources.",
18827
18914
  imageDesc: "Per-provider override of `box.image` for e2b (template id or `name:tag`, e.g. `agentbox-base:latest`). Written by `agentbox prepare --provider e2b`."
18915
+ },
18916
+ {
18917
+ name: "digitalocean",
18918
+ kind: "cloud",
18919
+ label: "DigitalOcean (cloud VPS)",
18920
+ loginHint: "paste a Personal Access Token from the DigitalOcean Console",
18921
+ rebuildMinutes: "7-10",
18922
+ blurb: "DigitalOcean Droplets",
18923
+ sizeDesc: "Per-provider override of `box.size` for digitalocean. Droplet size slug (e.g. `s-2vcpu-4gb`, `s-4vcpu-8gb`).",
18924
+ imageDesc: "Per-provider override of `box.image` for digitalocean (numeric snapshot id). Written by `agentbox prepare --provider digitalocean`."
18828
18925
  }
18829
18926
  ];
18830
18927
  var PROVIDER_NAMES = PROVIDERS.map((p) => p.name);
@@ -18847,12 +18944,14 @@ var BUILT_IN_DEFAULTS = {
18847
18944
  defaultCheckpointHetzner: "",
18848
18945
  defaultCheckpointVercel: "",
18849
18946
  defaultCheckpointE2b: "",
18947
+ defaultCheckpointDigitalocean: "",
18850
18948
  size: "",
18851
18949
  sizeDocker: "",
18852
18950
  sizeDaytona: "",
18853
18951
  sizeHetzner: "",
18854
18952
  sizeVercel: "",
18855
18953
  sizeE2b: "",
18954
+ sizeDigitalocean: "",
18856
18955
  withPlaywright: false,
18857
18956
  claudeInstall: "native",
18858
18957
  withEnv: false,
@@ -18869,6 +18968,7 @@ var BUILT_IN_DEFAULTS = {
18869
18968
  imageHetzner: "",
18870
18969
  imageVercel: "",
18871
18970
  imageE2b: "",
18971
+ imageDigitalocean: "",
18872
18972
  // Mirrors BOX_IMAGE_REGISTRY in @agentbox/sandbox-docker. Empty disables the
18873
18973
  // registry pull (always build the docker base image locally).
18874
18974
  imageRegistry: "ghcr.io/madarco/agentbox/box",
@@ -18878,11 +18978,14 @@ var BUILT_IN_DEFAULTS = {
18878
18978
  pidsLimit: 0,
18879
18979
  disk: "",
18880
18980
  bundleDepth: void 0,
18881
- vercelVcpus: 2,
18981
+ hetznerLocation: "nbg1",
18982
+ digitaloceanRegion: "nyc3",
18882
18983
  vercelTimeoutMs: 27e5,
18883
18984
  vercelNetworkPolicy: "",
18884
18985
  e2bTimeoutMs: 27e5,
18885
- cpMaxBytes: 100 * 1024 * 1024
18986
+ cpMaxBytes: 100 * 1024 * 1024,
18987
+ credentialSync: true,
18988
+ inbound: "locked"
18886
18989
  },
18887
18990
  checkpoint: {
18888
18991
  maxLayers: 3
@@ -19013,7 +19116,7 @@ var KEY_REGISTRY = [
19013
19116
  {
19014
19117
  key: "box.size",
19015
19118
  type: "string",
19016
- description: "Default VM size for cloud providers. Provider-interpreted: hetzner = server type (e.g. `cx33`); daytona = `cpu-memory-disk` GB (e.g. `4-8-20`). Used as fallback when no per-provider override is set. Docker/Vercel ignore it."
19119
+ description: "Default VM size for cloud providers. Provider-interpreted: hetzner = server type (e.g. `cx33`); daytona = `cpu-memory-disk` GB (e.g. `4-8-20`); vercel = vCPU count (1, 2, 4, 8); e2b = `cpu-memory` GB (e.g. `4-8`). Used as fallback when no per-provider override is set. Docker ignores it."
19017
19120
  },
19018
19121
  ...perProviderSizeKeys(),
19019
19122
  {
@@ -19118,9 +19221,14 @@ var KEY_REGISTRY = [
19118
19221
  description: "Cap git bundle history shipped to cloud sandboxes (daytona, hetzner). 0 = full history. Unset = adaptive default (last 200 commits; re-bundle at 100 if the bundle exceeds 20 MB). Ignored for docker (which bind-mounts .git/)."
19119
19222
  },
19120
19223
  {
19121
- key: "box.vercelVcpus",
19122
- type: "int",
19123
- description: "vCPUs for new --provider vercel boxes (Vercel couples RAM at 2048 MB/vCPU). Default 2. Vercel only accepts specific counts (e.g. 1, 2, 4, 8) \u2014 an unsupported value fails create with a 400. Vercel-only; ignored by other providers."
19224
+ key: "box.hetznerLocation",
19225
+ type: "string",
19226
+ description: "Hetzner datacenter location new --provider hetzner boxes are created in (e.g. `nbg1`, `fsn1`, `hel1`, `ash`). Default `nbg1`. Overridable per-create with `--location`. Hetzner-only; ignored by other providers."
19227
+ },
19228
+ {
19229
+ key: "box.digitaloceanRegion",
19230
+ type: "string",
19231
+ description: "DigitalOcean region new --provider digitalocean boxes are created in (e.g. `nyc3`, `nyc1`, `sfo3`, `ams3`, `fra1`). Default `nyc3`. Overridable per-create with `--location`. DigitalOcean-only; ignored by other providers."
19124
19232
  },
19125
19233
  {
19126
19234
  key: "box.vercelTimeoutMs",
@@ -19138,6 +19246,16 @@ var KEY_REGISTRY = [
19138
19246
  description: "Max bytes a single host\u2192box copy may transfer after excludes, shared by `agentbox cp` (blocked with a size breakdown unless --yes) and each `carry:` entry (rejected at resolve time). Default 104857600 (100 MiB).",
19139
19247
  advanced: true
19140
19248
  },
19249
+ {
19250
+ key: "box.credentialSync",
19251
+ type: "bool",
19252
+ description: "Automatically sync refreshed agent credentials (claude/codex/opencode) from boxes to the host backup and out to all other running boxes. Claude OAuth refresh rotates the refresh token, so without this every other copy 401s after any box refreshes. Default true; --no-credential-sync at create disables the in-box watcher for that box."
19253
+ },
19254
+ {
19255
+ key: "box.inbound",
19256
+ type: "string",
19257
+ description: "Inbound-access policy for VPS boxes (hetzner, digitalocean per-box firewall). `locked` (default) = SSH reachable only from your host's egress IP; `open` = SSH reachable from anywhere (0.0.0.0/0, key-only \u2014 to drive a box from a phone with the laptop off); a CIDR list (e.g. `203.0.113.5/32`) = host egress plus those. Override per box with `--inbound` or after create with `agentbox inbound <box>`. Ignored by non-VPS providers."
19258
+ },
19141
19259
  {
19142
19260
  key: "box.vercelNetworkPolicy",
19143
19261
  type: "string",
@@ -19251,8 +19369,8 @@ var KEY_REGISTRY = [
19251
19369
  {
19252
19370
  key: "git.pushMode",
19253
19371
  type: "enum",
19254
- enumValues: ["auto", "relay", "lease"],
19255
- description: "How a box's `git push` reaches GitHub: `relay` (the host relay pushes with your host credentials \u2014 they never enter the box), `lease` (the relay/plane leases a short-lived GitHub-App token and the box pushes directly, so it works with the laptop off), or `auto` (default \u2014 lease when `relay.controlPlaneUrl` is set for the box, else relay). Only affects cloud boxes; docker boxes always use `relay`. Forcing `relay` needs a reachable host relay for the box; forcing `lease` needs a reachable relay/plane with a GitHub App."
19372
+ enumValues: ["auto", "relay", "lease", "direct"],
19373
+ description: "How a box's `git push` reaches GitHub: `relay` (the host relay pushes with your host credentials \u2014 they never enter the box), `lease` (the relay/plane leases a short-lived GitHub-App token and the box pushes directly, so it works with the laptop off), `direct` (the box holds a COPY of your git credentials and pushes/pulls/signs entirely on its own \u2014 needs no host or hub, but the credentials live inside the box and its snapshots; set via `--with-credentials`, which copies them in behind a confirmation), or `auto` (default \u2014 lease when `relay.controlPlaneUrl` is set for the box, else relay). Only affects cloud boxes; docker boxes always use `relay`. Forcing `relay` needs a reachable host relay for the box; forcing `lease` needs a reachable relay/plane with a GitHub App; `direct` needs credentials to have been copied into the box at create time."
19256
19374
  },
19257
19375
  {
19258
19376
  key: "vnc.containerPort",
@@ -19486,34 +19604,34 @@ function branchHasLeafBelow(branchSpec, prefix) {
19486
19604
  }
19487
19605
  return false;
19488
19606
  }
19489
- var STATE_DIR2 = (0, import_path6.join)((0, import_os4.homedir)(), ".agentbox");
19490
- var GLOBAL_CONFIG_FILE = (0, import_path6.join)(STATE_DIR2, "config.yaml");
19491
- var PROJECTS_DIR = (0, import_path6.join)(STATE_DIR2, "projects");
19607
+ var STATE_DIR2 = (0, import_path7.join)((0, import_os4.homedir)(), ".agentbox");
19608
+ var GLOBAL_CONFIG_FILE = (0, import_path7.join)(STATE_DIR2, "config.yaml");
19609
+ var PROJECTS_DIR = (0, import_path7.join)(STATE_DIR2, "projects");
19492
19610
  var WORKSPACE_CONFIG_BASENAME = "agentbox.yaml";
19493
19611
  async function findProjectRoot(cwd) {
19494
19612
  const start = await canonicalize(cwd);
19495
19613
  let dir = start;
19496
19614
  for (let i2 = 0; i2 < 64; i2++) {
19497
- if (await fileExists((0, import_path6.join)(dir, WORKSPACE_CONFIG_BASENAME))) {
19615
+ if (await fileExists((0, import_path7.join)(dir, WORKSPACE_CONFIG_BASENAME))) {
19498
19616
  return { root: dir, hasAgentboxYaml: true };
19499
19617
  }
19500
- const parent = (0, import_path6.dirname)(dir);
19618
+ const parent = (0, import_path7.dirname)(dir);
19501
19619
  if (parent === dir) break;
19502
19620
  dir = parent;
19503
19621
  }
19504
19622
  return { root: start, hasAgentboxYaml: false };
19505
19623
  }
19506
19624
  async function canonicalize(p) {
19507
- const abs = (0, import_path6.resolve)(p);
19625
+ const abs = (0, import_path7.resolve)(p);
19508
19626
  try {
19509
- return await (0, import_promises14.realpath)(abs);
19627
+ return await (0, import_promises15.realpath)(abs);
19510
19628
  } catch {
19511
19629
  return abs;
19512
19630
  }
19513
19631
  }
19514
19632
  async function fileExists(p) {
19515
19633
  try {
19516
- const st = await (0, import_promises14.stat)(p);
19634
+ const st = await (0, import_promises15.stat)(p);
19517
19635
  return st.isFile();
19518
19636
  } catch {
19519
19637
  return false;
@@ -19527,21 +19645,21 @@ function sanitizeMnemonic(raw) {
19527
19645
  return raw.toLowerCase().replace(/-/g, "_").replace(/[^a-z0-9_]+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "").slice(0, 32) || "unnamed";
19528
19646
  }
19529
19647
  function projectDirSegment(absPath) {
19530
- return `${hashProjectPath(absPath)}-${sanitizeMnemonic((0, import_path6.basename)(absPath))}`;
19648
+ return `${hashProjectPath(absPath)}-${sanitizeMnemonic((0, import_path7.basename)(absPath))}`;
19531
19649
  }
19532
19650
  function projectConfigDir(absPath) {
19533
- return (0, import_path6.join)(PROJECTS_DIR, projectDirSegment(absPath));
19651
+ return (0, import_path7.join)(PROJECTS_DIR, projectDirSegment(absPath));
19534
19652
  }
19535
19653
  function projectConfigFile(absPath) {
19536
- return (0, import_path6.join)(projectConfigDir(absPath), "config.yaml");
19654
+ return (0, import_path7.join)(projectConfigDir(absPath), "config.yaml");
19537
19655
  }
19538
19656
  function workspaceConfigFile(workspacePath) {
19539
- return (0, import_path6.join)(workspacePath, WORKSPACE_CONFIG_BASENAME);
19657
+ return (0, import_path7.join)(workspacePath, WORKSPACE_CONFIG_BASENAME);
19540
19658
  }
19541
19659
  async function loadOptionalUserConfig(path6) {
19542
19660
  let text;
19543
19661
  try {
19544
- text = await (0, import_promises15.readFile)(path6, "utf8");
19662
+ text = await (0, import_promises16.readFile)(path6, "utf8");
19545
19663
  } catch (err) {
19546
19664
  if (err.code === "ENOENT") return {};
19547
19665
  throw err;
@@ -19552,7 +19670,7 @@ async function loadProjectAgentboxDefaults(workspacePath) {
19552
19670
  const path6 = workspaceConfigFile(workspacePath);
19553
19671
  let text;
19554
19672
  try {
19555
- text = await (0, import_promises15.readFile)(path6, "utf8");
19673
+ text = await (0, import_promises16.readFile)(path6, "utf8");
19556
19674
  } catch (err) {
19557
19675
  if (err.code === "ENOENT") return {};
19558
19676
  throw err;
@@ -19653,7 +19771,7 @@ function writeLeaf(obj, branch, leaf, value) {
19653
19771
  }
19654
19772
  cur[segs[segs.length - 1]] = value;
19655
19773
  }
19656
- var PROJECT_GC_COUNTER_FILE = (0, import_path7.join)(PROJECTS_DIR, ".gc.json");
19774
+ var PROJECT_GC_COUNTER_FILE = (0, import_path8.join)(PROJECTS_DIR, ".gc.json");
19657
19775
 
19658
19776
  // src/integrations.ts
19659
19777
  var INTEGRATION_RPC_TIMEOUT_MS = 12e4;
@@ -20275,6 +20393,10 @@ async function resolveCloudBackend(name) {
20275
20393
  const pkg = "@agentbox/sandbox-e2b";
20276
20394
  return loadCloudBackend(pkg, async () => (await import(pkg)).e2bBackend);
20277
20395
  }
20396
+ if (name === "digitalocean") {
20397
+ const pkg = "@agentbox/sandbox-digitalocean";
20398
+ return loadCloudBackend(pkg, async () => (await import(pkg)).digitaloceanBackend);
20399
+ }
20278
20400
  const plugin = pluginForProvider(name);
20279
20401
  if (plugin) {
20280
20402
  if (!isSupportedApiVersion(plugin.apiVersion)) {
@@ -20910,7 +21032,7 @@ async function runGitRpc(action, deps) {
20910
21032
  }
20911
21033
  if (params.hostOnly) {
20912
21034
  const dest = resolveLandDest(branch, params.as);
20913
- const stageSave = await (0, import_promises16.mkdtemp)((0, import_node_path6.join)((0, import_node_os4.tmpdir)(), "agentbox-git-save-"));
21035
+ const stageSave = await (0, import_promises17.mkdtemp)((0, import_node_path6.join)((0, import_node_os4.tmpdir)(), "agentbox-git-save-"));
20914
21036
  const hostBundleSave = (0, import_node_path6.join)(stageSave, "op.bundle");
20915
21037
  const remoteBundleSave = "/tmp/agentbox-rpc-save.bundle";
20916
21038
  try {
@@ -20942,7 +21064,7 @@ ${landed.stdout ?? ""}`,
20942
21064
  stderr: landed.stderr ?? ""
20943
21065
  };
20944
21066
  } finally {
20945
- await (0, import_promises16.rm)(stageSave, { recursive: true, force: true });
21067
+ await (0, import_promises17.rm)(stageSave, { recursive: true, force: true });
20946
21068
  await backend.exec(handle, `rm -f ${shellQuote(remoteBundleSave)}`).catch(() => {
20947
21069
  });
20948
21070
  }
@@ -21021,7 +21143,7 @@ ${landed.stdout ?? ""}`,
21021
21143
  }
21022
21144
  }
21023
21145
  }
21024
- const stage = await (0, import_promises16.mkdtemp)((0, import_node_path6.join)((0, import_node_os4.tmpdir)(), "agentbox-git-rpc-"));
21146
+ const stage = await (0, import_promises17.mkdtemp)((0, import_node_path6.join)((0, import_node_os4.tmpdir)(), "agentbox-git-rpc-"));
21025
21147
  const hostBundle = (0, import_node_path6.join)(stage, "op.bundle");
21026
21148
  const remoteBundle = "/tmp/agentbox-rpc.bundle";
21027
21149
  try {
@@ -21123,7 +21245,7 @@ relay: post-push in-box origin/upstream sync threw: ${err instanceof Error ? err
21123
21245
  stderr: sandboxFetch.stderr
21124
21246
  };
21125
21247
  } finally {
21126
- await (0, import_promises16.rm)(stage, { recursive: true, force: true });
21248
+ await (0, import_promises17.rm)(stage, { recursive: true, force: true });
21127
21249
  await backend.exec(handle, `rm -f ${shellQuote(remoteBundle)}`).catch(() => {
21128
21250
  });
21129
21251
  }
@@ -21609,8 +21731,86 @@ var EventBuffer = class {
21609
21731
  }
21610
21732
  };
21611
21733
 
21734
+ // src/credentials-fanout.ts
21735
+ var CREDENTIALS_UPDATED_EVENT = "credentials-updated";
21736
+ var CredentialsFanout = class {
21737
+ log;
21738
+ debounceMs;
21739
+ runPropagate;
21740
+ backupPathFor;
21741
+ pending = /* @__PURE__ */ new Map();
21742
+ chains = /* @__PURE__ */ new Map();
21743
+ constructor(deps) {
21744
+ this.log = deps.log;
21745
+ this.debounceMs = deps.debounceMs ?? 3e3;
21746
+ this.runPropagate = deps.runPropagate ?? defaultRunPropagate;
21747
+ this.backupPathFor = deps.backupPathFor;
21748
+ }
21749
+ /**
21750
+ * Validate, newest-wins-gate, persist the host backup, and schedule the
21751
+ * fan-out. Fast (no box I/O); the propagate CLI does the slow work detached.
21752
+ */
21753
+ async handle(sourceBoxId, payload) {
21754
+ const update = parseCredentialsUpdate(payload);
21755
+ if (!update) return { accepted: false, reason: "invalid payload" };
21756
+ const backupPath = this.backupPathFor?.(update.agent);
21757
+ const existing = await readCredentialBackup(update.agent, { backupPath });
21758
+ const verdict = shouldAcceptCredentialUpdate(update.agent, update.content, existing);
21759
+ if (!verdict.accept) {
21760
+ return { accepted: false, reason: verdict.reason };
21761
+ }
21762
+ await writeCredentialBackup(update.agent, update.content, { backupPath });
21763
+ this.log(
21764
+ `credentials: accepted ${update.agent} update from box ${sourceBoxId} (${verdict.reason}); fan-out in ${String(this.debounceMs)}ms`
21765
+ );
21766
+ this.schedule(update.agent, sourceBoxId);
21767
+ return { accepted: true, reason: verdict.reason };
21768
+ }
21769
+ schedule(agent, sourceBoxId) {
21770
+ const existing = this.pending.get(agent);
21771
+ if (existing) clearTimeout(existing);
21772
+ const timer = setTimeout(() => {
21773
+ this.pending.delete(agent);
21774
+ const prev = this.chains.get(agent) ?? Promise.resolve();
21775
+ const next = prev.then(() => this.runPropagate(agent, sourceBoxId)).catch((err) => {
21776
+ this.log(
21777
+ `credentials: ${agent} fan-out failed: ${err instanceof Error ? err.message : String(err)}`
21778
+ );
21779
+ });
21780
+ this.chains.set(agent, next);
21781
+ }, this.debounceMs);
21782
+ timer.unref();
21783
+ this.pending.set(agent, timer);
21784
+ }
21785
+ /** Pending debounce timers + in-flight chain, for tests/shutdown. */
21786
+ async flush() {
21787
+ for (const [agent, timer] of this.pending) {
21788
+ clearTimeout(timer);
21789
+ this.pending.delete(agent);
21790
+ void agent;
21791
+ }
21792
+ await Promise.all([...this.chains.values()]);
21793
+ }
21794
+ };
21795
+ async function defaultRunPropagate(agent, sourceBoxId) {
21796
+ const entry = process.env["AGENTBOX_CLI_ENTRY"];
21797
+ if (!entry) {
21798
+ throw new Error("AGENTBOX_CLI_ENTRY not set; cannot run credential propagate host-side");
21799
+ }
21800
+ const result = await execa(
21801
+ process.execPath,
21802
+ [entry, "credentials", "propagate", "--agent", agent, "--source-box", sourceBoxId],
21803
+ { reject: false, timeout: 3e5 }
21804
+ );
21805
+ if (result.exitCode !== 0) {
21806
+ throw new Error(
21807
+ `credentials propagate exited ${String(result.exitCode)}: ${String(result.stderr).slice(-300)}`
21808
+ );
21809
+ }
21810
+ }
21811
+
21612
21812
  // src/status-store.ts
21613
- var import_promises17 = require("fs/promises");
21813
+ var import_promises18 = require("fs/promises");
21614
21814
  var import_node_os5 = require("os");
21615
21815
  var import_node_path7 = require("path");
21616
21816
  function sanitizeMnemonic2(raw) {
@@ -21646,11 +21846,11 @@ var BoxStatusStore = class {
21646
21846
  const target = boxStatusPathFor(boxId, name, projectIndex);
21647
21847
  const tmp = `${target}.${String(process.pid)}.tmp`;
21648
21848
  try {
21649
- await (0, import_promises17.mkdir)(boxRunDirFor(boxId, name, projectIndex), { recursive: true });
21650
- await (0, import_promises17.writeFile)(tmp, JSON.stringify(status), "utf8");
21651
- await (0, import_promises17.rename)(tmp, target);
21849
+ await (0, import_promises18.mkdir)(boxRunDirFor(boxId, name, projectIndex), { recursive: true });
21850
+ await (0, import_promises18.writeFile)(tmp, JSON.stringify(status), "utf8");
21851
+ await (0, import_promises18.rename)(tmp, target);
21652
21852
  } catch {
21653
- await (0, import_promises17.rm)(tmp, { force: true }).catch(() => {
21853
+ await (0, import_promises18.rm)(tmp, { force: true }).catch(() => {
21654
21854
  });
21655
21855
  }
21656
21856
  }
@@ -21860,6 +22060,7 @@ function createRelayServer(opts) {
21860
22060
  const host = opts.host ?? "0.0.0.0";
21861
22061
  const mode = opts.mode ?? "host";
21862
22062
  const hostActions = mode === "box" ? new HostActionQueue() : null;
22063
+ const credentialsFanout = mode === "box" ? null : new CredentialsFanout({ log });
21863
22064
  if (mode === "box" && (!opts.bridgeToken || opts.bridgeToken.length === 0)) {
21864
22065
  throw new Error("relay mode='box' requires a non-empty bridgeToken");
21865
22066
  }
@@ -21985,6 +22186,14 @@ function createRelayServer(opts) {
21985
22186
  send(res, 202, { ok: true });
21986
22187
  return;
21987
22188
  }
22189
+ if (body.type === CREDENTIALS_UPDATED_EVENT && credentialsFanout) {
22190
+ const verdict = await credentialsFanout.handle(reg.boxId, body.payload);
22191
+ log(
22192
+ `credentials-updated box=${reg.boxId} accepted=${String(verdict.accepted)} (${verdict.reason})`
22193
+ );
22194
+ send(res, 202, { ok: true, accepted: verdict.accepted });
22195
+ return;
22196
+ }
21988
22197
  const ev = await store.appendEvent({
21989
22198
  boxId: reg.boxId,
21990
22199
  type: body.type,
@@ -22419,6 +22628,13 @@ function createRelayServer(opts) {
22419
22628
  previewToken: reg.previewToken,
22420
22629
  onEvents: async (evs) => {
22421
22630
  for (const ev of evs) {
22631
+ if (ev.type === CREDENTIALS_UPDATED_EVENT && credentialsFanout) {
22632
+ const verdict = await credentialsFanout.handle(reg.boxId, ev.payload);
22633
+ log(
22634
+ `credentials-updated box=${reg.boxId} accepted=${String(verdict.accepted)} (${verdict.reason})`
22635
+ );
22636
+ continue;
22637
+ }
22422
22638
  await store.appendEvent({
22423
22639
  boxId: reg.boxId,
22424
22640
  type: ev.type,
@@ -23133,22 +23349,22 @@ async function startRelayServer(opts) {
23133
23349
 
23134
23350
  // src/autopause.ts
23135
23351
  var import_node_child_process10 = require("child_process");
23136
- var import_promises21 = require("fs/promises");
23352
+ var import_promises22 = require("fs/promises");
23137
23353
 
23138
23354
  // src/queue.ts
23139
23355
  var import_node_child_process9 = require("child_process");
23140
23356
  var import_node_crypto7 = require("crypto");
23141
- var import_promises19 = require("fs/promises");
23357
+ var import_promises20 = require("fs/promises");
23142
23358
  var import_node_fs6 = require("fs");
23143
23359
  var import_node_path8 = require("path");
23144
- var import_promises20 = require("timers/promises");
23360
+ var import_promises21 = require("timers/promises");
23145
23361
  var QUEUE_DIR = (0, import_node_path8.join)(STATE_DIR, "queue");
23146
23362
  var PREPARE_MAX_CONCURRENT = 1;
23147
23363
  async function loadQueueConfig() {
23148
23364
  const d = BUILT_IN_DEFAULTS.queue;
23149
23365
  let global3 = {};
23150
23366
  try {
23151
- global3 = parseUserConfig(await (0, import_promises19.readFile)(GLOBAL_CONFIG_FILE, "utf8"), GLOBAL_CONFIG_FILE);
23367
+ global3 = parseUserConfig(await (0, import_promises20.readFile)(GLOBAL_CONFIG_FILE, "utf8"), GLOBAL_CONFIG_FILE);
23152
23368
  } catch {
23153
23369
  }
23154
23370
  const q = global3.queue ?? {};
@@ -23160,15 +23376,15 @@ async function loadQueueConfig() {
23160
23376
  };
23161
23377
  }
23162
23378
  async function writeJob(job) {
23163
- await (0, import_promises19.mkdir)(QUEUE_DIR, { recursive: true });
23379
+ await (0, import_promises20.mkdir)(QUEUE_DIR, { recursive: true });
23164
23380
  const final = (0, import_node_path8.join)(QUEUE_DIR, `${job.id}.json`);
23165
23381
  const tmp = `${final}.tmp.${String(process.pid)}.${String(Date.now())}`;
23166
- await (0, import_promises19.writeFile)(tmp, JSON.stringify(job, null, 2) + "\n", "utf8");
23167
- await (0, import_promises19.rename)(tmp, final);
23382
+ await (0, import_promises20.writeFile)(tmp, JSON.stringify(job, null, 2) + "\n", "utf8");
23383
+ await (0, import_promises20.rename)(tmp, final);
23168
23384
  }
23169
23385
  async function readJob(id) {
23170
23386
  try {
23171
- const raw = await (0, import_promises19.readFile)((0, import_node_path8.join)(QUEUE_DIR, `${id}.json`), "utf8");
23387
+ const raw = await (0, import_promises20.readFile)((0, import_node_path8.join)(QUEUE_DIR, `${id}.json`), "utf8");
23172
23388
  return JSON.parse(raw);
23173
23389
  } catch (err) {
23174
23390
  if (err.code === "ENOENT") return null;
@@ -23177,7 +23393,7 @@ async function readJob(id) {
23177
23393
  }
23178
23394
  async function deleteJob(id) {
23179
23395
  try {
23180
- await (0, import_promises19.unlink)((0, import_node_path8.join)(QUEUE_DIR, `${id}.json`));
23396
+ await (0, import_promises20.unlink)((0, import_node_path8.join)(QUEUE_DIR, `${id}.json`));
23181
23397
  } catch (err) {
23182
23398
  if (err.code !== "ENOENT") throw err;
23183
23399
  }
@@ -23185,7 +23401,7 @@ async function deleteJob(id) {
23185
23401
  async function loadQueue() {
23186
23402
  let entries;
23187
23403
  try {
23188
- entries = await (0, import_promises19.readdir)(QUEUE_DIR);
23404
+ entries = await (0, import_promises20.readdir)(QUEUE_DIR);
23189
23405
  } catch (err) {
23190
23406
  if (err.code === "ENOENT") return [];
23191
23407
  throw err;
@@ -23194,7 +23410,7 @@ async function loadQueue() {
23194
23410
  for (const name of entries) {
23195
23411
  if (!name.endsWith(".json")) continue;
23196
23412
  try {
23197
- const raw = await (0, import_promises19.readFile)((0, import_node_path8.join)(QUEUE_DIR, name), "utf8");
23413
+ const raw = await (0, import_promises20.readFile)((0, import_node_path8.join)(QUEUE_DIR, name), "utf8");
23198
23414
  out.push(JSON.parse(raw));
23199
23415
  } catch {
23200
23416
  }
@@ -23602,7 +23818,7 @@ async function defaultSpawnWorker(job) {
23602
23818
  `AGENTBOX_CLI_ENTRY not set or missing (${String(entry)}); cannot spawn queue worker`
23603
23819
  );
23604
23820
  }
23605
- await (0, import_promises19.mkdir)((0, import_node_path8.join)(STATE_DIR, "logs"), { recursive: true });
23821
+ await (0, import_promises20.mkdir)((0, import_node_path8.join)(STATE_DIR, "logs"), { recursive: true });
23606
23822
  const fd = (0, import_node_fs6.openSync)(job.logPath, "a");
23607
23823
  const command = job.kind === "prepare" ? "_run-queued-prepare" : "_run-queued-job";
23608
23824
  const child = (0, import_node_child_process9.spawn)(process.execPath, [entry, command, job.id], {
@@ -23638,7 +23854,7 @@ async function loadAutopauseConfig() {
23638
23854
  const d = BUILT_IN_DEFAULTS.autopause;
23639
23855
  let global3 = {};
23640
23856
  try {
23641
- global3 = parseUserConfig(await (0, import_promises21.readFile)(GLOBAL_CONFIG_FILE, "utf8"), GLOBAL_CONFIG_FILE);
23857
+ global3 = parseUserConfig(await (0, import_promises22.readFile)(GLOBAL_CONFIG_FILE, "utf8"), GLOBAL_CONFIG_FILE);
23642
23858
  } catch {
23643
23859
  }
23644
23860
  const a2 = global3.autopause ?? {};
@@ -23826,7 +24042,7 @@ async function pauseContainer(name) {
23826
24042
  }
23827
24043
 
23828
24044
  // src/cloud-keepalive.ts
23829
- var import_promises22 = require("fs/promises");
24045
+ var import_promises23 = require("fs/promises");
23830
24046
  function selectBoxesToRenew(entries, windowMs, now) {
23831
24047
  const out = [];
23832
24048
  for (const e of entries) {
@@ -23982,7 +24198,7 @@ async function defaultFallbackCreateTimeoutMs(backend) {
23982
24198
  const fallback = BUILT_IN_DEFAULTS.box.vercelTimeoutMs;
23983
24199
  try {
23984
24200
  const global3 = parseUserConfig(
23985
- await (0, import_promises22.readFile)(GLOBAL_CONFIG_FILE, "utf8"),
24201
+ await (0, import_promises23.readFile)(GLOBAL_CONFIG_FILE, "utf8"),
23986
24202
  GLOBAL_CONFIG_FILE
23987
24203
  );
23988
24204
  const v = global3.box?.vercelTimeoutMs;