@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,477 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/isolation-plugin/src/isolation/discovery.ts
|
|
3
|
+
import { existsSync as existsSync3 } from "fs";
|
|
4
|
+
import { resolve as resolve4 } from "path";
|
|
5
|
+
import { resolveRuntimeWorkspaceLayout } from "@rig/core/layout";
|
|
6
|
+
|
|
7
|
+
// packages/isolation-plugin/src/runtime-native.ts
|
|
8
|
+
import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
|
|
9
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, renameSync as renameSync2, rmSync, statSync as statSync2 } from "fs";
|
|
10
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
11
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
12
|
+
|
|
13
|
+
// packages/isolation-plugin/src/native-extract.ts
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "fs";
|
|
15
|
+
import { tmpdir } from "os";
|
|
16
|
+
import { resolve } from "path";
|
|
17
|
+
|
|
18
|
+
// packages/isolation-plugin/src/embedded-native-assets.ts
|
|
19
|
+
var embeddedNatives = null;
|
|
20
|
+
|
|
21
|
+
// packages/isolation-plugin/src/native-extract.ts
|
|
22
|
+
var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
|
|
23
|
+
var extractionCache = {};
|
|
24
|
+
function hasEmbeddedNatives() {
|
|
25
|
+
return embeddedNatives != null;
|
|
26
|
+
}
|
|
27
|
+
function extractEmbeddedNative(name) {
|
|
28
|
+
if (name in extractionCache) {
|
|
29
|
+
return extractionCache[name] ?? null;
|
|
30
|
+
}
|
|
31
|
+
const entry = embeddedNatives?.[name];
|
|
32
|
+
if (!entry) {
|
|
33
|
+
extractionCache[name] = null;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
|
|
38
|
+
mkdirSync(sharedNativeOutputDir, { recursive: true });
|
|
39
|
+
const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
|
|
40
|
+
if (!upToDate) {
|
|
41
|
+
const bytes = readFileSync(entry.filePath);
|
|
42
|
+
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
|
|
43
|
+
writeFileSync(tempPath, bytes, { mode: 493 });
|
|
44
|
+
renameSync(tempPath, targetPath);
|
|
45
|
+
}
|
|
46
|
+
extractionCache[name] = targetPath;
|
|
47
|
+
} catch {
|
|
48
|
+
extractionCache[name] = null;
|
|
49
|
+
}
|
|
50
|
+
return extractionCache[name] ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// packages/isolation-plugin/src/sidecar-arg.ts
|
|
54
|
+
var RIG_NATIVE_RUNTIME_SIDECAR_ARG = "__rig_native_runtime_sidecar";
|
|
55
|
+
|
|
56
|
+
// packages/isolation-plugin/src/runtime-native.ts
|
|
57
|
+
var sharedNativeRuntimeOutputDir = resolve2(tmpdir2(), "rig-native");
|
|
58
|
+
var sharedNativeRuntimeOutputPath = resolve2(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
|
|
59
|
+
var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
|
|
60
|
+
var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
|
|
61
|
+
function runtimeScanWorktreesNative(worktreesRoot) {
|
|
62
|
+
const response = runNativeRuntimeSidecar({
|
|
63
|
+
op: "scan-worktrees",
|
|
64
|
+
input: { worktreesRoot }
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(response.error);
|
|
68
|
+
}
|
|
69
|
+
return response.entries ?? [];
|
|
70
|
+
}
|
|
71
|
+
async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
|
|
72
|
+
const explicitLib = process.env.RIG_NATIVE_RUNTIME_LIB?.trim();
|
|
73
|
+
if (explicitLib && existsSync2(explicitLib)) {
|
|
74
|
+
return explicitLib;
|
|
75
|
+
}
|
|
76
|
+
const embeddedPath = extractEmbeddedNative("snapshot");
|
|
77
|
+
if (embeddedPath) {
|
|
78
|
+
return embeddedPath;
|
|
79
|
+
}
|
|
80
|
+
if (await buildNativeRuntimeLibrary(outputPath, options)) {
|
|
81
|
+
return outputPath;
|
|
82
|
+
}
|
|
83
|
+
return !options.force && existsSync2(outputPath) ? outputPath : null;
|
|
84
|
+
}
|
|
85
|
+
async function loadNativeRuntimeLibrary() {
|
|
86
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const explicitLib = process.env.RIG_NATIVE_RUNTIME_LIB?.trim();
|
|
90
|
+
if (explicitLib && existsSync2(explicitLib)) {
|
|
91
|
+
const loaded = tryDlopenNativeRuntimeLibrary(explicitLib);
|
|
92
|
+
if (loaded) {
|
|
93
|
+
return loaded;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const embeddedPath = extractEmbeddedNative("snapshot");
|
|
97
|
+
if (embeddedPath) {
|
|
98
|
+
const loaded = tryDlopenNativeRuntimeLibrary(embeddedPath);
|
|
99
|
+
if (loaded) {
|
|
100
|
+
return loaded;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const candidate of nativeRuntimeLibraryCandidates()) {
|
|
104
|
+
if (!candidate || !existsSync2(candidate)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const loaded = tryDlopenNativeRuntimeLibrary(candidate);
|
|
108
|
+
if (loaded) {
|
|
109
|
+
return loaded;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
|
|
113
|
+
if (!builtLibraryPath) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
|
|
117
|
+
}
|
|
118
|
+
function nativePackageLibraryCandidates(fromDir, names) {
|
|
119
|
+
const candidates = [];
|
|
120
|
+
let cursor = resolve2(fromDir);
|
|
121
|
+
for (let index = 0;index < 8; index += 1) {
|
|
122
|
+
for (const name of names) {
|
|
123
|
+
candidates.push(resolve2(cursor, "native", `${process.platform}-${process.arch}`, name), resolve2(cursor, "native", `${process.platform}-${process.arch}`, "lib", name), resolve2(cursor, "native", name), resolve2(cursor, "native", "lib", name));
|
|
124
|
+
}
|
|
125
|
+
const parent = dirname(cursor);
|
|
126
|
+
if (parent === cursor)
|
|
127
|
+
break;
|
|
128
|
+
cursor = parent;
|
|
129
|
+
}
|
|
130
|
+
return candidates;
|
|
131
|
+
}
|
|
132
|
+
function nativeRuntimeLibraryCandidates() {
|
|
133
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
|
|
134
|
+
const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
|
|
135
|
+
const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
|
|
136
|
+
return [...new Set([
|
|
137
|
+
explicit,
|
|
138
|
+
...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
|
|
139
|
+
execDir ? resolve2(execDir, colocatedNativeRuntimeFileName) : "",
|
|
140
|
+
execDir ? resolve2(execDir, platformSpecific) : "",
|
|
141
|
+
execDir ? resolve2(execDir, "..", colocatedNativeRuntimeFileName) : "",
|
|
142
|
+
execDir ? resolve2(execDir, "..", platformSpecific) : "",
|
|
143
|
+
execDir ? resolve2(execDir, "lib", colocatedNativeRuntimeFileName) : "",
|
|
144
|
+
execDir ? resolve2(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
|
|
145
|
+
sharedNativeRuntimeOutputPath
|
|
146
|
+
].filter(Boolean))];
|
|
147
|
+
}
|
|
148
|
+
function resolveNativeRuntimeSourcePath() {
|
|
149
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
|
|
150
|
+
if (explicit && existsSync2(explicit)) {
|
|
151
|
+
return explicit;
|
|
152
|
+
}
|
|
153
|
+
const bundled = resolve2(import.meta.dir, "../native/snapshot.zig");
|
|
154
|
+
return existsSync2(bundled) ? bundled : null;
|
|
155
|
+
}
|
|
156
|
+
function resolveNativeRuntimeSidecarSourcePath() {
|
|
157
|
+
const envRoots = [
|
|
158
|
+
process.cwd()?.trim(),
|
|
159
|
+
process.env.RIG_HOST_PROJECT_ROOT?.trim(),
|
|
160
|
+
process.env.PROJECT_RIG_ROOT?.trim()
|
|
161
|
+
].filter(Boolean);
|
|
162
|
+
for (const root of envRoots) {
|
|
163
|
+
for (const relative of [
|
|
164
|
+
"packages/isolation-plugin/src/runtime-native-sidecar.ts",
|
|
165
|
+
"packages/isolation-plugin/dist/src/runtime-native-sidecar.js"
|
|
166
|
+
]) {
|
|
167
|
+
const candidate = resolve2(root, relative);
|
|
168
|
+
if (existsSync2(candidate)) {
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const localCandidate of [
|
|
174
|
+
resolve2(import.meta.dir, "runtime-native-sidecar.js"),
|
|
175
|
+
resolve2(import.meta.dir, "runtime-native-sidecar.ts")
|
|
176
|
+
]) {
|
|
177
|
+
if (existsSync2(localCandidate))
|
|
178
|
+
return localCandidate;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
async function buildNativeRuntimeLibrary(outputPath, options = {}) {
|
|
183
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
const zigBinary = Bun.which("zig");
|
|
187
|
+
const sourcePath = resolveNativeRuntimeSourcePath();
|
|
188
|
+
if (!zigBinary || !sourcePath) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
192
|
+
try {
|
|
193
|
+
mkdirSync2(dirname(outputPath), { recursive: true });
|
|
194
|
+
const needsBuild = options.force === true || !existsSync2(outputPath) || statSync2(sourcePath).mtimeMs > statSync2(outputPath).mtimeMs;
|
|
195
|
+
if (!needsBuild) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
const build = Bun.spawn([
|
|
199
|
+
zigBinary,
|
|
200
|
+
"build-lib",
|
|
201
|
+
sourcePath,
|
|
202
|
+
"-dynamic",
|
|
203
|
+
"-O",
|
|
204
|
+
"ReleaseFast",
|
|
205
|
+
`-femit-bin=${tempOutputPath}`
|
|
206
|
+
], {
|
|
207
|
+
cwd: import.meta.dir,
|
|
208
|
+
stdout: "pipe",
|
|
209
|
+
stderr: "pipe"
|
|
210
|
+
});
|
|
211
|
+
const exitCode = await build.exited;
|
|
212
|
+
if (exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
213
|
+
rmSync(tempOutputPath, { force: true });
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
renameSync2(tempOutputPath, outputPath);
|
|
217
|
+
return true;
|
|
218
|
+
} catch {
|
|
219
|
+
rmSync(tempOutputPath, { force: true });
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function tryDlopenNativeRuntimeLibrary(outputPath) {
|
|
224
|
+
try {
|
|
225
|
+
return dlopen(outputPath, {
|
|
226
|
+
rig_scope_match: {
|
|
227
|
+
args: ["ptr", "ptr"],
|
|
228
|
+
returns: "u8"
|
|
229
|
+
},
|
|
230
|
+
snapshot_capture: {
|
|
231
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
232
|
+
returns: "ptr"
|
|
233
|
+
},
|
|
234
|
+
snapshot_delta: {
|
|
235
|
+
args: ["ptr", "ptr"],
|
|
236
|
+
returns: "ptr"
|
|
237
|
+
},
|
|
238
|
+
snapshot_store_delta: {
|
|
239
|
+
args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
240
|
+
returns: "ptr"
|
|
241
|
+
},
|
|
242
|
+
snapshot_inspect_delta: {
|
|
243
|
+
args: ["ptr", "u64"],
|
|
244
|
+
returns: "ptr"
|
|
245
|
+
},
|
|
246
|
+
snapshot_apply_delta: {
|
|
247
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
248
|
+
returns: "ptr"
|
|
249
|
+
},
|
|
250
|
+
snapshot_release: {
|
|
251
|
+
args: ["ptr"],
|
|
252
|
+
returns: "void"
|
|
253
|
+
},
|
|
254
|
+
runtime_hash_file: {
|
|
255
|
+
args: ["ptr", "u64"],
|
|
256
|
+
returns: "ptr"
|
|
257
|
+
},
|
|
258
|
+
runtime_hash_tree: {
|
|
259
|
+
args: ["ptr", "u64"],
|
|
260
|
+
returns: "ptr"
|
|
261
|
+
},
|
|
262
|
+
runtime_prepare_paths: {
|
|
263
|
+
args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
264
|
+
returns: "ptr"
|
|
265
|
+
},
|
|
266
|
+
runtime_link_dependency_layer: {
|
|
267
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
268
|
+
returns: "ptr"
|
|
269
|
+
},
|
|
270
|
+
runtime_scan_worktrees: {
|
|
271
|
+
args: ["ptr", "u64"],
|
|
272
|
+
returns: "ptr"
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
} catch {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function resolveNativeRuntimeSidecarCommand(request) {
|
|
280
|
+
if (hasEmbeddedNatives()) {
|
|
281
|
+
return {
|
|
282
|
+
argv: [process.execPath, RIG_NATIVE_RUNTIME_SIDECAR_ARG, JSON.stringify(request)],
|
|
283
|
+
env: {}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
const hostBinary = process.env.RIG_NATIVE_HOST_BINARY?.trim();
|
|
287
|
+
if (hostBinary) {
|
|
288
|
+
return {
|
|
289
|
+
argv: [hostBinary, RIG_NATIVE_RUNTIME_SIDECAR_ARG, JSON.stringify(request)],
|
|
290
|
+
env: {}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const sidecarSourcePath = resolveNativeRuntimeSidecarSourcePath();
|
|
294
|
+
if (!sidecarSourcePath) {
|
|
295
|
+
throw new Error("runtime-native-sidecar.ts source file not found.");
|
|
296
|
+
}
|
|
297
|
+
const bunCli = resolveNativeRuntimeSidecarInvocation();
|
|
298
|
+
return {
|
|
299
|
+
argv: [bunCli.command, sidecarSourcePath, JSON.stringify(request)],
|
|
300
|
+
env: bunCli.env
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function runNativeRuntimeSidecar(request) {
|
|
304
|
+
const { argv, env } = resolveNativeRuntimeSidecarCommand(request);
|
|
305
|
+
const proc = Bun.spawnSync(argv, {
|
|
306
|
+
cwd: process.env.RIG_HOST_PROJECT_ROOT?.trim() || process.cwd(),
|
|
307
|
+
stdout: "pipe",
|
|
308
|
+
stderr: "pipe",
|
|
309
|
+
env: {
|
|
310
|
+
...process.env,
|
|
311
|
+
...env,
|
|
312
|
+
RIG_NATIVE_RUNTIME_SIDECAR: "1"
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
if (proc.exitCode !== 0) {
|
|
316
|
+
throw new Error(proc.stderr.toString() || proc.stdout.toString() || `runtime native sidecar exited ${proc.exitCode}`);
|
|
317
|
+
}
|
|
318
|
+
const stdout = proc.stdout.toString().trim();
|
|
319
|
+
if (!stdout) {
|
|
320
|
+
throw new Error("runtime native sidecar returned empty output.");
|
|
321
|
+
}
|
|
322
|
+
const responseLine = stdout.split(`
|
|
323
|
+
`).map((line) => line.trim()).filter((line) => line.startsWith("{")).at(-1);
|
|
324
|
+
if (!responseLine) {
|
|
325
|
+
throw new Error(`runtime native sidecar returned no JSON response: ${stdout}`);
|
|
326
|
+
}
|
|
327
|
+
return JSON.parse(responseLine);
|
|
328
|
+
}
|
|
329
|
+
function resolveNativeRuntimeSidecarInvocation() {
|
|
330
|
+
const bunPath = Bun.which("bun");
|
|
331
|
+
if (bunPath) {
|
|
332
|
+
return { command: bunPath, env: {} };
|
|
333
|
+
}
|
|
334
|
+
if (process.execPath?.trim()) {
|
|
335
|
+
return {
|
|
336
|
+
command: process.execPath,
|
|
337
|
+
env: { BUN_BE_BUN: "1" }
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
throw new Error("bun is required to run the runtime native sidecar.");
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// packages/isolation-plugin/src/isolation/discovery.ts
|
|
344
|
+
import { loadRuntimeContext } from "@rig/core/runtime-context";
|
|
345
|
+
|
|
346
|
+
// packages/isolation-plugin/src/isolation/shared.ts
|
|
347
|
+
import { agentId, safeGitRefComponent, taskRuntimeId } from "@rig/core/safe-identifiers";
|
|
348
|
+
import { resolveCheckoutRoot } from "@rig/core/checkout-root";
|
|
349
|
+
var generatedCredentialFiles = new Set;
|
|
350
|
+
function resolveMonorepoRoot(projectRoot) {
|
|
351
|
+
return resolveCheckoutRoot(projectRoot);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// packages/isolation-plugin/src/isolation/worktree.ts
|
|
355
|
+
import { assertPathInsideRoot, safeGitRefComponent as safeGitRefComponent2, safePathSegment } from "@rig/core/safe-identifiers";
|
|
356
|
+
function runtimeWorktreeNameFromRuntimeId(runtimeId) {
|
|
357
|
+
return safePathSegment(runtimeId.replace(/^task-/, ""), { fallback: "runtime", maxLength: 72 });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// packages/isolation-plugin/src/isolation/toolchain.ts
|
|
361
|
+
import { assertPathInsideRoot as assertPathInsideRoot2, safePathSegment as safePathSegment2 } from "@rig/core/safe-identifiers";
|
|
362
|
+
|
|
363
|
+
// packages/isolation-plugin/src/isolation/runtime-binary-build.ts
|
|
364
|
+
import { resolveRigLayout } from "@rig/core/layout";
|
|
365
|
+
import { runtimeProvisioningEnv } from "@rig/core/runtime-provisioning-env";
|
|
366
|
+
var runtimeBinaryBuildQueue = Promise.resolve();
|
|
367
|
+
|
|
368
|
+
// packages/isolation-plugin/src/isolation/git-native.ts
|
|
369
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
370
|
+
import { dirname as dirname2, isAbsolute, resolve as resolve3 } from "path";
|
|
371
|
+
var sharedGitNativeOutputDir = resolve3(tmpdir3(), "rig-native");
|
|
372
|
+
var sharedGitNativeOutputPath = resolve3(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
373
|
+
|
|
374
|
+
// packages/isolation-plugin/src/isolation/toolchain.ts
|
|
375
|
+
import {
|
|
376
|
+
GUARD_TOOLCHAIN_SOURCES,
|
|
377
|
+
LIFECYCLE_TOOLCHAIN_SOURCES,
|
|
378
|
+
TOOL_MATERIALIZER
|
|
379
|
+
} from "@rig/contracts";
|
|
380
|
+
import { defineCapability } from "@rig/core/capability";
|
|
381
|
+
import { buildProjectPluginHost, requireInstalledCapability } from "@rig/core/capability-loaders";
|
|
382
|
+
import { resolveBunBinaryPath } from "@rig/core/runtime-paths";
|
|
383
|
+
var ToolMaterializerCap = defineCapability(TOOL_MATERIALIZER);
|
|
384
|
+
var GuardToolchainSourcesCap = defineCapability(GUARD_TOOLCHAIN_SOURCES);
|
|
385
|
+
var LifecycleToolchainSourcesCap = defineCapability(LIFECYCLE_TOOLCHAIN_SOURCES);
|
|
386
|
+
var SNAPSHOT_SIDECAR_SOURCE = ["packages", "isolation-plugin", "src", "snapshot-sidecar.ts"].join("/");
|
|
387
|
+
function runtimeWorktreeId(workspaceDir) {
|
|
388
|
+
return workspaceDir.split("/").at(-1) || "runtime";
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// packages/isolation-plugin/src/isolation/discovery.ts
|
|
392
|
+
async function readRuntimeMetadata(metadataPath) {
|
|
393
|
+
if (!existsSync3(metadataPath)) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
return await Bun.file(metadataPath).json();
|
|
398
|
+
} catch {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
async function listAgentRuntimes(projectRoot) {
|
|
403
|
+
const runtimes = [];
|
|
404
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
405
|
+
const worktreesRoot = resolve4(monorepoRoot, ".worktrees");
|
|
406
|
+
if (!existsSync3(worktreesRoot)) {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
const workspaces = runtimeScanWorktreesNative(worktreesRoot);
|
|
410
|
+
for (let scan of workspaces) {
|
|
411
|
+
let workspacePath = scan.workspaceDir;
|
|
412
|
+
const workspaceLayout = resolveRuntimeWorkspaceLayout(workspacePath);
|
|
413
|
+
const rootDir = scan.runtimeDir || workspaceLayout.runtimeDir;
|
|
414
|
+
const metadataPath = scan.metadataPath || resolve4(rootDir, "runtime.json");
|
|
415
|
+
const contextFile = scan.contextPath || workspaceLayout.contextPath;
|
|
416
|
+
let mode = "worktree";
|
|
417
|
+
let createdAt = new Date().toISOString();
|
|
418
|
+
let taskId = "";
|
|
419
|
+
let runtimeId = "";
|
|
420
|
+
let binDir = workspaceLayout.binDir;
|
|
421
|
+
let logsDir = workspaceLayout.logsDir;
|
|
422
|
+
let stateDir = workspaceLayout.stateDir;
|
|
423
|
+
let sessionDir = workspaceLayout.sessionDir;
|
|
424
|
+
const metadata = await readRuntimeMetadata(metadataPath);
|
|
425
|
+
if (metadata) {
|
|
426
|
+
runtimeId = metadata.id;
|
|
427
|
+
mode = metadata.mode;
|
|
428
|
+
createdAt = metadata.createdAt;
|
|
429
|
+
}
|
|
430
|
+
if (existsSync3(contextFile)) {
|
|
431
|
+
try {
|
|
432
|
+
const ctx = loadRuntimeContext(contextFile);
|
|
433
|
+
taskId = ctx.taskId;
|
|
434
|
+
workspacePath = ctx.workspaceDir;
|
|
435
|
+
binDir = ctx.binDir;
|
|
436
|
+
logsDir = ctx.logsDir;
|
|
437
|
+
stateDir = ctx.stateDir;
|
|
438
|
+
sessionDir = ctx.sessionDir;
|
|
439
|
+
} catch {}
|
|
440
|
+
}
|
|
441
|
+
if (!runtimeId) {
|
|
442
|
+
runtimeId = taskRuntimeId(taskId || runtimeWorktreeId(workspacePath));
|
|
443
|
+
}
|
|
444
|
+
runtimes.push({
|
|
445
|
+
id: runtimeId,
|
|
446
|
+
taskId,
|
|
447
|
+
mode,
|
|
448
|
+
rootDir,
|
|
449
|
+
workspaceDir: workspacePath,
|
|
450
|
+
homeDir: resolve4(rootDir, "home"),
|
|
451
|
+
tmpDir: resolve4(rootDir, "tmp"),
|
|
452
|
+
cacheDir: resolve4(rootDir, "cache"),
|
|
453
|
+
logsDir,
|
|
454
|
+
stateDir,
|
|
455
|
+
sessionDir,
|
|
456
|
+
claudeHomeDir: resolve4(rootDir, "home", ".claude"),
|
|
457
|
+
contextFile,
|
|
458
|
+
binDir,
|
|
459
|
+
createdAt
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return runtimes;
|
|
463
|
+
}
|
|
464
|
+
function runtimeRootForCleanup(projectRoot, runtimeId) {
|
|
465
|
+
let monorepoRoot = null;
|
|
466
|
+
try {
|
|
467
|
+
monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
468
|
+
} catch {}
|
|
469
|
+
const workspaceRootCandidate = monorepoRoot ?? projectRoot;
|
|
470
|
+
const initialWorkspaceDir = resolve4(workspaceRootCandidate, ".worktrees", runtimeWorktreeNameFromRuntimeId(runtimeId));
|
|
471
|
+
const runtimeRoot = resolveRuntimeWorkspaceLayout(initialWorkspaceDir).runtimeDir;
|
|
472
|
+
return { monorepoRoot, initialWorkspaceDir, runtimeRoot };
|
|
473
|
+
}
|
|
474
|
+
export {
|
|
475
|
+
runtimeRootForCleanup,
|
|
476
|
+
listAgentRuntimes
|
|
477
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type PendingFile = {
|
|
2
|
+
path: string;
|
|
3
|
+
status: string;
|
|
4
|
+
};
|
|
5
|
+
export type TreeCommitUpdate = {
|
|
6
|
+
path: string;
|
|
7
|
+
content: string;
|
|
8
|
+
sourceFilePath?: never;
|
|
9
|
+
} | {
|
|
10
|
+
path: string;
|
|
11
|
+
sourceFilePath: string;
|
|
12
|
+
content?: never;
|
|
13
|
+
};
|
|
14
|
+
export declare function runtimeRigGitFileName(): string;
|
|
15
|
+
export declare function ensureRigGitBinaryPath(outputPath?: string): Promise<string>;
|
|
16
|
+
export declare function ensureRigGitBinaryPathSync(outputPath?: string): string;
|
|
17
|
+
export declare function materializeRigGitBinary(targetDir: string): Promise<string>;
|
|
18
|
+
export declare function nativeBranchName(repoPath: string): string | null;
|
|
19
|
+
export declare function nativeHeadOid(repoPath: string): string | null;
|
|
20
|
+
export declare function nativeChangeCount(repoPath: string): number | null;
|
|
21
|
+
export declare function nativePendingFiles(repoPath: string): PendingFile[] | null;
|
|
22
|
+
export declare function nativeFileHasChanges(repoPath: string, filePath: string): boolean | null;
|
|
23
|
+
export declare function nativeFetchRef(repoPath: string, remote: string, branch: string): string;
|
|
24
|
+
export declare function nativeReadBlobAtRef(repoPath: string, ref: string, path: string): string;
|
|
25
|
+
export declare function nativeReadBlobBytesAtRef(repoPath: string, ref: string, path: string): Uint8Array;
|
|
26
|
+
export declare function buildTreeCommitUpdatesJson(updates: TreeCommitUpdate[]): string;
|
|
27
|
+
export declare function nativeWriteTreeCommit(repoPath: string, baseRef: string, updates: TreeCommitUpdate[], message: string): string;
|
|
28
|
+
export declare function nativePushRefWithLease(repoPath: string, localOid: string, remoteRef: string, expectedOldOid: string, remote?: string): string;
|