@h-rig/isolation-plugin 0.0.6-alpha.157 → 0.0.6-alpha.158
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/dist/src/embedded-native-assets.d.ts +7 -0
- package/dist/src/embedded-native-assets.js +6 -0
- package/dist/src/image-fingerprint-sidecar.d.ts +1 -0
- package/dist/src/image-fingerprint-sidecar.js +515 -0
- package/dist/src/image.d.ts +40 -0
- package/dist/src/image.js +1498 -0
- package/dist/src/index.js +4220 -20
- package/dist/src/isolation/binary-build-worker.d.ts +1 -0
- package/dist/src/isolation/binary-build-worker.js +323 -0
- package/dist/src/isolation/discovery.d.ts +7 -0
- package/dist/src/isolation/discovery.js +477 -0
- package/dist/src/isolation/git-native.d.ts +28 -0
- package/dist/src/isolation/git-native.js +598 -0
- package/dist/src/isolation/home.d.ts +25 -0
- package/dist/src/isolation/home.js +929 -0
- package/dist/src/isolation/index.d.ts +43 -0
- package/dist/src/isolation/index.js +4062 -0
- package/dist/src/isolation/provisioning-env.d.ts +1 -0
- package/dist/src/isolation/provisioning-env.js +6 -0
- package/dist/src/isolation/runner.d.ts +20 -0
- package/dist/src/isolation/runner.js +1881 -0
- package/dist/src/isolation/runtime-binary-build.d.ts +88 -0
- package/dist/src/isolation/runtime-binary-build.js +480 -0
- package/dist/src/isolation/shared.d.ts +29 -0
- package/dist/src/isolation/shared.js +283 -0
- package/dist/src/isolation/toolchain.d.ts +71 -0
- package/dist/src/isolation/toolchain.js +1348 -0
- package/dist/src/isolation/types.d.ts +15 -0
- package/dist/src/isolation/types.js +1 -0
- package/dist/src/isolation/worktree.d.ts +22 -0
- package/dist/src/isolation/worktree.js +353 -0
- package/dist/src/native-extract.d.ts +2 -0
- package/dist/src/native-extract.js +44 -0
- package/dist/src/plugin.d.ts +2 -2
- package/dist/src/plugin.js +4219 -19
- package/dist/src/runtime-config.d.ts +3 -0
- package/dist/src/runtime-config.js +215 -0
- package/dist/src/runtime-native-sidecar.d.ts +8 -0
- package/dist/src/runtime-native-sidecar.js +368 -0
- package/dist/src/runtime-native.d.ts +51 -0
- package/dist/src/runtime-native.js +485 -0
- package/dist/src/sandbox/backend-bwrap.d.ts +20 -0
- package/dist/src/sandbox/backend-bwrap.js +268 -0
- package/dist/src/sandbox/backend-none.d.ts +11 -0
- package/dist/src/sandbox/backend-none.js +20 -0
- package/dist/src/sandbox/backend-seatbelt.d.ts +13 -0
- package/dist/src/sandbox/backend-seatbelt.js +225 -0
- package/dist/src/sandbox/backend.d.ts +117 -0
- package/dist/src/sandbox/backend.js +864 -0
- package/dist/src/sandbox/orchestrator.d.ts +21 -0
- package/dist/src/sandbox/orchestrator.js +895 -0
- package/dist/src/sandbox/utils.d.ts +43 -0
- package/dist/src/sandbox/utils.js +94 -0
- package/dist/src/service.d.ts +10 -5
- package/dist/src/service.js +4145 -2
- package/dist/src/sidecar-arg.d.ts +7 -0
- package/dist/src/sidecar-arg.js +6 -0
- package/dist/src/sidecar-entrypoint.d.ts +9 -0
- package/dist/src/sidecar-entrypoint.js +401 -0
- package/dist/src/snapshot-sidecar.d.ts +2 -0
- package/dist/src/snapshot-sidecar.js +566 -0
- package/dist/src/snapshot.d.ts +64 -0
- package/dist/src/snapshot.js +515 -0
- package/dist/src/task-run-snapshot.d.ts +26 -0
- package/dist/src/task-run-snapshot.js +713 -0
- package/native/darwin-arm64/rig-git +0 -0
- package/native/darwin-arm64/rig-git.build-manifest.json +4 -0
- package/native/darwin-arm64/runtime-native.dylib +0 -0
- package/native/darwin-x64/rig-git +0 -0
- package/native/darwin-x64/runtime-native.dylib +0 -0
- package/native/linux-arm64/rig-git +0 -0
- package/native/linux-arm64/runtime-native.so +0 -0
- package/native/linux-x64/rig-git +0 -0
- package/native/linux-x64/runtime-native.so +0 -0
- package/native/win32-x64/rig-git.exe +0 -0
- package/native/win32-x64/runtime-native.dll +0 -0
- package/package.json +45 -5
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
3
|
+
|
|
4
|
+
// packages/isolation-plugin/src/sandbox/utils.ts
|
|
5
|
+
import { resolveMonorepoRoot as resolveMonorepoRoot2 } from "@rig/core/layout";
|
|
6
|
+
var init_utils = () => {};
|
|
7
|
+
|
|
8
|
+
// packages/isolation-plugin/src/isolation/index.ts
|
|
9
|
+
import { BROWSER_CONTRACT_SERVICE_CAPABILITY, MEMORY } from "@rig/contracts";
|
|
10
|
+
import { safePathSegment as safePathSegment3 } from "@rig/core/safe-identifiers";
|
|
11
|
+
|
|
12
|
+
// packages/isolation-plugin/src/isolation/git-native.ts
|
|
13
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
14
|
+
import { dirname, isAbsolute, resolve as resolve2 } from "path";
|
|
15
|
+
|
|
16
|
+
// packages/isolation-plugin/src/native-extract.ts
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "fs";
|
|
18
|
+
import { tmpdir } from "os";
|
|
19
|
+
import { resolve } from "path";
|
|
20
|
+
|
|
21
|
+
// packages/isolation-plugin/src/embedded-native-assets.ts
|
|
22
|
+
var embeddedNatives = null;
|
|
23
|
+
|
|
24
|
+
// packages/isolation-plugin/src/native-extract.ts
|
|
25
|
+
var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
|
|
26
|
+
var extractionCache = {};
|
|
27
|
+
function hasEmbeddedNatives() {
|
|
28
|
+
return embeddedNatives != null;
|
|
29
|
+
}
|
|
30
|
+
function extractEmbeddedNative(name) {
|
|
31
|
+
if (name in extractionCache) {
|
|
32
|
+
return extractionCache[name] ?? null;
|
|
33
|
+
}
|
|
34
|
+
const entry = embeddedNatives?.[name];
|
|
35
|
+
if (!entry) {
|
|
36
|
+
extractionCache[name] = null;
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
|
|
41
|
+
mkdirSync(sharedNativeOutputDir, { recursive: true });
|
|
42
|
+
const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
|
|
43
|
+
if (!upToDate) {
|
|
44
|
+
const bytes = readFileSync(entry.filePath);
|
|
45
|
+
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
|
|
46
|
+
writeFileSync(tempPath, bytes, { mode: 493 });
|
|
47
|
+
renameSync(tempPath, targetPath);
|
|
48
|
+
}
|
|
49
|
+
extractionCache[name] = targetPath;
|
|
50
|
+
} catch {
|
|
51
|
+
extractionCache[name] = null;
|
|
52
|
+
}
|
|
53
|
+
return extractionCache[name] ?? null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// packages/isolation-plugin/src/isolation/git-native.ts
|
|
57
|
+
var sharedGitNativeOutputDir = resolve2(tmpdir2(), "rig-native");
|
|
58
|
+
var sharedGitNativeOutputPath = resolve2(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
59
|
+
|
|
60
|
+
// packages/isolation-plugin/src/isolation/index.ts
|
|
61
|
+
import { defineCapability as defineCapability2 } from "@rig/core/capability";
|
|
62
|
+
import { loadCapabilityForRoot, requireCapabilityForRoot, requireInstalledCapability as requireInstalledCapability2 } from "@rig/core/capability-loaders";
|
|
63
|
+
import { buildPluginHostContext } from "@rig/core/plugin-host-context";
|
|
64
|
+
import { TASK_DATA_SERVICE_CAPABILITY } from "@rig/contracts";
|
|
65
|
+
import { resolveRuntimeWorkspaceLayout as resolveRuntimeWorkspaceLayout3 } from "@rig/core/layout";
|
|
66
|
+
import { ensureRuntimeOverlay } from "@rig/core/runtime-overlay";
|
|
67
|
+
import {
|
|
68
|
+
DEFAULT_RUNTIME_MEMORY_RETRIEVAL,
|
|
69
|
+
writeRuntimeContext
|
|
70
|
+
} from "@rig/core/runtime-context";
|
|
71
|
+
import { secretDefinesFromEnv } from "@rig/core/baked-secrets";
|
|
72
|
+
|
|
73
|
+
// packages/isolation-plugin/src/isolation/home.ts
|
|
74
|
+
import { resolveBunBinaryPath, resolveBunInstallDir, resolveClaudeBinaryPath, resolveClaudeInstallDir, resolveNodeInstallDir } from "@rig/core/runtime-paths";
|
|
75
|
+
import { resolveRuntimeSecrets } from "@rig/core/baked-secrets";
|
|
76
|
+
|
|
77
|
+
// packages/isolation-plugin/src/runtime-native.ts
|
|
78
|
+
import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
|
|
79
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, renameSync as renameSync2, rmSync, statSync as statSync2 } from "fs";
|
|
80
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
81
|
+
import { dirname as dirname2, resolve as resolve3 } from "path";
|
|
82
|
+
|
|
83
|
+
// packages/isolation-plugin/src/sidecar-arg.ts
|
|
84
|
+
var RIG_NATIVE_RUNTIME_SIDECAR_ARG = "__rig_native_runtime_sidecar";
|
|
85
|
+
|
|
86
|
+
// packages/isolation-plugin/src/runtime-native.ts
|
|
87
|
+
var sharedNativeRuntimeOutputDir = resolve3(tmpdir3(), "rig-native");
|
|
88
|
+
var sharedNativeRuntimeOutputPath = resolve3(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
|
|
89
|
+
var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
|
|
90
|
+
var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
|
|
91
|
+
function runtimeScanWorktreesNative(worktreesRoot) {
|
|
92
|
+
const response = runNativeRuntimeSidecar({
|
|
93
|
+
op: "scan-worktrees",
|
|
94
|
+
input: { worktreesRoot }
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
throw new Error(response.error);
|
|
98
|
+
}
|
|
99
|
+
return response.entries ?? [];
|
|
100
|
+
}
|
|
101
|
+
async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
|
|
102
|
+
const explicitLib = process.env.RIG_NATIVE_RUNTIME_LIB?.trim();
|
|
103
|
+
if (explicitLib && existsSync2(explicitLib)) {
|
|
104
|
+
return explicitLib;
|
|
105
|
+
}
|
|
106
|
+
const embeddedPath = extractEmbeddedNative("snapshot");
|
|
107
|
+
if (embeddedPath) {
|
|
108
|
+
return embeddedPath;
|
|
109
|
+
}
|
|
110
|
+
if (await buildNativeRuntimeLibrary(outputPath, options)) {
|
|
111
|
+
return outputPath;
|
|
112
|
+
}
|
|
113
|
+
return !options.force && existsSync2(outputPath) ? outputPath : null;
|
|
114
|
+
}
|
|
115
|
+
async function loadNativeRuntimeLibrary() {
|
|
116
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const explicitLib = process.env.RIG_NATIVE_RUNTIME_LIB?.trim();
|
|
120
|
+
if (explicitLib && existsSync2(explicitLib)) {
|
|
121
|
+
const loaded = tryDlopenNativeRuntimeLibrary(explicitLib);
|
|
122
|
+
if (loaded) {
|
|
123
|
+
return loaded;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const embeddedPath = extractEmbeddedNative("snapshot");
|
|
127
|
+
if (embeddedPath) {
|
|
128
|
+
const loaded = tryDlopenNativeRuntimeLibrary(embeddedPath);
|
|
129
|
+
if (loaded) {
|
|
130
|
+
return loaded;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const candidate of nativeRuntimeLibraryCandidates()) {
|
|
134
|
+
if (!candidate || !existsSync2(candidate)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const loaded = tryDlopenNativeRuntimeLibrary(candidate);
|
|
138
|
+
if (loaded) {
|
|
139
|
+
return loaded;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
|
|
143
|
+
if (!builtLibraryPath) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
|
|
147
|
+
}
|
|
148
|
+
function nativePackageLibraryCandidates(fromDir, names) {
|
|
149
|
+
const candidates = [];
|
|
150
|
+
let cursor = resolve3(fromDir);
|
|
151
|
+
for (let index = 0;index < 8; index += 1) {
|
|
152
|
+
for (const name of names) {
|
|
153
|
+
candidates.push(resolve3(cursor, "native", `${process.platform}-${process.arch}`, name), resolve3(cursor, "native", `${process.platform}-${process.arch}`, "lib", name), resolve3(cursor, "native", name), resolve3(cursor, "native", "lib", name));
|
|
154
|
+
}
|
|
155
|
+
const parent = dirname2(cursor);
|
|
156
|
+
if (parent === cursor)
|
|
157
|
+
break;
|
|
158
|
+
cursor = parent;
|
|
159
|
+
}
|
|
160
|
+
return candidates;
|
|
161
|
+
}
|
|
162
|
+
function nativeRuntimeLibraryCandidates() {
|
|
163
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
|
|
164
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
165
|
+
const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
|
|
166
|
+
return [...new Set([
|
|
167
|
+
explicit,
|
|
168
|
+
...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
|
|
169
|
+
execDir ? resolve3(execDir, colocatedNativeRuntimeFileName) : "",
|
|
170
|
+
execDir ? resolve3(execDir, platformSpecific) : "",
|
|
171
|
+
execDir ? resolve3(execDir, "..", colocatedNativeRuntimeFileName) : "",
|
|
172
|
+
execDir ? resolve3(execDir, "..", platformSpecific) : "",
|
|
173
|
+
execDir ? resolve3(execDir, "lib", colocatedNativeRuntimeFileName) : "",
|
|
174
|
+
execDir ? resolve3(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
|
|
175
|
+
sharedNativeRuntimeOutputPath
|
|
176
|
+
].filter(Boolean))];
|
|
177
|
+
}
|
|
178
|
+
function resolveNativeRuntimeSourcePath() {
|
|
179
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
|
|
180
|
+
if (explicit && existsSync2(explicit)) {
|
|
181
|
+
return explicit;
|
|
182
|
+
}
|
|
183
|
+
const bundled = resolve3(import.meta.dir, "../native/snapshot.zig");
|
|
184
|
+
return existsSync2(bundled) ? bundled : null;
|
|
185
|
+
}
|
|
186
|
+
function resolveNativeRuntimeSidecarSourcePath() {
|
|
187
|
+
const envRoots = [
|
|
188
|
+
process.cwd()?.trim(),
|
|
189
|
+
process.env.RIG_HOST_PROJECT_ROOT?.trim(),
|
|
190
|
+
process.env.PROJECT_RIG_ROOT?.trim()
|
|
191
|
+
].filter(Boolean);
|
|
192
|
+
for (const root of envRoots) {
|
|
193
|
+
for (const relative of [
|
|
194
|
+
"packages/isolation-plugin/src/runtime-native-sidecar.ts",
|
|
195
|
+
"packages/isolation-plugin/dist/src/runtime-native-sidecar.js"
|
|
196
|
+
]) {
|
|
197
|
+
const candidate = resolve3(root, relative);
|
|
198
|
+
if (existsSync2(candidate)) {
|
|
199
|
+
return candidate;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const localCandidate of [
|
|
204
|
+
resolve3(import.meta.dir, "runtime-native-sidecar.js"),
|
|
205
|
+
resolve3(import.meta.dir, "runtime-native-sidecar.ts")
|
|
206
|
+
]) {
|
|
207
|
+
if (existsSync2(localCandidate))
|
|
208
|
+
return localCandidate;
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
async function buildNativeRuntimeLibrary(outputPath, options = {}) {
|
|
213
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
const zigBinary = Bun.which("zig");
|
|
217
|
+
const sourcePath = resolveNativeRuntimeSourcePath();
|
|
218
|
+
if (!zigBinary || !sourcePath) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
222
|
+
try {
|
|
223
|
+
mkdirSync2(dirname2(outputPath), { recursive: true });
|
|
224
|
+
const needsBuild = options.force === true || !existsSync2(outputPath) || statSync2(sourcePath).mtimeMs > statSync2(outputPath).mtimeMs;
|
|
225
|
+
if (!needsBuild) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
const build = Bun.spawn([
|
|
229
|
+
zigBinary,
|
|
230
|
+
"build-lib",
|
|
231
|
+
sourcePath,
|
|
232
|
+
"-dynamic",
|
|
233
|
+
"-O",
|
|
234
|
+
"ReleaseFast",
|
|
235
|
+
`-femit-bin=${tempOutputPath}`
|
|
236
|
+
], {
|
|
237
|
+
cwd: import.meta.dir,
|
|
238
|
+
stdout: "pipe",
|
|
239
|
+
stderr: "pipe"
|
|
240
|
+
});
|
|
241
|
+
const exitCode = await build.exited;
|
|
242
|
+
if (exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
243
|
+
rmSync(tempOutputPath, { force: true });
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
renameSync2(tempOutputPath, outputPath);
|
|
247
|
+
return true;
|
|
248
|
+
} catch {
|
|
249
|
+
rmSync(tempOutputPath, { force: true });
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function tryDlopenNativeRuntimeLibrary(outputPath) {
|
|
254
|
+
try {
|
|
255
|
+
return dlopen(outputPath, {
|
|
256
|
+
rig_scope_match: {
|
|
257
|
+
args: ["ptr", "ptr"],
|
|
258
|
+
returns: "u8"
|
|
259
|
+
},
|
|
260
|
+
snapshot_capture: {
|
|
261
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
262
|
+
returns: "ptr"
|
|
263
|
+
},
|
|
264
|
+
snapshot_delta: {
|
|
265
|
+
args: ["ptr", "ptr"],
|
|
266
|
+
returns: "ptr"
|
|
267
|
+
},
|
|
268
|
+
snapshot_store_delta: {
|
|
269
|
+
args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
270
|
+
returns: "ptr"
|
|
271
|
+
},
|
|
272
|
+
snapshot_inspect_delta: {
|
|
273
|
+
args: ["ptr", "u64"],
|
|
274
|
+
returns: "ptr"
|
|
275
|
+
},
|
|
276
|
+
snapshot_apply_delta: {
|
|
277
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
278
|
+
returns: "ptr"
|
|
279
|
+
},
|
|
280
|
+
snapshot_release: {
|
|
281
|
+
args: ["ptr"],
|
|
282
|
+
returns: "void"
|
|
283
|
+
},
|
|
284
|
+
runtime_hash_file: {
|
|
285
|
+
args: ["ptr", "u64"],
|
|
286
|
+
returns: "ptr"
|
|
287
|
+
},
|
|
288
|
+
runtime_hash_tree: {
|
|
289
|
+
args: ["ptr", "u64"],
|
|
290
|
+
returns: "ptr"
|
|
291
|
+
},
|
|
292
|
+
runtime_prepare_paths: {
|
|
293
|
+
args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
294
|
+
returns: "ptr"
|
|
295
|
+
},
|
|
296
|
+
runtime_link_dependency_layer: {
|
|
297
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
298
|
+
returns: "ptr"
|
|
299
|
+
},
|
|
300
|
+
runtime_scan_worktrees: {
|
|
301
|
+
args: ["ptr", "u64"],
|
|
302
|
+
returns: "ptr"
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
} catch {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function resolveNativeRuntimeSidecarCommand(request) {
|
|
310
|
+
if (hasEmbeddedNatives()) {
|
|
311
|
+
return {
|
|
312
|
+
argv: [process.execPath, RIG_NATIVE_RUNTIME_SIDECAR_ARG, JSON.stringify(request)],
|
|
313
|
+
env: {}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const hostBinary = process.env.RIG_NATIVE_HOST_BINARY?.trim();
|
|
317
|
+
if (hostBinary) {
|
|
318
|
+
return {
|
|
319
|
+
argv: [hostBinary, RIG_NATIVE_RUNTIME_SIDECAR_ARG, JSON.stringify(request)],
|
|
320
|
+
env: {}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
const sidecarSourcePath = resolveNativeRuntimeSidecarSourcePath();
|
|
324
|
+
if (!sidecarSourcePath) {
|
|
325
|
+
throw new Error("runtime-native-sidecar.ts source file not found.");
|
|
326
|
+
}
|
|
327
|
+
const bunCli = resolveNativeRuntimeSidecarInvocation();
|
|
328
|
+
return {
|
|
329
|
+
argv: [bunCli.command, sidecarSourcePath, JSON.stringify(request)],
|
|
330
|
+
env: bunCli.env
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function runNativeRuntimeSidecar(request) {
|
|
334
|
+
const { argv, env } = resolveNativeRuntimeSidecarCommand(request);
|
|
335
|
+
const proc = Bun.spawnSync(argv, {
|
|
336
|
+
cwd: process.env.RIG_HOST_PROJECT_ROOT?.trim() || process.cwd(),
|
|
337
|
+
stdout: "pipe",
|
|
338
|
+
stderr: "pipe",
|
|
339
|
+
env: {
|
|
340
|
+
...process.env,
|
|
341
|
+
...env,
|
|
342
|
+
RIG_NATIVE_RUNTIME_SIDECAR: "1"
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
if (proc.exitCode !== 0) {
|
|
346
|
+
throw new Error(proc.stderr.toString() || proc.stdout.toString() || `runtime native sidecar exited ${proc.exitCode}`);
|
|
347
|
+
}
|
|
348
|
+
const stdout = proc.stdout.toString().trim();
|
|
349
|
+
if (!stdout) {
|
|
350
|
+
throw new Error("runtime native sidecar returned empty output.");
|
|
351
|
+
}
|
|
352
|
+
const responseLine = stdout.split(`
|
|
353
|
+
`).map((line) => line.trim()).filter((line) => line.startsWith("{")).at(-1);
|
|
354
|
+
if (!responseLine) {
|
|
355
|
+
throw new Error(`runtime native sidecar returned no JSON response: ${stdout}`);
|
|
356
|
+
}
|
|
357
|
+
return JSON.parse(responseLine);
|
|
358
|
+
}
|
|
359
|
+
function resolveNativeRuntimeSidecarInvocation() {
|
|
360
|
+
const bunPath = Bun.which("bun");
|
|
361
|
+
if (bunPath) {
|
|
362
|
+
return { command: bunPath, env: {} };
|
|
363
|
+
}
|
|
364
|
+
if (process.execPath?.trim()) {
|
|
365
|
+
return {
|
|
366
|
+
command: process.execPath,
|
|
367
|
+
env: { BUN_BE_BUN: "1" }
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
throw new Error("bun is required to run the runtime native sidecar.");
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// packages/isolation-plugin/src/isolation/home.ts
|
|
374
|
+
import { browserEnvFromContext, loadRuntimeContext, runtimeMemoryEnvFromContext, RUNTIME_CONTEXT_ENV } from "@rig/core/runtime-context";
|
|
375
|
+
|
|
376
|
+
// packages/isolation-plugin/src/isolation/shared.ts
|
|
377
|
+
import { agentId, safeGitRefComponent, taskRuntimeId } from "@rig/core/safe-identifiers";
|
|
378
|
+
import { resolveCheckoutRoot } from "@rig/core/checkout-root";
|
|
379
|
+
var generatedCredentialFiles = new Set;
|
|
380
|
+
function resolveMonorepoRoot(projectRoot) {
|
|
381
|
+
return resolveCheckoutRoot(projectRoot);
|
|
382
|
+
}
|
|
383
|
+
function sanitizeRuntimeRefSegment(value) {
|
|
384
|
+
return safeGitRefComponent(value, { fallback: "runtime", maxLength: 64 });
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// packages/isolation-plugin/src/isolation/home.ts
|
|
388
|
+
var GITHUB_KNOWN_HOSTS = [
|
|
389
|
+
"github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl",
|
|
390
|
+
"github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=",
|
|
391
|
+
"github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk="
|
|
392
|
+
].join(`
|
|
393
|
+
`);
|
|
394
|
+
|
|
395
|
+
// packages/isolation-plugin/src/isolation/discovery.ts
|
|
396
|
+
import { existsSync as existsSync3 } from "fs";
|
|
397
|
+
import { resolve as resolve4 } from "path";
|
|
398
|
+
import { resolveRuntimeWorkspaceLayout } from "@rig/core/layout";
|
|
399
|
+
import { loadRuntimeContext as loadRuntimeContext2 } from "@rig/core/runtime-context";
|
|
400
|
+
|
|
401
|
+
// packages/isolation-plugin/src/isolation/worktree.ts
|
|
402
|
+
import { assertPathInsideRoot, safeGitRefComponent as safeGitRefComponent2, safePathSegment } from "@rig/core/safe-identifiers";
|
|
403
|
+
|
|
404
|
+
// packages/isolation-plugin/src/isolation/toolchain.ts
|
|
405
|
+
import { assertPathInsideRoot as assertPathInsideRoot2, safePathSegment as safePathSegment2 } from "@rig/core/safe-identifiers";
|
|
406
|
+
|
|
407
|
+
// packages/isolation-plugin/src/isolation/runtime-binary-build.ts
|
|
408
|
+
import { resolveRigLayout } from "@rig/core/layout";
|
|
409
|
+
import { runtimeProvisioningEnv } from "@rig/core/runtime-provisioning-env";
|
|
410
|
+
var runtimeBinaryBuildQueue = Promise.resolve();
|
|
411
|
+
|
|
412
|
+
// packages/isolation-plugin/src/isolation/toolchain.ts
|
|
413
|
+
import {
|
|
414
|
+
GUARD_TOOLCHAIN_SOURCES,
|
|
415
|
+
LIFECYCLE_TOOLCHAIN_SOURCES,
|
|
416
|
+
TOOL_MATERIALIZER
|
|
417
|
+
} from "@rig/contracts";
|
|
418
|
+
import { defineCapability } from "@rig/core/capability";
|
|
419
|
+
import { buildProjectPluginHost, requireInstalledCapability } from "@rig/core/capability-loaders";
|
|
420
|
+
import { resolveBunBinaryPath as resolveBunBinaryPath2 } from "@rig/core/runtime-paths";
|
|
421
|
+
var ToolMaterializerCap = defineCapability(TOOL_MATERIALIZER);
|
|
422
|
+
var GuardToolchainSourcesCap = defineCapability(GUARD_TOOLCHAIN_SOURCES);
|
|
423
|
+
var LifecycleToolchainSourcesCap = defineCapability(LIFECYCLE_TOOLCHAIN_SOURCES);
|
|
424
|
+
var SNAPSHOT_SIDECAR_SOURCE = ["packages", "isolation-plugin", "src", "snapshot-sidecar.ts"].join("/");
|
|
425
|
+
function runtimeWorktreeId(workspaceDir) {
|
|
426
|
+
return workspaceDir.split("/").at(-1) || "runtime";
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// packages/isolation-plugin/src/isolation/discovery.ts
|
|
430
|
+
async function readRuntimeMetadata(metadataPath) {
|
|
431
|
+
if (!existsSync3(metadataPath)) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
try {
|
|
435
|
+
return await Bun.file(metadataPath).json();
|
|
436
|
+
} catch {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async function listAgentRuntimes(projectRoot) {
|
|
441
|
+
const runtimes = [];
|
|
442
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
443
|
+
const worktreesRoot = resolve4(monorepoRoot, ".worktrees");
|
|
444
|
+
if (!existsSync3(worktreesRoot)) {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
const workspaces = runtimeScanWorktreesNative(worktreesRoot);
|
|
448
|
+
for (let scan of workspaces) {
|
|
449
|
+
let workspacePath = scan.workspaceDir;
|
|
450
|
+
const workspaceLayout = resolveRuntimeWorkspaceLayout(workspacePath);
|
|
451
|
+
const rootDir = scan.runtimeDir || workspaceLayout.runtimeDir;
|
|
452
|
+
const metadataPath = scan.metadataPath || resolve4(rootDir, "runtime.json");
|
|
453
|
+
const contextFile = scan.contextPath || workspaceLayout.contextPath;
|
|
454
|
+
let mode = "worktree";
|
|
455
|
+
let createdAt = new Date().toISOString();
|
|
456
|
+
let taskId = "";
|
|
457
|
+
let runtimeId = "";
|
|
458
|
+
let binDir = workspaceLayout.binDir;
|
|
459
|
+
let logsDir = workspaceLayout.logsDir;
|
|
460
|
+
let stateDir = workspaceLayout.stateDir;
|
|
461
|
+
let sessionDir = workspaceLayout.sessionDir;
|
|
462
|
+
const metadata = await readRuntimeMetadata(metadataPath);
|
|
463
|
+
if (metadata) {
|
|
464
|
+
runtimeId = metadata.id;
|
|
465
|
+
mode = metadata.mode;
|
|
466
|
+
createdAt = metadata.createdAt;
|
|
467
|
+
}
|
|
468
|
+
if (existsSync3(contextFile)) {
|
|
469
|
+
try {
|
|
470
|
+
const ctx = loadRuntimeContext2(contextFile);
|
|
471
|
+
taskId = ctx.taskId;
|
|
472
|
+
workspacePath = ctx.workspaceDir;
|
|
473
|
+
binDir = ctx.binDir;
|
|
474
|
+
logsDir = ctx.logsDir;
|
|
475
|
+
stateDir = ctx.stateDir;
|
|
476
|
+
sessionDir = ctx.sessionDir;
|
|
477
|
+
} catch {}
|
|
478
|
+
}
|
|
479
|
+
if (!runtimeId) {
|
|
480
|
+
runtimeId = taskRuntimeId(taskId || runtimeWorktreeId(workspacePath));
|
|
481
|
+
}
|
|
482
|
+
runtimes.push({
|
|
483
|
+
id: runtimeId,
|
|
484
|
+
taskId,
|
|
485
|
+
mode,
|
|
486
|
+
rootDir,
|
|
487
|
+
workspaceDir: workspacePath,
|
|
488
|
+
homeDir: resolve4(rootDir, "home"),
|
|
489
|
+
tmpDir: resolve4(rootDir, "tmp"),
|
|
490
|
+
cacheDir: resolve4(rootDir, "cache"),
|
|
491
|
+
logsDir,
|
|
492
|
+
stateDir,
|
|
493
|
+
sessionDir,
|
|
494
|
+
claudeHomeDir: resolve4(rootDir, "home", ".claude"),
|
|
495
|
+
contextFile,
|
|
496
|
+
binDir,
|
|
497
|
+
createdAt
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
return runtimes;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// packages/isolation-plugin/src/isolation/runner.ts
|
|
504
|
+
import { existsSync as existsSync4, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
505
|
+
import { basename, resolve as resolve5 } from "path";
|
|
506
|
+
|
|
507
|
+
// packages/isolation-plugin/src/runtime-config.ts
|
|
508
|
+
import {
|
|
509
|
+
POLICY_VERSION
|
|
510
|
+
} from "@rig/contracts";
|
|
511
|
+
|
|
512
|
+
// packages/isolation-plugin/src/sandbox/backend.ts
|
|
513
|
+
init_utils();
|
|
514
|
+
import {
|
|
515
|
+
resolveBunInstallDir as resolveBunInstallDir2,
|
|
516
|
+
resolveClaudeInstallDir as resolveClaudeInstallDir2,
|
|
517
|
+
resolveNodeInstallDir as resolveNodeInstallDir2,
|
|
518
|
+
resolveRuntimeDependencyRoots
|
|
519
|
+
} from "@rig/core/runtime-paths";
|
|
520
|
+
|
|
521
|
+
// packages/isolation-plugin/src/isolation/runner.ts
|
|
522
|
+
import { resolveRuntimeWorkspaceLayout as resolveRuntimeWorkspaceLayout2 } from "@rig/core/layout";
|
|
523
|
+
import { resolveBunBinaryPath as resolveBunBinaryPath3 } from "@rig/core/runtime-paths";
|
|
524
|
+
var SNAPSHOT_SIDECAR_READY_TIMEOUT_MS = 1e4;
|
|
525
|
+
async function startRuntimeSnapshotSidecar(runtime, options = {}) {
|
|
526
|
+
const instanceId = sanitizeRuntimeRefSegment(options.instanceId?.trim() || runtime.id);
|
|
527
|
+
const readyFile = resolve5(runtime.stateDir, `runtime-snapshot-sidecar-${instanceId}.ready`);
|
|
528
|
+
const requestFile = resolve5(runtime.stateDir, `runtime-snapshot-sidecar-${instanceId}.request.json`);
|
|
529
|
+
rmSync2(readyFile, { force: true });
|
|
530
|
+
rmSync2(requestFile, { force: true });
|
|
531
|
+
const sidecarBinary = resolveSnapshotSidecarBinaryPath(runtime.binDir);
|
|
532
|
+
const useCompiledSidecar = shouldUseCompiledSnapshotSidecar(sidecarBinary);
|
|
533
|
+
const bunCli = useCompiledSidecar ? null : resolveBunCliInvocation();
|
|
534
|
+
const command = useCompiledSidecar ? [sidecarBinary] : [bunCli.command, resolveSnapshotSidecarScriptPath()];
|
|
535
|
+
const proc = Bun.spawn([
|
|
536
|
+
...command,
|
|
537
|
+
"--workspace",
|
|
538
|
+
runtime.workspaceDir,
|
|
539
|
+
"--task",
|
|
540
|
+
runtime.taskId,
|
|
541
|
+
"--runtime-id",
|
|
542
|
+
runtime.id,
|
|
543
|
+
"--instance-id",
|
|
544
|
+
instanceId,
|
|
545
|
+
"--ready-file",
|
|
546
|
+
readyFile,
|
|
547
|
+
"--request-file",
|
|
548
|
+
requestFile
|
|
549
|
+
], {
|
|
550
|
+
cwd: runtime.workspaceDir,
|
|
551
|
+
stdin: "ignore",
|
|
552
|
+
stdout: "pipe",
|
|
553
|
+
stderr: "pipe",
|
|
554
|
+
env: {
|
|
555
|
+
...process.env,
|
|
556
|
+
...bunCli?.env ?? {}
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
const stdoutTextPromise = drainStream(proc.stdout);
|
|
560
|
+
const stderrTextPromise = drainStream(proc.stderr);
|
|
561
|
+
await waitForSnapshotSidecarReady(readyFile, proc, stdoutTextPromise, stderrTextPromise);
|
|
562
|
+
return {
|
|
563
|
+
cancel: async () => {
|
|
564
|
+
try {
|
|
565
|
+
proc.kill("SIGTERM");
|
|
566
|
+
} catch {}
|
|
567
|
+
await proc.exited;
|
|
568
|
+
rmSync2(readyFile, { force: true });
|
|
569
|
+
rmSync2(requestFile, { force: true });
|
|
570
|
+
},
|
|
571
|
+
finalize: async (commandParts, exitCode) => {
|
|
572
|
+
writeFileSync2(requestFile, `${JSON.stringify({ command: commandParts, exitCode })}
|
|
573
|
+
`, "utf-8");
|
|
574
|
+
const [sidecarExitCode, stdout, stderr] = await Promise.all([
|
|
575
|
+
proc.exited,
|
|
576
|
+
stdoutTextPromise,
|
|
577
|
+
stderrTextPromise
|
|
578
|
+
]);
|
|
579
|
+
rmSync2(readyFile, { force: true });
|
|
580
|
+
rmSync2(requestFile, { force: true });
|
|
581
|
+
if (sidecarExitCode !== 0) {
|
|
582
|
+
throw new Error(`snapshot sidecar failed (${sidecarExitCode}): ${stderr || stdout}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
async function drainStream(stream) {
|
|
588
|
+
if (!stream)
|
|
589
|
+
return "";
|
|
590
|
+
try {
|
|
591
|
+
return await new Response(stream).text();
|
|
592
|
+
} catch {
|
|
593
|
+
return "";
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function resolveSnapshotSidecarScriptPath() {
|
|
597
|
+
return resolveRuntimeSourceScriptPath("snapshot-sidecar.ts");
|
|
598
|
+
}
|
|
599
|
+
function resolveSnapshotSidecarBinaryPath(binDir) {
|
|
600
|
+
return resolve5(binDir, "snapshot-sidecar");
|
|
601
|
+
}
|
|
602
|
+
function shouldUseCompiledSnapshotSidecar(binaryPath) {
|
|
603
|
+
if (!existsSync4(binaryPath)) {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
const preference = process.env.RIG_USE_COMPILED_SNAPSHOT_SIDECAR?.trim().toLowerCase();
|
|
607
|
+
if (!preference) {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
return preference === "1" || preference === "true" || preference === "yes";
|
|
611
|
+
}
|
|
612
|
+
function resolveRuntimeSourceScriptPath(fileName) {
|
|
613
|
+
const hostRoots = [
|
|
614
|
+
process.env.RIG_HOST_PROJECT_ROOT?.trim(),
|
|
615
|
+
process.env.PROJECT_RIG_ROOT?.trim()
|
|
616
|
+
].filter((value) => Boolean(value));
|
|
617
|
+
for (const root of hostRoots) {
|
|
618
|
+
const candidate = resolve5(root, "packages/isolation-plugin/src", fileName);
|
|
619
|
+
if (existsSync4(candidate)) {
|
|
620
|
+
return candidate;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return resolve5(import.meta.dir, "..", fileName);
|
|
624
|
+
}
|
|
625
|
+
function resolveBunCliInvocation() {
|
|
626
|
+
if (process.env.RIG_BUN_PATH?.trim()) {
|
|
627
|
+
return {
|
|
628
|
+
command: process.env.RIG_BUN_PATH.trim(),
|
|
629
|
+
env: {}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
const systemBun = Bun.which("bun")?.trim();
|
|
633
|
+
if (systemBun) {
|
|
634
|
+
return {
|
|
635
|
+
command: systemBun,
|
|
636
|
+
env: {}
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
if (process.execPath?.trim()) {
|
|
640
|
+
return {
|
|
641
|
+
command: process.execPath,
|
|
642
|
+
env: { BUN_BE_BUN: "1" }
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
return { command: "bun", env: {} };
|
|
646
|
+
}
|
|
647
|
+
async function waitForSnapshotSidecarReady(readyFile, proc, stdoutTextPromise, stderrTextPromise) {
|
|
648
|
+
const deadline = Date.now() + SNAPSHOT_SIDECAR_READY_TIMEOUT_MS;
|
|
649
|
+
while (Date.now() < deadline) {
|
|
650
|
+
if (existsSync4(readyFile)) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
const exitCode = proc.exitCode;
|
|
654
|
+
if (exitCode !== null) {
|
|
655
|
+
const [stderr, stdout] = await Promise.all([stderrTextPromise, stdoutTextPromise]);
|
|
656
|
+
throw new Error(`snapshot sidecar exited before ready (${exitCode}): ${stderr || stdout}`);
|
|
657
|
+
}
|
|
658
|
+
await Bun.sleep(25);
|
|
659
|
+
}
|
|
660
|
+
throw new Error(`snapshot sidecar did not become ready within ${SNAPSHOT_SIDECAR_READY_TIMEOUT_MS}ms`);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// packages/isolation-plugin/src/isolation/index.ts
|
|
664
|
+
var TaskDataCap = defineCapability2(TASK_DATA_SERVICE_CAPABILITY);
|
|
665
|
+
|
|
666
|
+
// packages/isolation-plugin/src/task-run-snapshot.ts
|
|
667
|
+
async function resolveTaskRunSnapshotSidecar(input) {
|
|
668
|
+
const listRuntimes = input.listRuntimes ?? listAgentRuntimes;
|
|
669
|
+
const startSidecar = input.startSidecar ?? startRuntimeSnapshotSidecar;
|
|
670
|
+
const runtimes = await listRuntimes(input.projectRoot);
|
|
671
|
+
const runtime = runtimes.find((candidate) => candidate.id === input.runtimeId) ?? (input.workspaceDir ? runtimes.find((candidate) => candidate.workspaceDir === input.workspaceDir) : undefined);
|
|
672
|
+
if (!runtime) {
|
|
673
|
+
return {
|
|
674
|
+
sidecar: null,
|
|
675
|
+
error: `Could not locate runtime metadata for ${input.runtimeId}.`
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
try {
|
|
679
|
+
return {
|
|
680
|
+
sidecar: await startSidecar(runtime),
|
|
681
|
+
error: null
|
|
682
|
+
};
|
|
683
|
+
} catch (error) {
|
|
684
|
+
return {
|
|
685
|
+
sidecar: null,
|
|
686
|
+
error: error instanceof Error ? error.message : String(error)
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
async function finalizeTaskRunSnapshot(input) {
|
|
691
|
+
const snapshotSidecar = await (input.snapshotSidecarPromise ?? Promise.resolve(null));
|
|
692
|
+
if (!snapshotSidecar) {
|
|
693
|
+
return "unavailable";
|
|
694
|
+
}
|
|
695
|
+
if (input.exit.error) {
|
|
696
|
+
await snapshotSidecar.cancel();
|
|
697
|
+
return "cancelled";
|
|
698
|
+
}
|
|
699
|
+
const exitCode = typeof input.exit.code === "number" ? input.exit.code : 1;
|
|
700
|
+
try {
|
|
701
|
+
await snapshotSidecar.finalize(input.latestProviderCommand ?? input.hostAgentCommand, exitCode);
|
|
702
|
+
return "finalized";
|
|
703
|
+
} catch (error) {
|
|
704
|
+
if (exitCode !== 0) {
|
|
705
|
+
throw error;
|
|
706
|
+
}
|
|
707
|
+
return "unavailable";
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
export {
|
|
711
|
+
resolveTaskRunSnapshotSidecar,
|
|
712
|
+
finalizeTaskRunSnapshot
|
|
713
|
+
};
|