@madarco/agentbox 0.24.6 → 0.25.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.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/dist/{_cloud-attach-ESCPOKG5.js → _cloud-attach-FGMI2ZHO.js} +5 -5
- package/dist/{chunk-4HPLS5HJ.js → chunk-3BR63LCB.js} +110 -9
- package/dist/chunk-3BR63LCB.js.map +1 -0
- package/dist/{chunk-OSPM4Q5V.js → chunk-3PSRBK24.js} +6 -6
- package/dist/chunk-3PSRBK24.js.map +1 -0
- package/dist/{chunk-CE3S7UDQ.js → chunk-4DBLYT2F.js} +44 -12
- package/dist/chunk-4DBLYT2F.js.map +1 -0
- package/dist/{chunk-3MDYQROX.js → chunk-4LS2TOF3.js} +17 -13
- package/dist/chunk-4LS2TOF3.js.map +1 -0
- package/dist/{chunk-H6A4BQMG.js → chunk-5F5SOSDY.js} +40 -1
- package/dist/chunk-5F5SOSDY.js.map +1 -0
- package/dist/{chunk-LJMGHFLZ.js → chunk-5VNL6SHJ.js} +3 -3
- package/dist/{chunk-7DPDUZ7L.js → chunk-67VF2QZC.js} +194 -56
- package/dist/chunk-67VF2QZC.js.map +1 -0
- package/dist/{chunk-RFRWS5CD.js → chunk-6GZK74GT.js} +2 -2
- package/dist/chunk-G3H2L3O2.js +0 -0
- package/dist/{chunk-5JDOTQTM.js → chunk-P5U6AP6K.js} +4 -4
- package/dist/chunk-WJFZJZIM.js +0 -0
- package/dist/{chunk-QHISF6O6.js → chunk-ZTSVY3YL.js} +3 -3
- package/dist/cloud-poller-SUNA6ZQC-7M5LJHHE.js +0 -0
- package/dist/{dist-VFPT5TDH.js → dist-4I7XHDC3.js} +6 -6
- package/dist/dist-5G42NFOG.js +677 -0
- package/dist/dist-5G42NFOG.js.map +1 -0
- package/dist/{dist-TRKHS6I7.js → dist-AZUD2LUA.js} +6 -6
- package/dist/{dist-FGXCG4JY.js → dist-MEK44IS5.js} +6 -6
- package/dist/{dist-HPPHBZTO.js → dist-SBDYDH7H.js} +8 -2
- package/dist/{dist-NOUPH5E6.js → dist-SN6ABGMD.js} +4 -4
- package/dist/{dist-3M53BF4E.js → dist-X7R2EMJL.js} +6 -6
- package/dist/index.js +114 -38
- package/dist/index.js.map +1 -1
- package/dist/{prepared-state-BUO75YLZ-46W2PAHH.js → prepared-state-75DIZ55S-5UAKJX3L.js} +2 -2
- package/package.json +29 -30
- package/runtime/_shared/agentbox-checkpoint-cleanup +0 -0
- package/runtime/_shared/agentbox-dockerd-start +0 -0
- package/runtime/_shared/agentbox-open +0 -0
- package/runtime/_shared/agentbox-portless-trust +0 -0
- package/runtime/_shared/agentbox-vnc-start +0 -0
- package/runtime/_shared/ctl.cjs +31 -4
- package/runtime/_shared/gh-shim +0 -0
- package/runtime/_shared/git-shim +0 -0
- package/runtime/_shared/linear-shim +0 -0
- package/runtime/_shared/ntn-shim +0 -0
- package/runtime/digitalocean/agentbox-checkpoint-cleanup +0 -0
- package/runtime/digitalocean/agentbox-dockerd-start +0 -0
- package/runtime/digitalocean/agentbox-open +0 -0
- package/runtime/digitalocean/agentbox-portless-trust +0 -0
- package/runtime/digitalocean/agentbox-vnc-start +0 -0
- package/runtime/digitalocean/ctl.cjs +31 -4
- package/runtime/digitalocean/gh-shim +0 -0
- package/runtime/digitalocean/git-shim +0 -0
- package/runtime/digitalocean/linear-shim +0 -0
- package/runtime/digitalocean/ntn-shim +0 -0
- package/runtime/digitalocean/scripts/install-box.sh +0 -0
- package/runtime/docker/packages/ctl/dist/bin.cjs +31 -4
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-open +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-portless-trust +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-sshd-start +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-vnc-start +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/chromium-resolver +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/gh-shim +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/git-shim +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/linear-shim +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/ntn-shim +0 -0
- package/runtime/e2b/agentbox-checkpoint-cleanup +0 -0
- package/runtime/e2b/agentbox-dockerd-start +0 -0
- package/runtime/e2b/agentbox-open +0 -0
- package/runtime/e2b/agentbox-vnc-start +0 -0
- package/runtime/e2b/ctl.cjs +31 -4
- package/runtime/e2b/gh-shim +0 -0
- package/runtime/e2b/git-shim +0 -0
- package/runtime/e2b/linear-shim +0 -0
- package/runtime/e2b/ntn-shim +0 -0
- package/runtime/e2b/scripts/build-template.sh +0 -0
- package/runtime/hetzner/agentbox-checkpoint-cleanup +0 -0
- package/runtime/hetzner/agentbox-dockerd-start +0 -0
- package/runtime/hetzner/agentbox-open +0 -0
- package/runtime/hetzner/agentbox-portless-trust +0 -0
- package/runtime/hetzner/agentbox-vnc-start +0 -0
- package/runtime/hetzner/ctl.cjs +31 -4
- package/runtime/hetzner/gh-shim +0 -0
- package/runtime/hetzner/git-shim +0 -0
- package/runtime/hetzner/linear-shim +0 -0
- package/runtime/hetzner/ntn-shim +0 -0
- package/runtime/hetzner/scripts/install-box.sh +0 -0
- package/runtime/hub/apps/hub/.next/BUILD_ID +1 -1
- package/runtime/hub/apps/hub/.next/build-manifest.json +3 -3
- package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
- package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
- package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +6 -6
- package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ro6vh6._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
- package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
- package/runtime/hub/apps/hub/{auth-HY5K55Y5.js → auth-MVL4NCQC.js} +3 -3
- package/runtime/hub/apps/hub/{auth-config-MNW2XGKK.js → auth-config-GRIXACTV.js} +3 -3
- package/runtime/hub/apps/hub/{chunk-5KMJIVZC.js → chunk-23AU7VYS.js} +111 -10
- package/runtime/hub/apps/hub/{chunk-OF242BLD.js → chunk-CKBHQ7OI.js} +1 -1
- package/runtime/hub/apps/hub/{chunk-DNR2YM2G.js → chunk-GARA7RQW.js} +58 -10
- package/runtime/hub/apps/hub/{chunk-PROXBLRJ.js → chunk-JLG5JJXD.js} +1 -1
- package/runtime/hub/apps/hub/{chunk-TZFWAJVB.js → chunk-OG4KH2FZ.js} +5 -0
- package/runtime/hub/apps/hub/chunk-QYJ37CUJ.js +62140 -0
- package/runtime/hub/apps/hub/{chunk-EY6HEDTK.js → chunk-RSENJ2FT.js} +17 -13
- package/runtime/hub/apps/hub/{chunk-EFW34I43.js → chunk-UDZ3VXRF.js} +1 -1
- package/runtime/hub/apps/hub/{chunk-TRUQCO4U.js → chunk-V3OMPMI3.js} +40 -1
- package/runtime/hub/apps/hub/{cloud-poller-SUNA6ZQC-VSKVMYHL.js → cloud-poller-SUNA6ZQC-YAWTNA2W.js} +1 -1
- package/runtime/hub/apps/hub/{dist-KV5ESR24.js → dist-DZGSA3US.js} +7 -7
- package/runtime/hub/apps/hub/{dist-NTKPAYA3.js → dist-IZ2JCN5R.js} +8 -2
- package/runtime/hub/apps/hub/{dist-M73U3ZDH.js → dist-JVU3QCLG.js} +7 -7
- package/runtime/hub/apps/hub/{dist-3DCKZYID.js → dist-TP4SXMDY.js} +596 -113
- package/runtime/hub/apps/hub/{dist-YCRESLWD.js → dist-VWSHZIPN.js} +7 -7
- package/runtime/hub/apps/hub/{dist-SX2NXGI6.js → dist-WZKTIA2R.js} +7 -7
- package/runtime/hub/apps/hub/{dist-RSWTJWRN.js → dist-YWY2DSSL.js} +5 -5
- package/runtime/hub/apps/hub/esm-VGBJAFLR.js +79 -0
- package/runtime/hub/apps/hub/{execa-4DLVNM6E.js → execa-AFY4ZODY.js} +2 -2
- package/runtime/hub/apps/hub/{hub-token-QKQWV2I6.js → hub-token-BJG6Q5II.js} +3 -3
- package/runtime/hub/apps/hub/{prepared-state-BUO75YLZ-KR4YLKDC.js → prepared-state-75DIZ55S-JDILR4OP.js} +3 -3
- package/runtime/hub/apps/hub/server.js +19 -19
- package/runtime/relay/bin.cjs +177 -42
- package/runtime/vercel/agentbox-checkpoint-cleanup +0 -0
- package/runtime/vercel/agentbox-dockerd-start +0 -0
- package/runtime/vercel/agentbox-open +0 -0
- package/runtime/vercel/agentbox-vnc-start +0 -0
- package/runtime/vercel/ctl.cjs +31 -4
- package/runtime/vercel/gh-shim +0 -0
- package/runtime/vercel/git-shim +0 -0
- package/runtime/vercel/linear-shim +0 -0
- package/runtime/vercel/ntn-shim +0 -0
- package/runtime/vercel/scripts/provision.sh +0 -0
- package/dist/chunk-3MDYQROX.js.map +0 -1
- package/dist/chunk-4HPLS5HJ.js.map +0 -1
- package/dist/chunk-7DPDUZ7L.js.map +0 -1
- package/dist/chunk-CE3S7UDQ.js.map +0 -1
- package/dist/chunk-H6A4BQMG.js.map +0 -1
- package/dist/chunk-OSPM4Q5V.js.map +0 -1
- package/dist/dist-2N3XHMBQ.js +0 -322
- package/dist/dist-2N3XHMBQ.js.map +0 -1
- /package/dist/{_cloud-attach-ESCPOKG5.js.map → _cloud-attach-FGMI2ZHO.js.map} +0 -0
- /package/dist/{chunk-LJMGHFLZ.js.map → chunk-5VNL6SHJ.js.map} +0 -0
- /package/dist/{chunk-RFRWS5CD.js.map → chunk-6GZK74GT.js.map} +0 -0
- /package/dist/{chunk-5JDOTQTM.js.map → chunk-P5U6AP6K.js.map} +0 -0
- /package/dist/{chunk-QHISF6O6.js.map → chunk-ZTSVY3YL.js.map} +0 -0
- /package/dist/{dist-HPPHBZTO.js.map → dist-4I7XHDC3.js.map} +0 -0
- /package/dist/{dist-NOUPH5E6.js.map → dist-AZUD2LUA.js.map} +0 -0
- /package/dist/{dist-FGXCG4JY.js.map → dist-MEK44IS5.js.map} +0 -0
- /package/dist/{dist-TRKHS6I7.js.map → dist-SBDYDH7H.js.map} +0 -0
- /package/dist/{dist-VFPT5TDH.js.map → dist-SN6ABGMD.js.map} +0 -0
- /package/dist/{dist-3M53BF4E.js.map → dist-X7R2EMJL.js.map} +0 -0
- /package/dist/{prepared-state-BUO75YLZ-46W2PAHH.js.map → prepared-state-75DIZ55S-5UAKJX3L.js.map} +0 -0
- /package/runtime/hub/apps/hub/.next/static/{2LDXStEUVHS2oK1ID_Uvo → fo5EgsHa6PFLTBagfLiuM}/_buildManifest.js +0 -0
- /package/runtime/hub/apps/hub/.next/static/{2LDXStEUVHS2oK1ID_Uvo → fo5EgsHa6PFLTBagfLiuM}/_clientMiddlewareManifest.js +0 -0
- /package/runtime/hub/apps/hub/.next/static/{2LDXStEUVHS2oK1ID_Uvo → fo5EgsHa6PFLTBagfLiuM}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DAYTONA_DEFAULT_RESOURCES,
|
|
4
|
+
DEFAULT_BOX_IMAGE_REF,
|
|
5
|
+
computeDaytonaContextFingerprint,
|
|
6
|
+
computeDockerBaseSha,
|
|
7
|
+
currentDaytonaBaseFingerprintLive,
|
|
8
|
+
daytonaBackend,
|
|
9
|
+
ensureDaytonaCredentials,
|
|
10
|
+
ensureDaytonaEnvLoaded,
|
|
11
|
+
getClient,
|
|
12
|
+
parseDaytonaSize,
|
|
13
|
+
preparedMatches,
|
|
14
|
+
readPreparedDaytonaState,
|
|
15
|
+
resolveDaytonaCustomClaudeMd,
|
|
16
|
+
resolveDockerfileContext,
|
|
17
|
+
setDaytonaCredentials,
|
|
18
|
+
waitForSnapshotActive,
|
|
19
|
+
writePreparedDaytonaState
|
|
20
|
+
} from "./chunk-67VF2QZC.js";
|
|
21
|
+
import {
|
|
22
|
+
cloudSnapshotName,
|
|
23
|
+
createCloudProvider,
|
|
24
|
+
currentCloudBaseFingerprint,
|
|
25
|
+
listCloudCheckpoints,
|
|
26
|
+
removeCloudCheckpointDir,
|
|
27
|
+
resolveCloudCheckpoint,
|
|
28
|
+
seedAgentStaticIntoCloudBox,
|
|
29
|
+
writeCloudCheckpointManifest
|
|
30
|
+
} from "./chunk-3BR63LCB.js";
|
|
31
|
+
import "./chunk-3PSRBK24.js";
|
|
32
|
+
import {
|
|
33
|
+
DAYTONA_VM_REGION,
|
|
34
|
+
loadEffectiveConfig,
|
|
35
|
+
resolveDaytonaClass
|
|
36
|
+
} from "./chunk-5F5SOSDY.js";
|
|
37
|
+
import {
|
|
38
|
+
BOX_IMAGE_REGISTRY,
|
|
39
|
+
claudeInstallFingerprint,
|
|
40
|
+
errSummary,
|
|
41
|
+
readCliStamp,
|
|
42
|
+
registryRefForSha,
|
|
43
|
+
stageAllAgentStatic
|
|
44
|
+
} from "./chunk-4LS2TOF3.js";
|
|
45
|
+
import "./chunk-G3H2L3O2.js";
|
|
46
|
+
import "./chunk-WJFZJZIM.js";
|
|
47
|
+
|
|
48
|
+
// ../../packages/sandbox-daytona/dist/index.js
|
|
49
|
+
import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
50
|
+
import { tmpdir } from "os";
|
|
51
|
+
import { dirname, join } from "path";
|
|
52
|
+
import { Image } from "@daytona/sdk";
|
|
53
|
+
import { createHash } from "crypto";
|
|
54
|
+
import { SandboxClass } from "@daytona/sdk";
|
|
55
|
+
var BACKEND_NAME = "daytona";
|
|
56
|
+
function makeDaytonaCheckpoint(cloudProvider2) {
|
|
57
|
+
return {
|
|
58
|
+
async create(box, name) {
|
|
59
|
+
if (!box.projectRoot) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"cloud checkpoint requires the box to have a project root (run `agentbox checkpoint` from inside the project)"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const sandboxId = box.cloud?.sandboxId;
|
|
65
|
+
if (!sandboxId) {
|
|
66
|
+
throw new Error(`daytona box ${box.name} has no sandboxId \u2014 record is malformed`);
|
|
67
|
+
}
|
|
68
|
+
const handle = { sandboxId, sandboxClass: box.cloud?.sandboxClass };
|
|
69
|
+
const snapshotName = `${cloudSnapshotName(box.projectRoot, name)}-${Math.floor(Date.now() / 1e3).toString(36)}`;
|
|
70
|
+
await daytonaBackend.createSnapshot?.(handle, snapshotName);
|
|
71
|
+
await cloudProvider2.reconnect(box);
|
|
72
|
+
const info = await writeCloudCheckpointManifest(box.projectRoot, BACKEND_NAME, name, {
|
|
73
|
+
snapshotName,
|
|
74
|
+
sourceBoxId: box.id,
|
|
75
|
+
sourceBoxName: box.name,
|
|
76
|
+
baseProvider: BACKEND_NAME,
|
|
77
|
+
baseFingerprint: currentCloudBaseFingerprint(BACKEND_NAME),
|
|
78
|
+
cliVersion: readCliStamp().cliVersion
|
|
79
|
+
});
|
|
80
|
+
return { ref: info.name };
|
|
81
|
+
},
|
|
82
|
+
async list(projectRoot) {
|
|
83
|
+
const entries = await listCloudCheckpoints(projectRoot, BACKEND_NAME);
|
|
84
|
+
return entries.map((e) => ({ ref: e.name, createdAt: e.manifest.createdAt }));
|
|
85
|
+
},
|
|
86
|
+
async remove(projectRoot, ref) {
|
|
87
|
+
const entry = await resolveCloudCheckpoint(projectRoot, BACKEND_NAME, ref);
|
|
88
|
+
if (!entry) return;
|
|
89
|
+
try {
|
|
90
|
+
await daytonaBackend.deleteSnapshot?.(entry.manifest.snapshotName);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
await removeCloudCheckpointDir(projectRoot, BACKEND_NAME, ref);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function buildSudoRepairCommand() {
|
|
98
|
+
return `docker run --rm --privileged -v /:/host alpine sh -c 'chown root:root /host/usr/bin/sudo && chmod 4755 /host/usr/bin/sudo && grep -q "\\b$(cat /host/etc/hostname)\\b" /host/etc/hosts || echo "127.0.0.1 $(cat /host/etc/hostname)" >> /host/etc/hosts'`;
|
|
99
|
+
}
|
|
100
|
+
function buildDockerWaitCommand() {
|
|
101
|
+
return "for i in $(seq 1 30); do docker info >/dev/null 2>&1 && exit 0; sleep 2; done; exit 1";
|
|
102
|
+
}
|
|
103
|
+
var VmBaseImageUnavailableError = class extends Error {
|
|
104
|
+
};
|
|
105
|
+
async function ghcrTagExists(ref) {
|
|
106
|
+
const m = /^ghcr\.io\/(.+):([^:]+)$/.exec(ref);
|
|
107
|
+
if (!m) return true;
|
|
108
|
+
const [, repo, tag] = m;
|
|
109
|
+
try {
|
|
110
|
+
const tokenRes = await fetch(
|
|
111
|
+
`https://ghcr.io/token?scope=repository:${repo}:pull&service=ghcr.io`
|
|
112
|
+
);
|
|
113
|
+
if (!tokenRes.ok) return false;
|
|
114
|
+
const { token } = await tokenRes.json();
|
|
115
|
+
if (!token) return false;
|
|
116
|
+
const res = await fetch(`https://ghcr.io/v2/${repo}/manifests/${tag}`, {
|
|
117
|
+
method: "HEAD",
|
|
118
|
+
headers: {
|
|
119
|
+
Authorization: `Bearer ${token}`,
|
|
120
|
+
Accept: [
|
|
121
|
+
"application/vnd.oci.image.index.v1+json",
|
|
122
|
+
"application/vnd.oci.image.manifest.v1+json",
|
|
123
|
+
"application/vnd.docker.distribution.manifest.list.v2+json",
|
|
124
|
+
"application/vnd.docker.distribution.manifest.v2+json"
|
|
125
|
+
].join(",")
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return res.ok;
|
|
129
|
+
} catch {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function fetchImageEnv(ref) {
|
|
134
|
+
const m = /^ghcr\.io\/(.+):([^:]+)$/.exec(ref);
|
|
135
|
+
if (!m) return null;
|
|
136
|
+
const [, repo, tag] = m;
|
|
137
|
+
const accept = [
|
|
138
|
+
"application/vnd.oci.image.index.v1+json",
|
|
139
|
+
"application/vnd.oci.image.manifest.v1+json",
|
|
140
|
+
"application/vnd.docker.distribution.manifest.list.v2+json",
|
|
141
|
+
"application/vnd.docker.distribution.manifest.v2+json"
|
|
142
|
+
].join(",");
|
|
143
|
+
try {
|
|
144
|
+
const tokenRes = await fetch(
|
|
145
|
+
`https://ghcr.io/token?scope=repository:${repo}:pull&service=ghcr.io`
|
|
146
|
+
);
|
|
147
|
+
if (!tokenRes.ok) return null;
|
|
148
|
+
const { token } = await tokenRes.json();
|
|
149
|
+
if (!token) return null;
|
|
150
|
+
const headers = { Authorization: `Bearer ${token}`, Accept: accept };
|
|
151
|
+
const get = async (r) => {
|
|
152
|
+
const res = await fetch(`https://ghcr.io/v2/${repo}/${r}`, { headers });
|
|
153
|
+
return res.ok ? await res.json() : null;
|
|
154
|
+
};
|
|
155
|
+
let manifest = await get(`manifests/${tag}`);
|
|
156
|
+
const children = manifest?.manifests;
|
|
157
|
+
if (children) {
|
|
158
|
+
const amd64 = children.find(
|
|
159
|
+
(c) => c.platform?.os === "linux" && c.platform.architecture === "amd64"
|
|
160
|
+
);
|
|
161
|
+
if (!amd64) return null;
|
|
162
|
+
manifest = await get(`manifests/${amd64.digest}`);
|
|
163
|
+
}
|
|
164
|
+
const configDigest = manifest?.config?.digest;
|
|
165
|
+
if (!configDigest) return null;
|
|
166
|
+
const config = await get(`blobs/${configDigest}`);
|
|
167
|
+
const env = config?.config?.Env;
|
|
168
|
+
if (!Array.isArray(env)) return null;
|
|
169
|
+
return env.filter((e) => typeof e === "string" && e.includes("="));
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function buildEnvRestoreCommand(env) {
|
|
175
|
+
const shQuote = (v) => `'${v.replace(/'/g, `'\\''`)}'`;
|
|
176
|
+
const profile = env.map((e) => {
|
|
177
|
+
const i = e.indexOf("=");
|
|
178
|
+
return `export ${e.slice(0, i)}=${shQuote(e.slice(i + 1))}`;
|
|
179
|
+
}).join("\n");
|
|
180
|
+
const envFile = env.join("\n");
|
|
181
|
+
const b64 = (s) => Buffer.from(`${s}
|
|
182
|
+
`, "utf8").toString("base64");
|
|
183
|
+
return `printf %s '${b64(profile)}' | base64 -d | sudo tee /etc/profile.d/agentbox-image-env.sh >/dev/null && sudo chmod 644 /etc/profile.d/agentbox-image-env.sh && printf %s '${b64(envFile)}' | base64 -d | sudo tee -a /etc/environment >/dev/null`;
|
|
184
|
+
}
|
|
185
|
+
async function bakeDaytonaVmBase(opts) {
|
|
186
|
+
const log = opts.onLog ?? (() => {
|
|
187
|
+
});
|
|
188
|
+
let imageEnv = [];
|
|
189
|
+
const override = opts.baseImage?.trim();
|
|
190
|
+
const registry = opts.registry && opts.registry.length > 0 ? opts.registry : BOX_IMAGE_REGISTRY;
|
|
191
|
+
const imageRef = override || registryRefForSha(opts.dockerBaseSha, registry);
|
|
192
|
+
if (!override && !await ghcrTagExists(imageRef)) {
|
|
193
|
+
throw new VmBaseImageUnavailableError(
|
|
194
|
+
`the linux-vm base needs a published box image, and '${imageRef}' isn't in the registry.`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (override) log(`using box.daytonaVmBaseImage override: ${imageRef}`);
|
|
198
|
+
const vmBaseStem = override ? `agentbox-vmbase-x${sha12(override)}` : `agentbox-vmbase-${opts.dockerBaseSha.slice(0, 12)}`;
|
|
199
|
+
let vmBaseName = vmBaseStem;
|
|
200
|
+
if (await snapshotIsActive(opts.client, vmBaseName)) {
|
|
201
|
+
log(`reusing linux-vm base image snapshot '${vmBaseName}'`);
|
|
202
|
+
} else {
|
|
203
|
+
vmBaseName = await createVmBaseSnapshot(opts, vmBaseStem, imageRef, log);
|
|
204
|
+
}
|
|
205
|
+
log("booting a throwaway sandbox to seed the base\u2026");
|
|
206
|
+
let sandbox;
|
|
207
|
+
try {
|
|
208
|
+
sandbox = await opts.client.create({ snapshot: vmBaseName }, { timeout: 900 });
|
|
209
|
+
} catch {
|
|
210
|
+
log(`linux-vm base '${vmBaseName}' failed to boot; rebuilding it under a fresh name\u2026`);
|
|
211
|
+
await deleteSnapshotQuietly(opts.client, vmBaseName);
|
|
212
|
+
vmBaseName = await createVmBaseSnapshot(opts, `${vmBaseStem}-${nonce()}`, imageRef, log);
|
|
213
|
+
sandbox = await opts.client.create({ snapshot: vmBaseName }, { timeout: 900 });
|
|
214
|
+
}
|
|
215
|
+
const handle = { sandboxId: sandbox.id, sandboxClass: "linux-vm" };
|
|
216
|
+
try {
|
|
217
|
+
const wait = await opts.backend.exec(handle, buildDockerWaitCommand());
|
|
218
|
+
if (wait.exitCode !== 0) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
"dockerd never came up in the VM base, so sudo cannot be repaired (the repair borrows root from the docker socket)."
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
log("repairing sudo (the VM rootfs conversion strips setuid bits)\u2026");
|
|
224
|
+
const repair = await opts.backend.exec(handle, buildSudoRepairCommand());
|
|
225
|
+
if (repair.exitCode !== 0) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`failed to restore sudo in the VM base (exit ${String(repair.exitCode)}): ${repair.stdout}${repair.stderr}`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
imageEnv = await fetchImageEnv(imageRef) ?? [];
|
|
231
|
+
if (imageEnv.length > 0) {
|
|
232
|
+
log(`restoring the image's ${String(imageEnv.length)} env vars (the VM conversion drops them)\u2026`);
|
|
233
|
+
const envFix = await opts.backend.exec(handle, buildEnvRestoreCommand(imageEnv));
|
|
234
|
+
if (envFix.exitCode !== 0) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`failed to restore the image environment in the VM base (exit ${String(envFix.exitCode)}): ${envFix.stdout}${envFix.stderr}`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
log(
|
|
241
|
+
`warning: could not read the environment of '${imageRef}' from the registry \u2014 a VM box may come up without DISPLAY (no in-box browser).`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
await seedAgentStaticIntoCloudBox(opts.backend, handle, {
|
|
245
|
+
hostWorkspace: opts.hostWorkspace,
|
|
246
|
+
claudeMdOverlay: opts.claudeMdOverlay,
|
|
247
|
+
onLog: log
|
|
248
|
+
});
|
|
249
|
+
log("stopping the sandbox to capture a cold snapshot\u2026");
|
|
250
|
+
await sandbox.stop();
|
|
251
|
+
const finalName = `${opts.snapshotName}-${nonce()}`;
|
|
252
|
+
log(`capturing base snapshot '${finalName}'\u2026`);
|
|
253
|
+
await sandbox._experimental_createSnapshot(finalName, 900);
|
|
254
|
+
await waitForSnapshotActive(opts.client, finalName);
|
|
255
|
+
log(`snapshot '${finalName}' is active`);
|
|
256
|
+
return { snapshotName: finalName, env: imageEnv };
|
|
257
|
+
} finally {
|
|
258
|
+
try {
|
|
259
|
+
await sandbox.delete(120);
|
|
260
|
+
} catch (err) {
|
|
261
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
262
|
+
log(`warning: could not delete the temporary bake sandbox ${sandbox.id}: ${msg}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function sha12(s) {
|
|
267
|
+
return createHash("sha256").update(s).digest("hex").slice(0, 12);
|
|
268
|
+
}
|
|
269
|
+
function nonce() {
|
|
270
|
+
return Math.floor(Date.now() / 1e3).toString(36);
|
|
271
|
+
}
|
|
272
|
+
async function createVmBaseSnapshot(opts, name, imageRef, log) {
|
|
273
|
+
log(`creating linux-vm base image snapshot '${name}' from ${imageRef}\u2026`);
|
|
274
|
+
await opts.client.snapshot.create(
|
|
275
|
+
{
|
|
276
|
+
name,
|
|
277
|
+
image: imageRef,
|
|
278
|
+
sandboxClass: SandboxClass.LINUX_VM,
|
|
279
|
+
regionId: opts.regionId,
|
|
280
|
+
// Always explicit: a snapshot with no `resources` gets Daytona's 1 vCPU /
|
|
281
|
+
// 1 GiB / 3 GiB default, and the box image does not fit in 3 GiB — the
|
|
282
|
+
// build dies mid-pull with a bare "internal error".
|
|
283
|
+
resources: opts.resources ?? { cpu: 2, memory: 4, disk: 8 }
|
|
284
|
+
},
|
|
285
|
+
{ onLogs: (c) => log(String(c).split("\n").filter(Boolean).join(" ")) }
|
|
286
|
+
);
|
|
287
|
+
return name;
|
|
288
|
+
}
|
|
289
|
+
async function snapshotIsActive(client, name) {
|
|
290
|
+
try {
|
|
291
|
+
const snap = await client.snapshot.get(name);
|
|
292
|
+
return snap?.state === "active";
|
|
293
|
+
} catch {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async function deleteSnapshotQuietly(client, name) {
|
|
298
|
+
try {
|
|
299
|
+
const snap = await client.snapshot.get(name);
|
|
300
|
+
await client.snapshot.delete(snap);
|
|
301
|
+
} catch {
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function defaultSnapshotName(fingerprint, sizeKey, sandboxClass) {
|
|
305
|
+
const suffix = `${sizeKey ? `-${sizeKey}` : ""}${sandboxClass === "linux-vm" ? "-vm" : ""}`;
|
|
306
|
+
if (fingerprint) return `agentbox-base-${fingerprint.slice(0, 12)}${suffix}`;
|
|
307
|
+
return `agentbox-base-${Math.floor(Date.now() / 1e3).toString()}${suffix}`;
|
|
308
|
+
}
|
|
309
|
+
function daytonaSeedPaths(kind) {
|
|
310
|
+
return {
|
|
311
|
+
contextRel: `agentbox-seed-${kind}.tar.gz`,
|
|
312
|
+
remoteTar: `/tmp/agentbox-seed-${kind}.tar.gz`
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
var DAYTONA_CLAUDE_MD_REL = "agentbox-custom-CLAUDE.md";
|
|
316
|
+
function buildDaytonaSeedCommands(usable) {
|
|
317
|
+
const cmds = [
|
|
318
|
+
"USER root",
|
|
319
|
+
`COPY ${DAYTONA_CLAUDE_MD_REL} /tmp/agentbox-custom-CLAUDE.md`,
|
|
320
|
+
...usable.map((s) => `COPY ${daytonaSeedPaths(s.kind).contextRel} ${daytonaSeedPaths(s.kind).remoteTar}`),
|
|
321
|
+
"RUN install -m 0644 /tmp/agentbox-custom-CLAUDE.md /etc/claude-code/CLAUDE.md && rm -f /tmp/agentbox-custom-CLAUDE.md",
|
|
322
|
+
...usable.map(
|
|
323
|
+
(s) => `RUN mkdir -p ${s.extractDir} && tar -xzf ${daytonaSeedPaths(s.kind).remoteTar} -C ${s.extractDir} --no-same-permissions --no-same-owner -m`
|
|
324
|
+
)
|
|
325
|
+
];
|
|
326
|
+
if (usable.length > 0) {
|
|
327
|
+
cmds.push(
|
|
328
|
+
"RUN chown -R vscode:vscode /home/vscode/.claude /home/vscode/.codex /home/vscode/.local && ( [ -d /home/vscode/.agents ] && chown -R vscode:vscode /home/vscode/.agents || true ) && rm -f /tmp/agentbox-seed-*.tar.gz"
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
cmds.push("USER vscode");
|
|
332
|
+
return cmds;
|
|
333
|
+
}
|
|
334
|
+
async function prepareDaytona(opts) {
|
|
335
|
+
ensureDaytonaEnvLoaded();
|
|
336
|
+
const log = opts.onLog ?? (() => {
|
|
337
|
+
});
|
|
338
|
+
const claudeInstall = opts.claudeInstall ?? "native";
|
|
339
|
+
const sizeSpec = opts.size?.trim() || void 0;
|
|
340
|
+
const sizeResources = sizeSpec ? parseDaytonaSize(sizeSpec) : void 0;
|
|
341
|
+
if (sizeSpec && !sizeResources) {
|
|
342
|
+
throw new Error(
|
|
343
|
+
`invalid --size '${sizeSpec}' for daytona: expected 'cpu-memory-disk' GB, e.g. '4-8-20'.`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
const sizeKey = sizeResources ? `${String(sizeResources.cpu)}-${String(sizeResources.memory)}-${String(sizeResources.disk)}` : void 0;
|
|
347
|
+
let sandboxClass = opts.sandboxClass === "container" ? "container" : "linux-vm";
|
|
348
|
+
const rawFingerprint = await computeDaytonaContextFingerprint();
|
|
349
|
+
const fingerprint = rawFingerprint ? {
|
|
350
|
+
...rawFingerprint,
|
|
351
|
+
contextSha256: claudeInstallFingerprint(rawFingerprint.contextSha256, claudeInstall)
|
|
352
|
+
} : rawFingerprint;
|
|
353
|
+
let snapshotName = opts.name ?? defaultSnapshotName(fingerprint?.contextSha256 ?? null, sizeKey, sandboxClass);
|
|
354
|
+
const prepared = readPreparedDaytonaState();
|
|
355
|
+
if (!opts.force && fingerprint && preparedMatches(prepared, fingerprint.contextSha256, sizeKey, sandboxClass)) {
|
|
356
|
+
try {
|
|
357
|
+
const existing = await getClient().snapshot.get(
|
|
358
|
+
prepared?.base?.imageRef ?? snapshotName
|
|
359
|
+
);
|
|
360
|
+
if (existing?.name) {
|
|
361
|
+
log(
|
|
362
|
+
`daytona snapshot '${existing.name}' up to date (fingerprint ${fingerprint.contextSha256.slice(0, 12)}) \u2014 skipping rebuild (pass --force to override)`
|
|
363
|
+
);
|
|
364
|
+
return { snapshotName: existing.name };
|
|
365
|
+
}
|
|
366
|
+
log(
|
|
367
|
+
`recorded snapshot '${prepared?.base?.imageRef ?? snapshotName}' not found on Daytona; rebuilding`
|
|
368
|
+
);
|
|
369
|
+
} catch {
|
|
370
|
+
log(
|
|
371
|
+
`recorded snapshot lookup failed; rebuilding (pass --force to silence)`
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
} else if (!opts.force && fingerprint && prepared?.base?.contextSha256) {
|
|
375
|
+
const bakedSize = prepared.extras?.size;
|
|
376
|
+
const bakedClass = prepared.extras?.class ?? "container";
|
|
377
|
+
const sameContext = prepared.base.contextSha256 === fingerprint.contextSha256;
|
|
378
|
+
if (sameContext && bakedClass !== sandboxClass) {
|
|
379
|
+
log(
|
|
380
|
+
`daytona sandbox class changed (was ${bakedClass}, now ${sandboxClass}); rebuilding snapshot`
|
|
381
|
+
);
|
|
382
|
+
} else if (sameContext && bakedSize !== sizeKey) {
|
|
383
|
+
log(
|
|
384
|
+
`daytona size changed (was ${bakedSize ?? "default"}, now ${sizeKey ?? "default"}); rebuilding snapshot`
|
|
385
|
+
);
|
|
386
|
+
} else {
|
|
387
|
+
log(
|
|
388
|
+
`daytona build context changed (was ${prepared.base.contextSha256.slice(0, 12)}, now ${fingerprint.contextSha256.slice(0, 12)}); rebuilding snapshot`
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const ctx = resolveDockerfileContext();
|
|
393
|
+
if (!ctx) {
|
|
394
|
+
throw new Error(
|
|
395
|
+
"could not locate AgentBox Dockerfile.box build context for the Daytona snapshot. Set AGENTBOX_DOCKER_CONTEXT to the directory containing Dockerfile.box."
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
const daytonaClaudeMd = resolveDaytonaCustomClaudeMd();
|
|
399
|
+
if (!daytonaClaudeMd) {
|
|
400
|
+
throw new Error(
|
|
401
|
+
"could not locate packages/sandbox-daytona/scripts/custom-system-CLAUDE.md (or its staged runtime/daytona/ copy). Ensure `pnpm -w build` ran so the CLI staging populated runtime/daytona/."
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
if (sandboxClass === "linux-vm") {
|
|
405
|
+
const dockerBaseSha = await computeDockerBaseSha(claudeInstall);
|
|
406
|
+
if (!dockerBaseSha) {
|
|
407
|
+
throw new Error(
|
|
408
|
+
"could not fingerprint the docker build context, which names the published box image a linux-vm base must boot from. Ensure `pnpm -w build` ran, or set `agentbox config set box.daytonaClass container`."
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
const baked = await bakeDaytonaVmBase({
|
|
413
|
+
client: getClient(opts.location ?? DAYTONA_VM_REGION),
|
|
414
|
+
backend: daytonaBackend,
|
|
415
|
+
regionId: opts.location ?? DAYTONA_VM_REGION,
|
|
416
|
+
snapshotName,
|
|
417
|
+
dockerBaseSha,
|
|
418
|
+
registry: opts.registry,
|
|
419
|
+
baseImage: opts.vmBaseImage,
|
|
420
|
+
// Always explicit: a snapshot created with no `resources` gets Daytona's
|
|
421
|
+
// 1 vCPU / 1 GiB / 3 GiB default, and the box image does not fit in 3 GiB
|
|
422
|
+
// (the build dies mid-pull with a bare "internal error").
|
|
423
|
+
resources: sizeResources ?? { ...DAYTONA_DEFAULT_RESOURCES },
|
|
424
|
+
hostWorkspace: opts.hostWorkspace,
|
|
425
|
+
claudeMdOverlay: daytonaClaudeMd,
|
|
426
|
+
onLog: log
|
|
427
|
+
});
|
|
428
|
+
if (fingerprint) {
|
|
429
|
+
writePreparedDaytonaState({
|
|
430
|
+
snapshotName: baked.snapshotName,
|
|
431
|
+
contextSha256: fingerprint.contextSha256,
|
|
432
|
+
size: sizeKey,
|
|
433
|
+
class: "linux-vm",
|
|
434
|
+
env: baked.env
|
|
435
|
+
});
|
|
436
|
+
log(`recorded daytona-prepared.json (fingerprint ${fingerprint.contextSha256.slice(0, 12)})`);
|
|
437
|
+
}
|
|
438
|
+
const superseded = prepared?.base?.imageRef;
|
|
439
|
+
if (superseded && superseded !== baked.snapshotName && prepared?.extras?.class === "linux-vm") {
|
|
440
|
+
log(`removing superseded snapshot '${superseded}'`);
|
|
441
|
+
await deleteSnapshotQuietly(getClient(opts.location ?? DAYTONA_VM_REGION), superseded);
|
|
442
|
+
}
|
|
443
|
+
return { snapshotName: baked.snapshotName };
|
|
444
|
+
} catch (err) {
|
|
445
|
+
if (!(err instanceof VmBaseImageUnavailableError)) throw err;
|
|
446
|
+
log(
|
|
447
|
+
`daytona: ${err.message} This usually means a locally modified Dockerfile.box. Daytona can't build a linux-vm base from a Dockerfile, so falling back to a container snapshot (no pause/resume).`
|
|
448
|
+
);
|
|
449
|
+
sandboxClass = "container";
|
|
450
|
+
snapshotName = opts.name ?? defaultSnapshotName(fingerprint?.contextSha256 ?? null, sizeKey, sandboxClass);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const stages = await stageAllAgentStatic({ hostWorkspace: opts.hostWorkspace });
|
|
454
|
+
for (const s of stages) {
|
|
455
|
+
for (const w of s.staged.warnings) log(w);
|
|
456
|
+
}
|
|
457
|
+
let tempDockerfile = null;
|
|
458
|
+
const dockerfilePath = claudeInstall === "npm" ? tempDockerfile = writeNpmDockerfile(ctx.dockerfile) : ctx.dockerfile;
|
|
459
|
+
let seedContextDir = null;
|
|
460
|
+
try {
|
|
461
|
+
let image = Image.fromDockerfile(dockerfilePath);
|
|
462
|
+
seedContextDir = mkdtempSync(join(tmpdir(), "agentbox-daytona-seed-"));
|
|
463
|
+
copyFileSync(daytonaClaudeMd, join(seedContextDir, DAYTONA_CLAUDE_MD_REL));
|
|
464
|
+
const usable = stages.filter((s) => s.staged.tarballPath !== null);
|
|
465
|
+
for (const s of usable) {
|
|
466
|
+
copyFileSync(s.staged.tarballPath, join(seedContextDir, daytonaSeedPaths(s.kind).contextRel));
|
|
467
|
+
}
|
|
468
|
+
image = image.dockerfileCommands(buildDaytonaSeedCommands(usable), seedContextDir);
|
|
469
|
+
const client = getClient(opts.location ?? "");
|
|
470
|
+
log(
|
|
471
|
+
`creating Daytona snapshot '${snapshotName}'${sizeResources ? ` (${sizeKey})` : ""}\u2026`
|
|
472
|
+
);
|
|
473
|
+
const snapshot = await client.snapshot.create(
|
|
474
|
+
{
|
|
475
|
+
name: snapshotName,
|
|
476
|
+
image,
|
|
477
|
+
...sizeResources ? { resources: sizeResources } : {},
|
|
478
|
+
...opts.location ? { regionId: opts.location } : {}
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
onLogs: (chunk) => log(String(chunk).split("\n").filter(Boolean).join(" "))
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
log(`snapshot '${snapshot.name}' is ${snapshot.state ?? "created"}`);
|
|
485
|
+
if (fingerprint) {
|
|
486
|
+
writePreparedDaytonaState({
|
|
487
|
+
snapshotName: snapshot.name ?? snapshotName,
|
|
488
|
+
contextSha256: fingerprint.contextSha256,
|
|
489
|
+
size: sizeKey,
|
|
490
|
+
class: "container"
|
|
491
|
+
});
|
|
492
|
+
log(
|
|
493
|
+
`recorded daytona-prepared.json (fingerprint ${fingerprint.contextSha256.slice(0, 12)})`
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
return { snapshotName: snapshot.name ?? snapshotName };
|
|
497
|
+
} finally {
|
|
498
|
+
await Promise.all(stages.map((s) => s.staged.cleanup()));
|
|
499
|
+
if (tempDockerfile) rmSync(tempDockerfile, { force: true });
|
|
500
|
+
if (seedContextDir) rmSync(seedContextDir, { recursive: true, force: true });
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function writeNpmDockerfile(originalPath) {
|
|
504
|
+
const original = readFileSync(originalPath, "utf8");
|
|
505
|
+
const flipped = original.replace(
|
|
506
|
+
"ARG AGENTBOX_CLAUDE_INSTALL=native",
|
|
507
|
+
"ARG AGENTBOX_CLAUDE_INSTALL=npm"
|
|
508
|
+
);
|
|
509
|
+
if (flipped === original) {
|
|
510
|
+
throw new Error(
|
|
511
|
+
`could not enable npm Claude install for Daytona: 'ARG AGENTBOX_CLAUDE_INSTALL=native' not found in ${originalPath}. The Dockerfile.box drifted from the expected shape.`
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
const target = join(dirname(originalPath), ".agentbox-claude-npm.Dockerfile");
|
|
515
|
+
writeFileSync(target, flipped);
|
|
516
|
+
return target;
|
|
517
|
+
}
|
|
518
|
+
function isAgentboxName(name) {
|
|
519
|
+
return typeof name === "string" && name.toLowerCase().startsWith("agentbox");
|
|
520
|
+
}
|
|
521
|
+
async function getDaytonaStatus() {
|
|
522
|
+
try {
|
|
523
|
+
ensureDaytonaEnvLoaded();
|
|
524
|
+
} catch (err) {
|
|
525
|
+
return {
|
|
526
|
+
configured: false,
|
|
527
|
+
snapshots: [],
|
|
528
|
+
volumes: [],
|
|
529
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
let client;
|
|
533
|
+
try {
|
|
534
|
+
client = getClient();
|
|
535
|
+
} catch (err) {
|
|
536
|
+
return {
|
|
537
|
+
configured: false,
|
|
538
|
+
snapshots: [],
|
|
539
|
+
volumes: [],
|
|
540
|
+
reason: err instanceof Error ? err.message.split("\n")[0] : String(err)
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
const snapshots = [];
|
|
544
|
+
const volumes = [];
|
|
545
|
+
let reason;
|
|
546
|
+
try {
|
|
547
|
+
const list = await client.snapshot.list();
|
|
548
|
+
const items = list.items ?? (Array.isArray(list) ? list : []);
|
|
549
|
+
for (const s of items) {
|
|
550
|
+
const dto = s;
|
|
551
|
+
if (!isAgentboxName(dto.name)) continue;
|
|
552
|
+
snapshots.push({
|
|
553
|
+
name: dto.name,
|
|
554
|
+
state: typeof dto.state === "string" ? dto.state : void 0,
|
|
555
|
+
sizeGb: typeof dto.size === "number" ? dto.size : void 0,
|
|
556
|
+
createdAt: typeof dto.createdAt === "string" ? dto.createdAt : void 0,
|
|
557
|
+
errorReason: typeof dto.errorReason === "string" ? dto.errorReason : void 0
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
} catch (err) {
|
|
561
|
+
reason = `snapshot list failed: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`;
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
const list = await client.volume.list();
|
|
565
|
+
const items = Array.isArray(list) ? list : list.items ?? [];
|
|
566
|
+
for (const v of items) {
|
|
567
|
+
const dto = v;
|
|
568
|
+
if (!isAgentboxName(dto.name)) continue;
|
|
569
|
+
volumes.push({
|
|
570
|
+
name: dto.name,
|
|
571
|
+
id: typeof dto.id === "string" ? dto.id : "",
|
|
572
|
+
state: typeof dto.state === "string" ? dto.state : void 0,
|
|
573
|
+
createdAt: typeof dto.createdAt === "string" ? dto.createdAt : void 0,
|
|
574
|
+
lastUsedAt: typeof dto.lastUsedAt === "string" ? dto.lastUsedAt : void 0
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
} catch (err) {
|
|
578
|
+
const msg = `volume list failed: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`;
|
|
579
|
+
reason = reason ? `${reason}; ${msg}` : msg;
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
configured: true,
|
|
583
|
+
snapshots: snapshots.sort((a, b) => (b.createdAt ?? "").localeCompare(a.createdAt ?? "")),
|
|
584
|
+
volumes: volumes.sort((a, b) => a.name.localeCompare(b.name)),
|
|
585
|
+
reason
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
async function readCredStatusSummary() {
|
|
589
|
+
const status = await getDaytonaStatus();
|
|
590
|
+
return { configured: status.configured };
|
|
591
|
+
}
|
|
592
|
+
async function doctorChecks() {
|
|
593
|
+
try {
|
|
594
|
+
const status = await getDaytonaStatus();
|
|
595
|
+
if (!status.configured) {
|
|
596
|
+
return [
|
|
597
|
+
{
|
|
598
|
+
label: "credentials",
|
|
599
|
+
status: "warn",
|
|
600
|
+
// The SDK's reason is a paragraph (env-var enumeration) — doctor just
|
|
601
|
+
// needs the vercel/e2b-style one-liner; `prepare --status` keeps it.
|
|
602
|
+
detail: "not configured",
|
|
603
|
+
hint: "`agentbox daytona login`"
|
|
604
|
+
}
|
|
605
|
+
];
|
|
606
|
+
}
|
|
607
|
+
const credRes = { label: "credentials", status: "ok", detail: "configured" };
|
|
608
|
+
return [credRes, await baseSnapshotCheck(status.snapshots.length)];
|
|
609
|
+
} catch (err) {
|
|
610
|
+
return [{ label: "credentials", status: "warn", detail: errSummary(err) }];
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async function baseSnapshotCheck(snapshotCount) {
|
|
614
|
+
if (snapshotCount === 0) {
|
|
615
|
+
return {
|
|
616
|
+
label: "base snapshot",
|
|
617
|
+
status: "warn",
|
|
618
|
+
detail: "none",
|
|
619
|
+
hint: "`agentbox prepare --provider daytona`"
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const prepared = readPreparedDaytonaState();
|
|
623
|
+
const bakedClass = prepared?.base ? prepared.extras?.class ?? "container" : void 0;
|
|
624
|
+
let wantClass;
|
|
625
|
+
try {
|
|
626
|
+
wantClass = resolveDaytonaClass((await loadEffectiveConfig(process.cwd())).effective);
|
|
627
|
+
} catch {
|
|
628
|
+
}
|
|
629
|
+
if (bakedClass && wantClass && bakedClass !== wantClass) {
|
|
630
|
+
return {
|
|
631
|
+
label: "base snapshot",
|
|
632
|
+
status: "warn",
|
|
633
|
+
detail: `baked as '${bakedClass}' but box.daytonaClass is '${wantClass}' \u2014 creates will fail`,
|
|
634
|
+
hint: "`agentbox prepare --provider daytona --force`"
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
return {
|
|
638
|
+
label: "base snapshot",
|
|
639
|
+
status: "ok",
|
|
640
|
+
detail: `${String(snapshotCount)} agentbox snapshot(s)${bakedClass ? ` (base: ${bakedClass})` : ""}`
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
var cloudProvider = createCloudProvider(daytonaBackend, {
|
|
644
|
+
defaultResources: { ...DAYTONA_DEFAULT_RESOURCES }
|
|
645
|
+
});
|
|
646
|
+
var daytonaProvider = {
|
|
647
|
+
...cloudProvider,
|
|
648
|
+
prepare: prepareDaytona,
|
|
649
|
+
// Overrides the generic cloud checkpoint: a Daytona cold snapshot needs the
|
|
650
|
+
// sandbox stopped, which kills the in-box daemons, so the capture has to
|
|
651
|
+
// reconnect the box afterwards. See `makeDaytonaCheckpoint`.
|
|
652
|
+
checkpoint: makeDaytonaCheckpoint(cloudProvider),
|
|
653
|
+
baseFingerprint: () => currentDaytonaBaseFingerprintLive()
|
|
654
|
+
};
|
|
655
|
+
var providerModule = {
|
|
656
|
+
provider: daytonaProvider,
|
|
657
|
+
backend: daytonaBackend,
|
|
658
|
+
ensureCredentials: ensureDaytonaCredentials,
|
|
659
|
+
readCredStatus: readCredStatusSummary,
|
|
660
|
+
setCredentials: setDaytonaCredentials,
|
|
661
|
+
currentBaseFingerprintLive: (claudeInstall) => currentDaytonaBaseFingerprintLive(claudeInstall),
|
|
662
|
+
doctorChecks
|
|
663
|
+
};
|
|
664
|
+
export {
|
|
665
|
+
DAYTONA_DEFAULT_RESOURCES,
|
|
666
|
+
DEFAULT_BOX_IMAGE_REF,
|
|
667
|
+
currentDaytonaBaseFingerprintLive,
|
|
668
|
+
daytonaBackend,
|
|
669
|
+
daytonaProvider,
|
|
670
|
+
ensureDaytonaCredentials,
|
|
671
|
+
ensureDaytonaEnvLoaded,
|
|
672
|
+
getDaytonaStatus,
|
|
673
|
+
providerModule,
|
|
674
|
+
resolveDockerfileContext,
|
|
675
|
+
setDaytonaCredentials
|
|
676
|
+
};
|
|
677
|
+
//# sourceMappingURL=dist-5G42NFOG.js.map
|