@madarco/agentbox 0.23.4 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/LICENSE +21 -0
- package/README.md +3 -2
- package/dist/{_cloud-attach-BQRWX3J2.js → _cloud-attach-T6GPR6LJ.js} +5 -5
- package/dist/{chunk-GGRZ3GZO.js → chunk-5KHEH47T.js} +91 -79
- package/dist/chunk-5KHEH47T.js.map +1 -0
- package/dist/{chunk-I6ZRWTPR.js → chunk-6U2S6QWD.js} +219 -18
- package/dist/chunk-6U2S6QWD.js.map +1 -0
- package/dist/{chunk-LK2JT2OO.js → chunk-DEDTPG2D.js} +880 -146
- package/dist/chunk-DEDTPG2D.js.map +1 -0
- package/dist/chunk-G3H2L3O2.js +0 -0
- package/dist/{chunk-LA4JMS27.js → chunk-I654PBHA.js} +290 -330
- package/dist/chunk-I654PBHA.js.map +1 -0
- package/dist/{chunk-W3FQPFP7.js → chunk-K2EDQGZP.js} +18 -4
- package/dist/chunk-K2EDQGZP.js.map +1 -0
- package/dist/{chunk-LSQXT5WZ.js → chunk-LC4E2EIZ.js} +3 -3
- package/dist/{chunk-LSQXT5WZ.js.map → chunk-LC4E2EIZ.js.map} +1 -1
- package/dist/{chunk-SFA57TGX.js → chunk-NACA6AM7.js} +183 -49
- package/dist/chunk-NACA6AM7.js.map +1 -0
- package/dist/{chunk-QEQFZLYR.js → chunk-RYQLFKCP.js} +20 -10
- package/dist/chunk-RYQLFKCP.js.map +1 -0
- package/dist/{chunk-QT3SHMLY.js → chunk-UIRBYL4G.js} +43 -12
- package/dist/chunk-UIRBYL4G.js.map +1 -0
- package/dist/chunk-WJFZJZIM.js +0 -0
- package/dist/chunk-WLHJZPFJ.js +845 -0
- package/dist/chunk-WLHJZPFJ.js.map +1 -0
- package/dist/cloud-poller-SUNA6ZQC-7M5LJHHE.js +0 -0
- package/dist/dist-3KIJ2KQ2.js +1437 -0
- package/dist/dist-3KIJ2KQ2.js.map +1 -0
- package/dist/{dist-V235KVEX.js → dist-7OUOHQPA.js} +196 -151
- package/dist/dist-7OUOHQPA.js.map +1 -0
- package/dist/{dist-Z2NEVV55.js → dist-B7TNWGVG.js} +8 -4
- package/dist/{dist-CUKBKS3N.js → dist-KYV3LEHG.js} +10 -6
- package/dist/{dist-FXQFTT75.js → dist-PHYCFYKH.js} +37 -17
- package/dist/dist-PHYCFYKH.js.map +1 -0
- package/dist/{dist-2BTJQUJS.js → dist-T5MXBZGP.js} +2 -2
- package/dist/{dist-QO4CTLAX.js → dist-Z7KEPQC7.js} +6 -6
- package/dist/index.js +2560 -1108
- package/dist/index.js.map +1 -1
- package/dist/{prepared-state-BUO75YLZ-CDTISC2C.js → prepared-state-BUO75YLZ-RQRFFBJW.js} +2 -2
- package/package.json +28 -28
- package/runtime/_shared/agentbox-checkpoint-cleanup +0 -0
- package/runtime/_shared/agentbox-codex-hooks.json +1 -1
- 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 +468 -97
- package/runtime/_shared/gh-shim +0 -0
- package/runtime/_shared/git-shim +53 -3
- package/runtime/_shared/linear-shim +0 -0
- package/runtime/_shared/ntn-shim +0 -0
- package/runtime/daytona/custom-system-CLAUDE.md +1 -1
- package/runtime/digitalocean/agentbox-checkpoint-cleanup +55 -0
- package/runtime/digitalocean/agentbox-codex-hooks.json +68 -0
- package/runtime/digitalocean/agentbox-dockerd-start +145 -0
- package/runtime/digitalocean/agentbox-open +28 -0
- package/runtime/digitalocean/agentbox-portless-trust +82 -0
- package/runtime/digitalocean/agentbox-setup-skill.md +317 -0
- package/runtime/digitalocean/agentbox-vnc-start +102 -0
- package/runtime/digitalocean/claude-managed-settings.json +116 -0
- package/runtime/digitalocean/ctl.cjs +27852 -0
- package/runtime/digitalocean/custom-system-CLAUDE.md +39 -0
- package/runtime/digitalocean/gh-shim +344 -0
- package/runtime/digitalocean/git-shim +181 -0
- package/runtime/digitalocean/linear-shim +181 -0
- package/runtime/digitalocean/ntn-shim +95 -0
- package/runtime/digitalocean/opencode-agentbox-plugin.js +76 -0
- package/runtime/digitalocean/scripts/install-box.sh +462 -0
- package/runtime/docker/Dockerfile.box +5 -0
- package/runtime/docker/packages/ctl/dist/bin.cjs +468 -97
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-codex-hooks.json +1 -1
- 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/custom-system-CLAUDE.md +2 -1
- package/runtime/docker/packages/sandbox-docker/scripts/gh-shim +0 -0
- package/runtime/docker/packages/sandbox-docker/scripts/git-shim +53 -3
- 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-codex-hooks.json +1 -1
- 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 +468 -97
- package/runtime/e2b/custom-system-CLAUDE.md +6 -3
- package/runtime/e2b/gh-shim +0 -0
- package/runtime/e2b/git-shim +53 -3
- package/runtime/e2b/linear-shim +0 -0
- package/runtime/e2b/ntn-shim +0 -0
- package/runtime/e2b/scripts/build-template.sh +16 -0
- package/runtime/hetzner/agentbox-checkpoint-cleanup +0 -0
- package/runtime/hetzner/agentbox-codex-hooks.json +1 -1
- 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 +468 -97
- package/runtime/hetzner/custom-system-CLAUDE.md +1 -1
- package/runtime/hetzner/gh-shim +0 -0
- package/runtime/hetzner/git-shim +53 -3
- package/runtime/hetzner/linear-shim +0 -0
- package/runtime/hetzner/ntn-shim +0 -0
- package/runtime/hetzner/scripts/install-box.sh +5 -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/(dashboard)/boxes/[id]/page_client-reference-manifest.js +1 -1
- package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
- package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page_client-reference-manifest.js +1 -1
- package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page_client-reference-manifest.js +1 -1
- 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 +12 -12
- package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0keu6we._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bqbkd5._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qa4a0v._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/_06f2faq._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +8 -8
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/_09gdzmo._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ro6vh6._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0tgpglr._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/_1laion6._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_0b_hsjl._.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/.next/static/chunks/1c5w3kqosumog.js +1 -0
- package/runtime/hub/apps/hub/.next/static/chunks/1o3ot_9-8jgzc.js +1 -0
- package/runtime/hub/apps/hub/.next/static/chunks/380qcmusmigzz.js +1 -0
- package/runtime/hub/apps/hub/.next/static/chunks/3uq9hf-roasav.js +1 -0
- package/runtime/hub/apps/hub/{auth-675P3LQS.js → auth-Q447765C.js} +2 -2
- package/runtime/hub/apps/hub/{auth-config-AOBEKRZQ.js → auth-config-SIL635ZD.js} +2 -2
- package/runtime/hub/apps/hub/{chunk-H22XP3NY.js → chunk-3VE7AYVK.js} +600 -145
- package/runtime/hub/apps/hub/{chunk-EXQCBM5Q.js → chunk-64WEKO34.js} +42 -11
- package/runtime/hub/apps/hub/{chunk-56YQBVN2.js → chunk-DZPQB2JZ.js} +1 -1
- package/runtime/hub/apps/hub/{chunk-2Z74R6ZT.js → chunk-FGBXEXUV.js} +351 -292
- package/runtime/hub/apps/hub/{chunk-AR7CEZ2G.js → chunk-YVELHPNY.js} +218 -17
- package/runtime/hub/apps/hub/{dist-LZNRLUYY.js → dist-33ZNVTC6.js} +183 -49
- package/runtime/hub/apps/hub/{dist-Q6G66Z57.js → dist-4SXAJBOC.js} +195 -150
- package/runtime/hub/apps/hub/{dist-SD4G36EP.js → dist-EPJFN2J3.js} +116 -86
- package/runtime/hub/apps/hub/{dist-STQK5XM6.js → dist-GF5EBRNG.js} +1 -1
- package/runtime/hub/apps/hub/{dist-LNHEG5P4.js → dist-UJVIROA4.js} +19 -5
- package/runtime/hub/apps/hub/dist-XULFTIMT.js +2212 -0
- package/runtime/hub/apps/hub/{dist-VV6Z2CQX.js → dist-YM5J25H6.js} +7 -3
- package/runtime/hub/apps/hub/{hub-token-2BZFBBW3.js → hub-token-UITZEWVP.js} +2 -2
- package/runtime/hub/apps/hub/package.json +1 -0
- package/runtime/hub/apps/hub/{prepared-state-BUO75YLZ-CAXQS5Y3.js → prepared-state-BUO75YLZ-O4GZMDRF.js} +1 -1
- package/runtime/hub/apps/hub/server.js +38 -19
- package/runtime/relay/bin.cjs +275 -59
- package/runtime/vercel/agentbox-checkpoint-cleanup +0 -0
- package/runtime/vercel/agentbox-codex-hooks.json +1 -1
- 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 +468 -97
- package/runtime/vercel/custom-system-CLAUDE.md +3 -2
- package/runtime/vercel/gh-shim +0 -0
- package/runtime/vercel/git-shim +53 -3
- package/runtime/vercel/linear-shim +0 -0
- package/runtime/vercel/ntn-shim +0 -0
- package/runtime/vercel/scripts/provision.sh +16 -0
- package/dist/chunk-GGRZ3GZO.js.map +0 -1
- package/dist/chunk-I6ZRWTPR.js.map +0 -1
- package/dist/chunk-LA4JMS27.js.map +0 -1
- package/dist/chunk-LK2JT2OO.js.map +0 -1
- package/dist/chunk-QEQFZLYR.js.map +0 -1
- package/dist/chunk-QT3SHMLY.js.map +0 -1
- package/dist/chunk-SFA57TGX.js.map +0 -1
- package/dist/chunk-W3FQPFP7.js.map +0 -1
- package/dist/dist-FXQFTT75.js.map +0 -1
- package/dist/dist-V235KVEX.js.map +0 -1
- package/runtime/hub/apps/hub/.next/static/chunks/0joh_xsiowfc4.js +0 -1
- package/runtime/hub/apps/hub/.next/static/chunks/20hq7-0depjid.js +0 -1
- package/runtime/hub/apps/hub/.next/static/chunks/3p86ecqhr_7yy.js +0 -1
- package/runtime/hub/apps/hub/.next/static/chunks/3qof5hg87qf5n.js +0 -1
- /package/dist/{_cloud-attach-BQRWX3J2.js.map → _cloud-attach-T6GPR6LJ.js.map} +0 -0
- /package/dist/{dist-2BTJQUJS.js.map → dist-B7TNWGVG.js.map} +0 -0
- /package/dist/{dist-CUKBKS3N.js.map → dist-KYV3LEHG.js.map} +0 -0
- /package/dist/{dist-QO4CTLAX.js.map → dist-T5MXBZGP.js.map} +0 -0
- /package/dist/{dist-Z2NEVV55.js.map → dist-Z7KEPQC7.js.map} +0 -0
- /package/dist/{prepared-state-BUO75YLZ-CDTISC2C.js.map → prepared-state-BUO75YLZ-RQRFFBJW.js.map} +0 -0
- /package/runtime/hub/apps/hub/.next/static/{eVq-z4zld_8DGQudbYogV → XtIjHGqvY4mQsOY2-m1Jy}/_buildManifest.js +0 -0
- /package/runtime/hub/apps/hub/.next/static/{eVq-z4zld_8DGQudbYogV → XtIjHGqvY4mQsOY2-m1Jy}/_clientMiddlewareManifest.js +0 -0
- /package/runtime/hub/apps/hub/.next/static/{eVq-z4zld_8DGQudbYogV → XtIjHGqvY4mQsOY2-m1Jy}/_ssgManifest.js +0 -0
|
@@ -295,39 +295,46 @@ import { mkdtemp, readFile as readFile4, writeFile as writeFile3 } from "fs/prom
|
|
|
295
295
|
import { tmpdir } from "os";
|
|
296
296
|
import { basename as basename2, join as join7 } from "path";
|
|
297
297
|
import { join as join8 } from "path";
|
|
298
|
+
import { chmod, mkdir as mkdir4, readdir as readdir2, readFile as readFile5, stat as stat4, writeFile as writeFile4 } from "fs/promises";
|
|
298
299
|
import { homedir as homedir6 } from "os";
|
|
299
|
-
import {
|
|
300
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
301
|
+
import { mkdir as mkdir5, mkdtemp as mkdtemp2, rm as rm3, writeFile as writeFile5 } from "fs/promises";
|
|
300
302
|
import { tmpdir as tmpdir2 } from "os";
|
|
301
|
-
import { join as
|
|
302
|
-
import { execa as execa3 } from "execa";
|
|
303
|
-
import { readdir as readdir2, stat as stat4 } from "fs/promises";
|
|
303
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
304
304
|
import { homedir as homedir7 } from "os";
|
|
305
|
-
import {
|
|
306
|
-
import {
|
|
307
|
-
import {
|
|
308
|
-
import {
|
|
309
|
-
import {
|
|
310
|
-
import {
|
|
311
|
-
import { createHash } from "crypto";
|
|
312
|
-
import { readFile as readFile6 } from "fs/promises";
|
|
305
|
+
import { mkdtemp as mkdtemp3, rm as rm4 } from "fs/promises";
|
|
306
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
307
|
+
import { join as join11 } from "path";
|
|
308
|
+
import { execa as execa3 } from "execa";
|
|
309
|
+
import { readdir as readdir3, stat as stat5 } from "fs/promises";
|
|
310
|
+
import { homedir as homedir8 } from "os";
|
|
313
311
|
import { join as join12 } from "path";
|
|
312
|
+
import { readdir as readdir4, realpath as realpath2, stat as stat6 } from "fs/promises";
|
|
313
|
+
import { isAbsolute, join as join13, relative } from "path";
|
|
314
|
+
import { stat as stat7 } from "fs/promises";
|
|
315
|
+
import { chmod as chmod2, mkdir as mkdir6, mkdtemp as mkdtemp4, readFile as readFile6, rename as rename3, rm as rm5, writeFile as writeFile6 } from "fs/promises";
|
|
316
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
317
|
+
import { dirname as dirname8, join as join14 } from "path";
|
|
318
|
+
import { createHash } from "crypto";
|
|
319
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
320
|
+
import { join as join15 } from "path";
|
|
314
321
|
import { execa as execa4 } from "execa";
|
|
315
322
|
import { createHash as createHash2 } from "crypto";
|
|
316
|
-
import { copyFile, mkdir as
|
|
317
|
-
import { homedir as
|
|
318
|
-
import { basename as basename22, dirname as
|
|
323
|
+
import { copyFile, mkdir as mkdir7, mkdtemp as mkdtemp5, readdir as readdir5, readFile as readFile8, rm as rm6, stat as stat8 } from "fs/promises";
|
|
324
|
+
import { homedir as homedir9, tmpdir as tmpdir5 } from "os";
|
|
325
|
+
import { basename as basename22, dirname as dirname9, join as join16 } from "path";
|
|
319
326
|
import { execa as execa5 } from "execa";
|
|
320
|
-
import { copyFile as copyFile2, mkdtemp as
|
|
321
|
-
import { homedir as
|
|
322
|
-
import { basename as basename3, join as
|
|
327
|
+
import { copyFile as copyFile2, mkdtemp as mkdtemp6, readdir as readdir6, readFile as readFile9, rm as rm7, stat as stat9, writeFile as writeFile7 } from "fs/promises";
|
|
328
|
+
import { homedir as homedir11, tmpdir as tmpdir6 } from "os";
|
|
329
|
+
import { basename as basename3, join as join17, relative as relative2 } from "path";
|
|
323
330
|
import { execa as execa6 } from "execa";
|
|
324
|
-
import { homedir as
|
|
331
|
+
import { homedir as homedir10 } from "os";
|
|
325
332
|
import { parse, stringify } from "smol-toml";
|
|
326
333
|
import { createHash as createHash3 } from "crypto";
|
|
327
334
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
328
|
-
import { readFile as
|
|
329
|
-
import { homedir as
|
|
330
|
-
import { dirname as
|
|
335
|
+
import { readFile as readFile10 } from "fs/promises";
|
|
336
|
+
import { homedir as homedir12 } from "os";
|
|
337
|
+
import { dirname as dirname10, resolve as pathResolve } from "path";
|
|
331
338
|
var STATE_DIR = join(homedir(), ".agentbox");
|
|
332
339
|
var STATE_FILE = join(STATE_DIR, "state.json");
|
|
333
340
|
var EMPTY = { version: 1, boxes: [] };
|
|
@@ -867,6 +874,47 @@ async function mintSshKey(targetDir, comment) {
|
|
|
867
874
|
const publicKey = (await readFile2(pub, "utf8")).trim();
|
|
868
875
|
return { dir, privatePath: priv, publicPath: pub, publicKey };
|
|
869
876
|
}
|
|
877
|
+
var OPEN_INBOUND_SOURCES = ["0.0.0.0/0", "::/0"];
|
|
878
|
+
function normalizeInboundCidr(raw) {
|
|
879
|
+
const trimmed = raw.trim();
|
|
880
|
+
if (trimmed.includes("/")) return trimmed;
|
|
881
|
+
if (trimmed.includes(":")) return `${trimmed}/128`;
|
|
882
|
+
return `${trimmed}/32`;
|
|
883
|
+
}
|
|
884
|
+
function parseInboundSpec(spec) {
|
|
885
|
+
let s = (spec ?? "").trim();
|
|
886
|
+
if (s === "" || /^lock(ed)?$/i.test(s)) return { mode: "locked", sources: [] };
|
|
887
|
+
if (/^open$/i.test(s)) return { mode: "open", sources: [] };
|
|
888
|
+
if (/^whitelist\b:?/i.test(s)) s = s.replace(/^whitelist\b:?/i, "").trim();
|
|
889
|
+
const sources = s.split(/[\s,]+/).map((x) => x.trim()).filter((x) => x.length > 0).map(normalizeInboundCidr);
|
|
890
|
+
if (sources.length === 0) {
|
|
891
|
+
throw new Error(
|
|
892
|
+
"inbound 'whitelist' needs at least one CIDR, e.g. `--inbound 203.0.113.5/32` or `--inbound whitelist:203.0.113.0/24`"
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
return { mode: "whitelist", sources };
|
|
896
|
+
}
|
|
897
|
+
function resolveInboundSources(policy, hostEgressCidr) {
|
|
898
|
+
if (policy.mode === "open") return [...OPEN_INBOUND_SOURCES];
|
|
899
|
+
const out = /* @__PURE__ */ new Set();
|
|
900
|
+
if (hostEgressCidr && hostEgressCidr.trim().length > 0) {
|
|
901
|
+
out.add(normalizeInboundCidr(hostEgressCidr));
|
|
902
|
+
}
|
|
903
|
+
if (policy.mode === "whitelist") {
|
|
904
|
+
for (const s of policy.sources) out.add(normalizeInboundCidr(s));
|
|
905
|
+
}
|
|
906
|
+
return [...out];
|
|
907
|
+
}
|
|
908
|
+
function describeInbound(policy) {
|
|
909
|
+
switch (policy.mode) {
|
|
910
|
+
case "open":
|
|
911
|
+
return "open (SSH reachable from anywhere \u2014 0.0.0.0/0, key-only)";
|
|
912
|
+
case "whitelist":
|
|
913
|
+
return `whitelist (host egress + ${policy.sources.join(", ")})`;
|
|
914
|
+
default:
|
|
915
|
+
return "locked (SSH reachable only from the host egress IP)";
|
|
916
|
+
}
|
|
917
|
+
}
|
|
870
918
|
var BOX_WORKSPACE = "/workspace";
|
|
871
919
|
function run(provider, box, argv) {
|
|
872
920
|
return provider.exec(box, argv, { cwd: BOX_WORKSPACE });
|
|
@@ -1207,6 +1255,17 @@ var AGENT_SYNC_SPECS = [
|
|
|
1207
1255
|
// separately; `state_*.sqlite*` is the resume-cwd index (rebuilt in-box);
|
|
1208
1256
|
// `packages`/`plugins/.plugin-appserver`/`computer-use` are heavy
|
|
1209
1257
|
// macOS-only artifacts; the rest is host-only session/log/cache state.
|
|
1258
|
+
//
|
|
1259
|
+
// `.tmp` carve-in: the git-marketplace snapshots (`.tmp/marketplaces/`,
|
|
1260
|
+
// ~13 MB) must reach the box or in-box `codex plugin` breaks
|
|
1261
|
+
// ("marketplace root does not contain a supported manifest" — and the
|
|
1262
|
+
// box can't re-clone, the git shim blocks `clone`). The includes are
|
|
1263
|
+
// emitted BEFORE the excludes (first-match-wins): the root `.tmp/` dir
|
|
1264
|
+
// and the marketplaces subtree transfer, `/.tmp/*` drops its other
|
|
1265
|
+
// children (the ~200 MB desktop-app `bundled-marketplaces` + `plugins`
|
|
1266
|
+
// payloads), and the unanchored `.tmp` still blocks nested `.tmp` dirs
|
|
1267
|
+
// elsewhere in the tree.
|
|
1268
|
+
include: ["/.tmp/", "/.tmp/marketplaces/***"],
|
|
1210
1269
|
exclude: [
|
|
1211
1270
|
"auth.json",
|
|
1212
1271
|
"sessions",
|
|
@@ -1220,6 +1279,7 @@ var AGENT_SYNC_SPECS = [
|
|
|
1220
1279
|
"cache",
|
|
1221
1280
|
"vendor_imports",
|
|
1222
1281
|
"tmp",
|
|
1282
|
+
"/.tmp/*",
|
|
1223
1283
|
".tmp",
|
|
1224
1284
|
".codex-global-state.json",
|
|
1225
1285
|
".codex-global-state.json.bak",
|
|
@@ -1316,6 +1376,512 @@ function resolveAgentSpec(name) {
|
|
|
1316
1376
|
if (!spec) throw new Error(`no agent sync spec for '${name}'`);
|
|
1317
1377
|
return spec;
|
|
1318
1378
|
}
|
|
1379
|
+
var SKILL_EXCLUDE_PREFIXES = ["agentbox-"];
|
|
1380
|
+
var CONTAINER_PLUGINS_PREFIX = "/home/vscode/.claude/plugins/";
|
|
1381
|
+
function pickNewItems(boxNames, hostNames, excludePrefixes = []) {
|
|
1382
|
+
const host = new Set(hostNames);
|
|
1383
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1384
|
+
const out = [];
|
|
1385
|
+
for (const name of boxNames) {
|
|
1386
|
+
if (name.length === 0 || host.has(name) || seen.has(name)) continue;
|
|
1387
|
+
if (excludePrefixes.some((p) => name.startsWith(p))) continue;
|
|
1388
|
+
seen.add(name);
|
|
1389
|
+
out.push(name);
|
|
1390
|
+
}
|
|
1391
|
+
return out.sort();
|
|
1392
|
+
}
|
|
1393
|
+
function rewritePluginPaths(value, hostPluginsPrefix) {
|
|
1394
|
+
if (typeof value === "string") {
|
|
1395
|
+
return value.split(CONTAINER_PLUGINS_PREFIX).join(hostPluginsPrefix);
|
|
1396
|
+
}
|
|
1397
|
+
if (Array.isArray(value)) {
|
|
1398
|
+
return value.map((v) => rewritePluginPaths(v, hostPluginsPrefix));
|
|
1399
|
+
}
|
|
1400
|
+
if (value !== null && typeof value === "object") {
|
|
1401
|
+
const out = {};
|
|
1402
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1403
|
+
out[k] = rewritePluginPaths(v, hostPluginsPrefix);
|
|
1404
|
+
}
|
|
1405
|
+
return out;
|
|
1406
|
+
}
|
|
1407
|
+
return value;
|
|
1408
|
+
}
|
|
1409
|
+
function isPlainObject2(v) {
|
|
1410
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
1411
|
+
}
|
|
1412
|
+
function additiveMerge(hostRoot, boxRoot, hostPluginsPrefix, selectMap, withMap) {
|
|
1413
|
+
const hostMap = selectMap(hostRoot);
|
|
1414
|
+
const boxMap = selectMap(boxRoot);
|
|
1415
|
+
if (!isPlainObject2(boxMap)) {
|
|
1416
|
+
return { data: hostRoot, changed: false, addedKeys: [] };
|
|
1417
|
+
}
|
|
1418
|
+
const base = isPlainObject2(hostMap) ? { ...hostMap } : {};
|
|
1419
|
+
const addedKeys = [];
|
|
1420
|
+
for (const [key, value] of Object.entries(boxMap)) {
|
|
1421
|
+
if (Object.prototype.hasOwnProperty.call(base, key)) continue;
|
|
1422
|
+
base[key] = rewritePluginPaths(value, hostPluginsPrefix);
|
|
1423
|
+
addedKeys.push(key);
|
|
1424
|
+
}
|
|
1425
|
+
if (addedKeys.length === 0) {
|
|
1426
|
+
return { data: hostRoot, changed: false, addedKeys: [] };
|
|
1427
|
+
}
|
|
1428
|
+
return { data: withMap(hostRoot, base), changed: true, addedKeys: addedKeys.sort() };
|
|
1429
|
+
}
|
|
1430
|
+
function mergeKnownMarketplaces(hostJson, boxJson, opts) {
|
|
1431
|
+
const prefix = `${opts.hostHome}/.claude/plugins/`;
|
|
1432
|
+
return additiveMerge(
|
|
1433
|
+
isPlainObject2(hostJson) ? hostJson : {},
|
|
1434
|
+
boxJson,
|
|
1435
|
+
prefix,
|
|
1436
|
+
(root) => root,
|
|
1437
|
+
(_host, merged) => merged
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
function mergeInstalledPlugins(hostJson, boxJson, opts) {
|
|
1441
|
+
const prefix = `${opts.hostHome}/.claude/plugins/`;
|
|
1442
|
+
const hostRoot = isPlainObject2(hostJson) ? hostJson : { plugins: {} };
|
|
1443
|
+
return additiveMerge(
|
|
1444
|
+
hostRoot,
|
|
1445
|
+
boxJson,
|
|
1446
|
+
prefix,
|
|
1447
|
+
(root) => isPlainObject2(root) ? root["plugins"] : void 0,
|
|
1448
|
+
(host, merged) => ({ ...host, plugins: merged })
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
function referencedPluginVersionKeys(installedPluginsJson) {
|
|
1452
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1453
|
+
if (!isPlainObject2(installedPluginsJson)) return keys;
|
|
1454
|
+
const plugins = installedPluginsJson["plugins"];
|
|
1455
|
+
if (!isPlainObject2(plugins)) return keys;
|
|
1456
|
+
for (const entries of Object.values(plugins)) {
|
|
1457
|
+
if (!Array.isArray(entries)) continue;
|
|
1458
|
+
for (const entry of entries) {
|
|
1459
|
+
if (!isPlainObject2(entry)) continue;
|
|
1460
|
+
const installPath = entry["installPath"];
|
|
1461
|
+
if (typeof installPath !== "string") continue;
|
|
1462
|
+
const segments = installPath.split("/").filter((s) => s.length > 0);
|
|
1463
|
+
if (segments.length < 3) continue;
|
|
1464
|
+
keys.add(segments.slice(-3).join("/"));
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return keys;
|
|
1468
|
+
}
|
|
1469
|
+
var CLAUDE_BOX_CONFIG_DIR = "/home/vscode/.claude";
|
|
1470
|
+
var CODEX_BOX_CONFIG_DIR = "/home/vscode/.codex";
|
|
1471
|
+
var OPENCODE_BOX_DATA_DIR = "/home/vscode/.local/share/opencode";
|
|
1472
|
+
var CLAUDE_PULL_DIR_CATEGORIES = ["skills", "agents", "commands"];
|
|
1473
|
+
function claudeInventoryScript(src) {
|
|
1474
|
+
return [
|
|
1475
|
+
"for cat in skills agents commands; do",
|
|
1476
|
+
` [ -d "${src}/$cat" ] || continue;`,
|
|
1477
|
+
` for d in "${src}/$cat"/*/; do`,
|
|
1478
|
+
' [ -d "$d" ] || continue;',
|
|
1479
|
+
' printf "DIR %s %s\\n" "$cat" "$(basename "$d")";',
|
|
1480
|
+
" done;",
|
|
1481
|
+
"done;",
|
|
1482
|
+
`if [ -d ${src}/plugins/cache ]; then`,
|
|
1483
|
+
` for m in ${src}/plugins/cache/*/; do`,
|
|
1484
|
+
' [ -d "$m" ] || continue;',
|
|
1485
|
+
' for p in "$m"*/; do',
|
|
1486
|
+
' [ -d "$p" ] || continue;',
|
|
1487
|
+
' printf "PLUGIN %s/%s\\n" "$(basename "$m")" "$(basename "$p")";',
|
|
1488
|
+
" done;",
|
|
1489
|
+
" done;",
|
|
1490
|
+
"fi;",
|
|
1491
|
+
"for f in installed_plugins known_marketplaces; do",
|
|
1492
|
+
` [ -f "${src}/plugins/$f.json" ] || continue;`,
|
|
1493
|
+
' printf "JSON %s " "$f";',
|
|
1494
|
+
` base64 -w0 "${src}/plugins/$f.json";`,
|
|
1495
|
+
' printf "\\n";',
|
|
1496
|
+
"done"
|
|
1497
|
+
].join(" ");
|
|
1498
|
+
}
|
|
1499
|
+
function parseClaudeInventory(stdout) {
|
|
1500
|
+
const dirs = { skills: [], agents: [], commands: [] };
|
|
1501
|
+
const plugins = [];
|
|
1502
|
+
const registries = {};
|
|
1503
|
+
for (const line of stdout.split("\n")) {
|
|
1504
|
+
if (line.startsWith("DIR ")) {
|
|
1505
|
+
const rest = line.slice(4);
|
|
1506
|
+
const sp = rest.indexOf(" ");
|
|
1507
|
+
if (sp === -1) continue;
|
|
1508
|
+
const cat = rest.slice(0, sp);
|
|
1509
|
+
const name = rest.slice(sp + 1);
|
|
1510
|
+
if (cat in dirs) dirs[cat].push(name);
|
|
1511
|
+
} else if (line.startsWith("PLUGIN ")) {
|
|
1512
|
+
plugins.push(line.slice(7));
|
|
1513
|
+
} else if (line.startsWith("JSON ")) {
|
|
1514
|
+
const rest = line.slice(5);
|
|
1515
|
+
const sp = rest.indexOf(" ");
|
|
1516
|
+
if (sp === -1) continue;
|
|
1517
|
+
const which = rest.slice(0, sp);
|
|
1518
|
+
try {
|
|
1519
|
+
registries[which] = JSON.parse(Buffer.from(rest.slice(sp + 1), "base64").toString("utf8"));
|
|
1520
|
+
} catch {
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return { dirs, plugins, registries };
|
|
1525
|
+
}
|
|
1526
|
+
async function listChildDirs(dir) {
|
|
1527
|
+
try {
|
|
1528
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
1529
|
+
return entries.filter((e) => e.isDirectory() || e.isSymbolicLink()).map((e) => e.name);
|
|
1530
|
+
} catch {
|
|
1531
|
+
return [];
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
async function readJsonFile(path) {
|
|
1535
|
+
try {
|
|
1536
|
+
return JSON.parse(await readFile5(path, "utf8"));
|
|
1537
|
+
} catch {
|
|
1538
|
+
return void 0;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
async function computeClaudePullPlan(inv, opts = {}) {
|
|
1542
|
+
const hostHome = opts.hostHome ?? homedir6();
|
|
1543
|
+
const hostClaude = join9(hostHome, ".claude");
|
|
1544
|
+
const newItems = [];
|
|
1545
|
+
const copyRels = [];
|
|
1546
|
+
for (const cat of CLAUDE_PULL_DIR_CATEGORIES) {
|
|
1547
|
+
const hostNames = await listChildDirs(join9(hostClaude, cat));
|
|
1548
|
+
const excludes = cat === "skills" ? SKILL_EXCLUDE_PREFIXES : [];
|
|
1549
|
+
for (const name of pickNewItems(inv.dirs[cat] ?? [], hostNames, excludes)) {
|
|
1550
|
+
newItems.push({ category: cat, name });
|
|
1551
|
+
copyRels.push(`${cat}/${name}`);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
const hostPluginKeys = [];
|
|
1555
|
+
for (const m of await listChildDirs(join9(hostClaude, "plugins", "cache"))) {
|
|
1556
|
+
for (const p of await listChildDirs(join9(hostClaude, "plugins", "cache", m))) {
|
|
1557
|
+
hostPluginKeys.push(`${m}/${p}`);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
for (const key of pickNewItems(inv.plugins, hostPluginKeys)) {
|
|
1561
|
+
newItems.push({ category: "plugins", name: key });
|
|
1562
|
+
copyRels.push(`plugins/cache/${key}`);
|
|
1563
|
+
}
|
|
1564
|
+
const hostInstalled = await readJsonFile(join9(hostClaude, "plugins", "installed_plugins.json"));
|
|
1565
|
+
const hostMarkets = await readJsonFile(join9(hostClaude, "plugins", "known_marketplaces.json"));
|
|
1566
|
+
const mergedInstalled = mergeInstalledPlugins(hostInstalled, inv.registries["installed_plugins"], {
|
|
1567
|
+
hostHome
|
|
1568
|
+
});
|
|
1569
|
+
const mergedMarkets = mergeKnownMarketplaces(hostMarkets, inv.registries["known_marketplaces"], {
|
|
1570
|
+
hostHome
|
|
1571
|
+
});
|
|
1572
|
+
const mergedRegistries = [];
|
|
1573
|
+
if (mergedInstalled.changed) mergedRegistries.push("installed_plugins.json");
|
|
1574
|
+
if (mergedMarkets.changed) mergedRegistries.push("known_marketplaces.json");
|
|
1575
|
+
return { newItems, copyRels, mergedInstalled, mergedMarkets, mergedRegistries };
|
|
1576
|
+
}
|
|
1577
|
+
async function writeClaudeMergedRegistries(plan, opts = {}) {
|
|
1578
|
+
if (!plan.mergedInstalled.changed && !plan.mergedMarkets.changed) return;
|
|
1579
|
+
const hostClaude = join9(opts.hostHome ?? homedir6(), ".claude");
|
|
1580
|
+
await mkdir4(join9(hostClaude, "plugins"), { recursive: true });
|
|
1581
|
+
if (plan.mergedMarkets.changed) {
|
|
1582
|
+
await writeFile4(
|
|
1583
|
+
join9(hostClaude, "plugins", "known_marketplaces.json"),
|
|
1584
|
+
`${JSON.stringify(plan.mergedMarkets.data, null, 2)}
|
|
1585
|
+
`
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
if (plan.mergedInstalled.changed) {
|
|
1589
|
+
await writeFile4(
|
|
1590
|
+
join9(hostClaude, "plugins", "installed_plugins.json"),
|
|
1591
|
+
`${JSON.stringify(plan.mergedInstalled.data, null, 2)}
|
|
1592
|
+
`
|
|
1593
|
+
);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
async function pullClaudeExtrasViaTransport(t, opts = {}) {
|
|
1597
|
+
const boxDir = opts.boxDir ?? CLAUDE_BOX_CONFIG_DIR;
|
|
1598
|
+
const inv = await t.exec(["sh", "-c", claudeInventoryScript(boxDir)]);
|
|
1599
|
+
if (inv.exitCode !== 0) {
|
|
1600
|
+
throw new Error(
|
|
1601
|
+
`failed to inventory ${boxDir} in the box: ${inv.stderr.trim() || `exit ${String(inv.exitCode)}`}`
|
|
1602
|
+
);
|
|
1603
|
+
}
|
|
1604
|
+
const inventory = parseClaudeInventory(inv.stdout);
|
|
1605
|
+
const plan = await computeClaudePullPlan(inventory, { hostHome: opts.hostHome });
|
|
1606
|
+
const result = {
|
|
1607
|
+
newItems: plan.newItems,
|
|
1608
|
+
mergedRegistries: plan.mergedRegistries,
|
|
1609
|
+
sourceRegistries: inventory.registries
|
|
1610
|
+
};
|
|
1611
|
+
if (opts.dryRun || plan.newItems.length === 0 && plan.mergedRegistries.length === 0) {
|
|
1612
|
+
return result;
|
|
1613
|
+
}
|
|
1614
|
+
const hostClaude = join9(opts.hostHome ?? homedir6(), ".claude");
|
|
1615
|
+
for (const rel of plan.copyRels) {
|
|
1616
|
+
const hostDest = join9(hostClaude, rel);
|
|
1617
|
+
await mkdir4(hostDest, { recursive: true });
|
|
1618
|
+
await t.pullTree(`${boxDir}/${rel}`, hostDest, { exclude: ["node_modules"] });
|
|
1619
|
+
}
|
|
1620
|
+
await writeClaudeMergedRegistries(plan, { hostHome: opts.hostHome });
|
|
1621
|
+
return result;
|
|
1622
|
+
}
|
|
1623
|
+
var CODEX_PULL_ITEMS = ["config.toml", "auth.json", "prompts"];
|
|
1624
|
+
var OPENCODE_PULL_DATA_ITEMS = ["auth.json"];
|
|
1625
|
+
var OPENCODE_PULL_CONFIG_ITEMS = [
|
|
1626
|
+
"opencode.json",
|
|
1627
|
+
"opencode.jsonc",
|
|
1628
|
+
"agents",
|
|
1629
|
+
"commands",
|
|
1630
|
+
"modes",
|
|
1631
|
+
"plugins",
|
|
1632
|
+
"skills",
|
|
1633
|
+
"tools",
|
|
1634
|
+
"themes"
|
|
1635
|
+
];
|
|
1636
|
+
function flatInventoryScript(groups) {
|
|
1637
|
+
const parts = [];
|
|
1638
|
+
for (const [group, { dir, items }] of Object.entries(groups)) {
|
|
1639
|
+
parts.push(
|
|
1640
|
+
`for f in ${items.join(" ")}; do if [ -d "${dir}/$f" ]; then echo "${group} DIR $f"; elif [ -e "${dir}/$f" ]; then echo "${group} FILE $f"; fi; done;`
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
parts.push("true");
|
|
1644
|
+
return parts.join(" ");
|
|
1645
|
+
}
|
|
1646
|
+
function parseFlatInventory(stdout) {
|
|
1647
|
+
const out = [];
|
|
1648
|
+
for (const line of stdout.split("\n")) {
|
|
1649
|
+
const m = /^(\S+) (FILE|DIR) (\S+)$/.exec(line.trim());
|
|
1650
|
+
if (!m) continue;
|
|
1651
|
+
out.push({ group: m[1], kind: m[2] === "DIR" ? "dir" : "file", name: m[3] });
|
|
1652
|
+
}
|
|
1653
|
+
return out;
|
|
1654
|
+
}
|
|
1655
|
+
async function pathExists(path) {
|
|
1656
|
+
try {
|
|
1657
|
+
await stat4(path);
|
|
1658
|
+
return true;
|
|
1659
|
+
} catch {
|
|
1660
|
+
return false;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
async function pullFlatEntry(t, entry, boxPath, hostPath) {
|
|
1664
|
+
if (entry.kind === "dir") {
|
|
1665
|
+
await mkdir4(hostPath, { recursive: true });
|
|
1666
|
+
await t.pullTree(boxPath, hostPath, { exclude: ["node_modules"] });
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
await mkdir4(dirname6(hostPath), { recursive: true });
|
|
1670
|
+
await t.pullFile(boxPath, hostPath);
|
|
1671
|
+
if (entry.name === "auth.json") await chmod(hostPath, 384);
|
|
1672
|
+
}
|
|
1673
|
+
async function pullCodexConfigViaTransport(t, opts = {}) {
|
|
1674
|
+
const boxDir = opts.boxDir ?? CODEX_BOX_CONFIG_DIR;
|
|
1675
|
+
const hostCodex = join9(opts.hostHome ?? homedir6(), ".codex");
|
|
1676
|
+
const script = flatInventoryScript({ codex: { dir: boxDir, items: CODEX_PULL_ITEMS } });
|
|
1677
|
+
const inv = await t.exec(["sh", "-c", script]);
|
|
1678
|
+
if (inv.exitCode !== 0) {
|
|
1679
|
+
throw new Error(
|
|
1680
|
+
`failed to inventory ${boxDir} in the box: ${inv.stderr.trim() || `exit ${String(inv.exitCode)}`}`
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
const entries = [];
|
|
1684
|
+
for (const entry of parseFlatInventory(inv.stdout)) {
|
|
1685
|
+
if (await pathExists(join9(hostCodex, entry.name))) continue;
|
|
1686
|
+
entries.push(entry);
|
|
1687
|
+
}
|
|
1688
|
+
const newItems = entries.map((e) => e.name);
|
|
1689
|
+
if (opts.dryRun || entries.length === 0) return { newItems };
|
|
1690
|
+
for (const entry of entries) {
|
|
1691
|
+
await pullFlatEntry(t, entry, `${boxDir}/${entry.name}`, join9(hostCodex, entry.name));
|
|
1692
|
+
}
|
|
1693
|
+
return { newItems };
|
|
1694
|
+
}
|
|
1695
|
+
async function pullOpencodeConfigViaTransport(t, opts = {}) {
|
|
1696
|
+
const boxDir = opts.boxDir ?? OPENCODE_BOX_DATA_DIR;
|
|
1697
|
+
const hostHome = opts.hostHome ?? homedir6();
|
|
1698
|
+
const hostBases = {
|
|
1699
|
+
data: join9(hostHome, ".local", "share", "opencode"),
|
|
1700
|
+
config: join9(hostHome, ".config", "opencode")
|
|
1701
|
+
};
|
|
1702
|
+
const script = flatInventoryScript({
|
|
1703
|
+
data: { dir: boxDir, items: OPENCODE_PULL_DATA_ITEMS },
|
|
1704
|
+
config: { dir: `${boxDir}/config`, items: OPENCODE_PULL_CONFIG_ITEMS }
|
|
1705
|
+
});
|
|
1706
|
+
const inv = await t.exec(["sh", "-c", script]);
|
|
1707
|
+
if (inv.exitCode !== 0) {
|
|
1708
|
+
throw new Error(
|
|
1709
|
+
`failed to inventory ${boxDir} in the box: ${inv.stderr.trim() || `exit ${String(inv.exitCode)}`}`
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
const entries = [];
|
|
1713
|
+
for (const entry of parseFlatInventory(inv.stdout)) {
|
|
1714
|
+
if (entry.group !== "data" && entry.group !== "config") continue;
|
|
1715
|
+
const hostBase = hostBases[entry.group];
|
|
1716
|
+
if (await pathExists(join9(hostBase, entry.name))) continue;
|
|
1717
|
+
entries.push({ ...entry, label: entry.group === "data" ? entry.name : `config/${entry.name}` });
|
|
1718
|
+
}
|
|
1719
|
+
const newItems = entries.map((e) => e.label);
|
|
1720
|
+
if (opts.dryRun || entries.length === 0) return { newItems };
|
|
1721
|
+
for (const entry of entries) {
|
|
1722
|
+
const boxPath = entry.group === "data" ? `${boxDir}/${entry.name}` : `${boxDir}/config/${entry.name}`;
|
|
1723
|
+
const hostPath = join9(hostBases[entry.group], entry.name);
|
|
1724
|
+
await pullFlatEntry(t, entry, boxPath, hostPath);
|
|
1725
|
+
}
|
|
1726
|
+
return { newItems };
|
|
1727
|
+
}
|
|
1728
|
+
function agentBoxConfigDir(agent) {
|
|
1729
|
+
switch (agent) {
|
|
1730
|
+
case "claude":
|
|
1731
|
+
return CLAUDE_BOX_CONFIG_DIR;
|
|
1732
|
+
case "codex":
|
|
1733
|
+
return CODEX_BOX_CONFIG_DIR;
|
|
1734
|
+
default:
|
|
1735
|
+
return OPENCODE_BOX_DATA_DIR;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
function claudeStagedItems(result) {
|
|
1739
|
+
return result.newItems.map((it) => ({
|
|
1740
|
+
rel: it.category === "plugins" ? `plugins/cache/${it.name}` : `${it.category}/${it.name}`,
|
|
1741
|
+
label: `${it.category}/${it.name}`,
|
|
1742
|
+
kind: "dir"
|
|
1743
|
+
}));
|
|
1744
|
+
}
|
|
1745
|
+
function codexStagedItems(newItems) {
|
|
1746
|
+
return newItems.map((name) => ({
|
|
1747
|
+
rel: name,
|
|
1748
|
+
label: name,
|
|
1749
|
+
kind: name === "prompts" ? "dir" : "file"
|
|
1750
|
+
}));
|
|
1751
|
+
}
|
|
1752
|
+
function opencodeStagedItems(newItems) {
|
|
1753
|
+
return newItems.map((label) => {
|
|
1754
|
+
const name = label.startsWith("config/") ? label.slice("config/".length) : label;
|
|
1755
|
+
const isFile = name === "auth.json" || name === "opencode.json" || name === "opencode.jsonc";
|
|
1756
|
+
return { rel: label, label, kind: isFile ? "file" : "dir" };
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
async function stageItemsViaTransport(t, boxDir, items, stagingDir) {
|
|
1760
|
+
for (const item of items) {
|
|
1761
|
+
const dest = join10(stagingDir, item.rel);
|
|
1762
|
+
if (item.kind === "dir") {
|
|
1763
|
+
await mkdir5(dest, { recursive: true });
|
|
1764
|
+
await t.pullTree(`${boxDir}/${item.rel}`, dest, { exclude: ["node_modules"] });
|
|
1765
|
+
} else {
|
|
1766
|
+
await mkdir5(dirname7(dest), { recursive: true });
|
|
1767
|
+
await t.pullFile(`${boxDir}/${item.rel}`, dest);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
async function makeStagingDir(agent) {
|
|
1772
|
+
return mkdtemp2(join10(tmpdir2(), `agentbox-${agent}-propagate-`));
|
|
1773
|
+
}
|
|
1774
|
+
async function removeStagingDir(stagingDir) {
|
|
1775
|
+
await rm3(stagingDir, { recursive: true, force: true });
|
|
1776
|
+
}
|
|
1777
|
+
function transportSettingsTarget(t, boxDir, label) {
|
|
1778
|
+
const abs = (rel) => `${boxDir}/${rel}`;
|
|
1779
|
+
return {
|
|
1780
|
+
label,
|
|
1781
|
+
async exists(rel) {
|
|
1782
|
+
const r = await t.exec(["sh", "-c", `test -e '${abs(rel)}'`]);
|
|
1783
|
+
return r.exitCode === 0;
|
|
1784
|
+
},
|
|
1785
|
+
readText(rel) {
|
|
1786
|
+
return t.readText(abs(rel));
|
|
1787
|
+
},
|
|
1788
|
+
async writeText(rel, content, opts) {
|
|
1789
|
+
const stage = await mkdtemp2(join10(tmpdir2(), "agentbox-target-write-"));
|
|
1790
|
+
try {
|
|
1791
|
+
const tmp = join10(stage, "file");
|
|
1792
|
+
await writeFile5(tmp, content);
|
|
1793
|
+
await t.exec(["sh", "-c", `mkdir -p '${dirname7(abs(rel))}'`]);
|
|
1794
|
+
await t.pushFile(tmp, abs(rel));
|
|
1795
|
+
if (opts?.mode !== void 0) {
|
|
1796
|
+
await t.exec(["sh", "-c", `chmod ${opts.mode.toString(8)} '${abs(rel)}'`]);
|
|
1797
|
+
}
|
|
1798
|
+
} finally {
|
|
1799
|
+
await rm3(stage, { recursive: true, force: true });
|
|
1800
|
+
}
|
|
1801
|
+
},
|
|
1802
|
+
async copyIn(stagingAbs, rel, kind) {
|
|
1803
|
+
if (kind === "dir") {
|
|
1804
|
+
await t.exec(["sh", "-c", `mkdir -p '${abs(rel)}'`]);
|
|
1805
|
+
await t.pushTree(stagingAbs, abs(rel), { exclude: ["node_modules"] });
|
|
1806
|
+
} else {
|
|
1807
|
+
await t.exec(["sh", "-c", `mkdir -p '${dirname7(abs(rel))}'`]);
|
|
1808
|
+
await t.pushFile(stagingAbs, abs(rel));
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
var CLAUDE_REGISTRY_FILES = [
|
|
1814
|
+
{ key: "installed_plugins", rel: "plugins/installed_plugins.json" },
|
|
1815
|
+
{ key: "known_marketplaces", rel: "plugins/known_marketplaces.json" }
|
|
1816
|
+
];
|
|
1817
|
+
async function propagateStagedSettings(target, staged) {
|
|
1818
|
+
const result = {
|
|
1819
|
+
target: target.label,
|
|
1820
|
+
copied: [],
|
|
1821
|
+
skipped: [],
|
|
1822
|
+
mergedRegistries: []
|
|
1823
|
+
};
|
|
1824
|
+
for (const item of staged.items) {
|
|
1825
|
+
if (await target.exists(item.rel)) {
|
|
1826
|
+
result.skipped.push(item.label);
|
|
1827
|
+
continue;
|
|
1828
|
+
}
|
|
1829
|
+
await target.copyIn(join10(staged.stagingDir, item.rel), item.rel, item.kind);
|
|
1830
|
+
result.copied.push(item.label);
|
|
1831
|
+
}
|
|
1832
|
+
if (staged.agent === "claude" && staged.sourceRegistries) {
|
|
1833
|
+
for (const { key, rel } of CLAUDE_REGISTRY_FILES) {
|
|
1834
|
+
const source = staged.sourceRegistries[key];
|
|
1835
|
+
if (source === void 0) continue;
|
|
1836
|
+
const raw = await target.readText(rel);
|
|
1837
|
+
let targetJson;
|
|
1838
|
+
try {
|
|
1839
|
+
targetJson = raw === null ? void 0 : JSON.parse(raw);
|
|
1840
|
+
} catch {
|
|
1841
|
+
targetJson = void 0;
|
|
1842
|
+
}
|
|
1843
|
+
const merged = key === "installed_plugins" ? mergeInstalledPlugins(targetJson, source, { hostHome: "/home/vscode" }) : mergeKnownMarketplaces(targetJson, source, { hostHome: "/home/vscode" });
|
|
1844
|
+
if (!merged.changed) continue;
|
|
1845
|
+
await target.writeText(rel, `${JSON.stringify(merged.data, null, 2)}
|
|
1846
|
+
`);
|
|
1847
|
+
result.mergedRegistries.push(rel);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return result;
|
|
1851
|
+
}
|
|
1852
|
+
function isolatedVolumeOf(box, agent) {
|
|
1853
|
+
switch (agent) {
|
|
1854
|
+
case "claude":
|
|
1855
|
+
return box.claudeConfigVolume;
|
|
1856
|
+
case "codex":
|
|
1857
|
+
return box.codexConfigVolume;
|
|
1858
|
+
default:
|
|
1859
|
+
return box.opencodeConfigVolume;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
function planPropagateTargets(boxes, opts) {
|
|
1863
|
+
const sharedVolume = resolveAgentSpec(opts.agent).dockerVolume;
|
|
1864
|
+
const inScope = boxes.filter(
|
|
1865
|
+
(b) => b.id !== opts.sourceBoxId && (opts.scope === "all" || (b.projectRoot ?? "") === (opts.projectRoot ?? ""))
|
|
1866
|
+
);
|
|
1867
|
+
const volumes = /* @__PURE__ */ new Map();
|
|
1868
|
+
const cloudBoxes = [];
|
|
1869
|
+
for (const box of inScope) {
|
|
1870
|
+
if ((box.provider ?? "docker") !== "docker") {
|
|
1871
|
+
cloudBoxes.push(box);
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
const volume = isolatedVolumeOf(box, opts.agent) ?? sharedVolume;
|
|
1875
|
+
if (volume === opts.excludeVolume) continue;
|
|
1876
|
+
const entry = volumes.get(volume) ?? { boxNames: [], shared: volume === sharedVolume };
|
|
1877
|
+
entry.boxNames.push(box.name);
|
|
1878
|
+
volumes.set(volume, entry);
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
dockerVolumes: [...volumes.entries()].map(([volume, v]) => ({ volume, ...v })),
|
|
1882
|
+
cloudBoxes
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1319
1885
|
function makeSyncContext(init) {
|
|
1320
1886
|
return {
|
|
1321
1887
|
boxName: init.boxName,
|
|
@@ -1324,7 +1890,7 @@ function makeSyncContext(init) {
|
|
|
1324
1890
|
hostWorkspace: init.hostWorkspace,
|
|
1325
1891
|
projectRoot: init.projectRoot ?? init.hostWorkspace,
|
|
1326
1892
|
boxWorkspace: init.boxWorkspace ?? "/workspace",
|
|
1327
|
-
hostHome: init.hostHome ??
|
|
1893
|
+
hostHome: init.hostHome ?? homedir7(),
|
|
1328
1894
|
onLog: init.onLog ?? (() => {
|
|
1329
1895
|
})
|
|
1330
1896
|
};
|
|
@@ -1396,8 +1962,8 @@ async function scanHostEnvFiles(workspaceDir, patterns) {
|
|
|
1396
1962
|
async function pushEnvFiles(ctx, transport, patterns) {
|
|
1397
1963
|
const list = await findEnvFilesForTar(ctx.hostWorkspace, patterns);
|
|
1398
1964
|
if (list.length === 0) return { copied: 0 };
|
|
1399
|
-
const stage = await
|
|
1400
|
-
const localTar =
|
|
1965
|
+
const stage = await mkdtemp3(join11(tmpdir3(), "agentbox-envfiles-"));
|
|
1966
|
+
const localTar = join11(stage, "envfiles.tar");
|
|
1401
1967
|
try {
|
|
1402
1968
|
const packed = await execa3(
|
|
1403
1969
|
"tar",
|
|
@@ -1417,7 +1983,7 @@ async function pushEnvFiles(ctx, transport, patterns) {
|
|
|
1417
1983
|
return { copied: 0 };
|
|
1418
1984
|
}
|
|
1419
1985
|
} finally {
|
|
1420
|
-
await
|
|
1986
|
+
await rm4(stage, { recursive: true, force: true });
|
|
1421
1987
|
}
|
|
1422
1988
|
return { copied: list.length };
|
|
1423
1989
|
}
|
|
@@ -1457,9 +2023,9 @@ function planCarryEntry(entry) {
|
|
|
1457
2023
|
parentChainNeeded
|
|
1458
2024
|
};
|
|
1459
2025
|
}
|
|
1460
|
-
async function
|
|
2026
|
+
async function pathExists2(p) {
|
|
1461
2027
|
try {
|
|
1462
|
-
await
|
|
2028
|
+
await stat5(p);
|
|
1463
2029
|
return true;
|
|
1464
2030
|
} catch {
|
|
1465
2031
|
return false;
|
|
@@ -1469,18 +2035,18 @@ function encodeClaudeProjectsKey(absPath) {
|
|
|
1469
2035
|
return absPath.replace(/[^a-zA-Z0-9]/g, "-");
|
|
1470
2036
|
}
|
|
1471
2037
|
var BOX_CLAUDE_PROJECT_DIR = "/home/vscode/.claude/projects/-workspace";
|
|
1472
|
-
async function resolveClaudeMemoryDir(hostWorkspace, hostHome =
|
|
2038
|
+
async function resolveClaudeMemoryDir(hostWorkspace, hostHome = homedir8()) {
|
|
1473
2039
|
if (hostWorkspace.length === 0) return null;
|
|
1474
|
-
const memDir =
|
|
2040
|
+
const memDir = join12(
|
|
1475
2041
|
hostHome,
|
|
1476
2042
|
".claude",
|
|
1477
2043
|
"projects",
|
|
1478
2044
|
encodeClaudeProjectsKey(hostWorkspace),
|
|
1479
2045
|
"memory"
|
|
1480
2046
|
);
|
|
1481
|
-
if (!await
|
|
2047
|
+
if (!await pathExists2(memDir)) return null;
|
|
1482
2048
|
try {
|
|
1483
|
-
const entries = await
|
|
2049
|
+
const entries = await readdir3(memDir);
|
|
1484
2050
|
if (entries.length === 0) return null;
|
|
1485
2051
|
} catch {
|
|
1486
2052
|
return null;
|
|
@@ -1509,13 +2075,13 @@ async function findUnsyncableSymlinks(root, reachableRoots) {
|
|
|
1509
2075
|
try {
|
|
1510
2076
|
let entries;
|
|
1511
2077
|
try {
|
|
1512
|
-
entries = await
|
|
2078
|
+
entries = await readdir4(realDir, { withFileTypes: true });
|
|
1513
2079
|
} catch {
|
|
1514
2080
|
return;
|
|
1515
2081
|
}
|
|
1516
2082
|
for (const ent of entries) {
|
|
1517
|
-
const realFull =
|
|
1518
|
-
const virtualFull = virtualDir ?
|
|
2083
|
+
const realFull = join13(realDir, ent.name);
|
|
2084
|
+
const virtualFull = virtualDir ? join13(virtualDir, ent.name) : ent.name;
|
|
1519
2085
|
if (ent.isSymbolicLink()) {
|
|
1520
2086
|
let real;
|
|
1521
2087
|
try {
|
|
@@ -1528,7 +2094,7 @@ async function findUnsyncableSymlinks(root, reachableRoots) {
|
|
|
1528
2094
|
unsyncable.push(virtualFull);
|
|
1529
2095
|
continue;
|
|
1530
2096
|
}
|
|
1531
|
-
const st = await
|
|
2097
|
+
const st = await stat6(real).catch(() => null);
|
|
1532
2098
|
if (st?.isDirectory()) await walk(real, virtualFull);
|
|
1533
2099
|
} else if (ent.isDirectory()) {
|
|
1534
2100
|
await walk(realFull, virtualFull);
|
|
@@ -1541,9 +2107,9 @@ async function findUnsyncableSymlinks(root, reachableRoots) {
|
|
|
1541
2107
|
await walk(root, "");
|
|
1542
2108
|
return unsyncable;
|
|
1543
2109
|
}
|
|
1544
|
-
async function
|
|
2110
|
+
async function pathExists3(p) {
|
|
1545
2111
|
try {
|
|
1546
|
-
await
|
|
2112
|
+
await stat7(p);
|
|
1547
2113
|
return true;
|
|
1548
2114
|
} catch {
|
|
1549
2115
|
return false;
|
|
@@ -1552,7 +2118,7 @@ async function pathExists2(p) {
|
|
|
1552
2118
|
async function seedAgentsVolume(args) {
|
|
1553
2119
|
const seed = args.transport.seedVolumeFromHost;
|
|
1554
2120
|
if (!seed) throw new Error("seedAgentsVolume requires a transport with seedVolumeFromHost");
|
|
1555
|
-
const willSync = args.syncFromHost && await
|
|
2121
|
+
const willSync = args.syncFromHost && await pathExists3(args.hostAgents);
|
|
1556
2122
|
if (!willSync) {
|
|
1557
2123
|
try {
|
|
1558
2124
|
await seed.call(args.transport, args.volume, []);
|
|
@@ -1593,7 +2159,7 @@ function isRealAgentCredential(agent, text) {
|
|
|
1593
2159
|
}
|
|
1594
2160
|
async function hostClaudeBackupExpired(path = CLAUDE_HOST_BACKUP, now = Date.now()) {
|
|
1595
2161
|
try {
|
|
1596
|
-
const parsed = JSON.parse(await
|
|
2162
|
+
const parsed = JSON.parse(await readFile6(path, "utf8"));
|
|
1597
2163
|
const exp = parsed?.claudeAiOauth?.expiresAt;
|
|
1598
2164
|
return typeof exp === "number" && Number.isFinite(exp) && exp < now;
|
|
1599
2165
|
} catch {
|
|
@@ -1602,7 +2168,7 @@ async function hostClaudeBackupExpired(path = CLAUDE_HOST_BACKUP, now = Date.now
|
|
|
1602
2168
|
}
|
|
1603
2169
|
async function hostBackupHasCredentials(path = CLAUDE_HOST_BACKUP) {
|
|
1604
2170
|
try {
|
|
1605
|
-
const parsed = JSON.parse(await
|
|
2171
|
+
const parsed = JSON.parse(await readFile6(path, "utf8"));
|
|
1606
2172
|
const rt = parsed?.claudeAiOauth?.refreshToken;
|
|
1607
2173
|
return typeof rt === "string" && rt.length > 0;
|
|
1608
2174
|
} catch {
|
|
@@ -1618,9 +2184,9 @@ async function extractCredentials(transport, opts = {}) {
|
|
|
1618
2184
|
try {
|
|
1619
2185
|
const text = await transport.readText(spec.credential.boxAbsPath);
|
|
1620
2186
|
if (!text || !isRealAgentCredential(spec.id, text)) continue;
|
|
1621
|
-
await
|
|
1622
|
-
await
|
|
1623
|
-
await
|
|
2187
|
+
await mkdir6(dirname8(hostBackup), { recursive: true });
|
|
2188
|
+
await writeFile6(hostBackup, text, { mode: 384 });
|
|
2189
|
+
await chmod2(hostBackup, 384).catch(() => {
|
|
1624
2190
|
});
|
|
1625
2191
|
extracted.push(spec.id);
|
|
1626
2192
|
log(`extracted ${spec.id} login from box to ${hostBackup}`);
|
|
@@ -1632,6 +2198,72 @@ async function extractCredentials(transport, opts = {}) {
|
|
|
1632
2198
|
}
|
|
1633
2199
|
return extracted;
|
|
1634
2200
|
}
|
|
2201
|
+
var MAX_CREDENTIAL_BYTES = 256 * 1024;
|
|
2202
|
+
function claudeExpiresAt(text) {
|
|
2203
|
+
try {
|
|
2204
|
+
const parsed = JSON.parse(text);
|
|
2205
|
+
const exp = parsed?.claudeAiOauth?.expiresAt;
|
|
2206
|
+
return typeof exp === "number" && Number.isFinite(exp) ? exp : null;
|
|
2207
|
+
} catch {
|
|
2208
|
+
return null;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
function shouldAcceptCredentialUpdate(agent, incoming, existing) {
|
|
2212
|
+
if (existing === null) return { accept: true, reason: "no existing backup" };
|
|
2213
|
+
if (existing === incoming) return { accept: false, reason: "unchanged" };
|
|
2214
|
+
if (resolveAgentSpec(agent).credential.realShape === "claude-oauth") {
|
|
2215
|
+
const incomingExp = claudeExpiresAt(incoming);
|
|
2216
|
+
const existingExp = claudeExpiresAt(existing);
|
|
2217
|
+
if (incomingExp === null) return { accept: false, reason: "incoming blob has no expiresAt" };
|
|
2218
|
+
if (existingExp !== null && incomingExp <= existingExp) {
|
|
2219
|
+
return { accept: false, reason: "not newer than backup" };
|
|
2220
|
+
}
|
|
2221
|
+
return { accept: true, reason: "newer expiresAt" };
|
|
2222
|
+
}
|
|
2223
|
+
return { accept: true, reason: "content changed" };
|
|
2224
|
+
}
|
|
2225
|
+
async function writeCredentialBackup(agent, content, opts = {}) {
|
|
2226
|
+
const path = opts.backupPath ?? resolveAgentSpec(agent).credential.hostBackup;
|
|
2227
|
+
await mkdir6(dirname8(path), { recursive: true });
|
|
2228
|
+
const tmp = `${path}.tmp-${String(process.pid)}`;
|
|
2229
|
+
await writeFile6(tmp, content, { mode: 384 });
|
|
2230
|
+
await rename3(tmp, path);
|
|
2231
|
+
await chmod2(path, 384).catch(() => {
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
async function readCredentialBackup(agent, opts = {}) {
|
|
2235
|
+
const path = opts.backupPath ?? resolveAgentSpec(agent).credential.hostBackup;
|
|
2236
|
+
try {
|
|
2237
|
+
return await readFile6(path, "utf8");
|
|
2238
|
+
} catch {
|
|
2239
|
+
return null;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
async function pushCredentialToBox(transport, agent, content) {
|
|
2243
|
+
const abs = resolveAgentSpec(agent).credential.boxAbsPath;
|
|
2244
|
+
const dir = abs.slice(0, abs.lastIndexOf("/"));
|
|
2245
|
+
const stage = await mkdtemp4(join14(tmpdir4(), "agentbox-cred-push-"));
|
|
2246
|
+
try {
|
|
2247
|
+
const tmp = join14(stage, "credential");
|
|
2248
|
+
await writeFile6(tmp, content, { mode: 384 });
|
|
2249
|
+
const mk = await transport.exec(["sh", "-c", `mkdir -p '${dir}'`]);
|
|
2250
|
+
if (mk.exitCode !== 0) {
|
|
2251
|
+
throw new Error(`mkdir ${dir} in box failed: ${mk.stderr.trim()}`);
|
|
2252
|
+
}
|
|
2253
|
+
await transport.pushFile(tmp, abs);
|
|
2254
|
+
const normalize22 = `chown "$(id -un):" '${abs}' && chmod 600 '${abs}'`;
|
|
2255
|
+
const norm = await transport.exec([
|
|
2256
|
+
"sh",
|
|
2257
|
+
"-c",
|
|
2258
|
+
`{ ${normalize22}; } 2>/dev/null || sudo sh -c "${normalize22.replaceAll('"', '\\"')}"`
|
|
2259
|
+
]);
|
|
2260
|
+
if (norm.exitCode !== 0) {
|
|
2261
|
+
throw new Error(`chown/chmod of ${abs} in box failed: ${norm.stderr.trim()}`);
|
|
2262
|
+
}
|
|
2263
|
+
} finally {
|
|
2264
|
+
await rm5(stage, { recursive: true, force: true });
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
1635
2267
|
var NON_REGULAR_TOKEN = "-";
|
|
1636
2268
|
function classifyUntrackedOverlay(boxToken, hostHash) {
|
|
1637
2269
|
if (boxToken === void 0) return "copy";
|
|
@@ -1780,7 +2412,7 @@ function makeHostGitPorts() {
|
|
|
1780
2412
|
return untracked.exitCode === 0 ? splitNul(untracked.stdout) : [];
|
|
1781
2413
|
},
|
|
1782
2414
|
async hashHostFile(hostMain, relPath) {
|
|
1783
|
-
return createHash("sha256").update(await
|
|
2415
|
+
return createHash("sha256").update(await readFile7(join15(hostMain, relPath))).digest("hex");
|
|
1784
2416
|
},
|
|
1785
2417
|
async packHostFiles(hostMain, relPaths) {
|
|
1786
2418
|
const tarOut = await execa4("tar", ["-C", hostMain, "--null", "-T", "-", "-cf", "-"], {
|
|
@@ -1795,9 +2427,9 @@ function makeHostGitPorts() {
|
|
|
1795
2427
|
var BOX_WORKFLOWS_DIR = "/home/vscode/.claude/workflows";
|
|
1796
2428
|
var BOX_DYNAMIC_SYNC_MANIFEST = "/home/vscode/.agentbox/dynamic-sync.json";
|
|
1797
2429
|
var BOX_MEMORY_DIR = `${BOX_CLAUDE_PROJECT_DIR}/memory`;
|
|
1798
|
-
async function
|
|
2430
|
+
async function pathExists4(p) {
|
|
1799
2431
|
try {
|
|
1800
|
-
await
|
|
2432
|
+
await stat8(p);
|
|
1801
2433
|
return true;
|
|
1802
2434
|
} catch {
|
|
1803
2435
|
return false;
|
|
@@ -1806,21 +2438,21 @@ async function pathExists3(p) {
|
|
|
1806
2438
|
async function walkFiles(root, prefix = "") {
|
|
1807
2439
|
let entries;
|
|
1808
2440
|
try {
|
|
1809
|
-
entries = await
|
|
2441
|
+
entries = await readdir5(root, { withFileTypes: true });
|
|
1810
2442
|
} catch {
|
|
1811
2443
|
return [];
|
|
1812
2444
|
}
|
|
1813
2445
|
const out = [];
|
|
1814
2446
|
for (const ent of entries) {
|
|
1815
2447
|
const rel = prefix ? `${prefix}/${ent.name}` : ent.name;
|
|
1816
|
-
const full =
|
|
2448
|
+
const full = join16(root, ent.name);
|
|
1817
2449
|
if (ent.isDirectory()) {
|
|
1818
2450
|
out.push(...await walkFiles(full, rel));
|
|
1819
2451
|
} else if (ent.isFile()) {
|
|
1820
2452
|
out.push(rel);
|
|
1821
2453
|
} else if (ent.isSymbolicLink()) {
|
|
1822
2454
|
try {
|
|
1823
|
-
const s = await
|
|
2455
|
+
const s = await stat8(full);
|
|
1824
2456
|
if (s.isFile()) out.push(rel);
|
|
1825
2457
|
} catch {
|
|
1826
2458
|
}
|
|
@@ -1829,7 +2461,7 @@ async function walkFiles(root, prefix = "") {
|
|
|
1829
2461
|
return out;
|
|
1830
2462
|
}
|
|
1831
2463
|
async function hashFile(absPath) {
|
|
1832
|
-
const buf = await
|
|
2464
|
+
const buf = await readFile8(absPath);
|
|
1833
2465
|
return createHash2("sha256").update(buf).digest("hex");
|
|
1834
2466
|
}
|
|
1835
2467
|
async function buildHostSet(name, hostDir, boxDst) {
|
|
@@ -1837,13 +2469,13 @@ async function buildHostSet(name, hostDir, boxDst) {
|
|
|
1837
2469
|
const rels = await walkFiles(hostDir);
|
|
1838
2470
|
const files = {};
|
|
1839
2471
|
for (const rel of rels) {
|
|
1840
|
-
files[rel] = await hashFile(
|
|
2472
|
+
files[rel] = await hashFile(join16(hostDir, rel));
|
|
1841
2473
|
}
|
|
1842
2474
|
return { dst: boxDst, files, hostDir };
|
|
1843
2475
|
}
|
|
1844
|
-
async function buildHostSyncManifest(workspacePath, hostHome =
|
|
1845
|
-
const workflowsDir =
|
|
1846
|
-
const workflowsHost = await
|
|
2476
|
+
async function buildHostSyncManifest(workspacePath, hostHome = homedir9()) {
|
|
2477
|
+
const workflowsDir = join16(hostHome, ".claude", "workflows");
|
|
2478
|
+
const workflowsHost = await pathExists4(workflowsDir) ? workflowsDir : null;
|
|
1847
2479
|
const memoryHost = await resolveClaudeMemoryDir(workspacePath, hostHome);
|
|
1848
2480
|
const [workflows, memory] = await Promise.all([
|
|
1849
2481
|
buildHostSet("workflows", workflowsHost, BOX_WORKFLOWS_DIR),
|
|
@@ -1864,7 +2496,7 @@ function computeSyncDelta(host, box) {
|
|
|
1864
2496
|
uploads.push({
|
|
1865
2497
|
set: name,
|
|
1866
2498
|
rel,
|
|
1867
|
-
absSrc:
|
|
2499
|
+
absSrc: join16(hostSet.hostDir, rel),
|
|
1868
2500
|
dst: `${hostSet.dst}/${rel}`
|
|
1869
2501
|
});
|
|
1870
2502
|
}
|
|
@@ -1883,15 +2515,15 @@ async function stageDynamicSyncTarball(uploads) {
|
|
|
1883
2515
|
return { tarballPath: null, cleanup: async () => {
|
|
1884
2516
|
} };
|
|
1885
2517
|
}
|
|
1886
|
-
const stageDir = await
|
|
2518
|
+
const stageDir = await mkdtemp5(join16(tmpdir5(), "agentbox-dynsync-stage-"));
|
|
1887
2519
|
let tarballPath = null;
|
|
1888
2520
|
try {
|
|
1889
2521
|
for (const up of uploads) {
|
|
1890
|
-
const target =
|
|
1891
|
-
await
|
|
2522
|
+
const target = join16(stageDir, up.set, up.rel);
|
|
2523
|
+
await mkdir7(dirname9(target), { recursive: true });
|
|
1892
2524
|
await copyFile(up.absSrc, target);
|
|
1893
2525
|
}
|
|
1894
|
-
tarballPath =
|
|
2526
|
+
tarballPath = join16(tmpdir5(), `agentbox-dynsync-${basename22(stageDir)}.tar.gz`);
|
|
1895
2527
|
await execa5("tar", ["-czf", tarballPath, "-C", stageDir, "."], {
|
|
1896
2528
|
env: { ...process.env, COPYFILE_DISABLE: "1" }
|
|
1897
2529
|
});
|
|
@@ -1899,13 +2531,13 @@ async function stageDynamicSyncTarball(uploads) {
|
|
|
1899
2531
|
return {
|
|
1900
2532
|
tarballPath: tp,
|
|
1901
2533
|
cleanup: async () => {
|
|
1902
|
-
await
|
|
1903
|
-
await
|
|
2534
|
+
await rm6(stageDir, { recursive: true, force: true });
|
|
2535
|
+
await rm6(tp, { force: true });
|
|
1904
2536
|
}
|
|
1905
2537
|
};
|
|
1906
2538
|
} catch (err) {
|
|
1907
|
-
await
|
|
1908
|
-
if (tarballPath) await
|
|
2539
|
+
await rm6(stageDir, { recursive: true, force: true });
|
|
2540
|
+
if (tarballPath) await rm6(tarballPath, { force: true });
|
|
1909
2541
|
throw err;
|
|
1910
2542
|
}
|
|
1911
2543
|
}
|
|
@@ -2025,7 +2657,7 @@ var BOX_WORKSPACE2 = "/workspace";
|
|
|
2025
2657
|
var MINIMAL_TRUSTED_CODEX_CONFIG = `[projects."${BOX_WORKSPACE2}"]
|
|
2026
2658
|
trust_level = "trusted"
|
|
2027
2659
|
`;
|
|
2028
|
-
function sanitizeCodexConfigForBox(tomlText, hostHome =
|
|
2660
|
+
function sanitizeCodexConfigForBox(tomlText, hostHome = homedir10()) {
|
|
2029
2661
|
const cfg = parse(tomlText);
|
|
2030
2662
|
let changed = false;
|
|
2031
2663
|
if (isRecord(cfg["mcp_servers"])) {
|
|
@@ -2071,13 +2703,52 @@ function sanitizeCodexConfigForBox(tomlText, hostHome = homedir9()) {
|
|
|
2071
2703
|
projects[BOX_WORKSPACE2] = wsEntry;
|
|
2072
2704
|
changed = true;
|
|
2073
2705
|
}
|
|
2074
|
-
|
|
2706
|
+
const keptMarketplaces = isRecord(cfg["marketplaces"]) ? Object.keys(cfg["marketplaces"]) : [];
|
|
2707
|
+
return { text: changed ? stringify(cfg) : tomlText, changed, keptMarketplaces };
|
|
2708
|
+
}
|
|
2709
|
+
var BOX_MERGED_TABLES = ["marketplaces", "plugins", "mcp_servers", "projects"];
|
|
2710
|
+
function mergeCodexConfigForBox(hostSanitizedText, boxText) {
|
|
2711
|
+
const host = parse(hostSanitizedText);
|
|
2712
|
+
const hostMarketplaces = () => isRecord(host["marketplaces"]) ? Object.keys(host["marketplaces"]) : [];
|
|
2713
|
+
if (boxText === null) {
|
|
2714
|
+
return { text: hostSanitizedText, marketplaces: hostMarketplaces(), mergedFromBox: false };
|
|
2715
|
+
}
|
|
2716
|
+
let box;
|
|
2717
|
+
try {
|
|
2718
|
+
box = parse(boxText);
|
|
2719
|
+
} catch {
|
|
2720
|
+
return { text: hostSanitizedText, marketplaces: hostMarketplaces(), mergedFromBox: false };
|
|
2721
|
+
}
|
|
2722
|
+
let merged = false;
|
|
2723
|
+
for (const table of BOX_MERGED_TABLES) {
|
|
2724
|
+
const boxTable = box[table];
|
|
2725
|
+
if (!isRecord(boxTable)) continue;
|
|
2726
|
+
const hostTable = isRecord(host[table]) ? host[table] : {};
|
|
2727
|
+
for (const [name, def] of Object.entries(boxTable)) {
|
|
2728
|
+
if (name in hostTable) continue;
|
|
2729
|
+
hostTable[name] = def;
|
|
2730
|
+
merged = true;
|
|
2731
|
+
}
|
|
2732
|
+
if (Object.keys(hostTable).length > 0) host[table] = hostTable;
|
|
2733
|
+
}
|
|
2734
|
+
for (const [key, value] of Object.entries(box)) {
|
|
2735
|
+
if (BOX_MERGED_TABLES.includes(key)) continue;
|
|
2736
|
+
if (key in host) continue;
|
|
2737
|
+
host[key] = value;
|
|
2738
|
+
merged = true;
|
|
2739
|
+
}
|
|
2740
|
+
const marketplaces = isRecord(host["marketplaces"]) ? Object.keys(host["marketplaces"]) : [];
|
|
2741
|
+
return {
|
|
2742
|
+
text: merged ? stringify(host) : hostSanitizedText,
|
|
2743
|
+
marketplaces,
|
|
2744
|
+
mergedFromBox: merged
|
|
2745
|
+
};
|
|
2075
2746
|
}
|
|
2076
2747
|
var CREDENTIALS_BACKUP_FILE = resolveAgentSpec("claude").credential.hostBackup;
|
|
2077
2748
|
var CLOUD_WORKSPACE = "/workspace";
|
|
2078
|
-
async function
|
|
2749
|
+
async function pathExists5(p) {
|
|
2079
2750
|
try {
|
|
2080
|
-
await
|
|
2751
|
+
await stat9(p);
|
|
2081
2752
|
return true;
|
|
2082
2753
|
} catch {
|
|
2083
2754
|
return false;
|
|
@@ -2088,15 +2759,15 @@ async function findBrokenSymlinks(root) {
|
|
|
2088
2759
|
async function walk(dir) {
|
|
2089
2760
|
let entries;
|
|
2090
2761
|
try {
|
|
2091
|
-
entries = await
|
|
2762
|
+
entries = await readdir6(dir, { withFileTypes: true });
|
|
2092
2763
|
} catch {
|
|
2093
2764
|
return;
|
|
2094
2765
|
}
|
|
2095
2766
|
for (const ent of entries) {
|
|
2096
|
-
const full =
|
|
2767
|
+
const full = join17(dir, ent.name);
|
|
2097
2768
|
if (ent.isSymbolicLink()) {
|
|
2098
2769
|
try {
|
|
2099
|
-
await
|
|
2770
|
+
await stat9(full);
|
|
2100
2771
|
} catch {
|
|
2101
2772
|
broken.push(relative2(root, full));
|
|
2102
2773
|
}
|
|
@@ -2109,14 +2780,15 @@ async function findBrokenSymlinks(root) {
|
|
|
2109
2780
|
return broken;
|
|
2110
2781
|
}
|
|
2111
2782
|
async function mkStageDir(prefix) {
|
|
2112
|
-
return
|
|
2783
|
+
return mkdtemp6(join17(tmpdir6(), `agentbox-${prefix}-stage-`));
|
|
2113
2784
|
}
|
|
2785
|
+
var STAGE_WRITABLE_CHMOD = "--chmod=Du+rwx,Fu+rw";
|
|
2114
2786
|
function emptyResult(warnings = []) {
|
|
2115
2787
|
return { tarballPath: null, cleanup: async () => {
|
|
2116
2788
|
}, warnings };
|
|
2117
2789
|
}
|
|
2118
2790
|
async function tarballFromDir(stageDir, agent) {
|
|
2119
|
-
const tarballPath =
|
|
2791
|
+
const tarballPath = join17(tmpdir6(), `agentbox-${agent}-${basename3(stageDir)}.tar.gz`);
|
|
2120
2792
|
await execa6("tar", ["-czf", tarballPath, "-C", stageDir, "."], {
|
|
2121
2793
|
env: { ...process.env, COPYFILE_DISABLE: "1" }
|
|
2122
2794
|
});
|
|
@@ -2125,7 +2797,7 @@ async function tarballFromDir(stageDir, agent) {
|
|
|
2125
2797
|
function makeCleanup(paths) {
|
|
2126
2798
|
return async () => {
|
|
2127
2799
|
for (const p of paths) {
|
|
2128
|
-
await
|
|
2800
|
+
await rm7(p, { recursive: true, force: true });
|
|
2129
2801
|
}
|
|
2130
2802
|
};
|
|
2131
2803
|
}
|
|
@@ -2133,7 +2805,7 @@ async function stageSingleFileTarball(agent, sourcePath, tarballEntryName) {
|
|
|
2133
2805
|
const stageDir = await mkStageDir(agent);
|
|
2134
2806
|
let tarballPath = null;
|
|
2135
2807
|
try {
|
|
2136
|
-
await copyFile2(sourcePath,
|
|
2808
|
+
await copyFile2(sourcePath, join17(stageDir, tarballEntryName));
|
|
2137
2809
|
tarballPath = await tarballFromDir(stageDir, agent);
|
|
2138
2810
|
return {
|
|
2139
2811
|
tarballPath,
|
|
@@ -2141,19 +2813,19 @@ async function stageSingleFileTarball(agent, sourcePath, tarballEntryName) {
|
|
|
2141
2813
|
warnings: []
|
|
2142
2814
|
};
|
|
2143
2815
|
} catch (err) {
|
|
2144
|
-
await
|
|
2145
|
-
if (tarballPath) await
|
|
2816
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
2817
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2146
2818
|
throw err;
|
|
2147
2819
|
}
|
|
2148
2820
|
}
|
|
2149
2821
|
var CLAUDE_STATIC_EXCLUDES = resolveAgentSpec("claude").staticPaths[0]?.exclude ?? [];
|
|
2150
2822
|
async function buildBoxClaudeJsonFromHost(opts) {
|
|
2151
2823
|
const { hostHome, hostWorkspace } = opts;
|
|
2152
|
-
const hostClaudeJson =
|
|
2824
|
+
const hostClaudeJson = join17(hostHome, ".claude.json");
|
|
2153
2825
|
let working;
|
|
2154
|
-
if (await
|
|
2826
|
+
if (await pathExists5(hostClaudeJson)) {
|
|
2155
2827
|
try {
|
|
2156
|
-
working = JSON.parse(await
|
|
2828
|
+
working = JSON.parse(await readFile9(hostClaudeJson, "utf8"));
|
|
2157
2829
|
} catch {
|
|
2158
2830
|
working = null;
|
|
2159
2831
|
}
|
|
@@ -2184,7 +2856,7 @@ async function buildBoxClaudeJsonFromHost(opts) {
|
|
|
2184
2856
|
return working;
|
|
2185
2857
|
}
|
|
2186
2858
|
async function stageClaudeJsonOnlyForUpload(opts = {}) {
|
|
2187
|
-
const hostHome = opts.hostHome ??
|
|
2859
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
2188
2860
|
const stageDir = await mkStageDir("claude-json-only");
|
|
2189
2861
|
let tarballPath = null;
|
|
2190
2862
|
try {
|
|
@@ -2192,7 +2864,7 @@ async function stageClaudeJsonOnlyForUpload(opts = {}) {
|
|
|
2192
2864
|
hostHome,
|
|
2193
2865
|
hostWorkspace: opts.hostWorkspace
|
|
2194
2866
|
});
|
|
2195
|
-
await
|
|
2867
|
+
await writeFile7(join17(stageDir, "_claude.json"), JSON.stringify(claudeJson, null, 2));
|
|
2196
2868
|
tarballPath = await tarballFromDir(stageDir, "claude-json-only");
|
|
2197
2869
|
return {
|
|
2198
2870
|
tarballPath,
|
|
@@ -2200,15 +2872,15 @@ async function stageClaudeJsonOnlyForUpload(opts = {}) {
|
|
|
2200
2872
|
warnings: []
|
|
2201
2873
|
};
|
|
2202
2874
|
} catch (err) {
|
|
2203
|
-
await
|
|
2204
|
-
if (tarballPath) await
|
|
2875
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
2876
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2205
2877
|
throw err;
|
|
2206
2878
|
}
|
|
2207
2879
|
}
|
|
2208
2880
|
async function stageClaudeStaticForUpload(opts = {}) {
|
|
2209
|
-
const hostHome = opts.hostHome ??
|
|
2210
|
-
const hostClaude =
|
|
2211
|
-
if (!await
|
|
2881
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
2882
|
+
const hostClaude = join17(hostHome, ".claude");
|
|
2883
|
+
if (!await pathExists5(hostClaude)) return emptyResult();
|
|
2212
2884
|
const stageDir = await mkStageDir("claude-static");
|
|
2213
2885
|
let tarballPath = null;
|
|
2214
2886
|
try {
|
|
@@ -2219,18 +2891,19 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2219
2891
|
];
|
|
2220
2892
|
await execa6("rsync", [
|
|
2221
2893
|
"-a",
|
|
2894
|
+
STAGE_WRITABLE_CHMOD,
|
|
2222
2895
|
"--copy-unsafe-links",
|
|
2223
2896
|
...excludes,
|
|
2224
2897
|
`${hostClaude}/`,
|
|
2225
2898
|
`${stageDir}/`
|
|
2226
2899
|
]);
|
|
2227
|
-
const settingsPath =
|
|
2228
|
-
if (await
|
|
2900
|
+
const settingsPath = join17(stageDir, "settings.json");
|
|
2901
|
+
if (await pathExists5(settingsPath)) {
|
|
2229
2902
|
try {
|
|
2230
|
-
const parsed = JSON.parse(await
|
|
2903
|
+
const parsed = JSON.parse(await readFile9(settingsPath, "utf8"));
|
|
2231
2904
|
const filtered = filterHostHooks(parsed, hostHome);
|
|
2232
2905
|
if (filtered.removedCommands.length > 0) {
|
|
2233
|
-
await
|
|
2906
|
+
await writeFile7(settingsPath, JSON.stringify(filtered.data, null, 2));
|
|
2234
2907
|
}
|
|
2235
2908
|
} catch {
|
|
2236
2909
|
}
|
|
@@ -2239,17 +2912,17 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2239
2912
|
hostHome,
|
|
2240
2913
|
hostWorkspace: opts.hostWorkspace
|
|
2241
2914
|
});
|
|
2242
|
-
await
|
|
2243
|
-
const pluginsDir =
|
|
2244
|
-
if (await
|
|
2915
|
+
await writeFile7(join17(stageDir, "_claude.json"), JSON.stringify(claudeJson, null, 2));
|
|
2916
|
+
const pluginsDir = join17(stageDir, "plugins");
|
|
2917
|
+
if (await pathExists5(pluginsDir)) {
|
|
2245
2918
|
try {
|
|
2246
|
-
const entries = await
|
|
2919
|
+
const entries = await readdir6(pluginsDir, { withFileTypes: true });
|
|
2247
2920
|
for (const ent of entries) {
|
|
2248
2921
|
if (!ent.isFile() || !ent.name.endsWith(".json")) continue;
|
|
2249
|
-
const file =
|
|
2250
|
-
const raw = await
|
|
2922
|
+
const file = join17(pluginsDir, ent.name);
|
|
2923
|
+
const raw = await readFile9(file, "utf8");
|
|
2251
2924
|
const replaced = raw.split(`${hostHome}/.claude/plugins/`).join("/home/vscode/.claude/plugins/");
|
|
2252
|
-
if (replaced !== raw) await
|
|
2925
|
+
if (replaced !== raw) await writeFile7(file, replaced);
|
|
2253
2926
|
}
|
|
2254
2927
|
} catch {
|
|
2255
2928
|
}
|
|
@@ -2261,42 +2934,69 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2261
2934
|
warnings: []
|
|
2262
2935
|
};
|
|
2263
2936
|
} catch (err) {
|
|
2264
|
-
await
|
|
2265
|
-
if (tarballPath) await
|
|
2937
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
2938
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2266
2939
|
throw err;
|
|
2267
2940
|
}
|
|
2268
2941
|
}
|
|
2269
2942
|
async function stageClaudeCredentialsForUpload() {
|
|
2270
|
-
if (!await
|
|
2943
|
+
if (!await pathExists5(CREDENTIALS_BACKUP_FILE)) return emptyResult();
|
|
2271
2944
|
return stageSingleFileTarball("claude-creds", CREDENTIALS_BACKUP_FILE, ".credentials.json");
|
|
2272
2945
|
}
|
|
2273
2946
|
var CODEX_STATIC_EXCLUDES = resolveAgentSpec("codex").staticPaths[0]?.exclude ?? [];
|
|
2947
|
+
var CODEX_STATIC_INCLUDES = resolveAgentSpec("codex").staticPaths[0]?.include ?? [];
|
|
2274
2948
|
var CODEX_KEYCHAIN_WARNING = 'codex: ~/.codex/auth.json missing. On macOS the codex CLI defaults to storing the OAuth token in the system Keychain, which isn\'t reachable from a remote sandbox. To share creds with cloud boxes either:\n - add `cli_auth_credentials_store = "file"` to ~/.codex/config.toml then re-run `codex login`, or\n - set OPENAI_API_KEY in your environment, or\n - run `codex login --with-api-key` for a file-backed login.\nSkipping codex seed; in-box codex will prompt for sign-in.';
|
|
2275
2949
|
async function sanitizeStagedCodexConfig(configPath, hostHome) {
|
|
2276
2950
|
try {
|
|
2277
|
-
if (!await
|
|
2278
|
-
const { text, changed } = sanitizeCodexConfigForBox(
|
|
2279
|
-
|
|
2951
|
+
if (!await pathExists5(configPath)) return { keptMarketplaces: [] };
|
|
2952
|
+
const { text, changed, keptMarketplaces } = sanitizeCodexConfigForBox(
|
|
2953
|
+
await readFile9(configPath, "utf8"),
|
|
2954
|
+
hostHome
|
|
2955
|
+
);
|
|
2956
|
+
if (changed) await writeFile7(configPath, text);
|
|
2957
|
+
return { keptMarketplaces };
|
|
2280
2958
|
} catch {
|
|
2959
|
+
return null;
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
async function purgeOrphanCodexMarketplaceDirs(stageDir, keptMarketplaces) {
|
|
2963
|
+
const kept = new Set(keptMarketplaces);
|
|
2964
|
+
for (const rel of ["plugins/cache", ".tmp/marketplaces"]) {
|
|
2965
|
+
const dir = join17(stageDir, rel);
|
|
2966
|
+
let entries;
|
|
2967
|
+
try {
|
|
2968
|
+
entries = await readdir6(dir);
|
|
2969
|
+
} catch {
|
|
2970
|
+
continue;
|
|
2971
|
+
}
|
|
2972
|
+
for (const name of entries) {
|
|
2973
|
+
if (kept.has(name)) continue;
|
|
2974
|
+
await rm7(join17(dir, name), { recursive: true, force: true });
|
|
2975
|
+
}
|
|
2281
2976
|
}
|
|
2282
2977
|
}
|
|
2283
2978
|
async function stageCodexStaticForUpload(opts = {}) {
|
|
2284
|
-
const hostHome = opts.hostHome ??
|
|
2285
|
-
const hostCodex =
|
|
2286
|
-
if (!await
|
|
2979
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
2980
|
+
const hostCodex = join17(hostHome, ".codex");
|
|
2981
|
+
if (!await pathExists5(hostCodex)) return emptyResult();
|
|
2287
2982
|
const stageDir = await mkStageDir("codex-static");
|
|
2288
2983
|
let tarballPath = null;
|
|
2289
2984
|
try {
|
|
2290
2985
|
const codexBroken = await findBrokenSymlinks(hostCodex);
|
|
2291
2986
|
await execa6("rsync", [
|
|
2292
2987
|
"-a",
|
|
2988
|
+
STAGE_WRITABLE_CHMOD,
|
|
2293
2989
|
"-L",
|
|
2294
2990
|
...codexBroken.map((r) => `--exclude=/${r}`),
|
|
2991
|
+
...CODEX_STATIC_INCLUDES.map((p) => `--include=${p}`),
|
|
2295
2992
|
...CODEX_STATIC_EXCLUDES.map((p) => `--exclude=${p}`),
|
|
2296
2993
|
`${hostCodex}/`,
|
|
2297
2994
|
`${stageDir}/`
|
|
2298
2995
|
]);
|
|
2299
|
-
await sanitizeStagedCodexConfig(
|
|
2996
|
+
const sanitized = await sanitizeStagedCodexConfig(join17(stageDir, "config.toml"), hostHome);
|
|
2997
|
+
if (sanitized !== null) {
|
|
2998
|
+
await purgeOrphanCodexMarketplaceDirs(stageDir, sanitized.keptMarketplaces);
|
|
2999
|
+
}
|
|
2300
3000
|
tarballPath = await tarballFromDir(stageDir, "codex-static");
|
|
2301
3001
|
return {
|
|
2302
3002
|
tarballPath,
|
|
@@ -2304,21 +3004,22 @@ async function stageCodexStaticForUpload(opts = {}) {
|
|
|
2304
3004
|
warnings: []
|
|
2305
3005
|
};
|
|
2306
3006
|
} catch (err) {
|
|
2307
|
-
await
|
|
2308
|
-
if (tarballPath) await
|
|
3007
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
3008
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2309
3009
|
throw err;
|
|
2310
3010
|
}
|
|
2311
3011
|
}
|
|
2312
3012
|
async function stageAgentsStaticForUpload(opts = {}) {
|
|
2313
|
-
const hostHome = opts.hostHome ??
|
|
2314
|
-
const hostAgents =
|
|
2315
|
-
if (!await
|
|
3013
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
3014
|
+
const hostAgents = join17(hostHome, ".agents");
|
|
3015
|
+
if (!await pathExists5(hostAgents)) return emptyResult();
|
|
2316
3016
|
const stageDir = await mkStageDir("agents-static");
|
|
2317
3017
|
let tarballPath = null;
|
|
2318
3018
|
try {
|
|
2319
3019
|
const broken = await findBrokenSymlinks(hostAgents);
|
|
2320
3020
|
await execa6("rsync", [
|
|
2321
3021
|
"-a",
|
|
3022
|
+
STAGE_WRITABLE_CHMOD,
|
|
2322
3023
|
"-L",
|
|
2323
3024
|
...broken.map((r) => `--exclude=/${r}`),
|
|
2324
3025
|
`${hostAgents}/`,
|
|
@@ -2331,28 +3032,28 @@ async function stageAgentsStaticForUpload(opts = {}) {
|
|
|
2331
3032
|
warnings: []
|
|
2332
3033
|
};
|
|
2333
3034
|
} catch (err) {
|
|
2334
|
-
await
|
|
2335
|
-
if (tarballPath) await
|
|
3035
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
3036
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2336
3037
|
throw err;
|
|
2337
3038
|
}
|
|
2338
3039
|
}
|
|
2339
3040
|
async function stageCodexCredentialsForUpload(opts = {}) {
|
|
2340
|
-
const hostHome = opts.hostHome ??
|
|
2341
|
-
const cloudBackup =
|
|
2342
|
-
if (await
|
|
3041
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
3042
|
+
const cloudBackup = join17(hostHome, ".agentbox", "codex-credentials.json");
|
|
3043
|
+
if (await pathExists5(cloudBackup)) {
|
|
2343
3044
|
return stageSingleFileTarball("codex-creds", cloudBackup, "auth.json");
|
|
2344
3045
|
}
|
|
2345
|
-
const hostAuth =
|
|
2346
|
-
if (!await
|
|
3046
|
+
const hostAuth = join17(hostHome, ".codex", "auth.json");
|
|
3047
|
+
if (!await pathExists5(hostAuth)) return emptyResult([CODEX_KEYCHAIN_WARNING]);
|
|
2347
3048
|
return stageSingleFileTarball("codex-creds", hostAuth, "auth.json");
|
|
2348
3049
|
}
|
|
2349
3050
|
var OPENCODE_DATA_EXCLUDES = resolveAgentSpec("opencode").staticPaths[0]?.exclude ?? [];
|
|
2350
3051
|
async function stageOpencodeStaticForUpload(opts = {}) {
|
|
2351
|
-
const hostHome = opts.hostHome ??
|
|
2352
|
-
const hostData =
|
|
2353
|
-
const hostConfig =
|
|
2354
|
-
const hasData = await
|
|
2355
|
-
const hasConfig = await
|
|
3052
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
3053
|
+
const hostData = join17(hostHome, ".local", "share", "opencode");
|
|
3054
|
+
const hostConfig = join17(hostHome, ".config", "opencode");
|
|
3055
|
+
const hasData = await pathExists5(hostData);
|
|
3056
|
+
const hasConfig = await pathExists5(hostConfig);
|
|
2356
3057
|
if (!hasData && !hasConfig) return emptyResult();
|
|
2357
3058
|
const stageDir = await mkStageDir("opencode-static");
|
|
2358
3059
|
let tarballPath = null;
|
|
@@ -2361,6 +3062,7 @@ async function stageOpencodeStaticForUpload(opts = {}) {
|
|
|
2361
3062
|
const dataBroken = await findBrokenSymlinks(hostData);
|
|
2362
3063
|
await execa6("rsync", [
|
|
2363
3064
|
"-a",
|
|
3065
|
+
STAGE_WRITABLE_CHMOD,
|
|
2364
3066
|
"-L",
|
|
2365
3067
|
...dataBroken.map((r) => `--exclude=/${r}`),
|
|
2366
3068
|
...OPENCODE_DATA_EXCLUDES.map((p) => `--exclude=${p}`),
|
|
@@ -2369,10 +3071,11 @@ async function stageOpencodeStaticForUpload(opts = {}) {
|
|
|
2369
3071
|
]);
|
|
2370
3072
|
}
|
|
2371
3073
|
if (hasConfig) {
|
|
2372
|
-
const configStage =
|
|
3074
|
+
const configStage = join17(stageDir, "config");
|
|
2373
3075
|
const cfgBroken = await findBrokenSymlinks(hostConfig);
|
|
2374
3076
|
await execa6("rsync", [
|
|
2375
3077
|
"-a",
|
|
3078
|
+
STAGE_WRITABLE_CHMOD,
|
|
2376
3079
|
"-L",
|
|
2377
3080
|
...cfgBroken.map((r) => `--exclude=/${r}`),
|
|
2378
3081
|
`${hostConfig}/`,
|
|
@@ -2386,25 +3089,25 @@ async function stageOpencodeStaticForUpload(opts = {}) {
|
|
|
2386
3089
|
warnings: []
|
|
2387
3090
|
};
|
|
2388
3091
|
} catch (err) {
|
|
2389
|
-
await
|
|
2390
|
-
if (tarballPath) await
|
|
3092
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
3093
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2391
3094
|
throw err;
|
|
2392
3095
|
}
|
|
2393
3096
|
}
|
|
2394
3097
|
async function stageOpencodeCredentialsForUpload(opts = {}) {
|
|
2395
|
-
const hostHome = opts.hostHome ??
|
|
2396
|
-
const cloudBackup =
|
|
2397
|
-
if (await
|
|
3098
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
3099
|
+
const cloudBackup = join17(hostHome, ".agentbox", "opencode-credentials.json");
|
|
3100
|
+
if (await pathExists5(cloudBackup)) {
|
|
2398
3101
|
return stageSingleFileTarball("opencode-creds", cloudBackup, "auth.json");
|
|
2399
3102
|
}
|
|
2400
|
-
const hostAuth =
|
|
2401
|
-
if (!await
|
|
3103
|
+
const hostAuth = join17(hostHome, ".local", "share", "opencode", "auth.json");
|
|
3104
|
+
if (!await pathExists5(hostAuth)) return emptyResult();
|
|
2402
3105
|
return stageSingleFileTarball("opencode-creds", hostAuth, "auth.json");
|
|
2403
3106
|
}
|
|
2404
3107
|
async function stageOpencodeStateForUpload(opts = {}) {
|
|
2405
|
-
const hostHome = opts.hostHome ??
|
|
2406
|
-
const hostModel =
|
|
2407
|
-
if (!await
|
|
3108
|
+
const hostHome = opts.hostHome ?? homedir11();
|
|
3109
|
+
const hostModel = join17(hostHome, ".local", "state", "opencode", "model.json");
|
|
3110
|
+
if (!await pathExists5(hostModel)) return emptyResult();
|
|
2408
3111
|
return stageSingleFileTarball("opencode-state", hostModel, "model.json");
|
|
2409
3112
|
}
|
|
2410
3113
|
var CLAUDE_STATIC_BOX_DIR = "/home/vscode/.claude";
|
|
@@ -2429,7 +3132,7 @@ function preparedStatePathFor(provider) {
|
|
|
2429
3132
|
if (!/^[A-Za-z0-9._-]+$/.test(provider)) {
|
|
2430
3133
|
throw new Error(`invalid provider name for prepared-state: ${JSON.stringify(provider)}`);
|
|
2431
3134
|
}
|
|
2432
|
-
return pathResolve(
|
|
3135
|
+
return pathResolve(homedir12(), ".agentbox", `${provider}-prepared.json`);
|
|
2433
3136
|
}
|
|
2434
3137
|
function readPreparedStateRaw(provider) {
|
|
2435
3138
|
const path = preparedStatePathFor(provider);
|
|
@@ -2442,14 +3145,14 @@ function readPreparedStateRaw(provider) {
|
|
|
2442
3145
|
}
|
|
2443
3146
|
function writePreparedStateRaw(provider, state) {
|
|
2444
3147
|
const path = preparedStatePathFor(provider);
|
|
2445
|
-
mkdirSync3(
|
|
3148
|
+
mkdirSync3(dirname10(path), { recursive: true });
|
|
2446
3149
|
const body = JSON.stringify(state, null, 2) + "\n";
|
|
2447
3150
|
const tmp = `${path}.tmp`;
|
|
2448
3151
|
writeFileSync3(tmp, body, { mode: 384 });
|
|
2449
3152
|
renameSync2(tmp, path);
|
|
2450
3153
|
}
|
|
2451
3154
|
async function sha256OfFile(path) {
|
|
2452
|
-
const buf = await
|
|
3155
|
+
const buf = await readFile10(path);
|
|
2453
3156
|
return createHash3("sha256").update(buf).digest("hex");
|
|
2454
3157
|
}
|
|
2455
3158
|
async function computeContextSha256(files) {
|
|
@@ -2531,11 +3234,11 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
2531
3234
|
import { execa as execa7 } from "execa";
|
|
2532
3235
|
import { existsSync as existsSync5 } from "fs";
|
|
2533
3236
|
import { fileURLToPath } from "url";
|
|
2534
|
-
import { dirname as
|
|
3237
|
+
import { dirname as dirname11, resolve as resolve3 } from "path";
|
|
2535
3238
|
var DEFAULT_BOX_IMAGE = "agentbox/box:dev";
|
|
2536
3239
|
async function resolveClaudeInstallMode() {
|
|
2537
3240
|
try {
|
|
2538
|
-
const { loadEffectiveConfig } = await import("./dist-
|
|
3241
|
+
const { loadEffectiveConfig } = await import("./dist-T5MXBZGP.js");
|
|
2539
3242
|
const cfg = await loadEffectiveConfig(process.cwd());
|
|
2540
3243
|
return cfg.effective.box.claudeInstall;
|
|
2541
3244
|
} catch {
|
|
@@ -2546,7 +3249,7 @@ var BOX_IMAGE_REGISTRY = "ghcr.io/madarco/agentbox/box";
|
|
|
2546
3249
|
function registryRefForSha(sha, registry = BOX_IMAGE_REGISTRY) {
|
|
2547
3250
|
return `${registry}:sha-${sha.slice(0, 16)}`;
|
|
2548
3251
|
}
|
|
2549
|
-
var here =
|
|
3252
|
+
var here = dirname11(fileURLToPath(import.meta.url));
|
|
2550
3253
|
function resolveDockerBuild() {
|
|
2551
3254
|
const override = process.env.AGENTBOX_DOCKER_CONTEXT;
|
|
2552
3255
|
if (override && existsSync5(resolve3(override, "Dockerfile.box"))) {
|
|
@@ -2649,7 +3352,7 @@ async function buildImage(opts = {}) {
|
|
|
2649
3352
|
return ref;
|
|
2650
3353
|
}
|
|
2651
3354
|
async function pullOrBuild(ref, fingerprint, opts = {}) {
|
|
2652
|
-
const { writePreparedDockerState: writePreparedDockerState2 } = await import("./prepared-state-BUO75YLZ-
|
|
3355
|
+
const { writePreparedDockerState: writePreparedDockerState2 } = await import("./prepared-state-BUO75YLZ-RQRFFBJW.js");
|
|
2653
3356
|
const registry = opts.registry ?? BOX_IMAGE_REGISTRY;
|
|
2654
3357
|
const allowPull = opts.allowPull !== false;
|
|
2655
3358
|
if (allowPull && registry && fingerprint) {
|
|
@@ -2676,7 +3379,7 @@ async function pullOrBuild(ref, fingerprint, opts = {}) {
|
|
|
2676
3379
|
return { source: "built" };
|
|
2677
3380
|
}
|
|
2678
3381
|
async function ensureImage(ref = DEFAULT_BOX_IMAGE, opts = {}) {
|
|
2679
|
-
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2, preparedMatches: preparedMatches2 } = await import("./prepared-state-BUO75YLZ-
|
|
3382
|
+
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2, preparedMatches: preparedMatches2 } = await import("./prepared-state-BUO75YLZ-RQRFFBJW.js");
|
|
2680
3383
|
const claudeInstall = opts.claudeInstall ?? await resolveClaudeInstallMode();
|
|
2681
3384
|
const rawFingerprint = await computeDockerContextFingerprint2({
|
|
2682
3385
|
contextDir: opts.contextDir
|
|
@@ -2726,7 +3429,7 @@ function classifyDockerBaseFreshness(input) {
|
|
|
2726
3429
|
return { state: "fresh" };
|
|
2727
3430
|
}
|
|
2728
3431
|
async function evaluateDockerBaseFreshness(opts = {}) {
|
|
2729
|
-
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2 } = await import("./prepared-state-BUO75YLZ-
|
|
3432
|
+
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2 } = await import("./prepared-state-BUO75YLZ-RQRFFBJW.js");
|
|
2730
3433
|
const ref = opts.ref ?? DEFAULT_BOX_IMAGE;
|
|
2731
3434
|
const imagePresent = await imageExists(ref);
|
|
2732
3435
|
if (!imagePresent) return { state: "unprepared" };
|
|
@@ -2826,6 +3529,9 @@ export {
|
|
|
2826
3529
|
ensureCloudSshAlias,
|
|
2827
3530
|
autoWriteSshConfig,
|
|
2828
3531
|
mintSshKey,
|
|
3532
|
+
parseInboundSpec,
|
|
3533
|
+
resolveInboundSources,
|
|
3534
|
+
describeInbound,
|
|
2829
3535
|
scratchBranchName,
|
|
2830
3536
|
boxGitCheckout,
|
|
2831
3537
|
boxGitNewBranch,
|
|
@@ -2846,6 +3552,29 @@ export {
|
|
|
2846
3552
|
pluginProviderNames,
|
|
2847
3553
|
pluginForProvider,
|
|
2848
3554
|
renderCarryEntries,
|
|
3555
|
+
AGENT_SYNC_SPECS,
|
|
3556
|
+
resolveAgentSpec,
|
|
3557
|
+
referencedPluginVersionKeys,
|
|
3558
|
+
claudeInventoryScript,
|
|
3559
|
+
parseClaudeInventory,
|
|
3560
|
+
computeClaudePullPlan,
|
|
3561
|
+
writeClaudeMergedRegistries,
|
|
3562
|
+
pullClaudeExtrasViaTransport,
|
|
3563
|
+
CODEX_PULL_ITEMS,
|
|
3564
|
+
OPENCODE_PULL_DATA_ITEMS,
|
|
3565
|
+
OPENCODE_PULL_CONFIG_ITEMS,
|
|
3566
|
+
pullCodexConfigViaTransport,
|
|
3567
|
+
pullOpencodeConfigViaTransport,
|
|
3568
|
+
agentBoxConfigDir,
|
|
3569
|
+
claudeStagedItems,
|
|
3570
|
+
codexStagedItems,
|
|
3571
|
+
opencodeStagedItems,
|
|
3572
|
+
stageItemsViaTransport,
|
|
3573
|
+
makeStagingDir,
|
|
3574
|
+
removeStagingDir,
|
|
3575
|
+
transportSettingsTarget,
|
|
3576
|
+
propagateStagedSettings,
|
|
3577
|
+
planPropagateTargets,
|
|
2849
3578
|
makeSyncContext,
|
|
2850
3579
|
DEFAULT_ENV_PATTERNS,
|
|
2851
3580
|
ENV_PRUNE_DIRS,
|
|
@@ -2865,6 +3594,10 @@ export {
|
|
|
2865
3594
|
hostClaudeBackupExpired,
|
|
2866
3595
|
hostBackupHasCredentials,
|
|
2867
3596
|
extractCredentials,
|
|
3597
|
+
shouldAcceptCredentialUpdate,
|
|
3598
|
+
writeCredentialBackup,
|
|
3599
|
+
readCredentialBackup,
|
|
3600
|
+
pushCredentialToBox,
|
|
2868
3601
|
resyncWorkspace,
|
|
2869
3602
|
makeHostGitPorts,
|
|
2870
3603
|
BOX_WORKFLOWS_DIR,
|
|
@@ -2879,6 +3612,7 @@ export {
|
|
|
2879
3612
|
setInstallMethodNative,
|
|
2880
3613
|
MINIMAL_TRUSTED_CODEX_CONFIG,
|
|
2881
3614
|
sanitizeCodexConfigForBox,
|
|
3615
|
+
mergeCodexConfigForBox,
|
|
2882
3616
|
stageClaudeJsonOnlyForUpload,
|
|
2883
3617
|
stageClaudeStaticForUpload,
|
|
2884
3618
|
stageClaudeCredentialsForUpload,
|
|
@@ -2916,4 +3650,4 @@ export {
|
|
|
2916
3650
|
writePreparedDockerState,
|
|
2917
3651
|
preparedMatches
|
|
2918
3652
|
};
|
|
2919
|
-
//# sourceMappingURL=chunk-
|
|
3653
|
+
//# sourceMappingURL=chunk-DEDTPG2D.js.map
|