@madarco/agentbox 0.17.1 → 0.19.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 +78 -0
- package/README.md +4 -3
- package/dist/{_cloud-attach-RUD4W33P.js → _cloud-attach-YM2KOWHO.js} +4 -4
- package/dist/{chunk-6QFPYU4Z.js → chunk-7K2A3NLE.js} +8 -5
- package/dist/chunk-7K2A3NLE.js.map +1 -0
- package/dist/{chunk-HFQZJO73.js → chunk-A5OFRJDI.js} +1322 -216
- package/dist/chunk-A5OFRJDI.js.map +1 -0
- package/dist/{chunk-YUGLNTT2.js → chunk-JK5V4OLT.js} +349 -16
- package/dist/chunk-JK5V4OLT.js.map +1 -0
- package/dist/{chunk-IA6YHH52.js → chunk-MODNW54N.js} +6 -3
- package/dist/{chunk-IA6YHH52.js.map → chunk-MODNW54N.js.map} +1 -1
- package/dist/{chunk-46NXCJ6Z.js → chunk-NXX3KQZ6.js} +2 -2
- package/dist/{chunk-3JXSW6PN.js → chunk-P6UT5XGE.js} +2 -2
- package/dist/{chunk-KTDJ5JTE.js → chunk-SPUUOEW2.js} +273 -54
- package/dist/chunk-SPUUOEW2.js.map +1 -0
- package/dist/{chunk-XWBFWUY2.js → chunk-Y6PUCLOE.js} +2 -2
- package/dist/{dist-VAATGBAR.js → dist-EKSNZHDY.js} +13 -3
- package/dist/{dist-TEKY3GFT.js → dist-FTCDWRAL.js} +18 -7
- package/dist/dist-FTCDWRAL.js.map +1 -0
- package/dist/{dist-CNABE32V.js → dist-PRDYMXCX.js} +10 -5
- package/dist/dist-PRDYMXCX.js.map +1 -0
- package/dist/{dist-BO2R55FX.js → dist-U2BHTWG4.js} +17 -5
- package/dist/dist-U2BHTWG4.js.map +1 -0
- package/dist/{dist-CROGTJ7N.js → dist-VQSZVBT3.js} +20 -6
- package/dist/dist-VQSZVBT3.js.map +1 -0
- package/dist/index.js +1009 -449
- package/dist/index.js.map +1 -1
- package/dist/{prepared-state-MQHD3M5F-OVABNV66.js → prepared-state-MQHD3M5F-5ZMCNY43.js} +2 -2
- package/package.json +3 -3
- package/runtime/docker/apps/cli/share/agentbox-setup/SKILL.md +1 -1
- package/runtime/docker/packages/ctl/dist/bin.cjs +142 -110
- package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +13 -0
- package/runtime/e2b/agentbox-setup-skill.md +1 -1
- package/runtime/e2b/ctl.cjs +142 -110
- package/runtime/hetzner/agentbox-dockerd-start +13 -0
- package/runtime/hetzner/agentbox-setup-skill.md +1 -1
- package/runtime/hetzner/ctl.cjs +142 -110
- package/runtime/relay/bin.cjs +270 -66
- package/runtime/vercel/agentbox-dockerd-start +145 -0
- package/runtime/vercel/agentbox-setup-skill.md +1 -1
- package/runtime/vercel/ctl.cjs +142 -110
- package/runtime/vercel/custom-system-CLAUDE.md +5 -4
- package/runtime/vercel/scripts/provision.sh +20 -5
- package/share/agentbox-setup/SKILL.md +1 -1
- package/share/host-skills/agentbox/SKILL.md +2 -2
- package/share/host-skills/codex/agentbox.md +10 -2
- package/dist/chunk-6QFPYU4Z.js.map +0 -1
- package/dist/chunk-HFQZJO73.js.map +0 -1
- package/dist/chunk-KTDJ5JTE.js.map +0 -1
- package/dist/chunk-YUGLNTT2.js.map +0 -1
- package/dist/dist-BO2R55FX.js.map +0 -1
- package/dist/dist-CNABE32V.js.map +0 -1
- package/dist/dist-CROGTJ7N.js.map +0 -1
- package/dist/dist-TEKY3GFT.js.map +0 -1
- /package/dist/{_cloud-attach-RUD4W33P.js.map → _cloud-attach-YM2KOWHO.js.map} +0 -0
- /package/dist/{chunk-46NXCJ6Z.js.map → chunk-NXX3KQZ6.js.map} +0 -0
- /package/dist/{chunk-3JXSW6PN.js.map → chunk-P6UT5XGE.js.map} +0 -0
- /package/dist/{chunk-XWBFWUY2.js.map → chunk-Y6PUCLOE.js.map} +0 -0
- /package/dist/{dist-VAATGBAR.js.map → dist-EKSNZHDY.js.map} +0 -0
- /package/dist/{prepared-state-MQHD3M5F-OVABNV66.js.map → prepared-state-MQHD3M5F-5ZMCNY43.js.map} +0 -0
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
stageOpencodeStateForUpload,
|
|
43
43
|
stageOpencodeStaticForUpload,
|
|
44
44
|
syncClaudeCredentials
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-A5OFRJDI.js";
|
|
46
46
|
import {
|
|
47
47
|
DEFAULT_BOX_IMAGE,
|
|
48
48
|
allocateProjectIndex,
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
recordBox,
|
|
55
55
|
removeBoxRecord,
|
|
56
56
|
renderCarryEntries
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-7K2A3NLE.js";
|
|
58
58
|
|
|
59
59
|
// ../../packages/sandbox-cloud/dist/index.js
|
|
60
60
|
import { basename as basename2 } from "path";
|
|
@@ -898,11 +898,23 @@ async function launchCloudCtlDaemon(args) {
|
|
|
898
898
|
if (args.bridgeToken) env.push(`AGENTBOX_BRIDGE_TOKEN=${quoteShellArgv([args.bridgeToken])}`);
|
|
899
899
|
if (args.webProxyPort !== void 0)
|
|
900
900
|
env.push(`AGENTBOX_WEB_PROXY_PORT=${quoteShellArgv([String(args.webProxyPort)])}`);
|
|
901
|
+
if (args.boxHost) env.push(`AGENTBOX_BOX_HOST=${quoteShellArgv([args.boxHost])}`);
|
|
902
|
+
const boxEnvFile = [
|
|
903
|
+
`AGENTBOX_BOX_ID=${quoteShellArgv([args.boxId])}`,
|
|
904
|
+
`AGENTBOX_BOX_NAME=${quoteShellArgv([args.boxName])}`,
|
|
905
|
+
`AGENTBOX_BOX_KIND=cloud`
|
|
906
|
+
];
|
|
907
|
+
if (args.webProxyPort !== void 0)
|
|
908
|
+
boxEnvFile.push(`AGENTBOX_WEB_PROXY_PORT=${quoteShellArgv([String(args.webProxyPort)])}`);
|
|
909
|
+
if (args.boxHost) boxEnvFile.push(`AGENTBOX_BOX_HOST=${quoteShellArgv([args.boxHost])}`);
|
|
901
910
|
const script = [
|
|
902
911
|
`set -e`,
|
|
903
912
|
`if command -v sudo >/dev/null 2>&1; then SUDO='sudo -n'; else SUDO=''; fi`,
|
|
904
|
-
`$SUDO mkdir -p /run/agentbox /var/log/agentbox`,
|
|
913
|
+
`$SUDO mkdir -p /run/agentbox /var/log/agentbox /etc/agentbox`,
|
|
905
914
|
`$SUDO chown "$(id -un):$(id -gn)" /run/agentbox /var/log/agentbox`,
|
|
915
|
+
`$SUDO tee /etc/agentbox/box.env >/dev/null <<'AGENTBOX_BOX_ENV_EOF'`,
|
|
916
|
+
...boxEnvFile,
|
|
917
|
+
`AGENTBOX_BOX_ENV_EOF`,
|
|
906
918
|
`export ${env.join(" ")}`,
|
|
907
919
|
`nohup /usr/local/bin/agentbox-ctl daemon >> /var/log/agentbox/ctl-daemon.log 2>&1 &`,
|
|
908
920
|
`disown`,
|
|
@@ -972,11 +984,16 @@ async function seedCloudWorkspace(args) {
|
|
|
972
984
|
const repos = await detectGitRepos(args.workspacePath);
|
|
973
985
|
const root = repos.find((r) => r.kind === "root");
|
|
974
986
|
const nested = repos.filter((r) => r.kind === "nested");
|
|
987
|
+
if (!root && args.overlay) {
|
|
988
|
+
log("checkpoint restore: non-git workspace \u2014 keeping snapshot /workspace as-is");
|
|
989
|
+
return { fromGit: false, branch: args.branch };
|
|
990
|
+
}
|
|
975
991
|
if (root) {
|
|
976
992
|
log(
|
|
977
|
-
nested.length > 0 ? `seeding /workspace from shallow git clone (+${String(nested.length)} nested repo${nested.length === 1 ? "" : "s"})` : "seeding /workspace from shallow git clone"
|
|
993
|
+
args.overlay ? nested.length > 0 ? `checkpoint restore: re-branching /workspace + ${String(nested.length)} nested repo${nested.length === 1 ? "" : "s"} (warm artifacts kept)` : "checkpoint restore: re-branching /workspace onto a fresh per-box branch (warm artifacts kept)" : nested.length > 0 ? `seeding /workspace from shallow git clone (+${String(nested.length)} nested repo${nested.length === 1 ? "" : "s"})` : "seeding /workspace from shallow git clone"
|
|
978
994
|
);
|
|
979
|
-
|
|
995
|
+
const resyncRepos = [];
|
|
996
|
+
const rootConflicts = await reseedRepo({
|
|
980
997
|
backend: args.backend,
|
|
981
998
|
handle: args.handle,
|
|
982
999
|
hostRepo: root.hostMainRepo,
|
|
@@ -985,22 +1002,34 @@ async function seedCloudWorkspace(args) {
|
|
|
985
1002
|
bundleDepth: args.bundleDepth,
|
|
986
1003
|
fromBranch: args.fromBranch,
|
|
987
1004
|
useBranch: args.useBranch,
|
|
1005
|
+
overlay: args.overlay,
|
|
1006
|
+
skipCarryOver: args.skipCarryOver,
|
|
988
1007
|
onLog: log
|
|
989
1008
|
});
|
|
1009
|
+
if (args.overlay) resyncRepos.push({ containerPath: workspaceDir, ...rootConflicts });
|
|
990
1010
|
for (const r of nested) {
|
|
991
1011
|
const sub = `${workspaceDir}/${r.relPathFromWorkspace}`;
|
|
992
1012
|
log(`seeding nested repo ${r.relPathFromWorkspace} from shallow git clone`);
|
|
993
|
-
await
|
|
1013
|
+
const nestedConflicts = await reseedRepo({
|
|
994
1014
|
backend: args.backend,
|
|
995
1015
|
handle: args.handle,
|
|
996
1016
|
hostRepo: r.hostMainRepo,
|
|
997
1017
|
branch: args.branch,
|
|
998
1018
|
workspaceDir: sub,
|
|
999
1019
|
bundleDepth: args.bundleDepth,
|
|
1020
|
+
overlay: args.overlay,
|
|
1021
|
+
skipCarryOver: args.skipCarryOver,
|
|
1000
1022
|
onLog: log
|
|
1001
1023
|
});
|
|
1024
|
+
if (args.overlay) resyncRepos.push({ containerPath: sub, ...nestedConflicts });
|
|
1002
1025
|
}
|
|
1003
|
-
|
|
1026
|
+
const resync = args.overlay ? {
|
|
1027
|
+
repos: resyncRepos,
|
|
1028
|
+
hadConflicts: resyncRepos.some(
|
|
1029
|
+
(r) => r.mergeConflicts.length > 0 || r.overlaySkipped.length > 0
|
|
1030
|
+
)
|
|
1031
|
+
} : void 0;
|
|
1032
|
+
return { fromGit: true, branch: args.branch, resync };
|
|
1004
1033
|
}
|
|
1005
1034
|
log("seeding /workspace from workspace tarball (no git detected)");
|
|
1006
1035
|
await seedFromTar({
|
|
@@ -1013,18 +1042,64 @@ async function seedCloudWorkspace(args) {
|
|
|
1013
1042
|
}
|
|
1014
1043
|
var STASH_CARRYOVER_REF = "refs/agentbox-carryover/stash";
|
|
1015
1044
|
var REMOTE_UNTRACKED_TAR = "/tmp/agentbox-carryover-untracked.tar.gz";
|
|
1045
|
+
var MERGE_CONFLICT_MARKER = "__AGENTBOX_MERGE_CONFLICT__:";
|
|
1046
|
+
var OVERLAY_SKIP_MARKER = "__AGENTBOX_OVERLAY_SKIP__:";
|
|
1047
|
+
function parseSeedConflicts(stdout) {
|
|
1048
|
+
const merge = /* @__PURE__ */ new Set();
|
|
1049
|
+
const overlay = /* @__PURE__ */ new Set();
|
|
1050
|
+
for (const raw of stdout.split("\n")) {
|
|
1051
|
+
const line = raw.trim();
|
|
1052
|
+
if (line.startsWith(MERGE_CONFLICT_MARKER)) {
|
|
1053
|
+
const p = line.slice(MERGE_CONFLICT_MARKER.length).trim();
|
|
1054
|
+
if (p) merge.add(p);
|
|
1055
|
+
} else if (line.startsWith(OVERLAY_SKIP_MARKER)) {
|
|
1056
|
+
const p = line.slice(OVERLAY_SKIP_MARKER.length).trim();
|
|
1057
|
+
if (p) overlay.add(p);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return { mergeConflicts: [...merge], overlaySkipped: [...overlay] };
|
|
1061
|
+
}
|
|
1062
|
+
function buildCarryOverSteps(opts) {
|
|
1063
|
+
const wd = quoteShellArgv([opts.workspaceDir]);
|
|
1064
|
+
const stashRef = quoteShellArgv(["refs/remotes/origin/agentbox-carryover/stash"]);
|
|
1065
|
+
const untracked = quoteShellArgv([REMOTE_UNTRACKED_TAR]);
|
|
1066
|
+
const steps = [];
|
|
1067
|
+
if (opts.hasStash) {
|
|
1068
|
+
steps.push(
|
|
1069
|
+
opts.detectConflicts ? `if git -C ${wd} rev-parse --verify ${stashRef} >/dev/null 2>&1; then if ! git -C ${wd} stash apply ${stashRef} >/dev/null 2>&1; then git -C ${wd} diff --name-only --diff-filter=U | while IFS= read -r p; do [ -n "$p" ] && echo "${MERGE_CONFLICT_MARKER}$p"; done || true ; git -C ${wd} checkout --ours -- . >/dev/null 2>&1 || true ; git -C ${wd} add -A >/dev/null 2>&1 || true ; fi ; git -C ${wd} update-ref -d ${stashRef} || true ; fi` : `if git -C ${wd} rev-parse --verify ${stashRef} >/dev/null 2>&1; then git -C ${wd} stash apply ${stashRef} || echo "agentbox: stash apply soft-failed; carry-over may be incomplete" >&2 ; git -C ${wd} update-ref -d ${stashRef} || true ; fi`
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
if (opts.hasUntracked) {
|
|
1073
|
+
steps.push(
|
|
1074
|
+
opts.detectConflicts ? `if [ -f ${untracked} ]; then tar -tzf ${untracked} | while IFS= read -r p; do case "$p" in ''|*/) continue ;; esac; if [ -e ${wd}/"$p" ]; then echo "${OVERLAY_SKIP_MARKER}$p"; fi; done || true ; tar -C ${wd} --skip-old-files -xzf ${untracked} || true ; rm -f ${untracked} ; fi` : `if [ -f ${untracked} ]; then tar -C ${wd} -xzf ${untracked} && rm -f ${untracked} ; fi`
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
return steps;
|
|
1078
|
+
}
|
|
1016
1079
|
var DEFAULT_BUNDLE_DEPTH = 200;
|
|
1017
1080
|
var LARGE_BUNDLE_DEPTH = 100;
|
|
1018
1081
|
var LARGE_BUNDLE_THRESHOLD_BYTES = 20 * 1024 * 1024;
|
|
1082
|
+
async function reseedRepo(args) {
|
|
1083
|
+
if (args.overlay) {
|
|
1084
|
+
const delta = await tryReseedRepoDelta(args);
|
|
1085
|
+
if (delta) return delta;
|
|
1086
|
+
(args.onLog ?? (() => {
|
|
1087
|
+
}))(
|
|
1088
|
+
`checkpoint restore: ${args.workspaceDir}: delta not usable, falling back to full clone`
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
return seedFromGitClone(args);
|
|
1092
|
+
}
|
|
1019
1093
|
async function seedFromGitClone(args) {
|
|
1020
1094
|
const log = args.onLog ?? (() => {
|
|
1021
1095
|
});
|
|
1096
|
+
let conflicts = { mergeConflicts: [], overlaySkipped: [] };
|
|
1022
1097
|
const stage = await mkdtemp5(join6(tmpdir5(), "agentbox-clone-"));
|
|
1023
1098
|
const cloneDir = join6(stage, "clone");
|
|
1024
1099
|
const tarPath = join6(stage, "workspace.tar.gz");
|
|
1025
1100
|
const untrackedTarPath = join6(stage, "untracked.tar.gz");
|
|
1026
|
-
const stashSha = args.useBranch ? null : await safeStashCreate(args.hostRepo);
|
|
1027
|
-
const untrackedSize = args.useBranch ? 0 : await maybeBuildUntrackedTar(args.hostRepo, untrackedTarPath);
|
|
1101
|
+
const stashSha = args.useBranch || args.skipCarryOver ? null : await safeStashCreate(args.hostRepo);
|
|
1102
|
+
const untrackedSize = args.useBranch || args.skipCarryOver ? 0 : await maybeBuildUntrackedTar(args.hostRepo, untrackedTarPath);
|
|
1028
1103
|
let stashRefCreated = false;
|
|
1029
1104
|
try {
|
|
1030
1105
|
if (stashSha) {
|
|
@@ -1065,14 +1140,30 @@ async function seedFromGitClone(args) {
|
|
|
1065
1140
|
}
|
|
1066
1141
|
const setOrigin = remoteUrl ? `git -C ${quoteShellArgv([args.workspaceDir])} remote set-url origin ${quoteShellArgv([remoteUrl])}` : ": # no host origin to copy";
|
|
1067
1142
|
const SUDO = `if command -v sudo >/dev/null 2>&1; then SUDO='sudo -n'; else SUDO=''; fi`;
|
|
1068
|
-
const carryOverSteps =
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1143
|
+
const carryOverSteps = buildCarryOverSteps({
|
|
1144
|
+
workspaceDir: args.workspaceDir,
|
|
1145
|
+
hasStash: Boolean(stashSha),
|
|
1146
|
+
hasUntracked: untrackedSize > 0,
|
|
1147
|
+
// Conflict detection (box-wins + markers) only matters on a checkpoint
|
|
1148
|
+
// restore, where /workspace already has the snapshot's files to collide
|
|
1149
|
+
// with. A fresh seed checks out onto an empty tree — nothing to conflict.
|
|
1150
|
+
detectConflicts: Boolean(args.overlay)
|
|
1151
|
+
});
|
|
1152
|
+
const gitDir = `${args.workspaceDir}/.git`;
|
|
1153
|
+
const prepSteps = args.overlay ? [`$SUDO rm -rf ${quoteShellArgv([gitDir])}`] : [
|
|
1154
|
+
`$SUDO rm -rf ${quoteShellArgv([args.workspaceDir])}`,
|
|
1155
|
+
`$SUDO mkdir -p ${quoteShellArgv([args.workspaceDir])}`,
|
|
1156
|
+
`$SUDO chown "$(id -un):$(id -gn)" ${quoteShellArgv([args.workspaceDir])}`
|
|
1157
|
+
];
|
|
1158
|
+
const checkoutSteps = args.overlay ? [
|
|
1159
|
+
args.useBranch ? `git -C ${quoteShellArgv([args.workspaceDir])} checkout -f ${quoteShellArgv([args.branch])}` : `git -C ${quoteShellArgv([args.workspaceDir])} checkout -f -B ${quoteShellArgv([args.branch])}`,
|
|
1160
|
+
`git -C ${quoteShellArgv([args.workspaceDir])} reset --hard HEAD`
|
|
1161
|
+
] : [
|
|
1162
|
+
// reuse: the clone already landed on `<branch>` (pinned via
|
|
1163
|
+
// `--branch`); a plain checkout materializes the working tree without
|
|
1164
|
+
// resetting the ref. fork: `-B` (re)points `<branch>` at clone HEAD.
|
|
1165
|
+
args.useBranch ? `git -C ${quoteShellArgv([args.workspaceDir])} checkout ${quoteShellArgv([args.branch])}` : `git -C ${quoteShellArgv([args.workspaceDir])} checkout -B ${quoteShellArgv([args.branch])}`
|
|
1166
|
+
];
|
|
1076
1167
|
const script = [
|
|
1077
1168
|
`set -euo pipefail`,
|
|
1078
1169
|
// Move out of any cwd we might inherit from Daytona's executeCommand
|
|
@@ -1082,18 +1173,13 @@ async function seedFromGitClone(args) {
|
|
|
1082
1173
|
// with "Unable to read current working directory".
|
|
1083
1174
|
`cd /tmp`,
|
|
1084
1175
|
SUDO,
|
|
1085
|
-
// rm -rf only the
|
|
1086
|
-
//
|
|
1087
|
-
//
|
|
1088
|
-
|
|
1089
|
-
`$SUDO mkdir -p ${quoteShellArgv([args.workspaceDir])}`,
|
|
1090
|
-
`$SUDO chown "$(id -un):$(id -gn)" ${quoteShellArgv([args.workspaceDir])}`,
|
|
1176
|
+
// Fresh: rm -rf only the dir we extract into (for nested repos that's
|
|
1177
|
+
// `/workspace/<rel>`, so the root clone is preserved). Overlay: rm only
|
|
1178
|
+
// `<dir>/.git`, preserving the warm working tree.
|
|
1179
|
+
...prepSteps,
|
|
1091
1180
|
`tar -C ${quoteShellArgv([args.workspaceDir])} -xzf ${quoteShellArgv([remoteTar])}`,
|
|
1092
1181
|
setOrigin,
|
|
1093
|
-
|
|
1094
|
-
// a plain checkout materializes the working tree without resetting the
|
|
1095
|
-
// ref. fork: `-B` (re)points `<branch>` at the clone HEAD.
|
|
1096
|
-
args.useBranch ? `git -C ${quoteShellArgv([args.workspaceDir])} checkout ${quoteShellArgv([args.branch])}` : `git -C ${quoteShellArgv([args.workspaceDir])} checkout -B ${quoteShellArgv([args.branch])}`,
|
|
1182
|
+
...checkoutSteps,
|
|
1097
1183
|
...carryOverSteps,
|
|
1098
1184
|
`rm -f ${quoteShellArgv([remoteTar])}`
|
|
1099
1185
|
].join("\n");
|
|
@@ -1101,12 +1187,131 @@ async function seedFromGitClone(args) {
|
|
|
1101
1187
|
if (r.exitCode !== 0) {
|
|
1102
1188
|
throw new Error(`workspace seed (clone) failed: ${r.stderr || r.stdout}`);
|
|
1103
1189
|
}
|
|
1190
|
+
if (args.overlay) conflicts = parseSeedConflicts(r.stdout);
|
|
1191
|
+
} finally {
|
|
1192
|
+
if (stashRefCreated) {
|
|
1193
|
+
await execa5("git", ["-C", args.hostRepo, "update-ref", "-d", STASH_CARRYOVER_REF], {
|
|
1194
|
+
reject: false
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
await rm6(stage, { recursive: true, force: true });
|
|
1198
|
+
}
|
|
1199
|
+
return conflicts;
|
|
1200
|
+
}
|
|
1201
|
+
var DELTA_TARGET_REF = "refs/agentbox-delta/target";
|
|
1202
|
+
var REMOTE_DELTA_BUNDLE = "/tmp/agentbox-delta.bundle";
|
|
1203
|
+
var SHA_RE = /^[0-9a-f]{40}$/;
|
|
1204
|
+
async function tryReseedRepoDelta(args) {
|
|
1205
|
+
const log = args.onLog ?? (() => {
|
|
1206
|
+
});
|
|
1207
|
+
const wd = quoteShellArgv([args.workspaceDir]);
|
|
1208
|
+
const tipRes = await args.backend.exec(
|
|
1209
|
+
args.handle,
|
|
1210
|
+
bashScript(`git -C ${wd} rev-parse HEAD 2>/dev/null || true`)
|
|
1211
|
+
);
|
|
1212
|
+
const checkpointTip = tipRes.stdout.trim();
|
|
1213
|
+
if (!SHA_RE.test(checkpointTip)) return null;
|
|
1214
|
+
const baseRef = args.useBranch ?? args.fromBranch ?? "HEAD";
|
|
1215
|
+
const targetRes = await execa5("git", ["-C", args.hostRepo, "rev-parse", baseRef], {
|
|
1216
|
+
reject: false
|
|
1217
|
+
});
|
|
1218
|
+
const target = targetRes.stdout.trim();
|
|
1219
|
+
if (targetRes.exitCode !== 0 || !SHA_RE.test(target)) return null;
|
|
1220
|
+
const hasTip = await execa5(
|
|
1221
|
+
"git",
|
|
1222
|
+
["-C", args.hostRepo, "cat-file", "-e", `${checkpointTip}^{commit}`],
|
|
1223
|
+
{ reject: false }
|
|
1224
|
+
);
|
|
1225
|
+
if (hasTip.exitCode !== 0) return null;
|
|
1226
|
+
const ancestor = await execa5(
|
|
1227
|
+
"git",
|
|
1228
|
+
["-C", args.hostRepo, "merge-base", "--is-ancestor", checkpointTip, target],
|
|
1229
|
+
{ reject: false }
|
|
1230
|
+
);
|
|
1231
|
+
if (ancestor.exitCode !== 0) return null;
|
|
1232
|
+
const stage = await mkdtemp5(join6(tmpdir5(), "agentbox-delta-"));
|
|
1233
|
+
const bundlePath = join6(stage, "delta.bundle");
|
|
1234
|
+
const untrackedTarPath = join6(stage, "untracked.tar.gz");
|
|
1235
|
+
const stashSha = args.useBranch || args.skipCarryOver ? null : await safeStashCreate(args.hostRepo);
|
|
1236
|
+
const untrackedSize = args.useBranch || args.skipCarryOver ? 0 : await maybeBuildUntrackedTar(args.hostRepo, untrackedTarPath);
|
|
1237
|
+
let stashRefCreated = false;
|
|
1238
|
+
try {
|
|
1239
|
+
if (stashSha) {
|
|
1240
|
+
const ref = await execa5(
|
|
1241
|
+
"git",
|
|
1242
|
+
["-C", args.hostRepo, "update-ref", STASH_CARRYOVER_REF, stashSha],
|
|
1243
|
+
{ reject: false }
|
|
1244
|
+
);
|
|
1245
|
+
stashRefCreated = ref.exitCode === 0;
|
|
1246
|
+
}
|
|
1247
|
+
const needTarget = target !== checkpointTip;
|
|
1248
|
+
if (needTarget) {
|
|
1249
|
+
await execa5("git", ["-C", args.hostRepo, "update-ref", DELTA_TARGET_REF, target], {
|
|
1250
|
+
reject: false
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
const bundleRefs = [];
|
|
1254
|
+
if (needTarget) bundleRefs.push(DELTA_TARGET_REF);
|
|
1255
|
+
if (stashRefCreated) bundleRefs.push(STASH_CARRYOVER_REF);
|
|
1256
|
+
let haveBundle = false;
|
|
1257
|
+
if (bundleRefs.length > 0) {
|
|
1258
|
+
const b = await execa5(
|
|
1259
|
+
"git",
|
|
1260
|
+
["-C", args.hostRepo, "bundle", "create", bundlePath, ...bundleRefs, `^${checkpointTip}`],
|
|
1261
|
+
{ reject: false }
|
|
1262
|
+
);
|
|
1263
|
+
if (b.exitCode !== 0) return null;
|
|
1264
|
+
haveBundle = true;
|
|
1265
|
+
await args.backend.uploadFile(args.handle, bundlePath, REMOTE_DELTA_BUNDLE);
|
|
1266
|
+
}
|
|
1267
|
+
if (untrackedSize > 0) {
|
|
1268
|
+
await args.backend.uploadFile(args.handle, untrackedTarPath, REMOTE_UNTRACKED_TAR);
|
|
1269
|
+
}
|
|
1270
|
+
log(
|
|
1271
|
+
needTarget ? `checkpoint restore: ${args.workspaceDir}: delta bundle (${checkpointTip.slice(0, 8)}..${target.slice(0, 8)})` : `checkpoint restore: ${args.workspaceDir}: no new host commits; re-branch + carry-over only`
|
|
1272
|
+
);
|
|
1273
|
+
const remoteUrl = await readOriginUrl(args.hostRepo);
|
|
1274
|
+
const setOrigin = remoteUrl ? `git -C ${wd} remote set-url origin ${quoteShellArgv([remoteUrl])}` : ": # no host origin to copy";
|
|
1275
|
+
const fetchRefspecs = [];
|
|
1276
|
+
if (needTarget) fetchRefspecs.push(`+${DELTA_TARGET_REF}:${DELTA_TARGET_REF}`);
|
|
1277
|
+
if (stashRefCreated)
|
|
1278
|
+
fetchRefspecs.push(`+${STASH_CARRYOVER_REF}:refs/remotes/origin/agentbox-carryover/stash`);
|
|
1279
|
+
const fetchStep = haveBundle && fetchRefspecs.length > 0 ? `git -C ${wd} fetch --no-tags ${quoteShellArgv([REMOTE_DELTA_BUNDLE])} ${fetchRefspecs.map((s) => quoteShellArgv([s])).join(" ")}` : ": # no delta bundle to fetch";
|
|
1280
|
+
const checkoutStep = args.useBranch ? `git -C ${wd} checkout -f ${quoteShellArgv([args.branch])}` : `git -C ${wd} checkout -f -B ${quoteShellArgv([args.branch])} ${quoteShellArgv([target])}`;
|
|
1281
|
+
const carryOverSteps = buildCarryOverSteps({
|
|
1282
|
+
workspaceDir: args.workspaceDir,
|
|
1283
|
+
hasStash: Boolean(stashSha),
|
|
1284
|
+
hasUntracked: untrackedSize > 0,
|
|
1285
|
+
detectConflicts: true
|
|
1286
|
+
});
|
|
1287
|
+
const SUDO = `if command -v sudo >/dev/null 2>&1; then SUDO='sudo -n'; else SUDO=''; fi`;
|
|
1288
|
+
const script = [
|
|
1289
|
+
`set -euo pipefail`,
|
|
1290
|
+
`cd /tmp`,
|
|
1291
|
+
SUDO,
|
|
1292
|
+
fetchStep,
|
|
1293
|
+
checkoutStep,
|
|
1294
|
+
`git -C ${wd} reset --hard ${quoteShellArgv([target])}`,
|
|
1295
|
+
setOrigin,
|
|
1296
|
+
...carryOverSteps,
|
|
1297
|
+
`git -C ${wd} update-ref -d ${quoteShellArgv([DELTA_TARGET_REF])} || true`,
|
|
1298
|
+
`rm -f ${quoteShellArgv([REMOTE_DELTA_BUNDLE])}`
|
|
1299
|
+
].join("\n");
|
|
1300
|
+
const r = await args.backend.exec(args.handle, bashScript(script));
|
|
1301
|
+
if (r.exitCode !== 0) {
|
|
1302
|
+
log(`checkpoint restore: ${args.workspaceDir}: delta apply failed, falling back: ${r.stderr || r.stdout}`);
|
|
1303
|
+
return null;
|
|
1304
|
+
}
|
|
1305
|
+
return parseSeedConflicts(r.stdout);
|
|
1104
1306
|
} finally {
|
|
1105
1307
|
if (stashRefCreated) {
|
|
1106
1308
|
await execa5("git", ["-C", args.hostRepo, "update-ref", "-d", STASH_CARRYOVER_REF], {
|
|
1107
1309
|
reject: false
|
|
1108
1310
|
});
|
|
1109
1311
|
}
|
|
1312
|
+
await execa5("git", ["-C", args.hostRepo, "update-ref", "-d", DELTA_TARGET_REF], {
|
|
1313
|
+
reject: false
|
|
1314
|
+
});
|
|
1110
1315
|
await rm6(stage, { recursive: true, force: true });
|
|
1111
1316
|
}
|
|
1112
1317
|
}
|
|
@@ -1234,6 +1439,15 @@ function parseLoopbackPort(url) {
|
|
|
1234
1439
|
return void 0;
|
|
1235
1440
|
}
|
|
1236
1441
|
}
|
|
1442
|
+
function deriveCloudBoxHost(boxName, webPreviewUrl) {
|
|
1443
|
+
if (!webPreviewUrl) return void 0;
|
|
1444
|
+
if (parseLoopbackPort(webPreviewUrl) !== void 0) return `${boxName}.localhost`;
|
|
1445
|
+
try {
|
|
1446
|
+
return new URL(webPreviewUrl).host;
|
|
1447
|
+
} catch {
|
|
1448
|
+
return void 0;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1237
1451
|
async function registerHostPortlessAlias(args) {
|
|
1238
1452
|
const localPort = parseLoopbackPort(args.previewUrl);
|
|
1239
1453
|
if (localPort === void 0) return void 0;
|
|
@@ -1413,7 +1627,8 @@ function createCloudProvider(backend, opts = {}) {
|
|
|
1413
1627
|
relayUrl: `http://127.0.0.1:${String(8788)}`,
|
|
1414
1628
|
relayToken: box.relayToken ?? "",
|
|
1415
1629
|
bridgeToken: box.cloud?.bridgeToken,
|
|
1416
|
-
webProxyPort: backend.webProxyPort
|
|
1630
|
+
webProxyPort: backend.webProxyPort,
|
|
1631
|
+
boxHost: deriveCloudBoxHost(box.name, webPreview?.url)
|
|
1417
1632
|
});
|
|
1418
1633
|
if (box.vncEnabled && box.vncPassword) {
|
|
1419
1634
|
try {
|
|
@@ -1538,21 +1753,23 @@ function createCloudProvider(backend, opts = {}) {
|
|
|
1538
1753
|
}
|
|
1539
1754
|
}
|
|
1540
1755
|
try {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1756
|
+
const seedResult = await seedCloudWorkspace({
|
|
1757
|
+
backend,
|
|
1758
|
+
handle,
|
|
1759
|
+
workspacePath: req.workspacePath,
|
|
1760
|
+
branch,
|
|
1761
|
+
workspaceDir: CLOUD_WORKSPACE_DIR,
|
|
1762
|
+
bundleDepth: req.bundleDepth,
|
|
1763
|
+
fromBranch: req.fromBranch,
|
|
1764
|
+
useBranch: req.useBranch,
|
|
1765
|
+
overlay: Boolean(snapshotName),
|
|
1766
|
+
// `--no-resync` (resyncOnStart === false): re-branch the box to the
|
|
1767
|
+
// host tip but skip replaying the host's uncommitted/untracked state
|
|
1768
|
+
// onto the warm checkpoint tree — matches docker's gated resync.
|
|
1769
|
+
skipCarryOver: Boolean(snapshotName) && req.resyncOnStart === false,
|
|
1770
|
+
onLog: log
|
|
1771
|
+
});
|
|
1772
|
+
const resync = seedResult.resync && seedResult.resync.hadConflicts ? seedResult.resync : void 0;
|
|
1556
1773
|
await refreshAgentCredentialsBackup({ onLog: log });
|
|
1557
1774
|
if (agentVolumes.agents.length > 0) {
|
|
1558
1775
|
await seedAgentVolumesIfFresh(backend, handle, {
|
|
@@ -1617,6 +1834,13 @@ function createCloudProvider(backend, opts = {}) {
|
|
|
1617
1834
|
);
|
|
1618
1835
|
}
|
|
1619
1836
|
}
|
|
1837
|
+
const wp = backend.webProxyPort ?? CLOUD_WEB_PROXY_PORT;
|
|
1838
|
+
let webPreview;
|
|
1839
|
+
try {
|
|
1840
|
+
webPreview = await backend.previewUrl(handle, wp);
|
|
1841
|
+
} catch {
|
|
1842
|
+
webPreview = void 0;
|
|
1843
|
+
}
|
|
1620
1844
|
log("launching agentbox-ctl daemon");
|
|
1621
1845
|
await launchCloudCtlDaemon({
|
|
1622
1846
|
backend,
|
|
@@ -1626,7 +1850,8 @@ function createCloudProvider(backend, opts = {}) {
|
|
|
1626
1850
|
relayUrl: `http://127.0.0.1:${String(8788)}`,
|
|
1627
1851
|
relayToken,
|
|
1628
1852
|
bridgeToken,
|
|
1629
|
-
webProxyPort: backend.webProxyPort
|
|
1853
|
+
webProxyPort: backend.webProxyPort,
|
|
1854
|
+
boxHost: deriveCloudBoxHost(name, webPreview?.url)
|
|
1630
1855
|
});
|
|
1631
1856
|
const vncEnabled = req.vnc?.enabled !== false;
|
|
1632
1857
|
const vncPassword = vncEnabled ? generateVncPassword() : void 0;
|
|
@@ -1640,13 +1865,6 @@ function createCloudProvider(backend, opts = {}) {
|
|
|
1640
1865
|
);
|
|
1641
1866
|
}
|
|
1642
1867
|
}
|
|
1643
|
-
const wp = backend.webProxyPort ?? CLOUD_WEB_PROXY_PORT;
|
|
1644
|
-
let webPreview;
|
|
1645
|
-
try {
|
|
1646
|
-
webPreview = await backend.previewUrl(handle, wp);
|
|
1647
|
-
} catch {
|
|
1648
|
-
webPreview = void 0;
|
|
1649
|
-
}
|
|
1650
1868
|
const portlessOpt = req.providerOptions?.["portless"] ?? true;
|
|
1651
1869
|
let portlessAliasName;
|
|
1652
1870
|
let portlessUrlResolved;
|
|
@@ -1772,12 +1990,13 @@ function createCloudProvider(backend, opts = {}) {
|
|
|
1772
1990
|
relayPreviewToken: relayPreview?.token,
|
|
1773
1991
|
bridgeToken,
|
|
1774
1992
|
snapshotRef: resolvedCheckpointRef,
|
|
1775
|
-
lastState: "running"
|
|
1993
|
+
lastState: "running",
|
|
1994
|
+
sessionTimeoutMs: timeoutMs
|
|
1776
1995
|
},
|
|
1777
1996
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1778
1997
|
};
|
|
1779
1998
|
await recordBox(record);
|
|
1780
|
-
return { record, imageBuilt: false };
|
|
1999
|
+
return { record, imageBuilt: false, resync };
|
|
1781
2000
|
} catch (err) {
|
|
1782
2001
|
try {
|
|
1783
2002
|
await backend.destroy(handle);
|
|
@@ -2077,4 +2296,4 @@ export {
|
|
|
2077
2296
|
createCloudProvider,
|
|
2078
2297
|
renderInnerCommand
|
|
2079
2298
|
};
|
|
2080
|
-
//# sourceMappingURL=chunk-
|
|
2299
|
+
//# sourceMappingURL=chunk-SPUUOEW2.js.map
|