@madarco/agentbox 0.25.1 → 0.26.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 +48 -0
- package/README.md +8 -7
- package/dist/{_cloud-attach-FGMI2ZHO.js → _cloud-attach-7WRQH6XZ.js} +5 -5
- package/dist/{chunk-5VNL6SHJ.js → chunk-7ZZAZPYX.js} +3 -3
- package/dist/{chunk-ZTSVY3YL.js → chunk-BA2VLJVU.js} +3 -3
- package/dist/{chunk-3BR63LCB.js → chunk-DJQMK4RN.js} +12 -4
- package/dist/chunk-DJQMK4RN.js.map +1 -0
- package/dist/{chunk-6GZK74GT.js → chunk-DQHMDDAT.js} +2 -2
- package/dist/{chunk-P5U6AP6K.js → chunk-I2OAJS3L.js} +40 -377
- package/dist/{chunk-P5U6AP6K.js.map → chunk-I2OAJS3L.js.map} +1 -1
- package/dist/{chunk-5F5SOSDY.js → chunk-JGZSA5ZI.js} +72 -23
- package/dist/chunk-JGZSA5ZI.js.map +1 -0
- package/dist/{chunk-67VF2QZC.js → chunk-K5KOLYIL.js} +3 -3
- package/dist/{chunk-4LS2TOF3.js → chunk-PK2QF4IR.js} +569 -195
- package/dist/chunk-PK2QF4IR.js.map +1 -0
- package/dist/{chunk-3PSRBK24.js → chunk-UIFL7F2G.js} +54 -37
- package/dist/chunk-UIFL7F2G.js.map +1 -0
- package/dist/{chunk-4DBLYT2F.js → chunk-ZY7M7MXH.js} +41 -16
- package/dist/chunk-ZY7M7MXH.js.map +1 -0
- package/dist/chunk-ZYKNSHOH.js +259 -0
- package/dist/chunk-ZYKNSHOH.js.map +1 -0
- package/dist/{dist-X7R2EMJL.js → dist-5IICYSR6.js} +42 -374
- package/dist/{dist-X7R2EMJL.js.map → dist-5IICYSR6.js.map} +1 -1
- package/dist/{dist-5G42NFOG.js → dist-AR5CHRSV.js} +86 -45
- package/dist/{dist-5G42NFOG.js.map → dist-AR5CHRSV.js.map} +1 -1
- package/dist/{dist-AZUD2LUA.js → dist-DTNYMBQ5.js} +12 -12
- package/dist/{dist-MEK44IS5.js → dist-K4LNH3EC.js} +6 -6
- package/dist/{dist-SN6ABGMD.js → dist-POVRY7HO.js} +8 -4
- package/dist/{dist-SBDYDH7H.js → dist-U2SVLJUQ.js} +4 -2
- package/dist/{dist-4I7XHDC3.js → dist-XYY6SIKG.js} +6 -6
- package/dist/dist-YA7EXBGG.js +809 -0
- package/dist/dist-YA7EXBGG.js.map +1 -0
- package/dist/index.js +971 -591
- package/dist/index.js.map +1 -1
- package/dist/{prepared-state-75DIZ55S-5UAKJX3L.js → prepared-state-75DIZ55S-W6NU3S3B.js} +2 -2
- package/package.json +8 -7
- package/runtime/_shared/ctl.cjs +83 -36
- package/runtime/digitalocean/ctl.cjs +83 -36
- package/runtime/docker/packages/ctl/dist/bin.cjs +83 -36
- package/runtime/e2b/ctl.cjs +83 -36
- package/runtime/hetzner/ctl.cjs +83 -36
- 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/(auth)/api/auth/[...all]/route.js +1 -1
- package/runtime/hub/apps/hub/.next/server/app/(auth)/api/auth/[...all]/route.js.nft.json +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/0-fj_better-auth_dist_adapters_kysely-adapter_index_mjs_0btft52._.js +3 -0
- package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +5 -5
- 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]__1-9g0ae._.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]__19pc87s._.js → [root-of-the-server]__1k8g143._.js} +2 -2
- package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qa4a0v._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +4 -4
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_0xy-j7z._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_010858m.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_04zwxnx.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_06exuc7.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_0f2ldrt.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_0f2tzep.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_116nh32.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_11dyjcb.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_1_4knli.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__08-1wwu._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0c9mbcn._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0gdfxj4._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0kc-hwp._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0lu73p6._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__10bfmwi._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__18qvdzb._.js +1 -1
- package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__1l2urlw._.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-MVL4NCQC.js → auth-DC44GQZY.js} +2 -2
- package/runtime/hub/apps/hub/{auth-config-GRIXACTV.js → auth-config-LALRDYDO.js} +2 -2
- package/runtime/hub/apps/hub/{chunk-JLG5JJXD.js → chunk-3FJNKSNZ.js} +1 -1
- package/runtime/hub/apps/hub/{chunk-RSENJ2FT.js → chunk-4QY2VZCF.js} +502 -132
- package/runtime/hub/apps/hub/{chunk-23AU7VYS.js → chunk-BARD2DI6.js} +11 -3
- package/runtime/hub/apps/hub/{chunk-V3OMPMI3.js → chunk-QSMPSV5Z.js} +70 -21
- package/runtime/hub/apps/hub/{chunk-GARA7RQW.js → chunk-XZZXPEVV.js} +57 -36
- package/runtime/hub/apps/hub/{dist-WZKTIA2R.js → dist-3ENKQN5G.js} +35 -365
- package/runtime/hub/apps/hub/{dist-TP4SXMDY.js → dist-6VGJOQYK.js} +84 -43
- package/runtime/hub/apps/hub/{dist-JVU3QCLG.js → dist-AE6IV4FV.js} +4 -4
- package/runtime/hub/apps/hub/{dist-IZ2JCN5R.js → dist-EQV4L7KP.js} +3 -1
- package/runtime/hub/apps/hub/dist-NNBELNA7.js +1017 -0
- package/runtime/hub/apps/hub/{dist-DZGSA3US.js → dist-RJJ2SDYO.js} +4 -4
- package/runtime/hub/apps/hub/{dist-VWSHZIPN.js → dist-TU7D6UTB.js} +37 -366
- package/runtime/hub/apps/hub/{dist-YWY2DSSL.js → dist-WAZKGVYL.js} +7 -3
- package/runtime/hub/apps/hub/{hub-token-BJG6Q5II.js → hub-token-COBZGSLS.js} +2 -2
- package/runtime/hub/apps/hub/package.json +1 -0
- package/runtime/hub/apps/hub/{prepared-state-75DIZ55S-JDILR4OP.js → prepared-state-75DIZ55S-NYEDSU2U.js} +1 -1
- package/runtime/hub/apps/hub/server.js +20 -16
- package/runtime/relay/bin.cjs +57 -20
- package/runtime/vercel/ctl.cjs +83 -36
- package/dist/chunk-3BR63LCB.js.map +0 -1
- package/dist/chunk-3PSRBK24.js.map +0 -1
- package/dist/chunk-4DBLYT2F.js.map +0 -1
- package/dist/chunk-4LS2TOF3.js.map +0 -1
- package/dist/chunk-5F5SOSDY.js.map +0 -1
- package/runtime/hub/apps/hub/.next/server/chunks/0zhp_better-auth_dist_adapters_kysely-adapter_index_mjs_1rl4qnh._.js +0 -3
- /package/dist/{_cloud-attach-FGMI2ZHO.js.map → _cloud-attach-7WRQH6XZ.js.map} +0 -0
- /package/dist/{chunk-5VNL6SHJ.js.map → chunk-7ZZAZPYX.js.map} +0 -0
- /package/dist/{chunk-ZTSVY3YL.js.map → chunk-BA2VLJVU.js.map} +0 -0
- /package/dist/{chunk-6GZK74GT.js.map → chunk-DQHMDDAT.js.map} +0 -0
- /package/dist/{chunk-67VF2QZC.js.map → chunk-K5KOLYIL.js.map} +0 -0
- /package/dist/{dist-4I7XHDC3.js.map → dist-DTNYMBQ5.js.map} +0 -0
- /package/dist/{dist-MEK44IS5.js.map → dist-K4LNH3EC.js.map} +0 -0
- /package/dist/{dist-AZUD2LUA.js.map → dist-POVRY7HO.js.map} +0 -0
- /package/dist/{dist-SBDYDH7H.js.map → dist-U2SVLJUQ.js.map} +0 -0
- /package/dist/{dist-SN6ABGMD.js.map → dist-XYY6SIKG.js.map} +0 -0
- /package/dist/{prepared-state-75DIZ55S-5UAKJX3L.js.map → prepared-state-75DIZ55S-W6NU3S3B.js.map} +0 -0
- /package/runtime/hub/apps/hub/.next/static/{fo5EgsHa6PFLTBagfLiuM → mJYh9UHTsLaGGyRjBSvme}/_buildManifest.js +0 -0
- /package/runtime/hub/apps/hub/.next/static/{fo5EgsHa6PFLTBagfLiuM → mJYh9UHTsLaGGyRjBSvme}/_clientMiddlewareManifest.js +0 -0
- /package/runtime/hub/apps/hub/.next/static/{fo5EgsHa6PFLTBagfLiuM → mJYh9UHTsLaGGyRjBSvme}/_ssgManifest.js +0 -0
|
@@ -283,57 +283,64 @@ import { dirname as dirname22, join as join3 } from "path";
|
|
|
283
283
|
import { mkdir as mkdir2, readFile as readFile2 } from "fs/promises";
|
|
284
284
|
import { join as join5, resolve } from "path";
|
|
285
285
|
import { execa as execa2 } from "execa";
|
|
286
|
-
import {
|
|
286
|
+
import { execa as execa3 } from "execa";
|
|
287
|
+
import { existsSync as existsSync2 } from "fs";
|
|
288
|
+
import { mkdir as mkdir3, rm as rm2 } from "fs/promises";
|
|
289
|
+
import { createServer } from "net";
|
|
287
290
|
import { homedir as homedir4 } from "os";
|
|
288
|
-
import {
|
|
289
|
-
import {
|
|
290
|
-
import {
|
|
291
|
+
import { join as join6, resolve as resolve22 } from "path";
|
|
292
|
+
import { execa as execa4 } from "execa";
|
|
293
|
+
import { chmodSync, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "fs";
|
|
291
294
|
import { homedir as homedir5 } from "os";
|
|
292
|
-
import { dirname as
|
|
295
|
+
import { dirname as dirname4, resolve as resolve3 } from "path";
|
|
296
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
|
|
297
|
+
import { mkdir as mkdir4, open as open2, readFile as readFile3, rename as rename2, rm as rm3, stat as stat3, writeFile as writeFile2 } from "fs/promises";
|
|
298
|
+
import { homedir as homedir6 } from "os";
|
|
299
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
293
300
|
import { setTimeout as delay2 } from "timers/promises";
|
|
294
301
|
import { mkdtemp, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
|
|
295
302
|
import { tmpdir } from "os";
|
|
296
|
-
import { basename as basename2, join as
|
|
297
|
-
import { join as
|
|
298
|
-
import { chmod, mkdir as
|
|
299
|
-
import { homedir as homedir6 } from "os";
|
|
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";
|
|
302
|
-
import { tmpdir as tmpdir2 } from "os";
|
|
303
|
-
import { dirname as dirname7, join as join10 } from "path";
|
|
303
|
+
import { basename as basename2, join as join8 } from "path";
|
|
304
|
+
import { join as join9 } from "path";
|
|
305
|
+
import { chmod, mkdir as mkdir5, readdir as readdir2, readFile as readFile5, stat as stat4, writeFile as writeFile4 } from "fs/promises";
|
|
304
306
|
import { homedir as homedir7 } from "os";
|
|
305
|
-
import {
|
|
306
|
-
import {
|
|
307
|
-
import {
|
|
308
|
-
import {
|
|
309
|
-
import { readdir as readdir3, stat as stat5 } from "fs/promises";
|
|
307
|
+
import { dirname as dirname6, join as join10 } from "path";
|
|
308
|
+
import { mkdir as mkdir6, mkdtemp as mkdtemp2, rm as rm4, writeFile as writeFile5 } from "fs/promises";
|
|
309
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
310
|
+
import { dirname as dirname7, join as join11 } from "path";
|
|
310
311
|
import { homedir as homedir8 } from "os";
|
|
312
|
+
import { mkdtemp as mkdtemp3, rm as rm5 } from "fs/promises";
|
|
313
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
311
314
|
import { join as join12 } from "path";
|
|
315
|
+
import { execa as execa5 } from "execa";
|
|
316
|
+
import { readdir as readdir3, stat as stat5 } from "fs/promises";
|
|
317
|
+
import { homedir as homedir9 } from "os";
|
|
318
|
+
import { join as join13 } from "path";
|
|
312
319
|
import { readdir as readdir4, realpath as realpath2, stat as stat6 } from "fs/promises";
|
|
313
|
-
import { isAbsolute, join as
|
|
320
|
+
import { isAbsolute, join as join14, relative } from "path";
|
|
314
321
|
import { stat as stat7 } from "fs/promises";
|
|
315
|
-
import { chmod as chmod2, mkdir as
|
|
322
|
+
import { chmod as chmod2, mkdir as mkdir7, mkdtemp as mkdtemp4, readFile as readFile6, rename as rename3, rm as rm6, writeFile as writeFile6 } from "fs/promises";
|
|
316
323
|
import { tmpdir as tmpdir4 } from "os";
|
|
317
|
-
import { dirname as dirname8, join as
|
|
324
|
+
import { dirname as dirname8, join as join15 } from "path";
|
|
318
325
|
import { createHash } from "crypto";
|
|
319
326
|
import { readFile as readFile7 } from "fs/promises";
|
|
320
|
-
import { join as
|
|
321
|
-
import { execa as execa4 } from "execa";
|
|
322
|
-
import { createHash as createHash2 } from "crypto";
|
|
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";
|
|
326
|
-
import { execa as execa5 } from "execa";
|
|
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";
|
|
327
|
+
import { join as join16 } from "path";
|
|
330
328
|
import { execa as execa6 } from "execa";
|
|
331
|
-
import {
|
|
329
|
+
import { createHash as createHash2 } from "crypto";
|
|
330
|
+
import { copyFile, mkdir as mkdir8, mkdtemp as mkdtemp5, readdir as readdir5, readFile as readFile8, rm as rm7, stat as stat8 } from "fs/promises";
|
|
331
|
+
import { homedir as homedir10, tmpdir as tmpdir5 } from "os";
|
|
332
|
+
import { basename as basename22, dirname as dirname9, join as join17 } from "path";
|
|
333
|
+
import { execa as execa7 } from "execa";
|
|
334
|
+
import { copyFile as copyFile2, mkdtemp as mkdtemp6, readdir as readdir6, readFile as readFile9, rm as rm8, stat as stat9, writeFile as writeFile7 } from "fs/promises";
|
|
335
|
+
import { homedir as homedir12, tmpdir as tmpdir6 } from "os";
|
|
336
|
+
import { basename as basename3, join as join18, relative as relative2 } from "path";
|
|
337
|
+
import { execa as execa8 } from "execa";
|
|
338
|
+
import { homedir as homedir11 } from "os";
|
|
332
339
|
import { parse, stringify } from "smol-toml";
|
|
333
340
|
import { createHash as createHash3 } from "crypto";
|
|
334
|
-
import { existsSync as
|
|
341
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
335
342
|
import { readFile as readFile10 } from "fs/promises";
|
|
336
|
-
import { homedir as
|
|
343
|
+
import { homedir as homedir13 } from "os";
|
|
337
344
|
import { dirname as dirname10, resolve as pathResolve } from "path";
|
|
338
345
|
var STATE_DIR = join(homedir(), ".agentbox");
|
|
339
346
|
var STATE_FILE = join(STATE_DIR, "state.json");
|
|
@@ -704,6 +711,9 @@ function buildBlock(opts) {
|
|
|
704
711
|
if (opts.port) {
|
|
705
712
|
lines.push(` Port ${String(opts.port)}`);
|
|
706
713
|
}
|
|
714
|
+
if (opts.proxyJump) {
|
|
715
|
+
lines.push(` ProxyJump ${opts.proxyJump}`);
|
|
716
|
+
}
|
|
707
717
|
if (opts.identityFile) {
|
|
708
718
|
lines.push(` IdentityFile ${opts.identityFile}`);
|
|
709
719
|
lines.push(` IdentitiesOnly yes`);
|
|
@@ -752,7 +762,8 @@ async function syncAgentboxSshConfig(statePath = stateFilePath()) {
|
|
|
752
762
|
hostname: ssh.host,
|
|
753
763
|
user: ssh.user,
|
|
754
764
|
identityFile: ssh.identityFile,
|
|
755
|
-
port: ssh.port
|
|
765
|
+
port: ssh.port,
|
|
766
|
+
proxyJump: ssh.proxyJump
|
|
756
767
|
})
|
|
757
768
|
);
|
|
758
769
|
}
|
|
@@ -824,12 +835,26 @@ async function resolveCloudSshTarget(box, provider, opts = {}) {
|
|
|
824
835
|
throw new Error(`cloud sandbox for ${box.name} is missing; was it deleted?`);
|
|
825
836
|
}
|
|
826
837
|
}
|
|
838
|
+
const alias = agentboxAliasFor(box.name);
|
|
839
|
+
if (provider.sshTarget) {
|
|
840
|
+
const t = await provider.sshTarget(box);
|
|
841
|
+
if (!t) {
|
|
842
|
+
throw new Error(`no SSH target for ${box.name} (its sshd did not come up)`);
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
alias,
|
|
846
|
+
host: t.host,
|
|
847
|
+
user: t.user,
|
|
848
|
+
identityFile: t.identityFile,
|
|
849
|
+
port: t.port,
|
|
850
|
+
proxyJump: t.proxyJump
|
|
851
|
+
};
|
|
852
|
+
}
|
|
827
853
|
const spec = await provider.buildAttach(box, "shell", { noTmux: true });
|
|
828
854
|
const target = parseSshTarget(spec.argv);
|
|
829
855
|
if (!target) {
|
|
830
856
|
throw new Error(`could not parse <user>@<host> from cloud SSH argv: ${spec.argv.join(" ")}`);
|
|
831
857
|
}
|
|
832
|
-
const alias = agentboxAliasFor(box.name);
|
|
833
858
|
return { alias, host: target.host, user: target.user, identityFile: target.identityFile };
|
|
834
859
|
}
|
|
835
860
|
async function ensureCloudSshAlias(box, provider, opts = {}) {
|
|
@@ -837,20 +862,26 @@ async function ensureCloudSshAlias(box, provider, opts = {}) {
|
|
|
837
862
|
await recordBoxSsh(box.id, {
|
|
838
863
|
host: conn.host,
|
|
839
864
|
user: conn.user,
|
|
840
|
-
identityFile: conn.identityFile
|
|
865
|
+
identityFile: conn.identityFile,
|
|
866
|
+
port: conn.port,
|
|
867
|
+
proxyJump: conn.proxyJump
|
|
841
868
|
});
|
|
842
869
|
await syncAgentboxSshConfig();
|
|
843
870
|
return conn;
|
|
844
871
|
}
|
|
872
|
+
var PROVIDERS_WITH_DIRECT_BOX_SSH = ["hetzner", "digitalocean", "daytona"];
|
|
845
873
|
async function autoWriteSshConfig(box, provider, enabled, logWarn) {
|
|
846
874
|
if (!enabled) return;
|
|
875
|
+
if (!provider.sshTarget && !PROVIDERS_WITH_DIRECT_BOX_SSH.includes(provider.name)) return;
|
|
847
876
|
try {
|
|
848
877
|
const conn = await resolveCloudSshTarget(box, provider, { bringOnline: false });
|
|
849
878
|
if (!conn.identityFile) return;
|
|
850
879
|
await recordBoxSsh(box.id, {
|
|
851
880
|
host: conn.host,
|
|
852
881
|
user: conn.user,
|
|
853
|
-
identityFile: conn.identityFile
|
|
882
|
+
identityFile: conn.identityFile,
|
|
883
|
+
port: conn.port,
|
|
884
|
+
proxyJump: conn.proxyJump
|
|
854
885
|
});
|
|
855
886
|
await syncAgentboxSshConfig();
|
|
856
887
|
} catch (err) {
|
|
@@ -874,6 +905,341 @@ async function mintSshKey(targetDir, comment) {
|
|
|
874
905
|
const publicKey = (await readFile2(pub, "utf8")).trim();
|
|
875
906
|
return { dir, privatePath: priv, publicPath: pub, publicKey };
|
|
876
907
|
}
|
|
908
|
+
function sshDestination(target) {
|
|
909
|
+
return target.user ? `${target.user}@${target.host}` : target.host;
|
|
910
|
+
}
|
|
911
|
+
function sshOptArgs(target) {
|
|
912
|
+
const out = [];
|
|
913
|
+
if (target.identity) {
|
|
914
|
+
out.push("-i", target.identity);
|
|
915
|
+
}
|
|
916
|
+
if (target.knownHosts) {
|
|
917
|
+
out.push(
|
|
918
|
+
"-o",
|
|
919
|
+
"StrictHostKeyChecking=accept-new",
|
|
920
|
+
"-o",
|
|
921
|
+
`UserKnownHostsFile=${target.knownHosts}`,
|
|
922
|
+
"-o",
|
|
923
|
+
"GlobalKnownHostsFile=/dev/null"
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
out.push(
|
|
927
|
+
"-o",
|
|
928
|
+
"BatchMode=yes",
|
|
929
|
+
"-o",
|
|
930
|
+
"LogLevel=ERROR",
|
|
931
|
+
// Detect a dead/stalled peer and drop the connection instead of hanging
|
|
932
|
+
// forever. If the host's IP flaps mid-command (roaming Wi-Fi, VPN toggle)
|
|
933
|
+
// the return traffic is silently dropped and the ssh channel would
|
|
934
|
+
// otherwise block with no EOF — seen as an `exec` that never returns.
|
|
935
|
+
// 15s * 4 = a ~60s fail-fast so callers (retry wrappers, cleanup) can react.
|
|
936
|
+
"-o",
|
|
937
|
+
"ServerAliveInterval=15",
|
|
938
|
+
"-o",
|
|
939
|
+
"ServerAliveCountMax=4"
|
|
940
|
+
);
|
|
941
|
+
if (target.port !== void 0) {
|
|
942
|
+
out.push("-o", `Port=${String(target.port)}`);
|
|
943
|
+
}
|
|
944
|
+
if (target.controlPath) {
|
|
945
|
+
out.push("-o", `ControlPath=${target.controlPath}`);
|
|
946
|
+
}
|
|
947
|
+
for (const [k, v] of Object.entries(target.options ?? {})) {
|
|
948
|
+
out.push("-o", `${k}=${v}`);
|
|
949
|
+
}
|
|
950
|
+
return out;
|
|
951
|
+
}
|
|
952
|
+
async function sshExec(target, remoteCmd, opts = {}) {
|
|
953
|
+
const argv = [...sshOptArgs(target), sshDestination(target), remoteCmd];
|
|
954
|
+
const child = execa3("ssh", argv, {
|
|
955
|
+
reject: false,
|
|
956
|
+
timeout: opts.timeoutMs,
|
|
957
|
+
env: { ...process.env, ...opts.env },
|
|
958
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
959
|
+
});
|
|
960
|
+
if (opts.onLine) {
|
|
961
|
+
const handle = (chunk) => {
|
|
962
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
963
|
+
for (const line of text.split(/\r?\n/)) {
|
|
964
|
+
if (line.length > 0) opts.onLine?.(line);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
child.stdout?.on("data", handle);
|
|
968
|
+
child.stderr?.on("data", handle);
|
|
969
|
+
}
|
|
970
|
+
const res = await child;
|
|
971
|
+
return {
|
|
972
|
+
exitCode: typeof res.exitCode === "number" ? res.exitCode : 1,
|
|
973
|
+
stdout: typeof res.stdout === "string" ? res.stdout : "",
|
|
974
|
+
stderr: typeof res.stderr === "string" ? res.stderr : ""
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
async function scpUpload(target, localPath, remotePath, opts = {}) {
|
|
978
|
+
const argv = [...sshOptArgs(target), localPath, `${sshDestination(target)}:${remotePath}`];
|
|
979
|
+
const res = await execa3("scp", argv, { reject: false, timeout: opts.timeoutMs });
|
|
980
|
+
if (res.exitCode !== 0) {
|
|
981
|
+
throw new Error(
|
|
982
|
+
`scp upload failed (exit ${String(res.exitCode)}): ${localPath} \u2192 ${remotePath}
|
|
983
|
+
${res.stderr ?? ""}`
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
async function scpDownload(target, remotePath, localPath, opts = {}) {
|
|
988
|
+
const argv = [...sshOptArgs(target), `${sshDestination(target)}:${remotePath}`, localPath];
|
|
989
|
+
const res = await execa3("scp", argv, { reject: false, timeout: opts.timeoutMs });
|
|
990
|
+
if (res.exitCode !== 0) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
`scp download failed (exit ${String(res.exitCode)}): ${remotePath} \u2192 ${localPath}
|
|
993
|
+
${res.stderr ?? ""}`
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
async function waitForSsh(target, deadlineMs, intervalMs = 5e3) {
|
|
998
|
+
const stop = Date.now() + deadlineMs;
|
|
999
|
+
while (Date.now() < stop) {
|
|
1000
|
+
const res = await sshExec(
|
|
1001
|
+
{ ...target, options: { ...target.options, ConnectTimeout: "5" } },
|
|
1002
|
+
"true",
|
|
1003
|
+
{ timeoutMs: 1e4 }
|
|
1004
|
+
);
|
|
1005
|
+
if (res.exitCode === 0) return true;
|
|
1006
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
1007
|
+
}
|
|
1008
|
+
return false;
|
|
1009
|
+
}
|
|
1010
|
+
var HOST = "127.0.0.1";
|
|
1011
|
+
var SshTunnelManager = class {
|
|
1012
|
+
/**
|
|
1013
|
+
* `namespace` scopes the on-disk ssh dir so sandbox-ids from different
|
|
1014
|
+
* providers can't collide (a droplet id and a server id are both integers).
|
|
1015
|
+
*/
|
|
1016
|
+
constructor(namespace) {
|
|
1017
|
+
this.namespace = namespace;
|
|
1018
|
+
}
|
|
1019
|
+
namespace;
|
|
1020
|
+
boxes = /* @__PURE__ */ new Map();
|
|
1021
|
+
/**
|
|
1022
|
+
* Open the ControlMaster for `boxId`. Idempotent: if a master is already up
|
|
1023
|
+
* for this box (socket exists + responsive), no-op. Otherwise spawn a fresh
|
|
1024
|
+
* `ssh -fNT -M` and wait for the socket to appear.
|
|
1025
|
+
*/
|
|
1026
|
+
async open(opts) {
|
|
1027
|
+
const boxSshDir = opts.boxSshDir ?? defaultBoxSshDir(opts.boxId, this.namespace);
|
|
1028
|
+
await mkdir3(boxSshDir, { recursive: true, mode: 448 });
|
|
1029
|
+
const controlPath = join6(boxSshDir, "control.sock");
|
|
1030
|
+
const knownHosts = join6(boxSshDir, "known_hosts");
|
|
1031
|
+
const tunnel = {
|
|
1032
|
+
controlPath,
|
|
1033
|
+
vpsHost: opts.vpsHost,
|
|
1034
|
+
vpsUser: opts.vpsUser,
|
|
1035
|
+
identity: opts.identity,
|
|
1036
|
+
port: opts.port,
|
|
1037
|
+
boxSshDir,
|
|
1038
|
+
forwards: /* @__PURE__ */ new Map()
|
|
1039
|
+
};
|
|
1040
|
+
if (existsSync2(controlPath) && await this.isAlive(controlPath)) {
|
|
1041
|
+
this.boxes.set(opts.boxId, tunnel);
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
if (existsSync2(controlPath)) {
|
|
1045
|
+
await rm2(controlPath, { force: true });
|
|
1046
|
+
}
|
|
1047
|
+
const connectTimeout = opts.connectTimeoutSeconds ?? 10;
|
|
1048
|
+
const argv = ["-fNT", "-M", "-S", controlPath];
|
|
1049
|
+
if (opts.identity) {
|
|
1050
|
+
argv.push(
|
|
1051
|
+
"-i",
|
|
1052
|
+
opts.identity,
|
|
1053
|
+
"-o",
|
|
1054
|
+
"StrictHostKeyChecking=accept-new",
|
|
1055
|
+
"-o",
|
|
1056
|
+
`UserKnownHostsFile=${knownHosts}`,
|
|
1057
|
+
"-o",
|
|
1058
|
+
"GlobalKnownHostsFile=/dev/null"
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
if (opts.port !== void 0) {
|
|
1062
|
+
argv.push("-o", `Port=${String(opts.port)}`);
|
|
1063
|
+
}
|
|
1064
|
+
argv.push(
|
|
1065
|
+
"-o",
|
|
1066
|
+
"BatchMode=yes",
|
|
1067
|
+
"-o",
|
|
1068
|
+
"LogLevel=ERROR",
|
|
1069
|
+
"-o",
|
|
1070
|
+
"ExitOnForwardFailure=yes",
|
|
1071
|
+
"-o",
|
|
1072
|
+
"ServerAliveInterval=30",
|
|
1073
|
+
"-o",
|
|
1074
|
+
"ServerAliveCountMax=3",
|
|
1075
|
+
"-o",
|
|
1076
|
+
`ConnectTimeout=${String(connectTimeout)}`,
|
|
1077
|
+
opts.vpsUser ? `${opts.vpsUser}@${opts.vpsHost}` : opts.vpsHost
|
|
1078
|
+
);
|
|
1079
|
+
const res = await execa4("ssh", argv, { reject: false });
|
|
1080
|
+
if (res.exitCode !== 0 || !existsSync2(controlPath)) {
|
|
1081
|
+
throw new Error(
|
|
1082
|
+
`ssh ControlMaster failed for ${opts.boxId} (exit ${String(res.exitCode)}): ${res.stderr || res.stdout || "(no output)"}`
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
this.boxes.set(opts.boxId, tunnel);
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Mint (or fetch the cached) `127.0.0.1:<localPort> → remote:127.0.0.1:<remotePort>`
|
|
1089
|
+
* forward. Returns the local port. Idempotent per (boxId, remotePort).
|
|
1090
|
+
*
|
|
1091
|
+
* The cached entry is only returned when the underlying ControlMaster is
|
|
1092
|
+
* still alive — without that check we'd happily hand back a localPort that
|
|
1093
|
+
* stopped listening when the master died (e.g. transient network blip, host
|
|
1094
|
+
* sleep/wake). When the master is dead we drop ALL cached forwards for this
|
|
1095
|
+
* box (they all share one tunnel) and re-mint from scratch.
|
|
1096
|
+
*/
|
|
1097
|
+
async forward(boxId, remotePort) {
|
|
1098
|
+
const tunnel = this.getTunnelOrThrow(boxId);
|
|
1099
|
+
const cached = tunnel.forwards.get(remotePort);
|
|
1100
|
+
if (cached !== void 0 && await this.isAlive(tunnel.controlPath)) {
|
|
1101
|
+
return cached;
|
|
1102
|
+
}
|
|
1103
|
+
if (cached !== void 0) {
|
|
1104
|
+
tunnel.forwards.clear();
|
|
1105
|
+
}
|
|
1106
|
+
const localPort = await pickFreePort();
|
|
1107
|
+
const argv = [
|
|
1108
|
+
"-O",
|
|
1109
|
+
"forward",
|
|
1110
|
+
"-L",
|
|
1111
|
+
`${HOST}:${String(localPort)}:${HOST}:${String(remotePort)}`,
|
|
1112
|
+
"-S",
|
|
1113
|
+
tunnel.controlPath,
|
|
1114
|
+
"dummy"
|
|
1115
|
+
// the target host is ignored when -O is used, but argv needs one
|
|
1116
|
+
];
|
|
1117
|
+
const res = await execa4("ssh", argv, { reject: false });
|
|
1118
|
+
if (res.exitCode !== 0) {
|
|
1119
|
+
throw new Error(
|
|
1120
|
+
`ssh -O forward failed for ${boxId} (exit ${String(res.exitCode)}): ${res.stderr || res.stdout || "(no output)"}`
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
tunnel.forwards.set(remotePort, localPort);
|
|
1124
|
+
return localPort;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Tear down a dead ControlMaster + every cached forward for this box, then
|
|
1128
|
+
* re-open from scratch. Idempotent. Returns when the master is open and the
|
|
1129
|
+
* box's forwards map is empty (ready for fresh forward() calls).
|
|
1130
|
+
*
|
|
1131
|
+
* Use case: the cloud-poller observes ECONNREFUSED on the local port and asks
|
|
1132
|
+
* the backend to refresh the preview URL — that path calls into here so the
|
|
1133
|
+
* master + forward both come back fresh.
|
|
1134
|
+
*/
|
|
1135
|
+
async refresh(opts) {
|
|
1136
|
+
const existing = this.boxes.get(opts.boxId);
|
|
1137
|
+
if (existing) {
|
|
1138
|
+
const alive = await this.isAlive(existing.controlPath);
|
|
1139
|
+
if (!alive && existsSync2(existing.controlPath)) {
|
|
1140
|
+
try {
|
|
1141
|
+
await execa4("ssh", ["-O", "exit", "-S", existing.controlPath, "dummy"], {
|
|
1142
|
+
reject: false
|
|
1143
|
+
});
|
|
1144
|
+
} catch {
|
|
1145
|
+
}
|
|
1146
|
+
await rm2(existing.controlPath, { force: true });
|
|
1147
|
+
}
|
|
1148
|
+
existing.forwards.clear();
|
|
1149
|
+
}
|
|
1150
|
+
await this.open(opts);
|
|
1151
|
+
}
|
|
1152
|
+
/** Tear down a single forward. Idempotent — unknown ports are no-ops. */
|
|
1153
|
+
async unforward(boxId, remotePort) {
|
|
1154
|
+
const tunnel = this.getTunnelOrThrow(boxId);
|
|
1155
|
+
const localPort = tunnel.forwards.get(remotePort);
|
|
1156
|
+
if (localPort === void 0) return;
|
|
1157
|
+
const argv = [
|
|
1158
|
+
"-O",
|
|
1159
|
+
"cancel",
|
|
1160
|
+
"-L",
|
|
1161
|
+
`${HOST}:${String(localPort)}:${HOST}:${String(remotePort)}`,
|
|
1162
|
+
"-S",
|
|
1163
|
+
tunnel.controlPath,
|
|
1164
|
+
"dummy"
|
|
1165
|
+
];
|
|
1166
|
+
await execa4("ssh", argv, { reject: false });
|
|
1167
|
+
tunnel.forwards.delete(remotePort);
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Close the ControlMaster (and all its forwards). Idempotent — if no master
|
|
1171
|
+
* is recorded, no-op. Removes the socket file.
|
|
1172
|
+
*/
|
|
1173
|
+
async close(boxId) {
|
|
1174
|
+
const tunnel = this.boxes.get(boxId);
|
|
1175
|
+
if (!tunnel) return;
|
|
1176
|
+
if (existsSync2(tunnel.controlPath)) {
|
|
1177
|
+
await execa4("ssh", ["-O", "exit", "-S", tunnel.controlPath, "dummy"], { reject: false });
|
|
1178
|
+
await rm2(tunnel.controlPath, { force: true });
|
|
1179
|
+
}
|
|
1180
|
+
this.boxes.delete(boxId);
|
|
1181
|
+
}
|
|
1182
|
+
/** Tear down every open box. */
|
|
1183
|
+
async closeAll() {
|
|
1184
|
+
const ids = Array.from(this.boxes.keys());
|
|
1185
|
+
await Promise.all(ids.map((id) => this.close(id)));
|
|
1186
|
+
}
|
|
1187
|
+
/** Path to the ControlMaster socket for `boxId`, if open. */
|
|
1188
|
+
controlPath(boxId) {
|
|
1189
|
+
return this.boxes.get(boxId)?.controlPath;
|
|
1190
|
+
}
|
|
1191
|
+
/** True if a ControlMaster is registered for `boxId` (regardless of liveness). */
|
|
1192
|
+
has(boxId) {
|
|
1193
|
+
return this.boxes.has(boxId);
|
|
1194
|
+
}
|
|
1195
|
+
/** Per-box ssh dir (tests use this to verify the layout). */
|
|
1196
|
+
boxSshDir(boxId) {
|
|
1197
|
+
return this.boxes.get(boxId)?.boxSshDir;
|
|
1198
|
+
}
|
|
1199
|
+
/** Re-open the manager record for an existing-on-disk control socket. */
|
|
1200
|
+
registerExisting(boxId, opts) {
|
|
1201
|
+
const boxSshDir = opts.boxSshDir ?? defaultBoxSshDir(opts.boxId, this.namespace);
|
|
1202
|
+
this.boxes.set(boxId, {
|
|
1203
|
+
controlPath: join6(boxSshDir, "control.sock"),
|
|
1204
|
+
vpsHost: opts.vpsHost,
|
|
1205
|
+
vpsUser: opts.vpsUser,
|
|
1206
|
+
identity: opts.identity,
|
|
1207
|
+
port: opts.port,
|
|
1208
|
+
boxSshDir,
|
|
1209
|
+
forwards: /* @__PURE__ */ new Map()
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
async isAlive(controlPath) {
|
|
1213
|
+
const res = await execa4("ssh", ["-O", "check", "-S", controlPath, "dummy"], { reject: false });
|
|
1214
|
+
return res.exitCode === 0;
|
|
1215
|
+
}
|
|
1216
|
+
getTunnelOrThrow(boxId) {
|
|
1217
|
+
const t = this.boxes.get(boxId);
|
|
1218
|
+
if (!t) throw new Error(`no SSH ControlMaster registered for box ${boxId}; call open() first`);
|
|
1219
|
+
return t;
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
function defaultBoxSshDir(boxId, namespace) {
|
|
1223
|
+
const safe = boxId.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1224
|
+
return namespace ? resolve22(homedir4(), ".agentbox", namespace, "boxes", safe, "ssh") : resolve22(homedir4(), ".agentbox", "boxes", safe, "ssh");
|
|
1225
|
+
}
|
|
1226
|
+
async function pickFreePort() {
|
|
1227
|
+
return new Promise((resolveOk, reject) => {
|
|
1228
|
+
const srv = createServer();
|
|
1229
|
+
srv.unref();
|
|
1230
|
+
srv.on("error", reject);
|
|
1231
|
+
srv.listen(0, HOST, () => {
|
|
1232
|
+
const addr = srv.address();
|
|
1233
|
+
if (!addr || typeof addr === "string") {
|
|
1234
|
+
srv.close();
|
|
1235
|
+
reject(new Error("could not get a free local port"));
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
const port = addr.port;
|
|
1239
|
+
srv.close(() => resolveOk(port));
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
877
1243
|
var OPEN_INBOUND_SOURCES = ["0.0.0.0/0", "::/0"];
|
|
878
1244
|
function normalizeInboundCidr(raw) {
|
|
879
1245
|
const trimmed = raw.trim();
|
|
@@ -990,7 +1356,7 @@ function errSummary(err) {
|
|
|
990
1356
|
return err instanceof Error ? firstLine(err.message) : String(err);
|
|
991
1357
|
}
|
|
992
1358
|
function secretsEnvPath() {
|
|
993
|
-
return
|
|
1359
|
+
return resolve3(homedir5(), ".agentbox", "secrets.env");
|
|
994
1360
|
}
|
|
995
1361
|
function writeManagedSecrets(managedKeys, record) {
|
|
996
1362
|
for (const k of managedKeys) delete process.env[k];
|
|
@@ -998,7 +1364,7 @@ function writeManagedSecrets(managedKeys, record) {
|
|
|
998
1364
|
const path = secretsEnvPath();
|
|
999
1365
|
mkdirSync2(dirname4(path), { recursive: true });
|
|
1000
1366
|
let existing = "";
|
|
1001
|
-
if (
|
|
1367
|
+
if (existsSync3(path)) {
|
|
1002
1368
|
try {
|
|
1003
1369
|
existing = readFileSync2(path, "utf8");
|
|
1004
1370
|
} catch {
|
|
@@ -1027,7 +1393,7 @@ function writeManagedSecrets(managedKeys, record) {
|
|
|
1027
1393
|
} catch {
|
|
1028
1394
|
}
|
|
1029
1395
|
}
|
|
1030
|
-
var PLUGINS_FILE =
|
|
1396
|
+
var PLUGINS_FILE = join7(homedir6(), ".agentbox", "plugins.json");
|
|
1031
1397
|
var SUPPORTED_SDK_API_VERSIONS = [1, 2];
|
|
1032
1398
|
function isSupportedApiVersion(v) {
|
|
1033
1399
|
return SUPPORTED_SDK_API_VERSIONS.includes(v);
|
|
@@ -1038,7 +1404,7 @@ var LOCK_ACQUIRE_TIMEOUT_MS2 = 2e4;
|
|
|
1038
1404
|
var LOCK_RETRY_MS2 = 25;
|
|
1039
1405
|
async function withFileLock(path, fn) {
|
|
1040
1406
|
const lockPath = `${path}.lock`;
|
|
1041
|
-
await
|
|
1407
|
+
await mkdir4(dirname5(path), { recursive: true });
|
|
1042
1408
|
const deadline = Date.now() + LOCK_ACQUIRE_TIMEOUT_MS2;
|
|
1043
1409
|
let held = false;
|
|
1044
1410
|
while (!held) {
|
|
@@ -1053,7 +1419,7 @@ async function withFileLock(path, fn) {
|
|
|
1053
1419
|
try {
|
|
1054
1420
|
const st = await stat3(lockPath);
|
|
1055
1421
|
if (Date.now() - st.mtimeMs > LOCK_STALE_MS2) {
|
|
1056
|
-
await
|
|
1422
|
+
await rm3(lockPath, { force: true });
|
|
1057
1423
|
continue;
|
|
1058
1424
|
}
|
|
1059
1425
|
} catch {
|
|
@@ -1066,7 +1432,7 @@ async function withFileLock(path, fn) {
|
|
|
1066
1432
|
try {
|
|
1067
1433
|
return await fn();
|
|
1068
1434
|
} finally {
|
|
1069
|
-
if (held) await
|
|
1435
|
+
if (held) await rm3(lockPath, { force: true }).catch(() => {
|
|
1070
1436
|
});
|
|
1071
1437
|
}
|
|
1072
1438
|
}
|
|
@@ -1079,7 +1445,7 @@ function normalize2(raw) {
|
|
|
1079
1445
|
}
|
|
1080
1446
|
function readPluginRegistrySync(path = PLUGINS_FILE) {
|
|
1081
1447
|
try {
|
|
1082
|
-
if (!
|
|
1448
|
+
if (!existsSync4(path)) return { ...EMPTY2 };
|
|
1083
1449
|
return normalize2(JSON.parse(readFileSync3(path, "utf8")));
|
|
1084
1450
|
} catch {
|
|
1085
1451
|
return { ...EMPTY2 };
|
|
@@ -1110,7 +1476,7 @@ async function readForWrite(path) {
|
|
|
1110
1476
|
return p;
|
|
1111
1477
|
}
|
|
1112
1478
|
async function writeRegistry(file, path = PLUGINS_FILE) {
|
|
1113
|
-
await
|
|
1479
|
+
await mkdir4(dirname5(path), { recursive: true });
|
|
1114
1480
|
const tmp = `${path}.tmp.${String(process.pid)}.${String(Date.now())}`;
|
|
1115
1481
|
await writeFile2(tmp, JSON.stringify(file, null, 2) + "\n", "utf8");
|
|
1116
1482
|
await rename2(tmp, path);
|
|
@@ -1157,7 +1523,7 @@ function wantsRender(e) {
|
|
|
1157
1523
|
async function renderCarryEntries(entries, ctx, onLog) {
|
|
1158
1524
|
if (!entries.some(wantsRender)) return entries;
|
|
1159
1525
|
const context = carryPlaceholderContext(ctx);
|
|
1160
|
-
const stage = await mkdtemp(
|
|
1526
|
+
const stage = await mkdtemp(join8(tmpdir(), "agentbox-carry-render-"));
|
|
1161
1527
|
const out = [];
|
|
1162
1528
|
for (const [i, entry] of entries.entries()) {
|
|
1163
1529
|
if (!wantsRender(entry)) {
|
|
@@ -1171,7 +1537,7 @@ async function renderCarryEntries(entries, ctx, onLog) {
|
|
|
1171
1537
|
context,
|
|
1172
1538
|
onWarn: (msg) => onLog?.(`carry: ${entry.rawSrc}: ${msg}`)
|
|
1173
1539
|
});
|
|
1174
|
-
const tmp =
|
|
1540
|
+
const tmp = join8(stage, `${String(i)}-${basename2(entry.absSrc)}`);
|
|
1175
1541
|
await writeFile3(tmp, rendered, "utf8");
|
|
1176
1542
|
out.push({ ...entry, absSrc: tmp, bytes: Buffer.byteLength(rendered) });
|
|
1177
1543
|
const what = [
|
|
@@ -1227,7 +1593,7 @@ var AGENT_SYNC_SPECS = [
|
|
|
1227
1593
|
credential: {
|
|
1228
1594
|
boxRelPath: ".credentials.json",
|
|
1229
1595
|
boxAbsPath: `${CLAUDE_BOX_DIR}/.credentials.json`,
|
|
1230
|
-
hostBackup:
|
|
1596
|
+
hostBackup: join9(STATE_DIR, "claude-credentials.json"),
|
|
1231
1597
|
cloudMountPath: "/home/vscode/.agentbox-creds/claude",
|
|
1232
1598
|
cloudSubpath: "claude/",
|
|
1233
1599
|
realShape: "claude-oauth"
|
|
@@ -1299,7 +1665,7 @@ var AGENT_SYNC_SPECS = [
|
|
|
1299
1665
|
credential: {
|
|
1300
1666
|
boxRelPath: "auth.json",
|
|
1301
1667
|
boxAbsPath: `${CODEX_BOX_DIR}/auth.json`,
|
|
1302
|
-
hostBackup:
|
|
1668
|
+
hostBackup: join9(STATE_DIR, "codex-credentials.json"),
|
|
1303
1669
|
cloudMountPath: "/home/vscode/.agentbox-creds/codex",
|
|
1304
1670
|
cloudSubpath: "codex/",
|
|
1305
1671
|
realShape: "nonempty-json"
|
|
@@ -1350,7 +1716,7 @@ var AGENT_SYNC_SPECS = [
|
|
|
1350
1716
|
credential: {
|
|
1351
1717
|
boxRelPath: "auth.json",
|
|
1352
1718
|
boxAbsPath: `${OPENCODE_BOX_DIR}/auth.json`,
|
|
1353
|
-
hostBackup:
|
|
1719
|
+
hostBackup: join9(STATE_DIR, "opencode-credentials.json"),
|
|
1354
1720
|
cloudMountPath: "/home/vscode/.agentbox-creds/opencode",
|
|
1355
1721
|
cloudSubpath: "opencode/",
|
|
1356
1722
|
realShape: "nonempty-json"
|
|
@@ -1539,12 +1905,12 @@ async function readJsonFile(path) {
|
|
|
1539
1905
|
}
|
|
1540
1906
|
}
|
|
1541
1907
|
async function computeClaudePullPlan(inv, opts = {}) {
|
|
1542
|
-
const hostHome = opts.hostHome ??
|
|
1543
|
-
const hostClaude =
|
|
1908
|
+
const hostHome = opts.hostHome ?? homedir7();
|
|
1909
|
+
const hostClaude = join10(hostHome, ".claude");
|
|
1544
1910
|
const newItems = [];
|
|
1545
1911
|
const copyRels = [];
|
|
1546
1912
|
for (const cat of CLAUDE_PULL_DIR_CATEGORIES) {
|
|
1547
|
-
const hostNames = await listChildDirs(
|
|
1913
|
+
const hostNames = await listChildDirs(join10(hostClaude, cat));
|
|
1548
1914
|
const excludes = cat === "skills" ? SKILL_EXCLUDE_PREFIXES : [];
|
|
1549
1915
|
for (const name of pickNewItems(inv.dirs[cat] ?? [], hostNames, excludes)) {
|
|
1550
1916
|
newItems.push({ category: cat, name });
|
|
@@ -1552,8 +1918,8 @@ async function computeClaudePullPlan(inv, opts = {}) {
|
|
|
1552
1918
|
}
|
|
1553
1919
|
}
|
|
1554
1920
|
const hostPluginKeys = [];
|
|
1555
|
-
for (const m of await listChildDirs(
|
|
1556
|
-
for (const p of await listChildDirs(
|
|
1921
|
+
for (const m of await listChildDirs(join10(hostClaude, "plugins", "cache"))) {
|
|
1922
|
+
for (const p of await listChildDirs(join10(hostClaude, "plugins", "cache", m))) {
|
|
1557
1923
|
hostPluginKeys.push(`${m}/${p}`);
|
|
1558
1924
|
}
|
|
1559
1925
|
}
|
|
@@ -1561,8 +1927,8 @@ async function computeClaudePullPlan(inv, opts = {}) {
|
|
|
1561
1927
|
newItems.push({ category: "plugins", name: key });
|
|
1562
1928
|
copyRels.push(`plugins/cache/${key}`);
|
|
1563
1929
|
}
|
|
1564
|
-
const hostInstalled = await readJsonFile(
|
|
1565
|
-
const hostMarkets = await readJsonFile(
|
|
1930
|
+
const hostInstalled = await readJsonFile(join10(hostClaude, "plugins", "installed_plugins.json"));
|
|
1931
|
+
const hostMarkets = await readJsonFile(join10(hostClaude, "plugins", "known_marketplaces.json"));
|
|
1566
1932
|
const mergedInstalled = mergeInstalledPlugins(hostInstalled, inv.registries["installed_plugins"], {
|
|
1567
1933
|
hostHome
|
|
1568
1934
|
});
|
|
@@ -1576,18 +1942,18 @@ async function computeClaudePullPlan(inv, opts = {}) {
|
|
|
1576
1942
|
}
|
|
1577
1943
|
async function writeClaudeMergedRegistries(plan, opts = {}) {
|
|
1578
1944
|
if (!plan.mergedInstalled.changed && !plan.mergedMarkets.changed) return;
|
|
1579
|
-
const hostClaude =
|
|
1580
|
-
await
|
|
1945
|
+
const hostClaude = join10(opts.hostHome ?? homedir7(), ".claude");
|
|
1946
|
+
await mkdir5(join10(hostClaude, "plugins"), { recursive: true });
|
|
1581
1947
|
if (plan.mergedMarkets.changed) {
|
|
1582
1948
|
await writeFile4(
|
|
1583
|
-
|
|
1949
|
+
join10(hostClaude, "plugins", "known_marketplaces.json"),
|
|
1584
1950
|
`${JSON.stringify(plan.mergedMarkets.data, null, 2)}
|
|
1585
1951
|
`
|
|
1586
1952
|
);
|
|
1587
1953
|
}
|
|
1588
1954
|
if (plan.mergedInstalled.changed) {
|
|
1589
1955
|
await writeFile4(
|
|
1590
|
-
|
|
1956
|
+
join10(hostClaude, "plugins", "installed_plugins.json"),
|
|
1591
1957
|
`${JSON.stringify(plan.mergedInstalled.data, null, 2)}
|
|
1592
1958
|
`
|
|
1593
1959
|
);
|
|
@@ -1611,10 +1977,10 @@ async function pullClaudeExtrasViaTransport(t, opts = {}) {
|
|
|
1611
1977
|
if (opts.dryRun || plan.newItems.length === 0 && plan.mergedRegistries.length === 0) {
|
|
1612
1978
|
return result;
|
|
1613
1979
|
}
|
|
1614
|
-
const hostClaude =
|
|
1980
|
+
const hostClaude = join10(opts.hostHome ?? homedir7(), ".claude");
|
|
1615
1981
|
for (const rel of plan.copyRels) {
|
|
1616
|
-
const hostDest =
|
|
1617
|
-
await
|
|
1982
|
+
const hostDest = join10(hostClaude, rel);
|
|
1983
|
+
await mkdir5(hostDest, { recursive: true });
|
|
1618
1984
|
await t.pullTree(`${boxDir}/${rel}`, hostDest, { exclude: ["node_modules"] });
|
|
1619
1985
|
}
|
|
1620
1986
|
await writeClaudeMergedRegistries(plan, { hostHome: opts.hostHome });
|
|
@@ -1662,17 +2028,17 @@ async function pathExists(path) {
|
|
|
1662
2028
|
}
|
|
1663
2029
|
async function pullFlatEntry(t, entry, boxPath, hostPath) {
|
|
1664
2030
|
if (entry.kind === "dir") {
|
|
1665
|
-
await
|
|
2031
|
+
await mkdir5(hostPath, { recursive: true });
|
|
1666
2032
|
await t.pullTree(boxPath, hostPath, { exclude: ["node_modules"] });
|
|
1667
2033
|
return;
|
|
1668
2034
|
}
|
|
1669
|
-
await
|
|
2035
|
+
await mkdir5(dirname6(hostPath), { recursive: true });
|
|
1670
2036
|
await t.pullFile(boxPath, hostPath);
|
|
1671
2037
|
if (entry.name === "auth.json") await chmod(hostPath, 384);
|
|
1672
2038
|
}
|
|
1673
2039
|
async function pullCodexConfigViaTransport(t, opts = {}) {
|
|
1674
2040
|
const boxDir = opts.boxDir ?? CODEX_BOX_CONFIG_DIR;
|
|
1675
|
-
const hostCodex =
|
|
2041
|
+
const hostCodex = join10(opts.hostHome ?? homedir7(), ".codex");
|
|
1676
2042
|
const script = flatInventoryScript({ codex: { dir: boxDir, items: CODEX_PULL_ITEMS } });
|
|
1677
2043
|
const inv = await t.exec(["sh", "-c", script]);
|
|
1678
2044
|
if (inv.exitCode !== 0) {
|
|
@@ -1682,22 +2048,22 @@ async function pullCodexConfigViaTransport(t, opts = {}) {
|
|
|
1682
2048
|
}
|
|
1683
2049
|
const entries = [];
|
|
1684
2050
|
for (const entry of parseFlatInventory(inv.stdout)) {
|
|
1685
|
-
if (await pathExists(
|
|
2051
|
+
if (await pathExists(join10(hostCodex, entry.name))) continue;
|
|
1686
2052
|
entries.push(entry);
|
|
1687
2053
|
}
|
|
1688
2054
|
const newItems = entries.map((e) => e.name);
|
|
1689
2055
|
if (opts.dryRun || entries.length === 0) return { newItems };
|
|
1690
2056
|
for (const entry of entries) {
|
|
1691
|
-
await pullFlatEntry(t, entry, `${boxDir}/${entry.name}`,
|
|
2057
|
+
await pullFlatEntry(t, entry, `${boxDir}/${entry.name}`, join10(hostCodex, entry.name));
|
|
1692
2058
|
}
|
|
1693
2059
|
return { newItems };
|
|
1694
2060
|
}
|
|
1695
2061
|
async function pullOpencodeConfigViaTransport(t, opts = {}) {
|
|
1696
2062
|
const boxDir = opts.boxDir ?? OPENCODE_BOX_DATA_DIR;
|
|
1697
|
-
const hostHome = opts.hostHome ??
|
|
2063
|
+
const hostHome = opts.hostHome ?? homedir7();
|
|
1698
2064
|
const hostBases = {
|
|
1699
|
-
data:
|
|
1700
|
-
config:
|
|
2065
|
+
data: join10(hostHome, ".local", "share", "opencode"),
|
|
2066
|
+
config: join10(hostHome, ".config", "opencode")
|
|
1701
2067
|
};
|
|
1702
2068
|
const script = flatInventoryScript({
|
|
1703
2069
|
data: { dir: boxDir, items: OPENCODE_PULL_DATA_ITEMS },
|
|
@@ -1713,14 +2079,14 @@ async function pullOpencodeConfigViaTransport(t, opts = {}) {
|
|
|
1713
2079
|
for (const entry of parseFlatInventory(inv.stdout)) {
|
|
1714
2080
|
if (entry.group !== "data" && entry.group !== "config") continue;
|
|
1715
2081
|
const hostBase = hostBases[entry.group];
|
|
1716
|
-
if (await pathExists(
|
|
2082
|
+
if (await pathExists(join10(hostBase, entry.name))) continue;
|
|
1717
2083
|
entries.push({ ...entry, label: entry.group === "data" ? entry.name : `config/${entry.name}` });
|
|
1718
2084
|
}
|
|
1719
2085
|
const newItems = entries.map((e) => e.label);
|
|
1720
2086
|
if (opts.dryRun || entries.length === 0) return { newItems };
|
|
1721
2087
|
for (const entry of entries) {
|
|
1722
2088
|
const boxPath = entry.group === "data" ? `${boxDir}/${entry.name}` : `${boxDir}/config/${entry.name}`;
|
|
1723
|
-
const hostPath =
|
|
2089
|
+
const hostPath = join10(hostBases[entry.group], entry.name);
|
|
1724
2090
|
await pullFlatEntry(t, entry, boxPath, hostPath);
|
|
1725
2091
|
}
|
|
1726
2092
|
return { newItems };
|
|
@@ -1758,21 +2124,21 @@ function opencodeStagedItems(newItems) {
|
|
|
1758
2124
|
}
|
|
1759
2125
|
async function stageItemsViaTransport(t, boxDir, items, stagingDir) {
|
|
1760
2126
|
for (const item of items) {
|
|
1761
|
-
const dest =
|
|
2127
|
+
const dest = join11(stagingDir, item.rel);
|
|
1762
2128
|
if (item.kind === "dir") {
|
|
1763
|
-
await
|
|
2129
|
+
await mkdir6(dest, { recursive: true });
|
|
1764
2130
|
await t.pullTree(`${boxDir}/${item.rel}`, dest, { exclude: ["node_modules"] });
|
|
1765
2131
|
} else {
|
|
1766
|
-
await
|
|
2132
|
+
await mkdir6(dirname7(dest), { recursive: true });
|
|
1767
2133
|
await t.pullFile(`${boxDir}/${item.rel}`, dest);
|
|
1768
2134
|
}
|
|
1769
2135
|
}
|
|
1770
2136
|
}
|
|
1771
2137
|
async function makeStagingDir(agent) {
|
|
1772
|
-
return mkdtemp2(
|
|
2138
|
+
return mkdtemp2(join11(tmpdir2(), `agentbox-${agent}-propagate-`));
|
|
1773
2139
|
}
|
|
1774
2140
|
async function removeStagingDir(stagingDir) {
|
|
1775
|
-
await
|
|
2141
|
+
await rm4(stagingDir, { recursive: true, force: true });
|
|
1776
2142
|
}
|
|
1777
2143
|
function transportSettingsTarget(t, boxDir, label) {
|
|
1778
2144
|
const abs = (rel) => `${boxDir}/${rel}`;
|
|
@@ -1786,9 +2152,9 @@ function transportSettingsTarget(t, boxDir, label) {
|
|
|
1786
2152
|
return t.readText(abs(rel));
|
|
1787
2153
|
},
|
|
1788
2154
|
async writeText(rel, content, opts) {
|
|
1789
|
-
const stage = await mkdtemp2(
|
|
2155
|
+
const stage = await mkdtemp2(join11(tmpdir2(), "agentbox-target-write-"));
|
|
1790
2156
|
try {
|
|
1791
|
-
const tmp =
|
|
2157
|
+
const tmp = join11(stage, "file");
|
|
1792
2158
|
await writeFile5(tmp, content);
|
|
1793
2159
|
await t.exec(["sh", "-c", `mkdir -p '${dirname7(abs(rel))}'`]);
|
|
1794
2160
|
await t.pushFile(tmp, abs(rel));
|
|
@@ -1796,7 +2162,7 @@ function transportSettingsTarget(t, boxDir, label) {
|
|
|
1796
2162
|
await t.exec(["sh", "-c", `chmod ${opts.mode.toString(8)} '${abs(rel)}'`]);
|
|
1797
2163
|
}
|
|
1798
2164
|
} finally {
|
|
1799
|
-
await
|
|
2165
|
+
await rm4(stage, { recursive: true, force: true });
|
|
1800
2166
|
}
|
|
1801
2167
|
},
|
|
1802
2168
|
async copyIn(stagingAbs, rel, kind) {
|
|
@@ -1826,7 +2192,7 @@ async function propagateStagedSettings(target, staged) {
|
|
|
1826
2192
|
result.skipped.push(item.label);
|
|
1827
2193
|
continue;
|
|
1828
2194
|
}
|
|
1829
|
-
await target.copyIn(
|
|
2195
|
+
await target.copyIn(join11(staged.stagingDir, item.rel), item.rel, item.kind);
|
|
1830
2196
|
result.copied.push(item.label);
|
|
1831
2197
|
}
|
|
1832
2198
|
if (staged.agent === "claude" && staged.sourceRegistries) {
|
|
@@ -1890,7 +2256,7 @@ function makeSyncContext(init) {
|
|
|
1890
2256
|
hostWorkspace: init.hostWorkspace,
|
|
1891
2257
|
projectRoot: init.projectRoot ?? init.hostWorkspace,
|
|
1892
2258
|
boxWorkspace: init.boxWorkspace ?? "/workspace",
|
|
1893
|
-
hostHome: init.hostHome ??
|
|
2259
|
+
hostHome: init.hostHome ?? homedir8(),
|
|
1894
2260
|
onLog: init.onLog ?? (() => {
|
|
1895
2261
|
})
|
|
1896
2262
|
};
|
|
@@ -1948,7 +2314,7 @@ function buildHostEnvFindArgs(patterns) {
|
|
|
1948
2314
|
}
|
|
1949
2315
|
async function findEnvFilesForTar(workspaceDir, patterns) {
|
|
1950
2316
|
if (patterns.length === 0) return [];
|
|
1951
|
-
const found = await
|
|
2317
|
+
const found = await execa5("find", buildHostEnvFindArgs(patterns).slice(1), {
|
|
1952
2318
|
cwd: workspaceDir,
|
|
1953
2319
|
reject: false
|
|
1954
2320
|
});
|
|
@@ -1962,10 +2328,10 @@ async function scanHostEnvFiles(workspaceDir, patterns) {
|
|
|
1962
2328
|
async function pushEnvFiles(ctx, transport, patterns) {
|
|
1963
2329
|
const list = await findEnvFilesForTar(ctx.hostWorkspace, patterns);
|
|
1964
2330
|
if (list.length === 0) return { copied: 0 };
|
|
1965
|
-
const stage = await mkdtemp3(
|
|
1966
|
-
const localTar =
|
|
2331
|
+
const stage = await mkdtemp3(join12(tmpdir3(), "agentbox-envfiles-"));
|
|
2332
|
+
const localTar = join12(stage, "envfiles.tar");
|
|
1967
2333
|
try {
|
|
1968
|
-
const packed = await
|
|
2334
|
+
const packed = await execa5(
|
|
1969
2335
|
"tar",
|
|
1970
2336
|
["-C", ctx.hostWorkspace, "--null", "-T", "-", "-cf", localTar],
|
|
1971
2337
|
{ input: list.join("\0"), reject: false }
|
|
@@ -1983,7 +2349,7 @@ async function pushEnvFiles(ctx, transport, patterns) {
|
|
|
1983
2349
|
return { copied: 0 };
|
|
1984
2350
|
}
|
|
1985
2351
|
} finally {
|
|
1986
|
-
await
|
|
2352
|
+
await rm5(stage, { recursive: true, force: true });
|
|
1987
2353
|
}
|
|
1988
2354
|
return { copied: list.length };
|
|
1989
2355
|
}
|
|
@@ -2035,9 +2401,9 @@ function encodeClaudeProjectsKey(absPath) {
|
|
|
2035
2401
|
return absPath.replace(/[^a-zA-Z0-9]/g, "-");
|
|
2036
2402
|
}
|
|
2037
2403
|
var BOX_CLAUDE_PROJECT_DIR = "/home/vscode/.claude/projects/-workspace";
|
|
2038
|
-
async function resolveClaudeMemoryDir(hostWorkspace, hostHome =
|
|
2404
|
+
async function resolveClaudeMemoryDir(hostWorkspace, hostHome = homedir9()) {
|
|
2039
2405
|
if (hostWorkspace.length === 0) return null;
|
|
2040
|
-
const memDir =
|
|
2406
|
+
const memDir = join13(
|
|
2041
2407
|
hostHome,
|
|
2042
2408
|
".claude",
|
|
2043
2409
|
"projects",
|
|
@@ -2080,8 +2446,8 @@ async function findUnsyncableSymlinks(root, reachableRoots) {
|
|
|
2080
2446
|
return;
|
|
2081
2447
|
}
|
|
2082
2448
|
for (const ent of entries) {
|
|
2083
|
-
const realFull =
|
|
2084
|
-
const virtualFull = virtualDir ?
|
|
2449
|
+
const realFull = join14(realDir, ent.name);
|
|
2450
|
+
const virtualFull = virtualDir ? join14(virtualDir, ent.name) : ent.name;
|
|
2085
2451
|
if (ent.isSymbolicLink()) {
|
|
2086
2452
|
let real;
|
|
2087
2453
|
try {
|
|
@@ -2184,7 +2550,7 @@ async function extractCredentials(transport, opts = {}) {
|
|
|
2184
2550
|
try {
|
|
2185
2551
|
const text = await transport.readText(spec.credential.boxAbsPath);
|
|
2186
2552
|
if (!text || !isRealAgentCredential(spec.id, text)) continue;
|
|
2187
|
-
await
|
|
2553
|
+
await mkdir7(dirname8(hostBackup), { recursive: true });
|
|
2188
2554
|
await writeFile6(hostBackup, text, { mode: 384 });
|
|
2189
2555
|
await chmod2(hostBackup, 384).catch(() => {
|
|
2190
2556
|
});
|
|
@@ -2224,7 +2590,7 @@ function shouldAcceptCredentialUpdate(agent, incoming, existing) {
|
|
|
2224
2590
|
}
|
|
2225
2591
|
async function writeCredentialBackup(agent, content, opts = {}) {
|
|
2226
2592
|
const path = opts.backupPath ?? resolveAgentSpec(agent).credential.hostBackup;
|
|
2227
|
-
await
|
|
2593
|
+
await mkdir7(dirname8(path), { recursive: true });
|
|
2228
2594
|
const tmp = `${path}.tmp-${String(process.pid)}`;
|
|
2229
2595
|
await writeFile6(tmp, content, { mode: 384 });
|
|
2230
2596
|
await rename3(tmp, path);
|
|
@@ -2242,9 +2608,9 @@ async function readCredentialBackup(agent, opts = {}) {
|
|
|
2242
2608
|
async function pushCredentialToBox(transport, agent, content) {
|
|
2243
2609
|
const abs = resolveAgentSpec(agent).credential.boxAbsPath;
|
|
2244
2610
|
const dir = abs.slice(0, abs.lastIndexOf("/"));
|
|
2245
|
-
const stage = await mkdtemp4(
|
|
2611
|
+
const stage = await mkdtemp4(join15(tmpdir4(), "agentbox-cred-push-"));
|
|
2246
2612
|
try {
|
|
2247
|
-
const tmp =
|
|
2613
|
+
const tmp = join15(stage, "credential");
|
|
2248
2614
|
await writeFile6(tmp, content, { mode: 384 });
|
|
2249
2615
|
const mk = await transport.exec(["sh", "-c", `mkdir -p '${dir}'`]);
|
|
2250
2616
|
if (mk.exitCode !== 0) {
|
|
@@ -2261,7 +2627,7 @@ async function pushCredentialToBox(transport, agent, content) {
|
|
|
2261
2627
|
throw new Error(`chown/chmod of ${abs} in box failed: ${norm.stderr.trim()}`);
|
|
2262
2628
|
}
|
|
2263
2629
|
} finally {
|
|
2264
|
-
await
|
|
2630
|
+
await rm6(stage, { recursive: true, force: true });
|
|
2265
2631
|
}
|
|
2266
2632
|
}
|
|
2267
2633
|
var NON_REGULAR_TOKEN = "-";
|
|
@@ -2391,20 +2757,20 @@ async function resyncWorkspace(worktrees, ports, onLog) {
|
|
|
2391
2757
|
function makeHostGitPorts() {
|
|
2392
2758
|
return {
|
|
2393
2759
|
async resolveHostRef(hostMain) {
|
|
2394
|
-
const hostBranchProbe = await
|
|
2760
|
+
const hostBranchProbe = await execa6(
|
|
2395
2761
|
"git",
|
|
2396
2762
|
["-C", hostMain, "symbolic-ref", "--short", "-q", "HEAD"],
|
|
2397
2763
|
{ reject: false }
|
|
2398
2764
|
);
|
|
2399
|
-
const hostRef = hostBranchProbe.exitCode === 0 && hostBranchProbe.stdout.trim() ? hostBranchProbe.stdout.trim() : (await
|
|
2765
|
+
const hostRef = hostBranchProbe.exitCode === 0 && hostBranchProbe.stdout.trim() ? hostBranchProbe.stdout.trim() : (await execa6("git", ["-C", hostMain, "rev-parse", "HEAD"], { reject: false })).stdout.trim();
|
|
2400
2766
|
return hostRef || null;
|
|
2401
2767
|
},
|
|
2402
2768
|
async createHostStash(hostMain) {
|
|
2403
|
-
const stash = await
|
|
2769
|
+
const stash = await execa6("git", ["-C", hostMain, "stash", "create"], { reject: false });
|
|
2404
2770
|
return stash.exitCode === 0 ? stash.stdout.trim() || null : null;
|
|
2405
2771
|
},
|
|
2406
2772
|
async listHostUntracked(hostMain) {
|
|
2407
|
-
const untracked = await
|
|
2773
|
+
const untracked = await execa6(
|
|
2408
2774
|
"git",
|
|
2409
2775
|
["-C", hostMain, "ls-files", "--others", "--exclude-standard", "-z"],
|
|
2410
2776
|
{ reject: false }
|
|
@@ -2412,10 +2778,10 @@ function makeHostGitPorts() {
|
|
|
2412
2778
|
return untracked.exitCode === 0 ? splitNul(untracked.stdout) : [];
|
|
2413
2779
|
},
|
|
2414
2780
|
async hashHostFile(hostMain, relPath) {
|
|
2415
|
-
return createHash("sha256").update(await readFile7(
|
|
2781
|
+
return createHash("sha256").update(await readFile7(join16(hostMain, relPath))).digest("hex");
|
|
2416
2782
|
},
|
|
2417
2783
|
async packHostFiles(hostMain, relPaths) {
|
|
2418
|
-
const tarOut = await
|
|
2784
|
+
const tarOut = await execa6("tar", ["-C", hostMain, "--null", "-T", "-", "-cf", "-"], {
|
|
2419
2785
|
input: relPaths.join("\0"),
|
|
2420
2786
|
encoding: "buffer",
|
|
2421
2787
|
reject: false
|
|
@@ -2445,7 +2811,7 @@ async function walkFiles(root, prefix = "") {
|
|
|
2445
2811
|
const out = [];
|
|
2446
2812
|
for (const ent of entries) {
|
|
2447
2813
|
const rel = prefix ? `${prefix}/${ent.name}` : ent.name;
|
|
2448
|
-
const full =
|
|
2814
|
+
const full = join17(root, ent.name);
|
|
2449
2815
|
if (ent.isDirectory()) {
|
|
2450
2816
|
out.push(...await walkFiles(full, rel));
|
|
2451
2817
|
} else if (ent.isFile()) {
|
|
@@ -2469,12 +2835,12 @@ async function buildHostSet(name, hostDir, boxDst) {
|
|
|
2469
2835
|
const rels = await walkFiles(hostDir);
|
|
2470
2836
|
const files = {};
|
|
2471
2837
|
for (const rel of rels) {
|
|
2472
|
-
files[rel] = await hashFile(
|
|
2838
|
+
files[rel] = await hashFile(join17(hostDir, rel));
|
|
2473
2839
|
}
|
|
2474
2840
|
return { dst: boxDst, files, hostDir };
|
|
2475
2841
|
}
|
|
2476
|
-
async function buildHostSyncManifest(workspacePath, hostHome =
|
|
2477
|
-
const workflowsDir =
|
|
2842
|
+
async function buildHostSyncManifest(workspacePath, hostHome = homedir10()) {
|
|
2843
|
+
const workflowsDir = join17(hostHome, ".claude", "workflows");
|
|
2478
2844
|
const workflowsHost = await pathExists4(workflowsDir) ? workflowsDir : null;
|
|
2479
2845
|
const memoryHost = await resolveClaudeMemoryDir(workspacePath, hostHome);
|
|
2480
2846
|
const [workflows, memory] = await Promise.all([
|
|
@@ -2496,7 +2862,7 @@ function computeSyncDelta(host, box) {
|
|
|
2496
2862
|
uploads.push({
|
|
2497
2863
|
set: name,
|
|
2498
2864
|
rel,
|
|
2499
|
-
absSrc:
|
|
2865
|
+
absSrc: join17(hostSet.hostDir, rel),
|
|
2500
2866
|
dst: `${hostSet.dst}/${rel}`
|
|
2501
2867
|
});
|
|
2502
2868
|
}
|
|
@@ -2515,29 +2881,29 @@ async function stageDynamicSyncTarball(uploads) {
|
|
|
2515
2881
|
return { tarballPath: null, cleanup: async () => {
|
|
2516
2882
|
} };
|
|
2517
2883
|
}
|
|
2518
|
-
const stageDir = await mkdtemp5(
|
|
2884
|
+
const stageDir = await mkdtemp5(join17(tmpdir5(), "agentbox-dynsync-stage-"));
|
|
2519
2885
|
let tarballPath = null;
|
|
2520
2886
|
try {
|
|
2521
2887
|
for (const up of uploads) {
|
|
2522
|
-
const target =
|
|
2523
|
-
await
|
|
2888
|
+
const target = join17(stageDir, up.set, up.rel);
|
|
2889
|
+
await mkdir8(dirname9(target), { recursive: true });
|
|
2524
2890
|
await copyFile(up.absSrc, target);
|
|
2525
2891
|
}
|
|
2526
|
-
tarballPath =
|
|
2527
|
-
await
|
|
2892
|
+
tarballPath = join17(tmpdir5(), `agentbox-dynsync-${basename22(stageDir)}.tar.gz`);
|
|
2893
|
+
await execa7("tar", ["-czf", tarballPath, "-C", stageDir, "."], {
|
|
2528
2894
|
env: { ...process.env, COPYFILE_DISABLE: "1" }
|
|
2529
2895
|
});
|
|
2530
2896
|
const tp = tarballPath;
|
|
2531
2897
|
return {
|
|
2532
2898
|
tarballPath: tp,
|
|
2533
2899
|
cleanup: async () => {
|
|
2534
|
-
await
|
|
2535
|
-
await
|
|
2900
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
2901
|
+
await rm7(tp, { force: true });
|
|
2536
2902
|
}
|
|
2537
2903
|
};
|
|
2538
2904
|
} catch (err) {
|
|
2539
|
-
await
|
|
2540
|
-
if (tarballPath) await
|
|
2905
|
+
await rm7(stageDir, { recursive: true, force: true });
|
|
2906
|
+
if (tarballPath) await rm7(tarballPath, { force: true });
|
|
2541
2907
|
throw err;
|
|
2542
2908
|
}
|
|
2543
2909
|
}
|
|
@@ -2657,7 +3023,7 @@ var BOX_WORKSPACE2 = "/workspace";
|
|
|
2657
3023
|
var MINIMAL_TRUSTED_CODEX_CONFIG = `[projects."${BOX_WORKSPACE2}"]
|
|
2658
3024
|
trust_level = "trusted"
|
|
2659
3025
|
`;
|
|
2660
|
-
function sanitizeCodexConfigForBox(tomlText, hostHome =
|
|
3026
|
+
function sanitizeCodexConfigForBox(tomlText, hostHome = homedir11()) {
|
|
2661
3027
|
const cfg = parse(tomlText);
|
|
2662
3028
|
let changed = false;
|
|
2663
3029
|
if (isRecord(cfg["mcp_servers"])) {
|
|
@@ -2764,7 +3130,7 @@ async function findBrokenSymlinks(root) {
|
|
|
2764
3130
|
return;
|
|
2765
3131
|
}
|
|
2766
3132
|
for (const ent of entries) {
|
|
2767
|
-
const full =
|
|
3133
|
+
const full = join18(dir, ent.name);
|
|
2768
3134
|
if (ent.isSymbolicLink()) {
|
|
2769
3135
|
try {
|
|
2770
3136
|
await stat9(full);
|
|
@@ -2780,7 +3146,7 @@ async function findBrokenSymlinks(root) {
|
|
|
2780
3146
|
return broken;
|
|
2781
3147
|
}
|
|
2782
3148
|
async function mkStageDir(prefix) {
|
|
2783
|
-
return mkdtemp6(
|
|
3149
|
+
return mkdtemp6(join18(tmpdir6(), `agentbox-${prefix}-stage-`));
|
|
2784
3150
|
}
|
|
2785
3151
|
var STAGE_WRITABLE_CHMOD = "--chmod=Du+rwx,Fu+rw";
|
|
2786
3152
|
function emptyResult(warnings = []) {
|
|
@@ -2788,8 +3154,8 @@ function emptyResult(warnings = []) {
|
|
|
2788
3154
|
}, warnings };
|
|
2789
3155
|
}
|
|
2790
3156
|
async function tarballFromDir(stageDir, agent) {
|
|
2791
|
-
const tarballPath =
|
|
2792
|
-
await
|
|
3157
|
+
const tarballPath = join18(tmpdir6(), `agentbox-${agent}-${basename3(stageDir)}.tar.gz`);
|
|
3158
|
+
await execa8("tar", ["-czf", tarballPath, "-C", stageDir, "."], {
|
|
2793
3159
|
env: { ...process.env, COPYFILE_DISABLE: "1" }
|
|
2794
3160
|
});
|
|
2795
3161
|
return tarballPath;
|
|
@@ -2797,7 +3163,7 @@ async function tarballFromDir(stageDir, agent) {
|
|
|
2797
3163
|
function makeCleanup(paths) {
|
|
2798
3164
|
return async () => {
|
|
2799
3165
|
for (const p of paths) {
|
|
2800
|
-
await
|
|
3166
|
+
await rm8(p, { recursive: true, force: true });
|
|
2801
3167
|
}
|
|
2802
3168
|
};
|
|
2803
3169
|
}
|
|
@@ -2805,7 +3171,7 @@ async function stageSingleFileTarball(agent, sourcePath, tarballEntryName) {
|
|
|
2805
3171
|
const stageDir = await mkStageDir(agent);
|
|
2806
3172
|
let tarballPath = null;
|
|
2807
3173
|
try {
|
|
2808
|
-
await copyFile2(sourcePath,
|
|
3174
|
+
await copyFile2(sourcePath, join18(stageDir, tarballEntryName));
|
|
2809
3175
|
tarballPath = await tarballFromDir(stageDir, agent);
|
|
2810
3176
|
return {
|
|
2811
3177
|
tarballPath,
|
|
@@ -2813,15 +3179,15 @@ async function stageSingleFileTarball(agent, sourcePath, tarballEntryName) {
|
|
|
2813
3179
|
warnings: []
|
|
2814
3180
|
};
|
|
2815
3181
|
} catch (err) {
|
|
2816
|
-
await
|
|
2817
|
-
if (tarballPath) await
|
|
3182
|
+
await rm8(stageDir, { recursive: true, force: true });
|
|
3183
|
+
if (tarballPath) await rm8(tarballPath, { force: true });
|
|
2818
3184
|
throw err;
|
|
2819
3185
|
}
|
|
2820
3186
|
}
|
|
2821
3187
|
var CLAUDE_STATIC_EXCLUDES = resolveAgentSpec("claude").staticPaths[0]?.exclude ?? [];
|
|
2822
3188
|
async function buildBoxClaudeJsonFromHost(opts) {
|
|
2823
3189
|
const { hostHome, hostWorkspace } = opts;
|
|
2824
|
-
const hostClaudeJson =
|
|
3190
|
+
const hostClaudeJson = join18(hostHome, ".claude.json");
|
|
2825
3191
|
let working;
|
|
2826
3192
|
if (await pathExists5(hostClaudeJson)) {
|
|
2827
3193
|
try {
|
|
@@ -2856,7 +3222,7 @@ async function buildBoxClaudeJsonFromHost(opts) {
|
|
|
2856
3222
|
return working;
|
|
2857
3223
|
}
|
|
2858
3224
|
async function stageClaudeJsonOnlyForUpload(opts = {}) {
|
|
2859
|
-
const hostHome = opts.hostHome ??
|
|
3225
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
2860
3226
|
const stageDir = await mkStageDir("claude-json-only");
|
|
2861
3227
|
let tarballPath = null;
|
|
2862
3228
|
try {
|
|
@@ -2864,7 +3230,7 @@ async function stageClaudeJsonOnlyForUpload(opts = {}) {
|
|
|
2864
3230
|
hostHome,
|
|
2865
3231
|
hostWorkspace: opts.hostWorkspace
|
|
2866
3232
|
});
|
|
2867
|
-
await writeFile7(
|
|
3233
|
+
await writeFile7(join18(stageDir, "_claude.json"), JSON.stringify(claudeJson, null, 2));
|
|
2868
3234
|
tarballPath = await tarballFromDir(stageDir, "claude-json-only");
|
|
2869
3235
|
return {
|
|
2870
3236
|
tarballPath,
|
|
@@ -2872,14 +3238,14 @@ async function stageClaudeJsonOnlyForUpload(opts = {}) {
|
|
|
2872
3238
|
warnings: []
|
|
2873
3239
|
};
|
|
2874
3240
|
} catch (err) {
|
|
2875
|
-
await
|
|
2876
|
-
if (tarballPath) await
|
|
3241
|
+
await rm8(stageDir, { recursive: true, force: true });
|
|
3242
|
+
if (tarballPath) await rm8(tarballPath, { force: true });
|
|
2877
3243
|
throw err;
|
|
2878
3244
|
}
|
|
2879
3245
|
}
|
|
2880
3246
|
async function stageClaudeStaticForUpload(opts = {}) {
|
|
2881
|
-
const hostHome = opts.hostHome ??
|
|
2882
|
-
const hostClaude =
|
|
3247
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3248
|
+
const hostClaude = join18(hostHome, ".claude");
|
|
2883
3249
|
if (!await pathExists5(hostClaude)) return emptyResult();
|
|
2884
3250
|
const stageDir = await mkStageDir("claude-static");
|
|
2885
3251
|
let tarballPath = null;
|
|
@@ -2889,7 +3255,7 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2889
3255
|
...CLAUDE_STATIC_EXCLUDES.map((p) => `--exclude=${p}`),
|
|
2890
3256
|
...broken.map((r) => `--exclude=/${r}`)
|
|
2891
3257
|
];
|
|
2892
|
-
await
|
|
3258
|
+
await execa8("rsync", [
|
|
2893
3259
|
"-a",
|
|
2894
3260
|
STAGE_WRITABLE_CHMOD,
|
|
2895
3261
|
"--copy-unsafe-links",
|
|
@@ -2897,7 +3263,7 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2897
3263
|
`${hostClaude}/`,
|
|
2898
3264
|
`${stageDir}/`
|
|
2899
3265
|
]);
|
|
2900
|
-
const settingsPath =
|
|
3266
|
+
const settingsPath = join18(stageDir, "settings.json");
|
|
2901
3267
|
if (await pathExists5(settingsPath)) {
|
|
2902
3268
|
try {
|
|
2903
3269
|
const parsed = JSON.parse(await readFile9(settingsPath, "utf8"));
|
|
@@ -2912,14 +3278,14 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2912
3278
|
hostHome,
|
|
2913
3279
|
hostWorkspace: opts.hostWorkspace
|
|
2914
3280
|
});
|
|
2915
|
-
await writeFile7(
|
|
2916
|
-
const pluginsDir =
|
|
3281
|
+
await writeFile7(join18(stageDir, "_claude.json"), JSON.stringify(claudeJson, null, 2));
|
|
3282
|
+
const pluginsDir = join18(stageDir, "plugins");
|
|
2917
3283
|
if (await pathExists5(pluginsDir)) {
|
|
2918
3284
|
try {
|
|
2919
3285
|
const entries = await readdir6(pluginsDir, { withFileTypes: true });
|
|
2920
3286
|
for (const ent of entries) {
|
|
2921
3287
|
if (!ent.isFile() || !ent.name.endsWith(".json")) continue;
|
|
2922
|
-
const file =
|
|
3288
|
+
const file = join18(pluginsDir, ent.name);
|
|
2923
3289
|
const raw = await readFile9(file, "utf8");
|
|
2924
3290
|
const replaced = raw.split(`${hostHome}/.claude/plugins/`).join("/home/vscode/.claude/plugins/");
|
|
2925
3291
|
if (replaced !== raw) await writeFile7(file, replaced);
|
|
@@ -2934,8 +3300,8 @@ async function stageClaudeStaticForUpload(opts = {}) {
|
|
|
2934
3300
|
warnings: []
|
|
2935
3301
|
};
|
|
2936
3302
|
} catch (err) {
|
|
2937
|
-
await
|
|
2938
|
-
if (tarballPath) await
|
|
3303
|
+
await rm8(stageDir, { recursive: true, force: true });
|
|
3304
|
+
if (tarballPath) await rm8(tarballPath, { force: true });
|
|
2939
3305
|
throw err;
|
|
2940
3306
|
}
|
|
2941
3307
|
}
|
|
@@ -2962,7 +3328,7 @@ async function sanitizeStagedCodexConfig(configPath, hostHome) {
|
|
|
2962
3328
|
async function purgeOrphanCodexMarketplaceDirs(stageDir, keptMarketplaces) {
|
|
2963
3329
|
const kept = new Set(keptMarketplaces);
|
|
2964
3330
|
for (const rel of ["plugins/cache", ".tmp/marketplaces"]) {
|
|
2965
|
-
const dir =
|
|
3331
|
+
const dir = join18(stageDir, rel);
|
|
2966
3332
|
let entries;
|
|
2967
3333
|
try {
|
|
2968
3334
|
entries = await readdir6(dir);
|
|
@@ -2971,19 +3337,19 @@ async function purgeOrphanCodexMarketplaceDirs(stageDir, keptMarketplaces) {
|
|
|
2971
3337
|
}
|
|
2972
3338
|
for (const name of entries) {
|
|
2973
3339
|
if (kept.has(name)) continue;
|
|
2974
|
-
await
|
|
3340
|
+
await rm8(join18(dir, name), { recursive: true, force: true });
|
|
2975
3341
|
}
|
|
2976
3342
|
}
|
|
2977
3343
|
}
|
|
2978
3344
|
async function stageCodexStaticForUpload(opts = {}) {
|
|
2979
|
-
const hostHome = opts.hostHome ??
|
|
2980
|
-
const hostCodex =
|
|
3345
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3346
|
+
const hostCodex = join18(hostHome, ".codex");
|
|
2981
3347
|
if (!await pathExists5(hostCodex)) return emptyResult();
|
|
2982
3348
|
const stageDir = await mkStageDir("codex-static");
|
|
2983
3349
|
let tarballPath = null;
|
|
2984
3350
|
try {
|
|
2985
3351
|
const codexBroken = await findBrokenSymlinks(hostCodex);
|
|
2986
|
-
await
|
|
3352
|
+
await execa8("rsync", [
|
|
2987
3353
|
"-a",
|
|
2988
3354
|
STAGE_WRITABLE_CHMOD,
|
|
2989
3355
|
"-L",
|
|
@@ -2993,7 +3359,7 @@ async function stageCodexStaticForUpload(opts = {}) {
|
|
|
2993
3359
|
`${hostCodex}/`,
|
|
2994
3360
|
`${stageDir}/`
|
|
2995
3361
|
]);
|
|
2996
|
-
const sanitized = await sanitizeStagedCodexConfig(
|
|
3362
|
+
const sanitized = await sanitizeStagedCodexConfig(join18(stageDir, "config.toml"), hostHome);
|
|
2997
3363
|
if (sanitized !== null) {
|
|
2998
3364
|
await purgeOrphanCodexMarketplaceDirs(stageDir, sanitized.keptMarketplaces);
|
|
2999
3365
|
}
|
|
@@ -3004,20 +3370,20 @@ async function stageCodexStaticForUpload(opts = {}) {
|
|
|
3004
3370
|
warnings: []
|
|
3005
3371
|
};
|
|
3006
3372
|
} catch (err) {
|
|
3007
|
-
await
|
|
3008
|
-
if (tarballPath) await
|
|
3373
|
+
await rm8(stageDir, { recursive: true, force: true });
|
|
3374
|
+
if (tarballPath) await rm8(tarballPath, { force: true });
|
|
3009
3375
|
throw err;
|
|
3010
3376
|
}
|
|
3011
3377
|
}
|
|
3012
3378
|
async function stageAgentsStaticForUpload(opts = {}) {
|
|
3013
|
-
const hostHome = opts.hostHome ??
|
|
3014
|
-
const hostAgents =
|
|
3379
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3380
|
+
const hostAgents = join18(hostHome, ".agents");
|
|
3015
3381
|
if (!await pathExists5(hostAgents)) return emptyResult();
|
|
3016
3382
|
const stageDir = await mkStageDir("agents-static");
|
|
3017
3383
|
let tarballPath = null;
|
|
3018
3384
|
try {
|
|
3019
3385
|
const broken = await findBrokenSymlinks(hostAgents);
|
|
3020
|
-
await
|
|
3386
|
+
await execa8("rsync", [
|
|
3021
3387
|
"-a",
|
|
3022
3388
|
STAGE_WRITABLE_CHMOD,
|
|
3023
3389
|
"-L",
|
|
@@ -3032,26 +3398,26 @@ async function stageAgentsStaticForUpload(opts = {}) {
|
|
|
3032
3398
|
warnings: []
|
|
3033
3399
|
};
|
|
3034
3400
|
} catch (err) {
|
|
3035
|
-
await
|
|
3036
|
-
if (tarballPath) await
|
|
3401
|
+
await rm8(stageDir, { recursive: true, force: true });
|
|
3402
|
+
if (tarballPath) await rm8(tarballPath, { force: true });
|
|
3037
3403
|
throw err;
|
|
3038
3404
|
}
|
|
3039
3405
|
}
|
|
3040
3406
|
async function stageCodexCredentialsForUpload(opts = {}) {
|
|
3041
|
-
const hostHome = opts.hostHome ??
|
|
3042
|
-
const cloudBackup =
|
|
3407
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3408
|
+
const cloudBackup = join18(hostHome, ".agentbox", "codex-credentials.json");
|
|
3043
3409
|
if (await pathExists5(cloudBackup)) {
|
|
3044
3410
|
return stageSingleFileTarball("codex-creds", cloudBackup, "auth.json");
|
|
3045
3411
|
}
|
|
3046
|
-
const hostAuth =
|
|
3412
|
+
const hostAuth = join18(hostHome, ".codex", "auth.json");
|
|
3047
3413
|
if (!await pathExists5(hostAuth)) return emptyResult([CODEX_KEYCHAIN_WARNING]);
|
|
3048
3414
|
return stageSingleFileTarball("codex-creds", hostAuth, "auth.json");
|
|
3049
3415
|
}
|
|
3050
3416
|
var OPENCODE_DATA_EXCLUDES = resolveAgentSpec("opencode").staticPaths[0]?.exclude ?? [];
|
|
3051
3417
|
async function stageOpencodeStaticForUpload(opts = {}) {
|
|
3052
|
-
const hostHome = opts.hostHome ??
|
|
3053
|
-
const hostData =
|
|
3054
|
-
const hostConfig =
|
|
3418
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3419
|
+
const hostData = join18(hostHome, ".local", "share", "opencode");
|
|
3420
|
+
const hostConfig = join18(hostHome, ".config", "opencode");
|
|
3055
3421
|
const hasData = await pathExists5(hostData);
|
|
3056
3422
|
const hasConfig = await pathExists5(hostConfig);
|
|
3057
3423
|
if (!hasData && !hasConfig) return emptyResult();
|
|
@@ -3060,7 +3426,7 @@ async function stageOpencodeStaticForUpload(opts = {}) {
|
|
|
3060
3426
|
try {
|
|
3061
3427
|
if (hasData) {
|
|
3062
3428
|
const dataBroken = await findBrokenSymlinks(hostData);
|
|
3063
|
-
await
|
|
3429
|
+
await execa8("rsync", [
|
|
3064
3430
|
"-a",
|
|
3065
3431
|
STAGE_WRITABLE_CHMOD,
|
|
3066
3432
|
"-L",
|
|
@@ -3071,9 +3437,9 @@ async function stageOpencodeStaticForUpload(opts = {}) {
|
|
|
3071
3437
|
]);
|
|
3072
3438
|
}
|
|
3073
3439
|
if (hasConfig) {
|
|
3074
|
-
const configStage =
|
|
3440
|
+
const configStage = join18(stageDir, "config");
|
|
3075
3441
|
const cfgBroken = await findBrokenSymlinks(hostConfig);
|
|
3076
|
-
await
|
|
3442
|
+
await execa8("rsync", [
|
|
3077
3443
|
"-a",
|
|
3078
3444
|
STAGE_WRITABLE_CHMOD,
|
|
3079
3445
|
"-L",
|
|
@@ -3089,24 +3455,24 @@ async function stageOpencodeStaticForUpload(opts = {}) {
|
|
|
3089
3455
|
warnings: []
|
|
3090
3456
|
};
|
|
3091
3457
|
} catch (err) {
|
|
3092
|
-
await
|
|
3093
|
-
if (tarballPath) await
|
|
3458
|
+
await rm8(stageDir, { recursive: true, force: true });
|
|
3459
|
+
if (tarballPath) await rm8(tarballPath, { force: true });
|
|
3094
3460
|
throw err;
|
|
3095
3461
|
}
|
|
3096
3462
|
}
|
|
3097
3463
|
async function stageOpencodeCredentialsForUpload(opts = {}) {
|
|
3098
|
-
const hostHome = opts.hostHome ??
|
|
3099
|
-
const cloudBackup =
|
|
3464
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3465
|
+
const cloudBackup = join18(hostHome, ".agentbox", "opencode-credentials.json");
|
|
3100
3466
|
if (await pathExists5(cloudBackup)) {
|
|
3101
3467
|
return stageSingleFileTarball("opencode-creds", cloudBackup, "auth.json");
|
|
3102
3468
|
}
|
|
3103
|
-
const hostAuth =
|
|
3469
|
+
const hostAuth = join18(hostHome, ".local", "share", "opencode", "auth.json");
|
|
3104
3470
|
if (!await pathExists5(hostAuth)) return emptyResult();
|
|
3105
3471
|
return stageSingleFileTarball("opencode-creds", hostAuth, "auth.json");
|
|
3106
3472
|
}
|
|
3107
3473
|
async function stageOpencodeStateForUpload(opts = {}) {
|
|
3108
|
-
const hostHome = opts.hostHome ??
|
|
3109
|
-
const hostModel =
|
|
3474
|
+
const hostHome = opts.hostHome ?? homedir12();
|
|
3475
|
+
const hostModel = join18(hostHome, ".local", "state", "opencode", "model.json");
|
|
3110
3476
|
if (!await pathExists5(hostModel)) return emptyResult();
|
|
3111
3477
|
return stageSingleFileTarball("opencode-state", hostModel, "model.json");
|
|
3112
3478
|
}
|
|
@@ -3132,11 +3498,11 @@ function preparedStatePathFor(provider) {
|
|
|
3132
3498
|
if (!/^[A-Za-z0-9._-]+$/.test(provider)) {
|
|
3133
3499
|
throw new Error(`invalid provider name for prepared-state: ${JSON.stringify(provider)}`);
|
|
3134
3500
|
}
|
|
3135
|
-
return pathResolve(
|
|
3501
|
+
return pathResolve(homedir13(), ".agentbox", `${provider}-prepared.json`);
|
|
3136
3502
|
}
|
|
3137
3503
|
function readPreparedStateRaw(provider) {
|
|
3138
3504
|
const path = preparedStatePathFor(provider);
|
|
3139
|
-
if (!
|
|
3505
|
+
if (!existsSync5(path)) return null;
|
|
3140
3506
|
try {
|
|
3141
3507
|
return JSON.parse(readFileSync4(path, "utf8"));
|
|
3142
3508
|
} catch {
|
|
@@ -3221,7 +3587,7 @@ function resolveContextFilesFrom(fileMap, opts) {
|
|
|
3221
3587
|
pathResolve(opts.contextDir, paths.staged),
|
|
3222
3588
|
pathResolve(opts.devRoot, paths.dev)
|
|
3223
3589
|
];
|
|
3224
|
-
const hit = candidates.find((p) =>
|
|
3590
|
+
const hit = candidates.find((p) => existsSync5(p));
|
|
3225
3591
|
if (!hit) return null;
|
|
3226
3592
|
out.push({ rel, abs: hit });
|
|
3227
3593
|
}
|
|
@@ -3235,14 +3601,14 @@ function registryRefForSha(sha, registry = BOX_IMAGE_REGISTRY) {
|
|
|
3235
3601
|
// ../../packages/sandbox-docker/dist/chunk-6T2XZZB5.js
|
|
3236
3602
|
import { dirname as dirname23, resolve as resolve23 } from "path";
|
|
3237
3603
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3238
|
-
import { execa as
|
|
3239
|
-
import { existsSync as
|
|
3604
|
+
import { execa as execa9 } from "execa";
|
|
3605
|
+
import { existsSync as existsSync6 } from "fs";
|
|
3240
3606
|
import { fileURLToPath } from "url";
|
|
3241
|
-
import { dirname as dirname11, resolve as
|
|
3607
|
+
import { dirname as dirname11, resolve as resolve4 } from "path";
|
|
3242
3608
|
var DEFAULT_BOX_IMAGE = "agentbox/box:dev";
|
|
3243
3609
|
async function resolveClaudeInstallMode() {
|
|
3244
3610
|
try {
|
|
3245
|
-
const { loadEffectiveConfig } = await import("./dist-
|
|
3611
|
+
const { loadEffectiveConfig } = await import("./dist-U2SVLJUQ.js");
|
|
3246
3612
|
const cfg = await loadEffectiveConfig(process.cwd());
|
|
3247
3613
|
return cfg.effective.box.claudeInstall;
|
|
3248
3614
|
} catch {
|
|
@@ -3252,28 +3618,28 @@ async function resolveClaudeInstallMode() {
|
|
|
3252
3618
|
var here = dirname11(fileURLToPath(import.meta.url));
|
|
3253
3619
|
function resolveDockerBuild() {
|
|
3254
3620
|
const override = process.env.AGENTBOX_DOCKER_CONTEXT;
|
|
3255
|
-
if (override &&
|
|
3256
|
-
return { dockerfile:
|
|
3621
|
+
if (override && existsSync6(resolve4(override, "Dockerfile.box"))) {
|
|
3622
|
+
return { dockerfile: resolve4(override, "Dockerfile.box"), context: override };
|
|
3257
3623
|
}
|
|
3258
|
-
const staged =
|
|
3259
|
-
if (
|
|
3260
|
-
return { dockerfile:
|
|
3624
|
+
const staged = resolve4(here, "..", "runtime", "docker");
|
|
3625
|
+
if (existsSync6(resolve4(staged, "Dockerfile.box"))) {
|
|
3626
|
+
return { dockerfile: resolve4(staged, "Dockerfile.box"), context: staged };
|
|
3261
3627
|
}
|
|
3262
|
-
const packageRoot =
|
|
3628
|
+
const packageRoot = resolve4(here, "..");
|
|
3263
3629
|
return {
|
|
3264
|
-
dockerfile:
|
|
3265
|
-
context:
|
|
3630
|
+
dockerfile: resolve4(packageRoot, "Dockerfile.box"),
|
|
3631
|
+
context: resolve4(packageRoot, "..", "..")
|
|
3266
3632
|
};
|
|
3267
3633
|
}
|
|
3268
3634
|
var { dockerfile: DOCKERFILE_PATH_RESOLVED, context: BUILD_CONTEXT_DIR_RESOLVED } = resolveDockerBuild();
|
|
3269
3635
|
var DOCKERFILE_PATH = DOCKERFILE_PATH_RESOLVED;
|
|
3270
3636
|
var BUILD_CONTEXT_DIR = BUILD_CONTEXT_DIR_RESOLVED;
|
|
3271
3637
|
async function imageExists(ref) {
|
|
3272
|
-
const result = await
|
|
3638
|
+
const result = await execa9("docker", ["image", "inspect", ref], { reject: false });
|
|
3273
3639
|
return result.exitCode === 0;
|
|
3274
3640
|
}
|
|
3275
3641
|
async function pullImage(target, opts = {}) {
|
|
3276
|
-
const subprocess =
|
|
3642
|
+
const subprocess = execa9("docker", ["pull", target], {
|
|
3277
3643
|
stderr: "pipe",
|
|
3278
3644
|
stdout: "pipe",
|
|
3279
3645
|
reject: false
|
|
@@ -3304,10 +3670,10 @@ async function pullImage(target, opts = {}) {
|
|
|
3304
3670
|
}
|
|
3305
3671
|
}
|
|
3306
3672
|
async function tagImage(source, target) {
|
|
3307
|
-
await
|
|
3673
|
+
await execa9("docker", ["tag", source, target]);
|
|
3308
3674
|
}
|
|
3309
3675
|
async function imageInfo(ref = DEFAULT_BOX_IMAGE) {
|
|
3310
|
-
const result = await
|
|
3676
|
+
const result = await execa9(
|
|
3311
3677
|
"docker",
|
|
3312
3678
|
["image", "inspect", "--format", "{{.Size}}|{{.Created}}", ref],
|
|
3313
3679
|
{ reject: false }
|
|
@@ -3334,7 +3700,7 @@ async function buildImage(opts = {}) {
|
|
|
3334
3700
|
if (process.env.AGENTBOX === "1") {
|
|
3335
3701
|
args.splice(1, 0, "--network=host");
|
|
3336
3702
|
}
|
|
3337
|
-
const subprocess =
|
|
3703
|
+
const subprocess = execa9("docker", args, {
|
|
3338
3704
|
stderr: "pipe",
|
|
3339
3705
|
stdout: "pipe"
|
|
3340
3706
|
});
|
|
@@ -3352,7 +3718,7 @@ async function buildImage(opts = {}) {
|
|
|
3352
3718
|
return ref;
|
|
3353
3719
|
}
|
|
3354
3720
|
async function pullOrBuild(ref, fingerprint, opts = {}) {
|
|
3355
|
-
const { writePreparedDockerState: writePreparedDockerState2 } = await import("./prepared-state-75DIZ55S-
|
|
3721
|
+
const { writePreparedDockerState: writePreparedDockerState2 } = await import("./prepared-state-75DIZ55S-W6NU3S3B.js");
|
|
3356
3722
|
const registry = opts.registry ?? BOX_IMAGE_REGISTRY;
|
|
3357
3723
|
const allowPull = opts.allowPull !== false;
|
|
3358
3724
|
if (allowPull && registry && fingerprint) {
|
|
@@ -3379,7 +3745,7 @@ async function pullOrBuild(ref, fingerprint, opts = {}) {
|
|
|
3379
3745
|
return { source: "built" };
|
|
3380
3746
|
}
|
|
3381
3747
|
async function ensureImage(ref = DEFAULT_BOX_IMAGE, opts = {}) {
|
|
3382
|
-
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2, preparedMatches: preparedMatches2 } = await import("./prepared-state-75DIZ55S-
|
|
3748
|
+
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2, preparedMatches: preparedMatches2 } = await import("./prepared-state-75DIZ55S-W6NU3S3B.js");
|
|
3383
3749
|
const claudeInstall = opts.claudeInstall ?? await resolveClaudeInstallMode();
|
|
3384
3750
|
const rawFingerprint = await computeDockerContextFingerprint2({
|
|
3385
3751
|
contextDir: opts.contextDir
|
|
@@ -3433,7 +3799,7 @@ function classifyDockerBaseFreshness(input) {
|
|
|
3433
3799
|
return { state: "fresh" };
|
|
3434
3800
|
}
|
|
3435
3801
|
async function evaluateDockerBaseFreshness(opts = {}) {
|
|
3436
|
-
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2 } = await import("./prepared-state-75DIZ55S-
|
|
3802
|
+
const { computeDockerContextFingerprint: computeDockerContextFingerprint2, readPreparedDockerState: readPreparedDockerState2 } = await import("./prepared-state-75DIZ55S-W6NU3S3B.js");
|
|
3437
3803
|
const ref = opts.ref ?? DEFAULT_BOX_IMAGE;
|
|
3438
3804
|
const imagePresent = await imageExists(ref);
|
|
3439
3805
|
if (!imagePresent) return { state: "unprepared" };
|
|
@@ -3533,6 +3899,14 @@ export {
|
|
|
3533
3899
|
ensureCloudSshAlias,
|
|
3534
3900
|
autoWriteSshConfig,
|
|
3535
3901
|
mintSshKey,
|
|
3902
|
+
sshDestination,
|
|
3903
|
+
sshOptArgs,
|
|
3904
|
+
sshExec,
|
|
3905
|
+
scpUpload,
|
|
3906
|
+
scpDownload,
|
|
3907
|
+
waitForSsh,
|
|
3908
|
+
SshTunnelManager,
|
|
3909
|
+
defaultBoxSshDir,
|
|
3536
3910
|
parseInboundSpec,
|
|
3537
3911
|
resolveInboundSources,
|
|
3538
3912
|
describeInbound,
|
|
@@ -3654,4 +4028,4 @@ export {
|
|
|
3654
4028
|
writePreparedDockerState,
|
|
3655
4029
|
preparedMatches
|
|
3656
4030
|
};
|
|
3657
|
-
//# sourceMappingURL=chunk-
|
|
4031
|
+
//# sourceMappingURL=chunk-PK2QF4IR.js.map
|