@h-rig/isolation-plugin 0.0.6-alpha.157 → 0.0.6-alpha.159

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.
Files changed (77) hide show
  1. package/dist/src/embedded-native-assets.d.ts +7 -0
  2. package/dist/src/embedded-native-assets.js +6 -0
  3. package/dist/src/image-fingerprint-sidecar.d.ts +1 -0
  4. package/dist/src/image-fingerprint-sidecar.js +515 -0
  5. package/dist/src/image.d.ts +40 -0
  6. package/dist/src/image.js +1498 -0
  7. package/dist/src/index.js +4220 -20
  8. package/dist/src/isolation/binary-build-worker.d.ts +1 -0
  9. package/dist/src/isolation/binary-build-worker.js +323 -0
  10. package/dist/src/isolation/discovery.d.ts +7 -0
  11. package/dist/src/isolation/discovery.js +477 -0
  12. package/dist/src/isolation/git-native.d.ts +28 -0
  13. package/dist/src/isolation/git-native.js +598 -0
  14. package/dist/src/isolation/home.d.ts +25 -0
  15. package/dist/src/isolation/home.js +929 -0
  16. package/dist/src/isolation/index.d.ts +43 -0
  17. package/dist/src/isolation/index.js +4062 -0
  18. package/dist/src/isolation/provisioning-env.d.ts +1 -0
  19. package/dist/src/isolation/provisioning-env.js +6 -0
  20. package/dist/src/isolation/runner.d.ts +20 -0
  21. package/dist/src/isolation/runner.js +1881 -0
  22. package/dist/src/isolation/runtime-binary-build.d.ts +88 -0
  23. package/dist/src/isolation/runtime-binary-build.js +480 -0
  24. package/dist/src/isolation/shared.d.ts +29 -0
  25. package/dist/src/isolation/shared.js +283 -0
  26. package/dist/src/isolation/toolchain.d.ts +71 -0
  27. package/dist/src/isolation/toolchain.js +1348 -0
  28. package/dist/src/isolation/types.d.ts +15 -0
  29. package/dist/src/isolation/types.js +1 -0
  30. package/dist/src/isolation/worktree.d.ts +22 -0
  31. package/dist/src/isolation/worktree.js +353 -0
  32. package/dist/src/native-extract.d.ts +2 -0
  33. package/dist/src/native-extract.js +44 -0
  34. package/dist/src/plugin.d.ts +2 -2
  35. package/dist/src/plugin.js +4219 -19
  36. package/dist/src/runtime-config.d.ts +3 -0
  37. package/dist/src/runtime-config.js +215 -0
  38. package/dist/src/runtime-native-sidecar.d.ts +8 -0
  39. package/dist/src/runtime-native-sidecar.js +368 -0
  40. package/dist/src/runtime-native.d.ts +51 -0
  41. package/dist/src/runtime-native.js +485 -0
  42. package/dist/src/sandbox/backend-bwrap.d.ts +20 -0
  43. package/dist/src/sandbox/backend-bwrap.js +268 -0
  44. package/dist/src/sandbox/backend-none.d.ts +11 -0
  45. package/dist/src/sandbox/backend-none.js +20 -0
  46. package/dist/src/sandbox/backend-seatbelt.d.ts +13 -0
  47. package/dist/src/sandbox/backend-seatbelt.js +225 -0
  48. package/dist/src/sandbox/backend.d.ts +117 -0
  49. package/dist/src/sandbox/backend.js +864 -0
  50. package/dist/src/sandbox/orchestrator.d.ts +21 -0
  51. package/dist/src/sandbox/orchestrator.js +895 -0
  52. package/dist/src/sandbox/utils.d.ts +43 -0
  53. package/dist/src/sandbox/utils.js +94 -0
  54. package/dist/src/service.d.ts +10 -5
  55. package/dist/src/service.js +4145 -2
  56. package/dist/src/sidecar-arg.d.ts +7 -0
  57. package/dist/src/sidecar-arg.js +6 -0
  58. package/dist/src/sidecar-entrypoint.d.ts +9 -0
  59. package/dist/src/sidecar-entrypoint.js +401 -0
  60. package/dist/src/snapshot-sidecar.d.ts +2 -0
  61. package/dist/src/snapshot-sidecar.js +566 -0
  62. package/dist/src/snapshot.d.ts +64 -0
  63. package/dist/src/snapshot.js +515 -0
  64. package/dist/src/task-run-snapshot.d.ts +26 -0
  65. package/dist/src/task-run-snapshot.js +713 -0
  66. package/native/darwin-arm64/rig-git +0 -0
  67. package/native/darwin-arm64/rig-git.build-manifest.json +4 -0
  68. package/native/darwin-arm64/runtime-native.dylib +0 -0
  69. package/native/darwin-x64/rig-git +0 -0
  70. package/native/darwin-x64/runtime-native.dylib +0 -0
  71. package/native/linux-arm64/rig-git +0 -0
  72. package/native/linux-arm64/runtime-native.so +0 -0
  73. package/native/linux-x64/rig-git +0 -0
  74. package/native/linux-x64/runtime-native.so +0 -0
  75. package/native/win32-x64/rig-git.exe +0 -0
  76. package/native/win32-x64/runtime-native.dll +0 -0
  77. package/package.json +45 -5
@@ -0,0 +1,7 @@
1
+ export type EmbeddedNative = {
2
+ name: string;
3
+ fileName: string;
4
+ filePath: string;
5
+ size: number;
6
+ };
7
+ export declare const embeddedNatives: Record<string, EmbeddedNative> | null;
@@ -0,0 +1,6 @@
1
+ // @bun
2
+ // packages/isolation-plugin/src/embedded-native-assets.ts
3
+ var embeddedNatives = null;
4
+ export {
5
+ embeddedNatives
6
+ };
@@ -0,0 +1 @@
1
+ export declare function runRuntimeImageFingerprintSidecar(argv?: string[]): Promise<void>;
@@ -0,0 +1,515 @@
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/image.ts
9
+ import { ptr as ptr2, toBuffer as toBuffer2 } from "bun:ffi";
10
+ import {
11
+ existsSync as existsSync3,
12
+ readFileSync as readFileSync2,
13
+ readdirSync,
14
+ mkdirSync as mkdirSync3,
15
+ writeFileSync as writeFileSync2,
16
+ renameSync as renameSync3,
17
+ rmSync as rmSync2,
18
+ cpSync,
19
+ lstatSync,
20
+ unlinkSync,
21
+ symlinkSync
22
+ } from "fs";
23
+ import { resolve as resolve4 } from "path";
24
+ import { resolveRigLayout as resolveRigLayout2 } from "@rig/core/layout";
25
+
26
+ // packages/isolation-plugin/src/runtime-native.ts
27
+ import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
28
+ import { copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, renameSync as renameSync2, rmSync, statSync as statSync2 } from "fs";
29
+ import { tmpdir as tmpdir2 } from "os";
30
+ import { dirname, resolve as resolve2 } from "path";
31
+
32
+ // packages/isolation-plugin/src/native-extract.ts
33
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "fs";
34
+ import { tmpdir } from "os";
35
+ import { resolve } from "path";
36
+
37
+ // packages/isolation-plugin/src/embedded-native-assets.ts
38
+ var embeddedNatives = null;
39
+
40
+ // packages/isolation-plugin/src/native-extract.ts
41
+ var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
42
+ var extractionCache = {};
43
+ function extractEmbeddedNative(name) {
44
+ if (name in extractionCache) {
45
+ return extractionCache[name] ?? null;
46
+ }
47
+ const entry = embeddedNatives?.[name];
48
+ if (!entry) {
49
+ extractionCache[name] = null;
50
+ return null;
51
+ }
52
+ try {
53
+ const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
54
+ mkdirSync(sharedNativeOutputDir, { recursive: true });
55
+ const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
56
+ if (!upToDate) {
57
+ const bytes = readFileSync(entry.filePath);
58
+ const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
59
+ writeFileSync(tempPath, bytes, { mode: 493 });
60
+ renameSync(tempPath, targetPath);
61
+ }
62
+ extractionCache[name] = targetPath;
63
+ } catch {
64
+ extractionCache[name] = null;
65
+ }
66
+ return extractionCache[name] ?? null;
67
+ }
68
+
69
+ // packages/isolation-plugin/src/runtime-native.ts
70
+ var sharedNativeRuntimeOutputDir = resolve2(tmpdir2(), "rig-native");
71
+ var sharedNativeRuntimeOutputPath = resolve2(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
72
+ var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
73
+ var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
74
+ function requireNativeRuntimeLibrary(feature) {
75
+ if (!nativeRuntimeLibrary) {
76
+ throw new Error(`Native Zig runtime is required for ${feature}`);
77
+ }
78
+ return nativeRuntimeLibrary;
79
+ }
80
+ async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
81
+ const explicitLib = process.env.RIG_NATIVE_RUNTIME_LIB?.trim();
82
+ if (explicitLib && existsSync2(explicitLib)) {
83
+ return explicitLib;
84
+ }
85
+ const embeddedPath = extractEmbeddedNative("snapshot");
86
+ if (embeddedPath) {
87
+ return embeddedPath;
88
+ }
89
+ if (await buildNativeRuntimeLibrary(outputPath, options)) {
90
+ return outputPath;
91
+ }
92
+ return !options.force && existsSync2(outputPath) ? outputPath : null;
93
+ }
94
+ async function loadNativeRuntimeLibrary() {
95
+ if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
96
+ return null;
97
+ }
98
+ const explicitLib = process.env.RIG_NATIVE_RUNTIME_LIB?.trim();
99
+ if (explicitLib && existsSync2(explicitLib)) {
100
+ const loaded = tryDlopenNativeRuntimeLibrary(explicitLib);
101
+ if (loaded) {
102
+ return loaded;
103
+ }
104
+ }
105
+ const embeddedPath = extractEmbeddedNative("snapshot");
106
+ if (embeddedPath) {
107
+ const loaded = tryDlopenNativeRuntimeLibrary(embeddedPath);
108
+ if (loaded) {
109
+ return loaded;
110
+ }
111
+ }
112
+ for (const candidate of nativeRuntimeLibraryCandidates()) {
113
+ if (!candidate || !existsSync2(candidate)) {
114
+ continue;
115
+ }
116
+ const loaded = tryDlopenNativeRuntimeLibrary(candidate);
117
+ if (loaded) {
118
+ return loaded;
119
+ }
120
+ }
121
+ const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
122
+ if (!builtLibraryPath) {
123
+ return null;
124
+ }
125
+ return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
126
+ }
127
+ function nativePackageLibraryCandidates(fromDir, names) {
128
+ const candidates = [];
129
+ let cursor = resolve2(fromDir);
130
+ for (let index = 0;index < 8; index += 1) {
131
+ for (const name of names) {
132
+ 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));
133
+ }
134
+ const parent = dirname(cursor);
135
+ if (parent === cursor)
136
+ break;
137
+ cursor = parent;
138
+ }
139
+ return candidates;
140
+ }
141
+ function nativeRuntimeLibraryCandidates() {
142
+ const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
143
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
144
+ const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
145
+ return [...new Set([
146
+ explicit,
147
+ ...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
148
+ execDir ? resolve2(execDir, colocatedNativeRuntimeFileName) : "",
149
+ execDir ? resolve2(execDir, platformSpecific) : "",
150
+ execDir ? resolve2(execDir, "..", colocatedNativeRuntimeFileName) : "",
151
+ execDir ? resolve2(execDir, "..", platformSpecific) : "",
152
+ execDir ? resolve2(execDir, "lib", colocatedNativeRuntimeFileName) : "",
153
+ execDir ? resolve2(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
154
+ sharedNativeRuntimeOutputPath
155
+ ].filter(Boolean))];
156
+ }
157
+ function resolveNativeRuntimeSourcePath() {
158
+ const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
159
+ if (explicit && existsSync2(explicit)) {
160
+ return explicit;
161
+ }
162
+ const bundled = resolve2(import.meta.dir, "../native/snapshot.zig");
163
+ return existsSync2(bundled) ? bundled : null;
164
+ }
165
+ async function buildNativeRuntimeLibrary(outputPath, options = {}) {
166
+ if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
167
+ return false;
168
+ }
169
+ const zigBinary = Bun.which("zig");
170
+ const sourcePath = resolveNativeRuntimeSourcePath();
171
+ if (!zigBinary || !sourcePath) {
172
+ return false;
173
+ }
174
+ const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
175
+ try {
176
+ mkdirSync2(dirname(outputPath), { recursive: true });
177
+ const needsBuild = options.force === true || !existsSync2(outputPath) || statSync2(sourcePath).mtimeMs > statSync2(outputPath).mtimeMs;
178
+ if (!needsBuild) {
179
+ return true;
180
+ }
181
+ const build = Bun.spawn([
182
+ zigBinary,
183
+ "build-lib",
184
+ sourcePath,
185
+ "-dynamic",
186
+ "-O",
187
+ "ReleaseFast",
188
+ `-femit-bin=${tempOutputPath}`
189
+ ], {
190
+ cwd: import.meta.dir,
191
+ stdout: "pipe",
192
+ stderr: "pipe"
193
+ });
194
+ const exitCode = await build.exited;
195
+ if (exitCode !== 0 || !existsSync2(tempOutputPath)) {
196
+ rmSync(tempOutputPath, { force: true });
197
+ return false;
198
+ }
199
+ renameSync2(tempOutputPath, outputPath);
200
+ return true;
201
+ } catch {
202
+ rmSync(tempOutputPath, { force: true });
203
+ return false;
204
+ }
205
+ }
206
+ function tryDlopenNativeRuntimeLibrary(outputPath) {
207
+ try {
208
+ return dlopen(outputPath, {
209
+ rig_scope_match: {
210
+ args: ["ptr", "ptr"],
211
+ returns: "u8"
212
+ },
213
+ snapshot_capture: {
214
+ args: ["ptr", "u64", "ptr", "u64"],
215
+ returns: "ptr"
216
+ },
217
+ snapshot_delta: {
218
+ args: ["ptr", "ptr"],
219
+ returns: "ptr"
220
+ },
221
+ snapshot_store_delta: {
222
+ args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
223
+ returns: "ptr"
224
+ },
225
+ snapshot_inspect_delta: {
226
+ args: ["ptr", "u64"],
227
+ returns: "ptr"
228
+ },
229
+ snapshot_apply_delta: {
230
+ args: ["ptr", "u64", "ptr", "u64"],
231
+ returns: "ptr"
232
+ },
233
+ snapshot_release: {
234
+ args: ["ptr"],
235
+ returns: "void"
236
+ },
237
+ runtime_hash_file: {
238
+ args: ["ptr", "u64"],
239
+ returns: "ptr"
240
+ },
241
+ runtime_hash_tree: {
242
+ args: ["ptr", "u64"],
243
+ returns: "ptr"
244
+ },
245
+ runtime_prepare_paths: {
246
+ args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
247
+ returns: "ptr"
248
+ },
249
+ runtime_link_dependency_layer: {
250
+ args: ["ptr", "u64", "ptr", "u64"],
251
+ returns: "ptr"
252
+ },
253
+ runtime_scan_worktrees: {
254
+ args: ["ptr", "u64"],
255
+ returns: "ptr"
256
+ }
257
+ });
258
+ } catch {
259
+ return null;
260
+ }
261
+ }
262
+
263
+ // packages/isolation-plugin/src/isolation/index.ts
264
+ import { BROWSER_CONTRACT_SERVICE_CAPABILITY, MEMORY } from "@rig/contracts";
265
+ import { safePathSegment as safePathSegment3 } from "@rig/core/safe-identifiers";
266
+
267
+ // packages/isolation-plugin/src/isolation/git-native.ts
268
+ import { tmpdir as tmpdir3 } from "os";
269
+ import { dirname as dirname2, isAbsolute, resolve as resolve3 } from "path";
270
+ var sharedGitNativeOutputDir = resolve3(tmpdir3(), "rig-native");
271
+ var sharedGitNativeOutputPath = resolve3(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
272
+
273
+ // packages/isolation-plugin/src/isolation/index.ts
274
+ import { defineCapability as defineCapability2 } from "@rig/core/capability";
275
+ import { loadCapabilityForRoot, requireCapabilityForRoot, requireInstalledCapability as requireInstalledCapability2 } from "@rig/core/capability-loaders";
276
+ import { buildPluginHostContext } from "@rig/core/plugin-host-context";
277
+ import { TASK_DATA_SERVICE_CAPABILITY } from "@rig/contracts";
278
+ import { resolveRuntimeWorkspaceLayout as resolveRuntimeWorkspaceLayout3 } from "@rig/core/layout";
279
+ import { ensureRuntimeOverlay } from "@rig/core/runtime-overlay";
280
+ import {
281
+ DEFAULT_RUNTIME_MEMORY_RETRIEVAL,
282
+ writeRuntimeContext
283
+ } from "@rig/core/runtime-context";
284
+ import { secretDefinesFromEnv } from "@rig/core/baked-secrets";
285
+
286
+ // packages/isolation-plugin/src/isolation/home.ts
287
+ import { resolveBunBinaryPath, resolveBunInstallDir, resolveClaudeBinaryPath, resolveClaudeInstallDir, resolveNodeInstallDir } from "@rig/core/runtime-paths";
288
+ import { resolveRuntimeSecrets } from "@rig/core/baked-secrets";
289
+ import { browserEnvFromContext, loadRuntimeContext, runtimeMemoryEnvFromContext, RUNTIME_CONTEXT_ENV } from "@rig/core/runtime-context";
290
+
291
+ // packages/isolation-plugin/src/isolation/shared.ts
292
+ import { agentId, safeGitRefComponent, taskRuntimeId } from "@rig/core/safe-identifiers";
293
+ import { resolveCheckoutRoot } from "@rig/core/checkout-root";
294
+ var generatedCredentialFiles = new Set;
295
+
296
+ // packages/isolation-plugin/src/isolation/home.ts
297
+ var GITHUB_KNOWN_HOSTS = [
298
+ "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl",
299
+ "github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=",
300
+ "github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk="
301
+ ].join(`
302
+ `);
303
+
304
+ // packages/isolation-plugin/src/isolation/discovery.ts
305
+ import { resolveRuntimeWorkspaceLayout } from "@rig/core/layout";
306
+ import { loadRuntimeContext as loadRuntimeContext2 } from "@rig/core/runtime-context";
307
+
308
+ // packages/isolation-plugin/src/isolation/worktree.ts
309
+ import { assertPathInsideRoot, safeGitRefComponent as safeGitRefComponent2, safePathSegment } from "@rig/core/safe-identifiers";
310
+
311
+ // packages/isolation-plugin/src/isolation/toolchain.ts
312
+ import { assertPathInsideRoot as assertPathInsideRoot2, safePathSegment as safePathSegment2 } from "@rig/core/safe-identifiers";
313
+
314
+ // packages/isolation-plugin/src/isolation/runtime-binary-build.ts
315
+ import { resolveRigLayout } from "@rig/core/layout";
316
+ import { runtimeProvisioningEnv } from "@rig/core/runtime-provisioning-env";
317
+ var runtimeBinaryBuildQueue = Promise.resolve();
318
+
319
+ // packages/isolation-plugin/src/isolation/toolchain.ts
320
+ import {
321
+ GUARD_TOOLCHAIN_SOURCES,
322
+ LIFECYCLE_TOOLCHAIN_SOURCES,
323
+ TOOL_MATERIALIZER
324
+ } from "@rig/contracts";
325
+ import { defineCapability } from "@rig/core/capability";
326
+ import { buildProjectPluginHost, requireInstalledCapability } from "@rig/core/capability-loaders";
327
+ import { resolveBunBinaryPath as resolveBunBinaryPath2 } from "@rig/core/runtime-paths";
328
+ var ToolMaterializerCap = defineCapability(TOOL_MATERIALIZER);
329
+ var GuardToolchainSourcesCap = defineCapability(GUARD_TOOLCHAIN_SOURCES);
330
+ var LifecycleToolchainSourcesCap = defineCapability(LIFECYCLE_TOOLCHAIN_SOURCES);
331
+ var SNAPSHOT_SIDECAR_SOURCE = ["packages", "isolation-plugin", "src", "snapshot-sidecar.ts"].join("/");
332
+
333
+ // packages/isolation-plugin/src/runtime-config.ts
334
+ import {
335
+ POLICY_VERSION
336
+ } from "@rig/contracts";
337
+
338
+ // packages/isolation-plugin/src/sandbox/backend.ts
339
+ init_utils();
340
+ import {
341
+ resolveBunInstallDir as resolveBunInstallDir2,
342
+ resolveClaudeInstallDir as resolveClaudeInstallDir2,
343
+ resolveNodeInstallDir as resolveNodeInstallDir2,
344
+ resolveRuntimeDependencyRoots
345
+ } from "@rig/core/runtime-paths";
346
+
347
+ // packages/isolation-plugin/src/isolation/runner.ts
348
+ import { resolveRuntimeWorkspaceLayout as resolveRuntimeWorkspaceLayout2 } from "@rig/core/layout";
349
+ import { resolveBunBinaryPath as resolveBunBinaryPath3 } from "@rig/core/runtime-paths";
350
+
351
+ // packages/isolation-plugin/src/isolation/index.ts
352
+ var TaskDataCap = defineCapability2(TASK_DATA_SERVICE_CAPABILITY);
353
+
354
+ // packages/isolation-plugin/src/isolation/provisioning-env.ts
355
+ import { runtimeProvisioningEnv as runtimeProvisioningEnv2 } from "@rig/core/runtime-provisioning-env";
356
+
357
+ // packages/isolation-plugin/src/image.ts
358
+ import { resolveBunBinaryPath as resolveBunBinaryPath4 } from "@rig/core/runtime-paths";
359
+ var HASH_RESULT_SIZE = 40;
360
+ var nativeRuntimeLibrary2 = null;
361
+ function sha256Hex2(input) {
362
+ const hasher = new Bun.CryptoHasher("sha256");
363
+ hasher.update(input);
364
+ return hasher.digest("hex");
365
+ }
366
+ function hashFile(filePath) {
367
+ if (!existsSync3(filePath)) {
368
+ return "";
369
+ }
370
+ return hashPathWithNative("runtime_hash_file", filePath);
371
+ }
372
+ function hashDirectory(dir) {
373
+ if (!existsSync3(dir)) {
374
+ return sha256Hex2("(empty)");
375
+ }
376
+ return hashPathWithNative("runtime_hash_tree", dir);
377
+ }
378
+ function hashDirectories(dirs) {
379
+ const combined = new Bun.CryptoHasher("sha256");
380
+ for (const { label, path } of dirs) {
381
+ const dirHash = hashDirectory(path);
382
+ combined.update(`${label}:${dirHash}
383
+ `);
384
+ }
385
+ return combined.digest("hex");
386
+ }
387
+ async function probeVersion(args) {
388
+ try {
389
+ const proc = Bun.spawn(args, { stdout: "pipe", stderr: "pipe" });
390
+ const [exitCode, stdout] = await Promise.all([
391
+ proc.exited,
392
+ new Response(proc.stdout).text()
393
+ ]);
394
+ if (exitCode === 0) {
395
+ return stdout.trim().split(`
396
+ `)[0] ?? "";
397
+ }
398
+ return "";
399
+ } catch {
400
+ return "";
401
+ }
402
+ }
403
+ async function computeRuntimeImageFingerprintNative(projectRoot) {
404
+ const [nodeVersion, claudeVersion] = await Promise.all([
405
+ probeVersion(["node", "--version"]),
406
+ probeVersion(["claude", "--version"])
407
+ ]);
408
+ const runtimeDir = resolve4(projectRoot, "packages", "runtime");
409
+ const cliDir = resolve4(projectRoot, "packages", "cli");
410
+ const runtimeCodeHash = hashDirectories([
411
+ { label: "packages/runtime", path: runtimeDir },
412
+ { label: "packages/cli", path: cliDir }
413
+ ]);
414
+ const policyPath = resolve4(projectRoot, "rig/policy/policy.json");
415
+ const policyHash = hashFile(policyPath);
416
+ const pluginsDir = resolve4(projectRoot, "rig/plugins");
417
+ const pluginsHash = hashDirectory(pluginsDir);
418
+ const baseLockfiles = [
419
+ "bun.lock",
420
+ "bun.lockb",
421
+ "package-lock.json",
422
+ "package.json",
423
+ "tsconfig.json"
424
+ ];
425
+ const extra = process.env.RIG_RUNTIME_IMAGE_EXTRA_LOCKFILES?.trim();
426
+ const lockfileCandidates = extra ? [...baseLockfiles, ...extra.split(",").map((p) => p.trim()).filter(Boolean)] : baseLockfiles;
427
+ const lockfileHashes = {};
428
+ for (const relPath of lockfileCandidates) {
429
+ const fullPath = resolve4(projectRoot, relPath);
430
+ if (existsSync3(fullPath)) {
431
+ lockfileHashes[relPath] = hashFile(fullPath);
432
+ }
433
+ }
434
+ return {
435
+ platform: process.platform,
436
+ bunVersion: Bun.version,
437
+ nodeVersion,
438
+ claudeVersion,
439
+ runtimeCodeHash,
440
+ policyHash,
441
+ pluginsHash,
442
+ lockfileHashes
443
+ };
444
+ }
445
+ function hashPathWithNative(symbol, path) {
446
+ const pathBuffer = Buffer.from(path, "utf8");
447
+ const runtimeLibrary = getNativeRuntimeLibrary();
448
+ const resultPtr = runtimeLibrary.symbols[symbol](Number(ptr2(pathBuffer)), pathBuffer.byteLength);
449
+ if (!resultPtr) {
450
+ throw new Error(`${symbol} returned null for ${path}`);
451
+ }
452
+ try {
453
+ const view = viewAt(resultPtr, HASH_RESULT_SIZE);
454
+ const error = readError(view, 24, 32);
455
+ if (error) {
456
+ throw new Error(`${symbol} failed: ${error}`);
457
+ }
458
+ return readString(readU64(view, 8), readU64(view, 16));
459
+ } finally {
460
+ runtimeLibrary.symbols.snapshot_release(resultPtr);
461
+ }
462
+ }
463
+ function getNativeRuntimeLibrary() {
464
+ if (nativeRuntimeLibrary2) {
465
+ return nativeRuntimeLibrary2;
466
+ }
467
+ nativeRuntimeLibrary2 = requireNativeRuntimeLibrary("runtime image hashing");
468
+ return nativeRuntimeLibrary2;
469
+ }
470
+ function viewAt(pointer, size) {
471
+ const buffer = toBuffer2(pointer, 0, size);
472
+ return new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
473
+ }
474
+ function readString(pointer, length) {
475
+ if (!pointer || length === 0) {
476
+ return "";
477
+ }
478
+ return Buffer.from(toBuffer2(pointer, 0, length)).toString("utf8");
479
+ }
480
+ function readU64(view, offset) {
481
+ return Number(view.getBigUint64(offset, true));
482
+ }
483
+ function readError(view, pointerOffset, lengthOffset) {
484
+ const errorPointer = readU64(view, pointerOffset);
485
+ const errorLength = readU64(view, lengthOffset);
486
+ if (!errorPointer || !errorLength) {
487
+ return null;
488
+ }
489
+ return readString(errorPointer, errorLength);
490
+ }
491
+ var LOCK_STALE_MS = 10 * 60 * 1000;
492
+
493
+ // packages/isolation-plugin/src/image-fingerprint-sidecar.ts
494
+ function parseProjectRoot(argv) {
495
+ for (let index = 0;index < argv.length; index += 1) {
496
+ if (argv[index] === "--project-root") {
497
+ return argv[index + 1] ?? "";
498
+ }
499
+ }
500
+ throw new Error("Usage: image-fingerprint-sidecar.ts --project-root <dir>");
501
+ }
502
+ async function runRuntimeImageFingerprintSidecar(argv = process.argv.slice(2)) {
503
+ const projectRoot = parseProjectRoot(argv);
504
+ const fingerprint = await computeRuntimeImageFingerprintNative(projectRoot);
505
+ process.stdout.write(JSON.stringify(fingerprint));
506
+ }
507
+ if (import.meta.main) {
508
+ runRuntimeImageFingerprintSidecar().catch((error) => {
509
+ console.error(error instanceof Error ? error.message : String(error));
510
+ process.exit(1);
511
+ });
512
+ }
513
+ export {
514
+ runRuntimeImageFingerprintSidecar
515
+ };
@@ -0,0 +1,40 @@
1
+ export type RuntimeImageFingerprint = {
2
+ platform: string;
3
+ bunVersion: string;
4
+ nodeVersion: string;
5
+ claudeVersion: string;
6
+ runtimeCodeHash: string;
7
+ policyHash: string;
8
+ pluginsHash: string;
9
+ lockfileHashes: Record<string, string>;
10
+ };
11
+ export type RuntimeImage = {
12
+ id: string;
13
+ rootDir: string;
14
+ binDir: string;
15
+ hooksDir: string;
16
+ pluginsDir: string;
17
+ validatorsDir: string;
18
+ depsDir: string;
19
+ manifestPath: string;
20
+ fingerprint: RuntimeImageFingerprint;
21
+ };
22
+ export declare function computeRuntimeImageFingerprint(projectRoot: string): Promise<RuntimeImageFingerprint>;
23
+ export declare function computeRuntimeImageFingerprintNative(projectRoot: string): Promise<RuntimeImageFingerprint>;
24
+ export declare function computeRuntimeImageId(fp: RuntimeImageFingerprint): string;
25
+ export declare function acquireRuntimeImageLock(lockPath: string): boolean;
26
+ export declare function releaseRuntimeImageLock(lockPath: string): void;
27
+ export declare function waitForRuntimeImageManifest(manifestPath: string, timeoutMs: number, pollMs?: number): Promise<boolean>;
28
+ /**
29
+ * Compute a deterministic 16-character hex ID from a fingerprint.
30
+ * Same inputs always produce the same ID.
31
+ */
32
+ export declare function computeRuntimeImageIdFromFingerprint(fp: RuntimeImageFingerprint): string;
33
+ /**
34
+ * Ensure the shared runtime image for this project exists and is up-to-date.
35
+ *
36
+ * - Cache hit: manifest exists → returns immediately without recompiling.
37
+ * - Cache miss or fingerprint mismatch: acquires a file lock, builds binaries
38
+ * in a temp dir, atomically renames to the final image dir, releases lock.
39
+ */
40
+ export declare function ensureRuntimeImage(projectRoot: string): Promise<RuntimeImage>;