@madarco/agentbox 0.27.1 → 0.27.2

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 (146) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{_cloud-attach-WDGM6FL5.js → _cloud-attach-FVD5YJCE.js} +6 -4
  3. package/dist/{chunk-NEF6MDJO.js → chunk-2PCU4OF5.js} +4 -4
  4. package/dist/{chunk-JE6UI5YR.js → chunk-47BVC7FN.js} +7 -59
  5. package/dist/chunk-47BVC7FN.js.map +1 -0
  6. package/dist/chunk-5ZK5MQA2.js +64 -0
  7. package/dist/chunk-5ZK5MQA2.js.map +1 -0
  8. package/dist/{chunk-26IKZRTT.js → chunk-A4OVGMVL.js} +23 -16
  9. package/dist/chunk-A4OVGMVL.js.map +1 -0
  10. package/dist/{chunk-KWOEUFVA.js → chunk-EZWPCTUO.js} +2 -2
  11. package/dist/{chunk-IDH5A4RR.js → chunk-F6NQZ4DC.js} +2 -2
  12. package/dist/chunk-IMN62QY5.js +285 -0
  13. package/dist/chunk-IMN62QY5.js.map +1 -0
  14. package/dist/{chunk-V5XXJH63.js → chunk-JNFUWQ4N.js} +2 -2
  15. package/dist/{chunk-UJEH2NJT.js → chunk-JRXNVEV3.js} +2 -271
  16. package/dist/chunk-JRXNVEV3.js.map +1 -0
  17. package/dist/{chunk-LL7NCMUU.js → chunk-QAJQXZ3N.js} +3 -3
  18. package/dist/{chunk-SJ75AIA2.js → chunk-QJT2XOKH.js} +8 -6
  19. package/dist/{chunk-SJ75AIA2.js.map → chunk-QJT2XOKH.js.map} +1 -1
  20. package/dist/{chunk-HR7NHH5J.js → chunk-RK2CEABS.js} +205 -5
  21. package/dist/{chunk-HR7NHH5J.js.map → chunk-RK2CEABS.js.map} +1 -1
  22. package/dist/cloud-backends.js +28 -0
  23. package/dist/cloud-backends.js.map +1 -0
  24. package/dist/{dist-O3LKOIE7.js → dist-2SXD3ITR.js} +6 -5
  25. package/dist/{dist-O3LKOIE7.js.map → dist-2SXD3ITR.js.map} +1 -1
  26. package/dist/{dist-FTKS2GI4.js → dist-4KTWNGU6.js} +6 -5
  27. package/dist/{dist-WVYAURMF.js → dist-6ZOCQZIP.js} +6 -5
  28. package/dist/{dist-OO52HARR.js → dist-7VCYREHM.js} +22 -20
  29. package/dist/{dist-KQTMCVME.js → dist-TL4YW7KZ.js} +6 -5
  30. package/dist/{dist-KQTMCVME.js.map → dist-TL4YW7KZ.js.map} +1 -1
  31. package/dist/{dist-TSFVB7AI.js → dist-UUOX4DBX.js} +6 -5
  32. package/dist/{dist-TSFVB7AI.js.map → dist-UUOX4DBX.js.map} +1 -1
  33. package/dist/dist-XSEK7LX3.js +156 -0
  34. package/dist/{dist-Z6L5MM5D.js → dist-YGXQMN2K.js} +6 -5
  35. package/dist/index.js +58 -54
  36. package/dist/index.js.map +1 -1
  37. package/dist/{prepared-state-75DIZ55S-TNJXWMXV.js → prepared-state-75DIZ55S-B33TDOJZ.js} +3 -2
  38. package/dist/prepared-state-75DIZ55S-B33TDOJZ.js.map +1 -0
  39. package/package.json +1 -1
  40. package/runtime/_shared/ctl.cjs +186 -172
  41. package/runtime/digitalocean/ctl.cjs +186 -172
  42. package/runtime/docker/packages/ctl/dist/bin.cjs +186 -172
  43. package/runtime/e2b/ctl.cjs +186 -172
  44. package/runtime/hetzner/ctl.cjs +186 -172
  45. package/runtime/hub/apps/hub/.next/BUILD_ID +1 -1
  46. package/runtime/hub/apps/hub/.next/build-manifest.json +3 -3
  47. package/runtime/hub/apps/hub/.next/prerender-manifest.json +3 -3
  48. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/approvals/page/server-reference-manifest.json +1 -1
  49. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/approvals/page_client-reference-manifest.js +1 -1
  50. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/boxes/[id]/page/server-reference-manifest.json +12 -12
  51. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/boxes/[id]/page_client-reference-manifest.js +1 -1
  52. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page/server-reference-manifest.json +11 -11
  53. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
  54. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page/server-reference-manifest.json +8 -8
  55. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page_client-reference-manifest.js +1 -1
  56. package/runtime/hub/apps/hub/.next/server/app/[...path]/route.js +1 -1
  57. package/runtime/hub/apps/hub/.next/server/app/[...path]/route.js.nft.json +1 -1
  58. package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
  59. package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
  60. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  61. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  62. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  63. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  64. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  65. package/runtime/hub/apps/hub/.next/server/chunks/151__@better-auth_core_dist_0ecdp_3._.js +1 -1
  66. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__04h15ml._.js +1 -1
  67. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__04jgk9x._.js +1 -1
  68. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__07ednlo._.js +1 -1
  69. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0a7djvw._.js +1 -1
  70. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0ig1bot._.js +1 -1
  71. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0szd4sh._.js +1 -1
  72. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0t7o5ed._.js +1 -1
  73. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1-0flwc._.js +1 -1
  74. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1-9g0ae._.js +1 -1
  75. package/runtime/hub/apps/hub/.next/server/chunks/{[root-of-the-server]__1e4z_-v._.js → [root-of-the-server]__11izd5j._.js} +2 -2
  76. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__13ioh5z._.js +1 -1
  77. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__13jwk_k._.js +1 -1
  78. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__16_uteg._.js +1 -1
  79. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__16p2m-g._.js +1 -1
  80. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1_gu2yk._.js +1 -1
  81. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1ai-945._.js +1 -1
  82. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bu2zio._.js +1 -1
  83. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1ctczev._.js +1 -1
  84. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1f2sueq._.js +1 -1
  85. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1f9zctr._.js +1 -1
  86. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1md9kdw._.js +1 -1
  87. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1mttufy._.js +1 -1
  88. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1pp5oib._.js +1 -1
  89. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qwhzmi._.js +1 -1
  90. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1thipug._.js +1 -1
  91. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1xeczo7._.js +1 -1
  92. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__20503l7._.js +1 -1
  93. package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +2 -2
  94. package/runtime/hub/apps/hub/.next/server/chunks/packages_relay_dist_control-plane_03a-9aj.js +3 -3
  95. package/runtime/hub/apps/hub/.next/server/chunks/ssr/044u_hub__next-internal_server_app_(dashboard)_projects_[id]_page_actions_15f56np.js +1 -1
  96. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_03s-ah2._.js +1 -1
  97. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0kpdmm-._.js +1 -1
  98. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ozyjt1._.js +1 -1
  99. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0r4px38._.js +1 -1
  100. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_18w2zeh._.js +1 -1
  101. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub__next-internal_server_app_(dashboard)_approvals_page_actions_1mi0bpn.js +1 -1
  102. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub__next-internal_server_app_(dashboard)_boxes_[id]_page_actions_0k7kgn2.js +1 -1
  103. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub__next-internal_server_app_(dashboard)_page_actions_1t3u0xy.js +1 -1
  104. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_app_(dashboard)_boxes_[id]_page_tsx_1-j_972._.js +1 -1
  105. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_app_(dashboard)_boxes_components_box-table_tsx_0a9pyn_._.js +1 -1
  106. package/runtime/hub/apps/hub/.next/server/chunks/ssr/packages_relay_dist_control-plane_0ve-wz4.js +1 -1
  107. package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
  108. package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
  109. package/runtime/hub/apps/hub/.next/server/server-reference-manifest.js +1 -1
  110. package/runtime/hub/apps/hub/.next/server/server-reference-manifest.json +18 -18
  111. package/runtime/hub/apps/hub/.next/static/chunks/{30de2x24ntwkg.js → 1-maeq_pl3z29.js} +1 -1
  112. package/runtime/hub/apps/hub/.next/static/chunks/{2gfw8-qyx5xi_.js → 1f-pwhlfklk8h.js} +1 -1
  113. package/runtime/hub/apps/hub/.next/static/chunks/{3tqnniym2yvpb.js → 1g922r_mc5ciw.js} +1 -1
  114. package/runtime/hub/apps/hub/.next/static/chunks/{070w7h5rh5ja6.js → 2k1tvmngrtdgs.js} +1 -1
  115. package/runtime/hub/apps/hub/.next/static/chunks/{3e5n630psqst8.js → 2omimeqtc8qnp.js} +1 -1
  116. package/runtime/hub/apps/hub/.next/static/chunks/{2awpm9w8crker.js → 3urpddxa8b_je.js} +1 -1
  117. package/runtime/hub/apps/hub/{chunk-YJ5MJOXK.js → chunk-5ARPIPV4.js} +194 -171
  118. package/runtime/hub/apps/hub/{chunk-EHBJKZCL.js → chunk-AEIOQFZ4.js} +245 -2
  119. package/runtime/hub/apps/hub/dist-2EOAT3PC.js +155 -0
  120. package/runtime/hub/apps/hub/{dist-LYDHYTP2.js → dist-DQIL673Y.js} +2 -2
  121. package/runtime/hub/apps/hub/{dist-GTVVXCBP.js → dist-EURE7AUA.js} +2 -2
  122. package/runtime/hub/apps/hub/{dist-JG45OFT2.js → dist-EYHD64SR.js} +16 -16
  123. package/runtime/hub/apps/hub/{dist-G6TXUSPZ.js → dist-GFXXCXLS.js} +2 -2
  124. package/runtime/hub/apps/hub/{dist-DX6IYMAH.js → dist-IVA2PC7N.js} +2 -2
  125. package/runtime/hub/apps/hub/{dist-6FPPUSWZ.js → dist-MMTT7VYJ.js} +1 -1
  126. package/runtime/hub/apps/hub/{dist-3I7KUI6W.js → dist-TAWVTJGU.js} +2 -2
  127. package/runtime/hub/apps/hub/server.js +28 -15
  128. package/runtime/relay/bin.cjs +37 -3
  129. package/runtime/vercel/ctl.cjs +186 -172
  130. package/dist/chunk-26IKZRTT.js.map +0 -1
  131. package/dist/chunk-JE6UI5YR.js.map +0 -1
  132. package/dist/chunk-UJEH2NJT.js.map +0 -1
  133. /package/dist/{_cloud-attach-WDGM6FL5.js.map → _cloud-attach-FVD5YJCE.js.map} +0 -0
  134. /package/dist/{chunk-NEF6MDJO.js.map → chunk-2PCU4OF5.js.map} +0 -0
  135. /package/dist/{chunk-KWOEUFVA.js.map → chunk-EZWPCTUO.js.map} +0 -0
  136. /package/dist/{chunk-IDH5A4RR.js.map → chunk-F6NQZ4DC.js.map} +0 -0
  137. /package/dist/{chunk-V5XXJH63.js.map → chunk-JNFUWQ4N.js.map} +0 -0
  138. /package/dist/{chunk-LL7NCMUU.js.map → chunk-QAJQXZ3N.js.map} +0 -0
  139. /package/dist/{dist-FTKS2GI4.js.map → dist-4KTWNGU6.js.map} +0 -0
  140. /package/dist/{dist-OO52HARR.js.map → dist-6ZOCQZIP.js.map} +0 -0
  141. /package/dist/{dist-WVYAURMF.js.map → dist-7VCYREHM.js.map} +0 -0
  142. /package/dist/{dist-Z6L5MM5D.js.map → dist-XSEK7LX3.js.map} +0 -0
  143. /package/dist/{prepared-state-75DIZ55S-TNJXWMXV.js.map → dist-YGXQMN2K.js.map} +0 -0
  144. /package/runtime/hub/apps/hub/.next/static/{PWF2iHQOg9-rRyfqVDLrh → Wddru2A-5szSWhZWYoMwi}/_buildManifest.js +0 -0
  145. /package/runtime/hub/apps/hub/.next/static/{PWF2iHQOg9-rRyfqVDLrh → Wddru2A-5szSWhZWYoMwi}/_clientMiddlewareManifest.js +0 -0
  146. /package/runtime/hub/apps/hub/.next/static/{PWF2iHQOg9-rRyfqVDLrh → Wddru2A-5szSWhZWYoMwi}/_ssgManifest.js +0 -0
@@ -12,7 +12,7 @@ import {
12
12
  preparedStatePathFor,
13
13
  readPreparedStateRaw,
14
14
  writePreparedStateRaw
15
- } from "./chunk-UJEH2NJT.js";
15
+ } from "./chunk-JRXNVEV3.js";
16
16
 
17
17
  // ../../packages/sandbox-digitalocean/dist/chunk-7SUT53X5.js
18
18
  import { existsSync, readFileSync } from "fs";
@@ -991,4 +991,4 @@ export {
991
991
  updatePreparedState,
992
992
  currentDigitalOceanBaseFingerprintLive
993
993
  };
994
- //# sourceMappingURL=chunk-KWOEUFVA.js.map
994
+ //# sourceMappingURL=chunk-EZWPCTUO.js.map
@@ -12,7 +12,7 @@ import {
12
12
  resolveContextFilesFrom,
13
13
  writeManagedSecrets,
14
14
  writePreparedStateRaw
15
- } from "./chunk-UJEH2NJT.js";
15
+ } from "./chunk-JRXNVEV3.js";
16
16
 
17
17
  // ../../packages/sandbox-daytona/dist/chunk-HEUB57SZ.js
18
18
  import { existsSync } from "fs";
@@ -989,4 +989,4 @@ export {
989
989
  readDaytonaCredStatus,
990
990
  maskKey
991
991
  };
992
- //# sourceMappingURL=chunk-IDH5A4RR.js.map
992
+ //# sourceMappingURL=chunk-F6NQZ4DC.js.map
@@ -0,0 +1,285 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ BOX_IMAGE_REGISTRY,
4
+ DOCKER_CONTEXT_FILE_MAP,
5
+ claudeInstallFingerprint,
6
+ computeContextSha256,
7
+ readCliStamp,
8
+ readPreparedStateRaw,
9
+ registryRefForSha,
10
+ resolveContextFilesFrom,
11
+ writePreparedStateRaw
12
+ } from "./chunk-JRXNVEV3.js";
13
+
14
+ // ../../packages/sandbox-docker/dist/chunk-6T2XZZB5.js
15
+ import { dirname as dirname2, resolve as resolve2 } from "path";
16
+ import { fileURLToPath as fileURLToPath2 } from "url";
17
+ import { execa } from "execa";
18
+ import { existsSync } from "fs";
19
+ import { fileURLToPath } from "url";
20
+ import { dirname, resolve } from "path";
21
+ var DEFAULT_BOX_IMAGE = "agentbox/box:dev";
22
+ async function resolveClaudeInstallMode() {
23
+ try {
24
+ const { loadEffectiveConfig } = await import("./dist-U2SVLJUQ.js");
25
+ const cfg = await loadEffectiveConfig(process.cwd());
26
+ return cfg.effective.box.claudeInstall;
27
+ } catch {
28
+ return "native";
29
+ }
30
+ }
31
+ var here = dirname(fileURLToPath(import.meta.url));
32
+ function resolveDockerBuild() {
33
+ const override = process.env.AGENTBOX_DOCKER_CONTEXT;
34
+ if (override && existsSync(resolve(override, "Dockerfile.box"))) {
35
+ return { dockerfile: resolve(override, "Dockerfile.box"), context: override };
36
+ }
37
+ const staged = resolve(here, "..", "runtime", "docker");
38
+ if (existsSync(resolve(staged, "Dockerfile.box"))) {
39
+ return { dockerfile: resolve(staged, "Dockerfile.box"), context: staged };
40
+ }
41
+ const packageRoot = resolve(here, "..");
42
+ return {
43
+ dockerfile: resolve(packageRoot, "Dockerfile.box"),
44
+ context: resolve(packageRoot, "..", "..")
45
+ };
46
+ }
47
+ var { dockerfile: DOCKERFILE_PATH_RESOLVED, context: BUILD_CONTEXT_DIR_RESOLVED } = resolveDockerBuild();
48
+ var DOCKERFILE_PATH = DOCKERFILE_PATH_RESOLVED;
49
+ var BUILD_CONTEXT_DIR = BUILD_CONTEXT_DIR_RESOLVED;
50
+ async function imageExists(ref) {
51
+ const result = await execa("docker", ["image", "inspect", ref], { reject: false });
52
+ return result.exitCode === 0;
53
+ }
54
+ async function pullImage(target, opts = {}) {
55
+ const subprocess = execa("docker", ["pull", target], {
56
+ stderr: "pipe",
57
+ stdout: "pipe",
58
+ reject: false
59
+ });
60
+ let heartbeat;
61
+ if (opts.onProgress) {
62
+ let lastLineAt = Date.now();
63
+ const forward = (chunk) => {
64
+ lastLineAt = Date.now();
65
+ const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
66
+ for (const line of text.split(/\r?\n/)) {
67
+ if (line.length > 0) opts.onProgress?.(line);
68
+ }
69
+ };
70
+ subprocess.stdout?.on("data", forward);
71
+ subprocess.stderr?.on("data", forward);
72
+ heartbeat = setInterval(() => {
73
+ if (Date.now() - lastLineAt >= 2e4) {
74
+ opts.onProgress?.(`still extracting ${target} \u2014 large layers can take a few minutes`);
75
+ }
76
+ }, 2e4);
77
+ }
78
+ try {
79
+ const result = await subprocess;
80
+ return result.exitCode === 0;
81
+ } finally {
82
+ if (heartbeat) clearInterval(heartbeat);
83
+ }
84
+ }
85
+ async function tagImage(source, target) {
86
+ await execa("docker", ["tag", source, target]);
87
+ }
88
+ async function imageInfo(ref = DEFAULT_BOX_IMAGE) {
89
+ const result = await execa(
90
+ "docker",
91
+ ["image", "inspect", "--format", "{{.Size}}|{{.Created}}", ref],
92
+ { reject: false }
93
+ );
94
+ if (result.exitCode !== 0) return { ref, exists: false };
95
+ const [sizeStr, createdAt] = result.stdout.trim().split("|");
96
+ const sizeBytes = sizeStr ? Number.parseInt(sizeStr, 10) : NaN;
97
+ return {
98
+ ref,
99
+ exists: true,
100
+ sizeBytes: Number.isFinite(sizeBytes) ? sizeBytes : void 0,
101
+ createdAt: createdAt && createdAt.length > 0 ? createdAt : void 0
102
+ };
103
+ }
104
+ async function buildImage(opts = {}) {
105
+ const ref = opts.ref ?? DEFAULT_BOX_IMAGE;
106
+ const dockerfile = opts.dockerfile ?? DOCKERFILE_PATH;
107
+ const contextDir = opts.contextDir ?? BUILD_CONTEXT_DIR;
108
+ const args = ["build", "-t", ref, "-f", dockerfile];
109
+ for (const [k, v] of Object.entries(opts.buildArgs ?? {})) {
110
+ args.push("--build-arg", `${k}=${v}`);
111
+ }
112
+ args.push(contextDir);
113
+ if (process.env.AGENTBOX === "1") {
114
+ args.splice(1, 0, "--network=host");
115
+ }
116
+ const subprocess = execa("docker", args, {
117
+ stderr: "pipe",
118
+ stdout: "pipe"
119
+ });
120
+ if (opts.onProgress) {
121
+ const forward = (chunk) => {
122
+ const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
123
+ for (const line of text.split(/\r?\n/)) {
124
+ if (line.length > 0) opts.onProgress?.(line);
125
+ }
126
+ };
127
+ subprocess.stdout?.on("data", forward);
128
+ subprocess.stderr?.on("data", forward);
129
+ }
130
+ await subprocess;
131
+ return ref;
132
+ }
133
+ async function pullOrBuild(ref, fingerprint, opts = {}) {
134
+ const { writePreparedDockerState: writePreparedDockerState2 } = await import("./prepared-state-75DIZ55S-B33TDOJZ.js");
135
+ const registry = opts.registry ?? BOX_IMAGE_REGISTRY;
136
+ const allowPull = opts.allowPull !== false;
137
+ if (allowPull && registry && fingerprint) {
138
+ const target = registryRefForSha(fingerprint.contextSha256, registry);
139
+ opts.onProgress?.(`[image] pulling ${target}`);
140
+ if (await pullImage(target, { onProgress: opts.onProgress })) {
141
+ await tagImage(target, ref);
142
+ writePreparedDockerState2({ imageRef: ref, contextSha256: fingerprint.contextSha256 });
143
+ opts.onProgress?.(`[image] pulled ${target} -> ${ref}`);
144
+ return { source: "pulled" };
145
+ }
146
+ opts.onProgress?.(`[image] registry miss, building ${ref} locally`);
147
+ }
148
+ await buildImage({
149
+ ref,
150
+ dockerfile: opts.dockerfile,
151
+ contextDir: opts.contextDir,
152
+ buildArgs: opts.buildArgs,
153
+ onProgress: opts.onProgress
154
+ });
155
+ if (fingerprint) {
156
+ writePreparedDockerState2({ imageRef: ref, contextSha256: fingerprint.contextSha256 });
157
+ }
158
+ return { source: "built" };
159
+ }
160
+ async function ensureImage(ref = DEFAULT_BOX_IMAGE, opts = {}) {
161
+ const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2, preparedMatches: preparedMatches2 } = await import("./prepared-state-75DIZ55S-B33TDOJZ.js");
162
+ const claudeInstall = opts.claudeInstall ?? await resolveClaudeInstallMode();
163
+ const rawFingerprint = await computeDockerContextFingerprint2({
164
+ contextDir: opts.contextDir
165
+ });
166
+ const fingerprint = rawFingerprint ? {
167
+ ...rawFingerprint,
168
+ contextSha256: claudeInstallFingerprint(rawFingerprint.contextSha256, claudeInstall)
169
+ } : null;
170
+ const prepared = readPreparedDockerState2();
171
+ const exists = await imageExists(ref);
172
+ let reason;
173
+ if (!exists) {
174
+ reason = `image ${ref} not present`;
175
+ } else if (!fingerprint) {
176
+ return { ref, built: false, reason: "image present (fingerprint skipped)" };
177
+ } else if (!prepared) {
178
+ reason = "no docker-prepared.json on disk";
179
+ } else if (!preparedMatches2(prepared, fingerprint.contextSha256)) {
180
+ reason = `build context changed (was ${prepared.base?.contextSha256?.slice(0, 12) ?? "<none>"}, now ${fingerprint.contextSha256.slice(0, 12)})`;
181
+ }
182
+ if (!reason) {
183
+ return { ref, built: false, reason: "image up to date" };
184
+ }
185
+ opts.onProgress?.(`[image] ${ref}: ${reason}`);
186
+ const npm = claudeInstall === "npm";
187
+ const { source } = await pullOrBuild(ref, fingerprint, {
188
+ onProgress: opts.onProgress,
189
+ dockerfile: opts.dockerfile,
190
+ contextDir: opts.contextDir,
191
+ // npm mode pulls too. CI publishes both install variants, and `fingerprint`
192
+ // is already folded with the mode above — so the pull asks for the npm
193
+ // image's own tag and hits. (It used to be native-only, which meant npm
194
+ // users rebuilt the image locally on every first create, forever.) A tag
195
+ // that genuinely isn't published still falls back to a local build.
196
+ allowPull: opts.allowPull,
197
+ registry: opts.registry,
198
+ buildArgs: npm ? { AGENTBOX_CLAUDE_INSTALL: "npm" } : void 0
199
+ });
200
+ return { ref, built: source === "built", reason };
201
+ }
202
+ function classifyDockerBaseFreshness(input) {
203
+ if (!input.imagePresent) return { state: "unprepared" };
204
+ if (!input.fingerprint) return { state: "unknown" };
205
+ if (!input.stampedSha) return { state: "stale", reason: "no docker-prepared.json on disk" };
206
+ if (input.stampedSha !== input.fingerprint) {
207
+ return {
208
+ state: "stale",
209
+ reason: `build context changed (was ${input.stampedSha.slice(0, 12)}, now ${input.fingerprint.slice(0, 12)})`
210
+ };
211
+ }
212
+ return { state: "fresh" };
213
+ }
214
+ async function evaluateDockerBaseFreshness(opts = {}) {
215
+ const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2 } = await import("./prepared-state-75DIZ55S-B33TDOJZ.js");
216
+ const ref = opts.ref ?? DEFAULT_BOX_IMAGE;
217
+ const imagePresent = await imageExists(ref);
218
+ if (!imagePresent) return { state: "unprepared" };
219
+ const claudeInstall = opts.claudeInstall ?? await resolveClaudeInstallMode();
220
+ const raw = await computeDockerContextFingerprint2({ contextDir: opts.contextDir });
221
+ return classifyDockerBaseFreshness({
222
+ imagePresent,
223
+ fingerprint: raw ? claudeInstallFingerprint(raw.contextSha256, claudeInstall) : null,
224
+ stampedSha: readPreparedDockerState2()?.base?.contextSha256 ?? null
225
+ });
226
+ }
227
+ var SCHEMA = 1;
228
+ function resolveContextFiles(opts = {}) {
229
+ const ctx = opts.contextDir ?? BUILD_CONTEXT_DIR;
230
+ const here2 = dirname2(fileURLToPath2(import.meta.url));
231
+ const packageRoot = resolve2(here2, "..");
232
+ return resolveContextFilesFrom(DOCKER_CONTEXT_FILE_MAP, {
233
+ contextDir: ctx,
234
+ devRoot: packageRoot
235
+ });
236
+ }
237
+ async function computeDockerContextFingerprint(opts = {}) {
238
+ const files = resolveContextFiles(opts);
239
+ if (!files) return null;
240
+ return { contextSha256: await computeContextSha256(files), files };
241
+ }
242
+ function readPreparedDockerState() {
243
+ const raw = readPreparedStateRaw("docker");
244
+ if (raw === null || typeof raw !== "object") return null;
245
+ const parsed = raw;
246
+ if (parsed.schema !== SCHEMA) return null;
247
+ return { schema: SCHEMA, base: parsed.base };
248
+ }
249
+ function writePreparedDockerState(opts) {
250
+ const stamp = readCliStamp();
251
+ const state = {
252
+ schema: SCHEMA,
253
+ base: {
254
+ imageRef: opts.imageRef ?? DEFAULT_BOX_IMAGE,
255
+ contextSha256: opts.contextSha256,
256
+ cliVersion: stamp.cliVersion,
257
+ cliCommit: stamp.cliCommit,
258
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
259
+ }
260
+ };
261
+ writePreparedStateRaw("docker", state);
262
+ }
263
+ function preparedMatches(state, current) {
264
+ return state?.base?.contextSha256 === current;
265
+ }
266
+
267
+ export {
268
+ DEFAULT_BOX_IMAGE,
269
+ DOCKERFILE_PATH,
270
+ BUILD_CONTEXT_DIR,
271
+ imageExists,
272
+ pullImage,
273
+ tagImage,
274
+ imageInfo,
275
+ pullOrBuild,
276
+ ensureImage,
277
+ classifyDockerBaseFreshness,
278
+ evaluateDockerBaseFreshness,
279
+ resolveContextFiles,
280
+ computeDockerContextFingerprint,
281
+ readPreparedDockerState,
282
+ writePreparedDockerState,
283
+ preparedMatches
284
+ };
285
+ //# sourceMappingURL=chunk-IMN62QY5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../packages/sandbox-docker/src/prepared-state.ts","../../../packages/sandbox-docker/src/image.ts"],"sourcesContent":["/**\n * Docker provider's `~/.agentbox/docker-prepared.json` reader/writer + the\n * build-context fingerprint that drives base-image invalidation.\n *\n * The fingerprint is a SHA-256 over every file `docker build` would COPY\n * into the image — Dockerfile + scripts + baked config files. Two CLIs\n * with identical staged runtime trees produce the same hash; a one-byte\n * edit to any baked asset flips it, which is the signal `ensureImage()`\n * uses to rebuild instead of reusing the cached image.\n */\n\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n computeContextSha256,\n DOCKER_CONTEXT_FILE_MAP,\n readCliStamp,\n readPreparedStateRaw,\n resolveContextFilesFrom,\n writePreparedStateRaw,\n type ContextFile,\n type PreparedBaseSnapshot,\n} from '@agentbox/sandbox-core';\nimport { BUILD_CONTEXT_DIR, DEFAULT_BOX_IMAGE, DOCKERFILE_PATH } from './image.js';\n\nconst SCHEMA = 1 as const;\n\nexport type PreparedDockerState = PreparedBaseSnapshot<string, never>;\n\n/**\n * Resolve every fingerprint input to an absolute path. The canonical file\n * list lives in `@agentbox/sandbox-core` (DOCKER_CONTEXT_FILE_MAP) so the\n * daytona provider can hash the same inputs without depending on this\n * package. Two layouts are tried in order, mirroring `resolveDockerBuild()`\n * in `image.ts`:\n * 1. Build context dir (staged runtime / env override).\n * 2. Sandbox-docker package root (dev fallback).\n *\n * Returns `null` when *any* required file is missing — callers treat that\n * as \"can't fingerprint\" and skip the cache-hit shortcut (always rebuild).\n */\nexport function resolveContextFiles(opts: { contextDir?: string } = {}): ContextFile[] | null {\n const ctx = opts.contextDir ?? BUILD_CONTEXT_DIR;\n const here = dirname(fileURLToPath(import.meta.url));\n // sandbox-docker's package root = parent of src/ or parent of dist/.\n const packageRoot = resolve(here, '..');\n return resolveContextFilesFrom(DOCKER_CONTEXT_FILE_MAP, {\n contextDir: ctx,\n devRoot: packageRoot,\n });\n}\n\nexport interface ResolvedFingerprint {\n contextSha256: string;\n /** Files that fed the hash (in canonical sorted order). */\n files: ContextFile[];\n}\n\nexport async function computeDockerContextFingerprint(opts: {\n contextDir?: string;\n} = {}): Promise<ResolvedFingerprint | null> {\n const files = resolveContextFiles(opts);\n if (!files) return null;\n return { contextSha256: await computeContextSha256(files), files };\n}\n\nexport function readPreparedDockerState(): PreparedDockerState | null {\n const raw = readPreparedStateRaw('docker');\n if (raw === null || typeof raw !== 'object') return null;\n const parsed = raw as Partial<PreparedDockerState>;\n if (parsed.schema !== SCHEMA) return null;\n return { schema: SCHEMA, base: parsed.base };\n}\n\nexport function writePreparedDockerState(opts: {\n imageRef?: string;\n contextSha256: string;\n}): void {\n const stamp = readCliStamp();\n const state: PreparedDockerState = {\n schema: SCHEMA,\n base: {\n imageRef: opts.imageRef ?? DEFAULT_BOX_IMAGE,\n contextSha256: opts.contextSha256,\n cliVersion: stamp.cliVersion,\n cliCommit: stamp.cliCommit,\n createdAt: new Date().toISOString(),\n },\n };\n writePreparedStateRaw('docker', state);\n}\n\n/** Convenience for `ensureImage` and `prepare` — true when the stamped fingerprint matches. */\nexport function preparedMatches(state: PreparedDockerState | null, current: string): boolean {\n return state?.base?.contextSha256 === current;\n}\n\n/** Re-export so callers don't reach into image.ts just for the Dockerfile path. */\nexport { DOCKERFILE_PATH };\n","import { execa } from 'execa';\nimport { existsSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { dirname, resolve } from 'node:path';\nimport {\n BOX_IMAGE_REGISTRY,\n claudeInstallFingerprint,\n registryRefForSha,\n} from '@agentbox/sandbox-core';\n\nexport const DEFAULT_BOX_IMAGE = 'agentbox/box:dev';\n\n/**\n * Resolve the effective `box.claudeInstall` for the current project. Docker\n * builds its image lazily at create time, so every `ensureImage` path must\n * agree on the mode or a native rebuild would clobber an npm-baked image (and\n * vice-versa). Lazy-imported to keep the module load cheap; falls back to\n * `native` if config can't be read.\n */\nasync function resolveClaudeInstallMode(): Promise<'native' | 'npm'> {\n try {\n const { loadEffectiveConfig } = await import('@agentbox/config');\n const cfg = await loadEffectiveConfig(process.cwd());\n return cfg.effective.box.claudeInstall;\n } catch {\n return 'native';\n }\n}\n\n// The registry ref lives in @agentbox/sandbox-core: daytona's linux-vm bake\n// needs it too (a VM snapshot can only be built from a prebuilt registry image),\n// and importing it from here would drag execa into that import graph. Re-exported\n// so existing `@agentbox/sandbox-docker` consumers keep working.\nexport { BOX_IMAGE_REGISTRY, registryRefForSha };\n\nconst here = dirname(fileURLToPath(import.meta.url));\n\n// The Dockerfile's COPY lines reference monorepo-relative paths\n// (packages/ctl/dist/bin.cjs, apps/cli/share/..., packages/sandbox-docker/scripts/*),\n// so the build context must be a dir containing that tree.\n//\n// Resolution order:\n// 0. AGENTBOX_DOCKER_CONTEXT env override (dir holding Dockerfile.box).\n// 1. Staged context shipped with the bundled `agent-box` package: this\n// module is bundled into the CLI at <root>/dist, the stage step mirrors\n// the COPY tree at <root>/runtime/docker (sibling of dist/, uniform in\n// dev and when installed).\n// 2. Legacy monorepo: Dockerfile.box at the sandbox-docker package root,\n// build context = monorepo root.\nfunction resolveDockerBuild(): { dockerfile: string; context: string } {\n const override = process.env.AGENTBOX_DOCKER_CONTEXT;\n if (override && existsSync(resolve(override, 'Dockerfile.box'))) {\n return { dockerfile: resolve(override, 'Dockerfile.box'), context: override };\n }\n const staged = resolve(here, '..', 'runtime', 'docker');\n if (existsSync(resolve(staged, 'Dockerfile.box'))) {\n return { dockerfile: resolve(staged, 'Dockerfile.box'), context: staged };\n }\n // Legacy: src/ (or the unbundled package dist/) is one level under the\n // package root; the monorepo root is two more up.\n const packageRoot = resolve(here, '..');\n return {\n dockerfile: resolve(packageRoot, 'Dockerfile.box'),\n context: resolve(packageRoot, '..', '..'),\n };\n}\n\nconst { dockerfile: DOCKERFILE_PATH_RESOLVED, context: BUILD_CONTEXT_DIR_RESOLVED } =\n resolveDockerBuild();\nexport const DOCKERFILE_PATH = DOCKERFILE_PATH_RESOLVED;\nexport const BUILD_CONTEXT_DIR = BUILD_CONTEXT_DIR_RESOLVED;\n\nexport async function imageExists(ref: string): Promise<boolean> {\n const result = await execa('docker', ['image', 'inspect', ref], { reject: false });\n return result.exitCode === 0;\n}\n\n/**\n * Attempt `docker pull <target>`. Returns true on success, false on any\n * failure (missing tag, offline, auth) — callers fall back to a local build.\n * Never throws. Single attempt: a missing tag is the expected \"build locally\"\n * signal, not a transient error worth retrying.\n */\nexport async function pullImage(\n target: string,\n opts: { onProgress?: (line: string) => void } = {},\n): Promise<boolean> {\n const subprocess = execa('docker', ['pull', target], {\n stderr: 'pipe',\n stdout: 'pipe',\n reject: false,\n });\n let heartbeat: NodeJS.Timeout | undefined;\n if (opts.onProgress) {\n let lastLineAt = Date.now();\n const forward = (chunk: Buffer | string): void => {\n lastLineAt = Date.now();\n const text = typeof chunk === 'string' ? chunk : chunk.toString('utf8');\n for (const line of text.split(/\\r?\\n/)) {\n if (line.length > 0) opts.onProgress?.(line);\n }\n };\n subprocess.stdout?.on('data', forward);\n subprocess.stderr?.on('data', forward);\n // Piped (non-TTY) `docker pull` prints nothing between the last\n // \"Download complete\" and each \"Pull complete\" — the entire extraction\n // phase is silent, which for a multi-GB image reads as a hang. Emit a\n // keepalive so the create spinner keeps moving.\n heartbeat = setInterval(() => {\n if (Date.now() - lastLineAt >= 20_000) {\n opts.onProgress?.(`still extracting ${target} — large layers can take a few minutes`);\n }\n }, 20_000);\n }\n try {\n const result = await subprocess;\n return result.exitCode === 0;\n } finally {\n if (heartbeat) clearInterval(heartbeat);\n }\n}\n\nexport async function tagImage(source: string, target: string): Promise<void> {\n await execa('docker', ['tag', source, target]);\n}\n\nexport interface ImageInfo {\n /** Image ref (e.g. `agentbox/box:dev`). */\n ref: string;\n /** True when the engine has the image locally. */\n exists: boolean;\n /** Image size in bytes, when known. */\n sizeBytes?: number;\n /** ISO-8601 creation time, when known. */\n createdAt?: string;\n}\n\n/**\n * Read-only inspect of a Docker image. Used by `agentbox prepare` (no-args\n * status mode) to surface base-image state. Never throws — returns\n * `{ exists: false }` on any error so the status command works even when\n * the docker daemon is unreachable.\n */\nexport async function imageInfo(ref: string = DEFAULT_BOX_IMAGE): Promise<ImageInfo> {\n const result = await execa(\n 'docker',\n ['image', 'inspect', '--format', '{{.Size}}|{{.Created}}', ref],\n { reject: false },\n );\n if (result.exitCode !== 0) return { ref, exists: false };\n const [sizeStr, createdAt] = result.stdout.trim().split('|');\n const sizeBytes = sizeStr ? Number.parseInt(sizeStr, 10) : NaN;\n return {\n ref,\n exists: true,\n sizeBytes: Number.isFinite(sizeBytes) ? sizeBytes : undefined,\n createdAt: createdAt && createdAt.length > 0 ? createdAt : undefined,\n };\n}\n\nexport interface BuildImageOptions {\n ref?: string;\n dockerfile?: string;\n contextDir?: string;\n /** `--build-arg K=V` pairs forwarded to `docker build` (e.g. AGENTBOX_CLAUDE_INSTALL). */\n buildArgs?: Record<string, string>;\n onProgress?: (line: string) => void;\n}\n\nexport async function buildImage(opts: BuildImageOptions = {}): Promise<string> {\n const ref = opts.ref ?? DEFAULT_BOX_IMAGE;\n const dockerfile = opts.dockerfile ?? DOCKERFILE_PATH;\n const contextDir = opts.contextDir ?? BUILD_CONTEXT_DIR;\n\n // Dogfood path: when building from inside an agentbox (docker-in-docker),\n // the default bridge network can't bind-mount /proc/<pid>/ns/net for the\n // build container, breaking any RUN that needs network (e.g. apt, curl).\n // Falling back to host networking sidesteps the missing capability.\n const args = ['build', '-t', ref, '-f', dockerfile];\n for (const [k, v] of Object.entries(opts.buildArgs ?? {})) {\n args.push('--build-arg', `${k}=${v}`);\n }\n args.push(contextDir);\n if (process.env.AGENTBOX === '1') {\n args.splice(1, 0, '--network=host');\n }\n\n const subprocess = execa('docker', args, {\n stderr: 'pipe',\n stdout: 'pipe',\n });\n\n if (opts.onProgress) {\n const forward = (chunk: Buffer | string): void => {\n const text = typeof chunk === 'string' ? chunk : chunk.toString('utf8');\n for (const line of text.split(/\\r?\\n/)) {\n if (line.length > 0) opts.onProgress?.(line);\n }\n };\n subprocess.stdout?.on('data', forward);\n subprocess.stderr?.on('data', forward);\n }\n\n await subprocess;\n return ref;\n}\n\nexport interface PullOrBuildOptions {\n onProgress?: (line: string) => void;\n /** Dockerfile path. Defaults to `Dockerfile.box` next to this package. */\n dockerfile?: string;\n /** Build context directory. Defaults to the staged runtime / monorepo root. */\n contextDir?: string;\n /** Try the registry before building. Defaults to true. */\n allowPull?: boolean;\n /** Registry repo to pull from. Defaults to `BOX_IMAGE_REGISTRY`; empty disables pulling. */\n registry?: string;\n /** `--build-arg K=V` pairs forwarded to the local `docker build` (ignored on a registry pull). */\n buildArgs?: Record<string, string>;\n}\n\n/**\n * Make `ref` present locally, preferring a registry pull over a local build.\n *\n * When `fingerprint` is non-null and pulling is allowed, pull the\n * fingerprint-tagged image and retag it to `ref`; on a miss (or when pulling\n * is disabled / unfingerprintable) build from the staged context. Either way,\n * a known fingerprint is stamped into docker-prepared.json so the next\n * `ensureImage()` treats this as a cache hit.\n */\nexport async function pullOrBuild(\n ref: string,\n fingerprint: { contextSha256: string } | null,\n opts: PullOrBuildOptions = {},\n): Promise<{ source: 'pulled' | 'built' }> {\n const { writePreparedDockerState } = await import('./prepared-state.js');\n const registry = opts.registry ?? BOX_IMAGE_REGISTRY;\n const allowPull = opts.allowPull !== false;\n\n if (allowPull && registry && fingerprint) {\n const target = registryRefForSha(fingerprint.contextSha256, registry);\n opts.onProgress?.(`[image] pulling ${target}`);\n if (await pullImage(target, { onProgress: opts.onProgress })) {\n await tagImage(target, ref);\n writePreparedDockerState({ imageRef: ref, contextSha256: fingerprint.contextSha256 });\n opts.onProgress?.(`[image] pulled ${target} -> ${ref}`);\n return { source: 'pulled' };\n }\n opts.onProgress?.(`[image] registry miss, building ${ref} locally`);\n }\n\n await buildImage({\n ref,\n dockerfile: opts.dockerfile,\n contextDir: opts.contextDir,\n buildArgs: opts.buildArgs,\n onProgress: opts.onProgress,\n });\n if (fingerprint) {\n writePreparedDockerState({ imageRef: ref, contextSha256: fingerprint.contextSha256 });\n }\n return { source: 'built' };\n}\n\nexport interface EnsureImageOptions {\n onProgress?: (line: string) => void;\n /** Dockerfile path. Defaults to `Dockerfile.box` next to this package. */\n dockerfile?: string;\n /** Build context directory. Defaults to the monorepo root. */\n contextDir?: string;\n /** Try the registry before building. Defaults to true. */\n allowPull?: boolean;\n /** Registry repo to pull from. Defaults to `BOX_IMAGE_REGISTRY`; empty disables pulling. */\n registry?: string;\n /**\n * How Claude Code is installed into the image. Folded into the build-context\n * fingerprint so a mode switch rebuilds (and an npm image isn't clobbered by\n * a native rebuild). Defaults to the resolved `box.claudeInstall`.\n */\n claudeInstall?: 'native' | 'npm';\n}\n\nexport async function ensureImage(\n ref: string = DEFAULT_BOX_IMAGE,\n opts: EnsureImageOptions = {},\n): Promise<{ ref: string; built: boolean; reason?: string }> {\n // Lazy import: prepared-state imports back into image.ts for the default\n // DOCKERFILE_PATH/BUILD_CONTEXT_DIR constants, so loading it at top-level\n // would create a circular ESM init order.\n const { computeDockerContextFingerprint, readPreparedDockerState, preparedMatches } =\n await import('./prepared-state.js');\n\n const claudeInstall = opts.claudeInstall ?? (await resolveClaudeInstallMode());\n const rawFingerprint = await computeDockerContextFingerprint({\n contextDir: opts.contextDir,\n });\n // Fold the install mode into the sha so native↔npm are distinct cache\n // identities (`native` leaves the hash unchanged).\n const fingerprint = rawFingerprint\n ? {\n ...rawFingerprint,\n contextSha256: claudeInstallFingerprint(rawFingerprint.contextSha256, claudeInstall),\n }\n : null;\n const prepared = readPreparedDockerState();\n const exists = await imageExists(ref);\n\n let reason: string | undefined;\n if (!exists) {\n reason = `image ${ref} not present`;\n } else if (!fingerprint) {\n // Couldn't enumerate the context (partial dev rebuild?). Don't rebuild\n // unconditionally — that would surprise users mid-iteration. Trust the\n // image-exists check and leave the prepared file untouched.\n return { ref, built: false, reason: 'image present (fingerprint skipped)' };\n } else if (!prepared) {\n reason = 'no docker-prepared.json on disk';\n } else if (!preparedMatches(prepared, fingerprint.contextSha256)) {\n reason =\n `build context changed (was ${prepared.base?.contextSha256?.slice(0, 12) ?? '<none>'}, ` +\n `now ${fingerprint.contextSha256.slice(0, 12)})`;\n }\n\n if (!reason) {\n return { ref, built: false, reason: 'image up to date' };\n }\n\n opts.onProgress?.(`[image] ${ref}: ${reason}`);\n const npm = claudeInstall === 'npm';\n const { source } = await pullOrBuild(ref, fingerprint, {\n onProgress: opts.onProgress,\n dockerfile: opts.dockerfile,\n contextDir: opts.contextDir,\n // npm mode pulls too. CI publishes both install variants, and `fingerprint`\n // is already folded with the mode above — so the pull asks for the npm\n // image's own tag and hits. (It used to be native-only, which meant npm\n // users rebuilt the image locally on every first create, forever.) A tag\n // that genuinely isn't published still falls back to a local build.\n allowPull: opts.allowPull,\n registry: opts.registry,\n buildArgs: npm ? { AGENTBOX_CLAUDE_INSTALL: 'npm' } : undefined,\n });\n return { ref, built: source === 'built', reason };\n}\n\n/**\n * Read-only freshness classification of the docker base image, for surfaces\n * (hub API, tray) that want to announce an upcoming bake without triggering\n * it. `unknown` means \"couldn't fingerprint\" and MUST stay inert — the\n * matching `ensureImage` path trusts the existing image and does not rebuild.\n */\nexport type DockerBaseFreshness =\n | { state: 'fresh' }\n | { state: 'unknown' }\n | { state: 'unprepared' }\n | { state: 'stale'; reason: string };\n\n/**\n * Pure decision core shared by `evaluateDockerBaseFreshness`. Mirrors\n * `ensureImage`'s rebuild predicate exactly — if the two ever disagree, the\n * freshness surfaces would announce a bake that create then skips (or miss\n * one it performs). `stampedSha` is `docker-prepared.json`'s fingerprint,\n * null when the stamp is missing/invalid.\n */\nexport function classifyDockerBaseFreshness(input: {\n imagePresent: boolean;\n fingerprint: string | null;\n stampedSha: string | null;\n}): DockerBaseFreshness {\n if (!input.imagePresent) return { state: 'unprepared' };\n if (!input.fingerprint) return { state: 'unknown' };\n if (!input.stampedSha) return { state: 'stale', reason: 'no docker-prepared.json on disk' };\n if (input.stampedSha !== input.fingerprint) {\n return {\n state: 'stale',\n reason:\n `build context changed (was ${input.stampedSha.slice(0, 12)}, ` +\n `now ${input.fingerprint.slice(0, 12)})`,\n };\n }\n return { state: 'fresh' };\n}\n\n/**\n * Cheap live check: would `ensureImage` bake on the next create? The only\n * docker work is one `docker image inspect`; the rest hashes the ~15 build\n * context files. Never builds, pulls, or writes the prepared stamp.\n */\nexport async function evaluateDockerBaseFreshness(\n opts: { ref?: string; claudeInstall?: 'native' | 'npm'; contextDir?: string } = {},\n): Promise<DockerBaseFreshness> {\n // Lazy import for the same circular-init reason as in ensureImage above.\n const { computeDockerContextFingerprint, readPreparedDockerState } =\n await import('./prepared-state.js');\n const ref = opts.ref ?? DEFAULT_BOX_IMAGE;\n const imagePresent = await imageExists(ref);\n if (!imagePresent) return { state: 'unprepared' };\n const claudeInstall = opts.claudeInstall ?? (await resolveClaudeInstallMode());\n const raw = await computeDockerContextFingerprint({ contextDir: opts.contextDir });\n return classifyDockerBaseFreshness({\n imagePresent,\n fingerprint: raw ? claudeInstallFingerprint(raw.contextSha256, claudeInstall) : null,\n stampedSha: readPreparedDockerState()?.base?.contextSha256 ?? null,\n });\n}\n\n"],"mappings":";;;;;;;;;;;;;;AAWA,SAAS,WAAAA,UAAS,WAAAC,gBAAe;AACjC,SAAS,iBAAAC,sBAAqB;ACZ9B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,eAAe;AAO1B,IAAM,oBAAoB;AASjC,eAAe,2BAAsD;AACnE,MAAI;AACF,UAAM,EAAE,oBAAoB,IAAI,MAAM,OAAO,oBAAkB;AAC/D,UAAM,MAAM,MAAM,oBAAoB,QAAQ,IAAI,CAAC;A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AC,GAAwC;AAC3C,QAAM,QAAQ,oBAAoB,IAAI;AACtC,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,EAAE,eAAe,MAAM,qBAAqB,KAAK,GAAG,MAAM;AACnE;AAEO,SAAS,0BAAsD;AACpE,QAAM,MAAM,qBAAqB,QAAQ;AACzC,MAAI,QAAQ,QAAQ,OAAO,QAAQ,SAAU,QAAO;AACpD,QAAM,SAAS;AACf,MAAI,OAAO,WAAW,OAAQ,QAAO;AACrC,SAAO,EAAE,QAAQ,QAAQ,MAAM,OAAO,KAAK;AAC7C;AAEO,SAAS,yBAAyB,MAGhC;AACP,QAAM,QAAQ,aAAa;AAC3B,QAAM,QAA6B;IACjC,QAAQ;IACR,MAAM;MACJ,UAAU,KAAK,YAAY;MAC3B,eAAe,KAAK;MACpB,YAAY,MAAM;MAClB,WAAW,MAAM;MACjB,YAAW,oBAAI,KAAK,GAAE,YAAY;IACpC;EACF;AACA,wBAAsB,UAAU,KAAK;AACvC;AAGO,SAAS,gBAAgB,OAAmC,SAA0B;AAC3F,SAAO,OAAO,MAAM,kBAAkB;AACxC;","names":["dirname","resolve","fileURLToPath","writePreparedDockerState","computeDockerContextFingerprint","readPreparedDockerState","preparedMatches","here","dirname","fileURLToPath","resolve"]}
@@ -8,7 +8,7 @@ import {
8
8
  readPreparedStateRaw,
9
9
  writeManagedSecrets,
10
10
  writePreparedStateRaw
11
- } from "./chunk-UJEH2NJT.js";
11
+ } from "./chunk-JRXNVEV3.js";
12
12
 
13
13
  // ../../packages/sandbox-e2b/dist/chunk-WQRH5SXA.js
14
14
  import { existsSync, readFileSync } from "fs";
@@ -324,4 +324,4 @@ export {
324
324
  currentE2bBaseFingerprintLive,
325
325
  ensureE2bBaseTemplate
326
326
  };
327
- //# sourceMappingURL=chunk-V5XXJH63.js.map
327
+ //# sourceMappingURL=chunk-JNFUWQ4N.js.map
@@ -3610,259 +3610,6 @@ function registryRefForSha(sha, registry = BOX_IMAGE_REGISTRY) {
3610
3610
  return `${registry}:sha-${sha.slice(0, 16)}`;
3611
3611
  }
3612
3612
 
3613
- // ../../packages/sandbox-docker/dist/chunk-6T2XZZB5.js
3614
- import { dirname as dirname23, resolve as resolve23 } from "path";
3615
- import { fileURLToPath as fileURLToPath2 } from "url";
3616
- import { execa as execa9 } from "execa";
3617
- import { existsSync as existsSync6 } from "fs";
3618
- import { fileURLToPath } from "url";
3619
- import { dirname as dirname11, resolve as resolve4 } from "path";
3620
- var DEFAULT_BOX_IMAGE = "agentbox/box:dev";
3621
- async function resolveClaudeInstallMode() {
3622
- try {
3623
- const { loadEffectiveConfig } = await import("./dist-U2SVLJUQ.js");
3624
- const cfg = await loadEffectiveConfig(process.cwd());
3625
- return cfg.effective.box.claudeInstall;
3626
- } catch {
3627
- return "native";
3628
- }
3629
- }
3630
- var here = dirname11(fileURLToPath(import.meta.url));
3631
- function resolveDockerBuild() {
3632
- const override = process.env.AGENTBOX_DOCKER_CONTEXT;
3633
- if (override && existsSync6(resolve4(override, "Dockerfile.box"))) {
3634
- return { dockerfile: resolve4(override, "Dockerfile.box"), context: override };
3635
- }
3636
- const staged = resolve4(here, "..", "runtime", "docker");
3637
- if (existsSync6(resolve4(staged, "Dockerfile.box"))) {
3638
- return { dockerfile: resolve4(staged, "Dockerfile.box"), context: staged };
3639
- }
3640
- const packageRoot = resolve4(here, "..");
3641
- return {
3642
- dockerfile: resolve4(packageRoot, "Dockerfile.box"),
3643
- context: resolve4(packageRoot, "..", "..")
3644
- };
3645
- }
3646
- var { dockerfile: DOCKERFILE_PATH_RESOLVED, context: BUILD_CONTEXT_DIR_RESOLVED } = resolveDockerBuild();
3647
- var DOCKERFILE_PATH = DOCKERFILE_PATH_RESOLVED;
3648
- var BUILD_CONTEXT_DIR = BUILD_CONTEXT_DIR_RESOLVED;
3649
- async function imageExists(ref) {
3650
- const result = await execa9("docker", ["image", "inspect", ref], { reject: false });
3651
- return result.exitCode === 0;
3652
- }
3653
- async function pullImage(target, opts = {}) {
3654
- const subprocess = execa9("docker", ["pull", target], {
3655
- stderr: "pipe",
3656
- stdout: "pipe",
3657
- reject: false
3658
- });
3659
- let heartbeat;
3660
- if (opts.onProgress) {
3661
- let lastLineAt = Date.now();
3662
- const forward = (chunk) => {
3663
- lastLineAt = Date.now();
3664
- const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
3665
- for (const line of text.split(/\r?\n/)) {
3666
- if (line.length > 0) opts.onProgress?.(line);
3667
- }
3668
- };
3669
- subprocess.stdout?.on("data", forward);
3670
- subprocess.stderr?.on("data", forward);
3671
- heartbeat = setInterval(() => {
3672
- if (Date.now() - lastLineAt >= 2e4) {
3673
- opts.onProgress?.(`still extracting ${target} \u2014 large layers can take a few minutes`);
3674
- }
3675
- }, 2e4);
3676
- }
3677
- try {
3678
- const result = await subprocess;
3679
- return result.exitCode === 0;
3680
- } finally {
3681
- if (heartbeat) clearInterval(heartbeat);
3682
- }
3683
- }
3684
- async function tagImage(source, target) {
3685
- await execa9("docker", ["tag", source, target]);
3686
- }
3687
- async function imageInfo(ref = DEFAULT_BOX_IMAGE) {
3688
- const result = await execa9(
3689
- "docker",
3690
- ["image", "inspect", "--format", "{{.Size}}|{{.Created}}", ref],
3691
- { reject: false }
3692
- );
3693
- if (result.exitCode !== 0) return { ref, exists: false };
3694
- const [sizeStr, createdAt] = result.stdout.trim().split("|");
3695
- const sizeBytes = sizeStr ? Number.parseInt(sizeStr, 10) : NaN;
3696
- return {
3697
- ref,
3698
- exists: true,
3699
- sizeBytes: Number.isFinite(sizeBytes) ? sizeBytes : void 0,
3700
- createdAt: createdAt && createdAt.length > 0 ? createdAt : void 0
3701
- };
3702
- }
3703
- async function buildImage(opts = {}) {
3704
- const ref = opts.ref ?? DEFAULT_BOX_IMAGE;
3705
- const dockerfile = opts.dockerfile ?? DOCKERFILE_PATH;
3706
- const contextDir = opts.contextDir ?? BUILD_CONTEXT_DIR;
3707
- const args = ["build", "-t", ref, "-f", dockerfile];
3708
- for (const [k, v] of Object.entries(opts.buildArgs ?? {})) {
3709
- args.push("--build-arg", `${k}=${v}`);
3710
- }
3711
- args.push(contextDir);
3712
- if (process.env.AGENTBOX === "1") {
3713
- args.splice(1, 0, "--network=host");
3714
- }
3715
- const subprocess = execa9("docker", args, {
3716
- stderr: "pipe",
3717
- stdout: "pipe"
3718
- });
3719
- if (opts.onProgress) {
3720
- const forward = (chunk) => {
3721
- const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
3722
- for (const line of text.split(/\r?\n/)) {
3723
- if (line.length > 0) opts.onProgress?.(line);
3724
- }
3725
- };
3726
- subprocess.stdout?.on("data", forward);
3727
- subprocess.stderr?.on("data", forward);
3728
- }
3729
- await subprocess;
3730
- return ref;
3731
- }
3732
- async function pullOrBuild(ref, fingerprint, opts = {}) {
3733
- const { writePreparedDockerState: writePreparedDockerState2 } = await import("./prepared-state-75DIZ55S-TNJXWMXV.js");
3734
- const registry = opts.registry ?? BOX_IMAGE_REGISTRY;
3735
- const allowPull = opts.allowPull !== false;
3736
- if (allowPull && registry && fingerprint) {
3737
- const target = registryRefForSha(fingerprint.contextSha256, registry);
3738
- opts.onProgress?.(`[image] pulling ${target}`);
3739
- if (await pullImage(target, { onProgress: opts.onProgress })) {
3740
- await tagImage(target, ref);
3741
- writePreparedDockerState2({ imageRef: ref, contextSha256: fingerprint.contextSha256 });
3742
- opts.onProgress?.(`[image] pulled ${target} -> ${ref}`);
3743
- return { source: "pulled" };
3744
- }
3745
- opts.onProgress?.(`[image] registry miss, building ${ref} locally`);
3746
- }
3747
- await buildImage({
3748
- ref,
3749
- dockerfile: opts.dockerfile,
3750
- contextDir: opts.contextDir,
3751
- buildArgs: opts.buildArgs,
3752
- onProgress: opts.onProgress
3753
- });
3754
- if (fingerprint) {
3755
- writePreparedDockerState2({ imageRef: ref, contextSha256: fingerprint.contextSha256 });
3756
- }
3757
- return { source: "built" };
3758
- }
3759
- async function ensureImage(ref = DEFAULT_BOX_IMAGE, opts = {}) {
3760
- const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2, preparedMatches: preparedMatches2 } = await import("./prepared-state-75DIZ55S-TNJXWMXV.js");
3761
- const claudeInstall = opts.claudeInstall ?? await resolveClaudeInstallMode();
3762
- const rawFingerprint = await computeDockerContextFingerprint2({
3763
- contextDir: opts.contextDir
3764
- });
3765
- const fingerprint = rawFingerprint ? {
3766
- ...rawFingerprint,
3767
- contextSha256: claudeInstallFingerprint(rawFingerprint.contextSha256, claudeInstall)
3768
- } : null;
3769
- const prepared = readPreparedDockerState2();
3770
- const exists = await imageExists(ref);
3771
- let reason;
3772
- if (!exists) {
3773
- reason = `image ${ref} not present`;
3774
- } else if (!fingerprint) {
3775
- return { ref, built: false, reason: "image present (fingerprint skipped)" };
3776
- } else if (!prepared) {
3777
- reason = "no docker-prepared.json on disk";
3778
- } else if (!preparedMatches2(prepared, fingerprint.contextSha256)) {
3779
- reason = `build context changed (was ${prepared.base?.contextSha256?.slice(0, 12) ?? "<none>"}, now ${fingerprint.contextSha256.slice(0, 12)})`;
3780
- }
3781
- if (!reason) {
3782
- return { ref, built: false, reason: "image up to date" };
3783
- }
3784
- opts.onProgress?.(`[image] ${ref}: ${reason}`);
3785
- const npm = claudeInstall === "npm";
3786
- const { source } = await pullOrBuild(ref, fingerprint, {
3787
- onProgress: opts.onProgress,
3788
- dockerfile: opts.dockerfile,
3789
- contextDir: opts.contextDir,
3790
- // npm mode pulls too. CI publishes both install variants, and `fingerprint`
3791
- // is already folded with the mode above — so the pull asks for the npm
3792
- // image's own tag and hits. (It used to be native-only, which meant npm
3793
- // users rebuilt the image locally on every first create, forever.) A tag
3794
- // that genuinely isn't published still falls back to a local build.
3795
- allowPull: opts.allowPull,
3796
- registry: opts.registry,
3797
- buildArgs: npm ? { AGENTBOX_CLAUDE_INSTALL: "npm" } : void 0
3798
- });
3799
- return { ref, built: source === "built", reason };
3800
- }
3801
- function classifyDockerBaseFreshness(input) {
3802
- if (!input.imagePresent) return { state: "unprepared" };
3803
- if (!input.fingerprint) return { state: "unknown" };
3804
- if (!input.stampedSha) return { state: "stale", reason: "no docker-prepared.json on disk" };
3805
- if (input.stampedSha !== input.fingerprint) {
3806
- return {
3807
- state: "stale",
3808
- reason: `build context changed (was ${input.stampedSha.slice(0, 12)}, now ${input.fingerprint.slice(0, 12)})`
3809
- };
3810
- }
3811
- return { state: "fresh" };
3812
- }
3813
- async function evaluateDockerBaseFreshness(opts = {}) {
3814
- const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2 } = await import("./prepared-state-75DIZ55S-TNJXWMXV.js");
3815
- const ref = opts.ref ?? DEFAULT_BOX_IMAGE;
3816
- const imagePresent = await imageExists(ref);
3817
- if (!imagePresent) return { state: "unprepared" };
3818
- const claudeInstall = opts.claudeInstall ?? await resolveClaudeInstallMode();
3819
- const raw = await computeDockerContextFingerprint2({ contextDir: opts.contextDir });
3820
- return classifyDockerBaseFreshness({
3821
- imagePresent,
3822
- fingerprint: raw ? claudeInstallFingerprint(raw.contextSha256, claudeInstall) : null,
3823
- stampedSha: readPreparedDockerState2()?.base?.contextSha256 ?? null
3824
- });
3825
- }
3826
- var SCHEMA = 1;
3827
- function resolveContextFiles(opts = {}) {
3828
- const ctx = opts.contextDir ?? BUILD_CONTEXT_DIR;
3829
- const here2 = dirname23(fileURLToPath2(import.meta.url));
3830
- const packageRoot = resolve23(here2, "..");
3831
- return resolveContextFilesFrom(DOCKER_CONTEXT_FILE_MAP, {
3832
- contextDir: ctx,
3833
- devRoot: packageRoot
3834
- });
3835
- }
3836
- async function computeDockerContextFingerprint(opts = {}) {
3837
- const files = resolveContextFiles(opts);
3838
- if (!files) return null;
3839
- return { contextSha256: await computeContextSha256(files), files };
3840
- }
3841
- function readPreparedDockerState() {
3842
- const raw = readPreparedStateRaw("docker");
3843
- if (raw === null || typeof raw !== "object") return null;
3844
- const parsed = raw;
3845
- if (parsed.schema !== SCHEMA) return null;
3846
- return { schema: SCHEMA, base: parsed.base };
3847
- }
3848
- function writePreparedDockerState(opts) {
3849
- const stamp = readCliStamp();
3850
- const state = {
3851
- schema: SCHEMA,
3852
- base: {
3853
- imageRef: opts.imageRef ?? DEFAULT_BOX_IMAGE,
3854
- contextSha256: opts.contextSha256,
3855
- cliVersion: stamp.cliVersion,
3856
- cliCommit: stamp.cliCommit,
3857
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
3858
- }
3859
- };
3860
- writePreparedStateRaw("docker", state);
3861
- }
3862
- function preparedMatches(state, current) {
3863
- return state?.base?.contextSha256 === current;
3864
- }
3865
-
3866
3613
  export {
3867
3614
  resolveAgentLauncher,
3868
3615
  ReplaceError,
@@ -4023,22 +3770,6 @@ export {
4023
3770
  DOCKER_CONTEXT_FILE_MAP,
4024
3771
  resolveContextFilesFrom,
4025
3772
  BOX_IMAGE_REGISTRY,
4026
- registryRefForSha,
4027
- DEFAULT_BOX_IMAGE,
4028
- DOCKERFILE_PATH,
4029
- BUILD_CONTEXT_DIR,
4030
- imageExists,
4031
- pullImage,
4032
- tagImage,
4033
- imageInfo,
4034
- pullOrBuild,
4035
- ensureImage,
4036
- classifyDockerBaseFreshness,
4037
- evaluateDockerBaseFreshness,
4038
- resolveContextFiles,
4039
- computeDockerContextFingerprint,
4040
- readPreparedDockerState,
4041
- writePreparedDockerState,
4042
- preparedMatches
3773
+ registryRefForSha
4043
3774
  };
4044
- //# sourceMappingURL=chunk-UJEH2NJT.js.map
3775
+ //# sourceMappingURL=chunk-JRXNVEV3.js.map