@h-rig/provider-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.
Files changed (73) hide show
  1. package/dist/bin/rig-agent-dispatch.d.ts +2 -0
  2. package/dist/bin/rig-agent-dispatch.js +863 -0
  3. package/dist/src/agent-harness/agent-mode.d.ts +1 -0
  4. package/dist/src/agent-harness/agent-mode.js +48 -0
  5. package/dist/src/agent-harness/agent-wrapper.d.ts +53 -0
  6. package/dist/src/agent-harness/agent-wrapper.js +916 -0
  7. package/dist/src/agent-harness/controlled-bash.d.ts +3 -0
  8. package/dist/src/agent-harness/controlled-bash.js +45 -0
  9. package/dist/src/agent-harness/git-ops.d.ts +2 -0
  10. package/dist/src/agent-harness/git-ops.js +27 -0
  11. package/dist/src/agent-harness/repo-ops.d.ts +8 -0
  12. package/dist/src/agent-harness/repo-ops.js +471 -0
  13. package/dist/src/agent-harness/rig-agent-entrypoint.d.ts +1 -0
  14. package/dist/src/agent-harness/rig-agent-entrypoint.js +1277 -0
  15. package/dist/src/agent-harness/rig-agent.d.ts +2 -0
  16. package/dist/src/agent-harness/rig-agent.js +1244 -0
  17. package/dist/src/agent-harness/runtime-snapshot-config.d.ts +2 -0
  18. package/dist/src/agent-harness/runtime-snapshot-config.js +25 -0
  19. package/dist/src/agent-harness/task-data.d.ts +2 -0
  20. package/dist/src/agent-harness/task-data.js +12 -0
  21. package/dist/src/agent-harness/task-ops.d.ts +10 -0
  22. package/dist/src/agent-harness/task-ops.js +53 -0
  23. package/dist/src/index.js +3366 -16
  24. package/dist/src/pi-settings-materializer.d.ts +10 -0
  25. package/dist/src/pi-settings-materializer.js +52 -0
  26. package/dist/src/plugin.d.ts +9 -2
  27. package/dist/src/plugin.js +3360 -8
  28. package/dist/src/service.d.ts +1 -1
  29. package/dist/src/session-asset-materializer-service.d.ts +13 -0
  30. package/dist/src/session-asset-materializer-service.js +124 -0
  31. package/dist/src/skill-materializer.d.ts +25 -0
  32. package/dist/src/skill-materializer.js +46 -0
  33. package/dist/src/tooling/binary-build-worker.d.ts +1 -0
  34. package/dist/src/tooling/binary-build-worker.js +323 -0
  35. package/dist/src/tooling/browser-tool-entrypoint.d.ts +2 -0
  36. package/dist/src/tooling/browser-tool-entrypoint.js +125 -0
  37. package/dist/src/tooling/browser-tools.d.ts +3 -0
  38. package/dist/src/tooling/browser-tools.js +27 -0
  39. package/dist/src/tooling/claude-router-binary.d.ts +3 -0
  40. package/dist/src/tooling/claude-router-binary.js +381 -0
  41. package/dist/src/tooling/claude-router.d.ts +22 -0
  42. package/dist/src/tooling/claude-router.js +524 -0
  43. package/dist/src/tooling/embedded-native-assets.d.ts +7 -0
  44. package/dist/src/tooling/embedded-native-assets.js +6 -0
  45. package/dist/src/tooling/file-tools.d.ts +5 -0
  46. package/dist/src/tooling/file-tools.js +224 -0
  47. package/dist/src/tooling/gateway.d.ts +4 -0
  48. package/dist/src/tooling/gateway.js +430 -0
  49. package/dist/src/tooling/native-extract.d.ts +2 -0
  50. package/dist/src/tooling/native-extract.js +44 -0
  51. package/dist/src/tooling/runtime-binary-build.d.ts +88 -0
  52. package/dist/src/tooling/runtime-binary-build.js +480 -0
  53. package/dist/src/tooling/shell-tools.d.ts +5 -0
  54. package/dist/src/tooling/shell-tools.js +217 -0
  55. package/native/darwin-arm64/rig-shell +0 -0
  56. package/native/darwin-arm64/rig-shell.build-manifest.json +4 -0
  57. package/native/darwin-arm64/rig-tools +0 -0
  58. package/native/darwin-arm64/rig-tools.build-manifest.json +4 -0
  59. package/native/darwin-x64/rig-shell +0 -0
  60. package/native/darwin-x64/rig-tools +0 -0
  61. package/native/linux-arm64/rig-shell +0 -0
  62. package/native/linux-arm64/rig-tools +0 -0
  63. package/native/linux-x64/rig-shell +0 -0
  64. package/native/linux-x64/rig-tools +0 -0
  65. package/native/win32-x64/rig-shell.exe +0 -0
  66. package/native/win32-x64/rig-tools.exe +0 -0
  67. package/package.json +54 -5
  68. package/dist/src/claude-stream-records.d.ts +0 -24
  69. package/dist/src/claude-stream-records.js +0 -158
  70. package/dist/src/codex-app-server.d.ts +0 -16
  71. package/dist/src/codex-app-server.js +0 -548
  72. package/dist/src/codex-exec-records.d.ts +0 -27
  73. package/dist/src/codex-exec-records.js +0 -203
@@ -0,0 +1,224 @@
1
+ // @bun
2
+ // packages/provider-plugin/src/tooling/file-tools.ts
3
+ import { chmodSync, copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, rmSync, symlinkSync } from "fs";
4
+ import { tmpdir as tmpdir2 } from "os";
5
+ import { basename, dirname, resolve as resolve2 } from "path";
6
+ import { RUNTIME_FILE_TOOL_NAMES } from "@rig/contracts";
7
+
8
+ // packages/provider-plugin/src/tooling/native-extract.ts
9
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "fs";
10
+ import { tmpdir } from "os";
11
+ import { resolve } from "path";
12
+
13
+ // packages/provider-plugin/src/tooling/embedded-native-assets.ts
14
+ var embeddedNatives = null;
15
+
16
+ // packages/provider-plugin/src/tooling/native-extract.ts
17
+ var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
18
+ var extractionCache = {};
19
+ function extractEmbeddedNative(name) {
20
+ if (name in extractionCache) {
21
+ return extractionCache[name] ?? null;
22
+ }
23
+ const entry = embeddedNatives?.[name];
24
+ if (!entry) {
25
+ extractionCache[name] = null;
26
+ return null;
27
+ }
28
+ try {
29
+ const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
30
+ mkdirSync(sharedNativeOutputDir, { recursive: true });
31
+ const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
32
+ if (!upToDate) {
33
+ const bytes = readFileSync(entry.filePath);
34
+ const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
35
+ writeFileSync(tempPath, bytes, { mode: 493 });
36
+ renameSync(tempPath, targetPath);
37
+ }
38
+ extractionCache[name] = targetPath;
39
+ } catch {
40
+ extractionCache[name] = null;
41
+ }
42
+ return extractionCache[name] ?? null;
43
+ }
44
+
45
+ // packages/provider-plugin/src/tooling/file-tools.ts
46
+ var sharedNativeToolsOutputDir = resolve2(tmpdir2(), "rig-native");
47
+ var sharedNativeToolsOutputPath = resolve2(sharedNativeToolsOutputDir, `rig-tools-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
48
+ function runtimeRigToolsFileName() {
49
+ return `rig-tools${process.platform === "win32" ? ".exe" : ""}`;
50
+ }
51
+ function runtimeFileToolNames() {
52
+ return [...RUNTIME_FILE_TOOL_NAMES];
53
+ }
54
+ async function ensureRigToolsBinaryPath(outputPath = sharedNativeToolsOutputPath) {
55
+ const explicitBin = process.env.RIG_NATIVE_TOOLS_BIN?.trim();
56
+ if (explicitBin && existsSync2(explicitBin)) {
57
+ return explicitBin;
58
+ }
59
+ const embedded = extractEmbeddedNative("rig-tools");
60
+ if (embedded) {
61
+ return embedded;
62
+ }
63
+ const sourcePath = resolveRigToolsSourcePath();
64
+ if (!sourcePath) {
65
+ const bundledBinary = resolveBundledRigToolsBinaryPath();
66
+ if (bundledBinary) {
67
+ return bundledBinary;
68
+ }
69
+ throw new Error("rig-tools.zig source file not found.");
70
+ }
71
+ const zigBinary = Bun.which("zig");
72
+ if (!zigBinary) {
73
+ throw new Error("zig is required to build native Rig file tools.");
74
+ }
75
+ mkdirSync2(dirname(outputPath), { recursive: true });
76
+ const sourceDigest = await sha256File(sourcePath);
77
+ const buildKey = JSON.stringify({
78
+ version: 1,
79
+ zigBinary,
80
+ platform: process.platform,
81
+ arch: process.arch,
82
+ sourcePath,
83
+ sourceDigest
84
+ });
85
+ const manifestPath = nativeBuildManifestPath(outputPath);
86
+ const needsBuild = !existsSync2(outputPath) || !await hasMatchingNativeBuildManifest(manifestPath, buildKey);
87
+ if (!needsBuild) {
88
+ return outputPath;
89
+ }
90
+ const build = Bun.spawn([
91
+ zigBinary,
92
+ "build-exe",
93
+ sourcePath,
94
+ "-O",
95
+ "ReleaseFast",
96
+ `-femit-bin=${outputPath}`
97
+ ], {
98
+ cwd: dirname(sourcePath),
99
+ stdout: "pipe",
100
+ stderr: "pipe"
101
+ });
102
+ const [exitCode, stdout, stderr] = await Promise.all([
103
+ build.exited,
104
+ new Response(build.stdout).text(),
105
+ new Response(build.stderr).text()
106
+ ]);
107
+ if (exitCode !== 0 || !existsSync2(outputPath)) {
108
+ const details = [stderr.trim(), stdout.trim()].filter(Boolean).join(`
109
+ `);
110
+ throw new Error(`Failed to build native Rig file tools: ${details || `zig exited with code ${exitCode}`}`);
111
+ }
112
+ await Bun.write(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
113
+ `);
114
+ return outputPath;
115
+ }
116
+ async function materializeRuntimeFileTools(targetDir) {
117
+ const sourcePath = await ensureRigToolsBinaryPath();
118
+ const targetPath = resolve2(targetDir, runtimeRigToolsFileName());
119
+ mkdirSync2(targetDir, { recursive: true });
120
+ const sourceDigest = await sha256File(sourcePath);
121
+ const buildKey = JSON.stringify({
122
+ version: 1,
123
+ sourcePath,
124
+ sourceDigest
125
+ });
126
+ const needsCopy = !existsSync2(targetPath) || !await hasMatchingNativeBuildManifest(nativeBuildManifestPath(targetPath), buildKey);
127
+ if (needsCopy) {
128
+ copyFileSync(sourcePath, targetPath);
129
+ chmodSync(targetPath, 493);
130
+ await Bun.write(nativeBuildManifestPath(targetPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
131
+ `);
132
+ }
133
+ for (const tool of runtimeFileToolNames()) {
134
+ const toolPath = resolve2(targetDir, tool);
135
+ if (existsSync2(toolPath)) {
136
+ rmSync(toolPath, { force: true, recursive: true });
137
+ }
138
+ symlinkSync(targetPath, toolPath);
139
+ }
140
+ return targetPath;
141
+ }
142
+ function resolveRigToolsSourcePath() {
143
+ for (const candidate of rigToolsSourceCandidates()) {
144
+ if (candidate && existsSync2(candidate)) {
145
+ return candidate;
146
+ }
147
+ }
148
+ return null;
149
+ }
150
+ function resolveBundledRigToolsBinaryPath() {
151
+ for (const candidate of rigToolsBinaryCandidates()) {
152
+ if (candidate && existsSync2(candidate)) {
153
+ return candidate;
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+ function rigToolsSourceCandidates() {
159
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
160
+ const cwd = process.cwd()?.trim() || "";
161
+ const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
162
+ const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
163
+ return [...new Set([
164
+ process.env.RIG_NATIVE_TOOLS_SOURCE?.trim() || "",
165
+ cwd ? resolve2(cwd, "packages/provider-plugin/native/rig-tools.zig") : "",
166
+ projectRoot ? resolve2(projectRoot, "packages/provider-plugin/native/rig-tools.zig") : "",
167
+ hostProjectRoot ? resolve2(hostProjectRoot, "packages/provider-plugin/native/rig-tools.zig") : "",
168
+ execDir ? resolve2(execDir, "..", "..", "packages/provider-plugin/native/rig-tools.zig") : "",
169
+ execDir ? resolve2(execDir, "..", "native", "rig-tools.zig") : "",
170
+ resolve2(import.meta.dir, "../../native/rig-tools.zig")
171
+ ].filter(Boolean))];
172
+ }
173
+ function nativePackageBinaryCandidates(fromDir, fileName) {
174
+ const candidates = [];
175
+ let cursor = resolve2(fromDir);
176
+ for (let index = 0;index < 8; index += 1) {
177
+ candidates.push(resolve2(cursor, "native", `${process.platform}-${process.arch}`, fileName), resolve2(cursor, "native", `${process.platform}-${process.arch}`, "bin", fileName), resolve2(cursor, "native", fileName), resolve2(cursor, "native", "bin", fileName));
178
+ const parent = dirname(cursor);
179
+ if (parent === cursor)
180
+ break;
181
+ cursor = parent;
182
+ }
183
+ return candidates;
184
+ }
185
+ function rigToolsBinaryCandidates() {
186
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
187
+ const fileName = runtimeRigToolsFileName();
188
+ return [...new Set([
189
+ process.env.RIG_NATIVE_TOOLS_BIN?.trim() || "",
190
+ ...nativePackageBinaryCandidates(import.meta.dir, fileName),
191
+ execDir ? resolve2(execDir, fileName) : "",
192
+ execDir ? resolve2(execDir, "..", fileName) : "",
193
+ execDir ? resolve2(execDir, "..", "bin", fileName) : ""
194
+ ].filter(Boolean))];
195
+ }
196
+ function runtimeFileToolBasename(path) {
197
+ return basename(path);
198
+ }
199
+ function nativeBuildManifestPath(outputPath) {
200
+ return `${outputPath}.build-manifest.json`;
201
+ }
202
+ async function hasMatchingNativeBuildManifest(manifestPath, buildKey) {
203
+ if (!existsSync2(manifestPath)) {
204
+ return false;
205
+ }
206
+ try {
207
+ const manifest = await Bun.file(manifestPath).json();
208
+ return manifest.version === 1 && manifest.buildKey === buildKey;
209
+ } catch {
210
+ return false;
211
+ }
212
+ }
213
+ async function sha256File(path) {
214
+ const hasher = new Bun.CryptoHasher("sha256");
215
+ hasher.update(await Bun.file(path).arrayBuffer());
216
+ return hasher.digest("hex");
217
+ }
218
+ export {
219
+ runtimeRigToolsFileName,
220
+ runtimeFileToolNames,
221
+ runtimeFileToolBasename,
222
+ materializeRuntimeFileTools,
223
+ ensureRigToolsBinaryPath
224
+ };
@@ -0,0 +1,4 @@
1
+ export declare function runtimeGatewayToolNames(): string[];
2
+ export { materializeRuntimeBrowserTools, runtimeBrowserToolNames, } from "./browser-tools";
3
+ export { materializeRuntimeFileTools, runtimeFileToolNames, } from "./file-tools";
4
+ export declare function materializeRuntimeToolGateway(binDir: string): Promise<string>;
@@ -0,0 +1,430 @@
1
+ // @bun
2
+ // packages/provider-plugin/src/tooling/gateway.ts
3
+ import { existsSync as existsSync5, rmSync as rmSync3, symlinkSync as symlinkSync3 } from "fs";
4
+ import { resolve as resolve5 } from "path";
5
+ import { RUNTIME_SHELL_TOOL_NAMES as RUNTIME_SHELL_TOOL_NAMES2 } from "@rig/contracts";
6
+
7
+ // packages/provider-plugin/src/tooling/shell-tools.ts
8
+ import { chmodSync, copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
9
+ import { tmpdir as tmpdir2 } from "os";
10
+ import { basename, dirname, resolve as resolve2 } from "path";
11
+ import { RUNTIME_SHELL_TOOL_NAMES } from "@rig/contracts";
12
+
13
+ // packages/provider-plugin/src/tooling/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/provider-plugin/src/tooling/embedded-native-assets.ts
19
+ var embeddedNatives = null;
20
+
21
+ // packages/provider-plugin/src/tooling/native-extract.ts
22
+ var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
23
+ var extractionCache = {};
24
+ function extractEmbeddedNative(name) {
25
+ if (name in extractionCache) {
26
+ return extractionCache[name] ?? null;
27
+ }
28
+ const entry = embeddedNatives?.[name];
29
+ if (!entry) {
30
+ extractionCache[name] = null;
31
+ return null;
32
+ }
33
+ try {
34
+ const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
35
+ mkdirSync(sharedNativeOutputDir, { recursive: true });
36
+ const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
37
+ if (!upToDate) {
38
+ const bytes = readFileSync(entry.filePath);
39
+ const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
40
+ writeFileSync(tempPath, bytes, { mode: 493 });
41
+ renameSync(tempPath, targetPath);
42
+ }
43
+ extractionCache[name] = targetPath;
44
+ } catch {
45
+ extractionCache[name] = null;
46
+ }
47
+ return extractionCache[name] ?? null;
48
+ }
49
+
50
+ // packages/provider-plugin/src/tooling/shell-tools.ts
51
+ var sharedNativeShellOutputDir = resolve2(tmpdir2(), "rig-native");
52
+ var sharedNativeShellOutputPath = resolve2(sharedNativeShellOutputDir, `rig-shell-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
53
+ function runtimeRigShellFileName() {
54
+ return `rig-shell${process.platform === "win32" ? ".exe" : ""}`;
55
+ }
56
+ async function ensureRigShellBinaryPath(outputPath = sharedNativeShellOutputPath) {
57
+ const explicitBin = process.env.RIG_NATIVE_SHELL_BIN?.trim();
58
+ if (explicitBin && existsSync2(explicitBin)) {
59
+ return explicitBin;
60
+ }
61
+ const embedded = extractEmbeddedNative("rig-shell");
62
+ if (embedded) {
63
+ return embedded;
64
+ }
65
+ const sourcePath = resolveRigShellSourcePath();
66
+ if (!sourcePath) {
67
+ const bundledBinary = resolveBundledRigShellBinaryPath();
68
+ if (bundledBinary) {
69
+ return bundledBinary;
70
+ }
71
+ throw new Error("rig-shell.zig source file not found.");
72
+ }
73
+ const zigBinary = Bun.which("zig");
74
+ if (!zigBinary) {
75
+ throw new Error("zig is required to build the native Rig shell.");
76
+ }
77
+ mkdirSync2(dirname(outputPath), { recursive: true });
78
+ const sourceDigest = await sha256File(sourcePath);
79
+ const buildKey = JSON.stringify({
80
+ version: 1,
81
+ zigBinary,
82
+ platform: process.platform,
83
+ arch: process.arch,
84
+ sourcePath,
85
+ sourceDigest
86
+ });
87
+ const manifestPath = nativeBuildManifestPath(outputPath);
88
+ const needsBuild = !existsSync2(outputPath) || !await hasMatchingNativeBuildManifest(manifestPath, buildKey);
89
+ if (!needsBuild) {
90
+ return outputPath;
91
+ }
92
+ const build = Bun.spawn([
93
+ zigBinary,
94
+ "build-exe",
95
+ sourcePath,
96
+ "-O",
97
+ "ReleaseFast",
98
+ `-femit-bin=${outputPath}`
99
+ ], {
100
+ cwd: dirname(sourcePath),
101
+ stdout: "pipe",
102
+ stderr: "pipe"
103
+ });
104
+ const [exitCode, stdout, stderr] = await Promise.all([
105
+ build.exited,
106
+ new Response(build.stdout).text(),
107
+ new Response(build.stderr).text()
108
+ ]);
109
+ if (exitCode !== 0 || !existsSync2(outputPath)) {
110
+ const details = [stderr.trim(), stdout.trim()].filter(Boolean).join(`
111
+ `);
112
+ throw new Error(`Failed to build native Rig shell: ${details || `zig exited with code ${exitCode}`}`);
113
+ }
114
+ await Bun.write(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
115
+ `);
116
+ return outputPath;
117
+ }
118
+ async function materializeRigShellBinary(targetDir) {
119
+ const sourcePath = await ensureRigShellBinaryPath();
120
+ const targetPath = resolve2(targetDir, runtimeRigShellFileName());
121
+ mkdirSync2(targetDir, { recursive: true });
122
+ const sourceDigest = await sha256File(sourcePath);
123
+ const buildKey = JSON.stringify({
124
+ version: 1,
125
+ sourcePath,
126
+ sourceDigest
127
+ });
128
+ const needsCopy = !existsSync2(targetPath) || !await hasMatchingNativeBuildManifest(nativeBuildManifestPath(targetPath), buildKey);
129
+ if (needsCopy) {
130
+ copyFileSync(sourcePath, targetPath);
131
+ chmodSync(targetPath, 493);
132
+ await Bun.write(nativeBuildManifestPath(targetPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
133
+ `);
134
+ }
135
+ return targetPath;
136
+ }
137
+ function resolveRigShellSourcePath() {
138
+ for (const candidate of rigShellSourceCandidates()) {
139
+ if (candidate && existsSync2(candidate)) {
140
+ return candidate;
141
+ }
142
+ }
143
+ return null;
144
+ }
145
+ function resolveBundledRigShellBinaryPath() {
146
+ for (const candidate of rigShellBinaryCandidates()) {
147
+ if (candidate && existsSync2(candidate)) {
148
+ return candidate;
149
+ }
150
+ }
151
+ return null;
152
+ }
153
+ function rigShellSourceCandidates() {
154
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
155
+ const cwd = process.cwd()?.trim() || "";
156
+ const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
157
+ const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
158
+ return [...new Set([
159
+ process.env.RIG_NATIVE_SHELL_SOURCE?.trim() || "",
160
+ cwd ? resolve2(cwd, "packages/provider-plugin/native/rig-shell.zig") : "",
161
+ projectRoot ? resolve2(projectRoot, "packages/provider-plugin/native/rig-shell.zig") : "",
162
+ hostProjectRoot ? resolve2(hostProjectRoot, "packages/provider-plugin/native/rig-shell.zig") : "",
163
+ execDir ? resolve2(execDir, "..", "..", "packages/provider-plugin/native/rig-shell.zig") : "",
164
+ execDir ? resolve2(execDir, "..", "native", "rig-shell.zig") : "",
165
+ resolve2(import.meta.dir, "../../native/rig-shell.zig")
166
+ ].filter(Boolean))];
167
+ }
168
+ function nativePackageBinaryCandidates(fromDir, fileName) {
169
+ const candidates = [];
170
+ let cursor = resolve2(fromDir);
171
+ for (let index = 0;index < 8; index += 1) {
172
+ candidates.push(resolve2(cursor, "native", `${process.platform}-${process.arch}`, fileName), resolve2(cursor, "native", `${process.platform}-${process.arch}`, "bin", fileName), resolve2(cursor, "native", fileName), resolve2(cursor, "native", "bin", fileName));
173
+ const parent = dirname(cursor);
174
+ if (parent === cursor)
175
+ break;
176
+ cursor = parent;
177
+ }
178
+ return candidates;
179
+ }
180
+ function rigShellBinaryCandidates() {
181
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
182
+ const fileName = runtimeRigShellFileName();
183
+ return [...new Set([
184
+ process.env.RIG_NATIVE_SHELL_BIN?.trim() || "",
185
+ ...nativePackageBinaryCandidates(import.meta.dir, fileName),
186
+ execDir ? resolve2(execDir, fileName) : "",
187
+ execDir ? resolve2(execDir, "..", fileName) : "",
188
+ execDir ? resolve2(execDir, "..", "bin", fileName) : ""
189
+ ].filter(Boolean))];
190
+ }
191
+ function nativeBuildManifestPath(outputPath) {
192
+ return `${outputPath}.build-manifest.json`;
193
+ }
194
+ async function hasMatchingNativeBuildManifest(manifestPath, buildKey) {
195
+ if (!existsSync2(manifestPath)) {
196
+ return false;
197
+ }
198
+ try {
199
+ const manifest = await Bun.file(manifestPath).json();
200
+ return manifest.version === 1 && manifest.buildKey === buildKey;
201
+ } catch {
202
+ return false;
203
+ }
204
+ }
205
+ async function sha256File(path) {
206
+ const hasher = new Bun.CryptoHasher("sha256");
207
+ hasher.update(await Bun.file(path).arrayBuffer());
208
+ return hasher.digest("hex");
209
+ }
210
+
211
+ // packages/provider-plugin/src/tooling/browser-tools.ts
212
+ import { existsSync as existsSync3, rmSync, symlinkSync } from "fs";
213
+ import { resolve as resolve3 } from "path";
214
+ import { RUNTIME_BROWSER_TOOL_NAMES } from "@rig/contracts";
215
+ function runtimeBrowserToolBinaryName() {
216
+ return `rig-browser-tool${process.platform === "win32" ? ".exe" : ""}`;
217
+ }
218
+ function runtimeBrowserToolNames() {
219
+ return [...RUNTIME_BROWSER_TOOL_NAMES];
220
+ }
221
+ async function materializeRuntimeBrowserTools(targetDir) {
222
+ const binaryPath = resolve3(targetDir, runtimeBrowserToolBinaryName());
223
+ for (const tool of runtimeBrowserToolNames()) {
224
+ const toolPath = resolve3(targetDir, tool);
225
+ if (existsSync3(toolPath)) {
226
+ rmSync(toolPath, { force: true, recursive: true });
227
+ }
228
+ symlinkSync(binaryPath, toolPath);
229
+ }
230
+ return binaryPath;
231
+ }
232
+ // packages/provider-plugin/src/tooling/file-tools.ts
233
+ import { chmodSync as chmodSync2, copyFileSync as copyFileSync2, existsSync as existsSync4, mkdirSync as mkdirSync3, rmSync as rmSync2, symlinkSync as symlinkSync2 } from "fs";
234
+ import { tmpdir as tmpdir3 } from "os";
235
+ import { basename as basename2, dirname as dirname2, resolve as resolve4 } from "path";
236
+ import { RUNTIME_FILE_TOOL_NAMES } from "@rig/contracts";
237
+ var sharedNativeToolsOutputDir = resolve4(tmpdir3(), "rig-native");
238
+ var sharedNativeToolsOutputPath = resolve4(sharedNativeToolsOutputDir, `rig-tools-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
239
+ function runtimeRigToolsFileName() {
240
+ return `rig-tools${process.platform === "win32" ? ".exe" : ""}`;
241
+ }
242
+ function runtimeFileToolNames() {
243
+ return [...RUNTIME_FILE_TOOL_NAMES];
244
+ }
245
+ async function ensureRigToolsBinaryPath(outputPath = sharedNativeToolsOutputPath) {
246
+ const explicitBin = process.env.RIG_NATIVE_TOOLS_BIN?.trim();
247
+ if (explicitBin && existsSync4(explicitBin)) {
248
+ return explicitBin;
249
+ }
250
+ const embedded = extractEmbeddedNative("rig-tools");
251
+ if (embedded) {
252
+ return embedded;
253
+ }
254
+ const sourcePath = resolveRigToolsSourcePath();
255
+ if (!sourcePath) {
256
+ const bundledBinary = resolveBundledRigToolsBinaryPath();
257
+ if (bundledBinary) {
258
+ return bundledBinary;
259
+ }
260
+ throw new Error("rig-tools.zig source file not found.");
261
+ }
262
+ const zigBinary = Bun.which("zig");
263
+ if (!zigBinary) {
264
+ throw new Error("zig is required to build native Rig file tools.");
265
+ }
266
+ mkdirSync3(dirname2(outputPath), { recursive: true });
267
+ const sourceDigest = await sha256File2(sourcePath);
268
+ const buildKey = JSON.stringify({
269
+ version: 1,
270
+ zigBinary,
271
+ platform: process.platform,
272
+ arch: process.arch,
273
+ sourcePath,
274
+ sourceDigest
275
+ });
276
+ const manifestPath = nativeBuildManifestPath2(outputPath);
277
+ const needsBuild = !existsSync4(outputPath) || !await hasMatchingNativeBuildManifest2(manifestPath, buildKey);
278
+ if (!needsBuild) {
279
+ return outputPath;
280
+ }
281
+ const build = Bun.spawn([
282
+ zigBinary,
283
+ "build-exe",
284
+ sourcePath,
285
+ "-O",
286
+ "ReleaseFast",
287
+ `-femit-bin=${outputPath}`
288
+ ], {
289
+ cwd: dirname2(sourcePath),
290
+ stdout: "pipe",
291
+ stderr: "pipe"
292
+ });
293
+ const [exitCode, stdout, stderr] = await Promise.all([
294
+ build.exited,
295
+ new Response(build.stdout).text(),
296
+ new Response(build.stderr).text()
297
+ ]);
298
+ if (exitCode !== 0 || !existsSync4(outputPath)) {
299
+ const details = [stderr.trim(), stdout.trim()].filter(Boolean).join(`
300
+ `);
301
+ throw new Error(`Failed to build native Rig file tools: ${details || `zig exited with code ${exitCode}`}`);
302
+ }
303
+ await Bun.write(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
304
+ `);
305
+ return outputPath;
306
+ }
307
+ async function materializeRuntimeFileTools(targetDir) {
308
+ const sourcePath = await ensureRigToolsBinaryPath();
309
+ const targetPath = resolve4(targetDir, runtimeRigToolsFileName());
310
+ mkdirSync3(targetDir, { recursive: true });
311
+ const sourceDigest = await sha256File2(sourcePath);
312
+ const buildKey = JSON.stringify({
313
+ version: 1,
314
+ sourcePath,
315
+ sourceDigest
316
+ });
317
+ const needsCopy = !existsSync4(targetPath) || !await hasMatchingNativeBuildManifest2(nativeBuildManifestPath2(targetPath), buildKey);
318
+ if (needsCopy) {
319
+ copyFileSync2(sourcePath, targetPath);
320
+ chmodSync2(targetPath, 493);
321
+ await Bun.write(nativeBuildManifestPath2(targetPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
322
+ `);
323
+ }
324
+ for (const tool of runtimeFileToolNames()) {
325
+ const toolPath = resolve4(targetDir, tool);
326
+ if (existsSync4(toolPath)) {
327
+ rmSync2(toolPath, { force: true, recursive: true });
328
+ }
329
+ symlinkSync2(targetPath, toolPath);
330
+ }
331
+ return targetPath;
332
+ }
333
+ function resolveRigToolsSourcePath() {
334
+ for (const candidate of rigToolsSourceCandidates()) {
335
+ if (candidate && existsSync4(candidate)) {
336
+ return candidate;
337
+ }
338
+ }
339
+ return null;
340
+ }
341
+ function resolveBundledRigToolsBinaryPath() {
342
+ for (const candidate of rigToolsBinaryCandidates()) {
343
+ if (candidate && existsSync4(candidate)) {
344
+ return candidate;
345
+ }
346
+ }
347
+ return null;
348
+ }
349
+ function rigToolsSourceCandidates() {
350
+ const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
351
+ const cwd = process.cwd()?.trim() || "";
352
+ const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
353
+ const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
354
+ return [...new Set([
355
+ process.env.RIG_NATIVE_TOOLS_SOURCE?.trim() || "",
356
+ cwd ? resolve4(cwd, "packages/provider-plugin/native/rig-tools.zig") : "",
357
+ projectRoot ? resolve4(projectRoot, "packages/provider-plugin/native/rig-tools.zig") : "",
358
+ hostProjectRoot ? resolve4(hostProjectRoot, "packages/provider-plugin/native/rig-tools.zig") : "",
359
+ execDir ? resolve4(execDir, "..", "..", "packages/provider-plugin/native/rig-tools.zig") : "",
360
+ execDir ? resolve4(execDir, "..", "native", "rig-tools.zig") : "",
361
+ resolve4(import.meta.dir, "../../native/rig-tools.zig")
362
+ ].filter(Boolean))];
363
+ }
364
+ function nativePackageBinaryCandidates2(fromDir, fileName) {
365
+ const candidates = [];
366
+ let cursor = resolve4(fromDir);
367
+ for (let index = 0;index < 8; index += 1) {
368
+ candidates.push(resolve4(cursor, "native", `${process.platform}-${process.arch}`, fileName), resolve4(cursor, "native", `${process.platform}-${process.arch}`, "bin", fileName), resolve4(cursor, "native", fileName), resolve4(cursor, "native", "bin", fileName));
369
+ const parent = dirname2(cursor);
370
+ if (parent === cursor)
371
+ break;
372
+ cursor = parent;
373
+ }
374
+ return candidates;
375
+ }
376
+ function rigToolsBinaryCandidates() {
377
+ const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
378
+ const fileName = runtimeRigToolsFileName();
379
+ return [...new Set([
380
+ process.env.RIG_NATIVE_TOOLS_BIN?.trim() || "",
381
+ ...nativePackageBinaryCandidates2(import.meta.dir, fileName),
382
+ execDir ? resolve4(execDir, fileName) : "",
383
+ execDir ? resolve4(execDir, "..", fileName) : "",
384
+ execDir ? resolve4(execDir, "..", "bin", fileName) : ""
385
+ ].filter(Boolean))];
386
+ }
387
+ function nativeBuildManifestPath2(outputPath) {
388
+ return `${outputPath}.build-manifest.json`;
389
+ }
390
+ async function hasMatchingNativeBuildManifest2(manifestPath, buildKey) {
391
+ if (!existsSync4(manifestPath)) {
392
+ return false;
393
+ }
394
+ try {
395
+ const manifest = await Bun.file(manifestPath).json();
396
+ return manifest.version === 1 && manifest.buildKey === buildKey;
397
+ } catch {
398
+ return false;
399
+ }
400
+ }
401
+ async function sha256File2(path) {
402
+ const hasher = new Bun.CryptoHasher("sha256");
403
+ hasher.update(await Bun.file(path).arrayBuffer());
404
+ return hasher.digest("hex");
405
+ }
406
+
407
+ // packages/provider-plugin/src/tooling/gateway.ts
408
+ function runtimeGatewayToolNames() {
409
+ return [...RUNTIME_SHELL_TOOL_NAMES2];
410
+ }
411
+ async function materializeRuntimeToolGateway(binDir) {
412
+ const shellPath = await materializeRigShellBinary(binDir);
413
+ for (const tool of runtimeGatewayToolNames()) {
414
+ const toolPath = resolve5(binDir, tool);
415
+ if (existsSync5(toolPath)) {
416
+ rmSync3(toolPath, { force: true, recursive: true });
417
+ }
418
+ symlinkSync3(shellPath, toolPath);
419
+ }
420
+ await materializeRuntimeBrowserTools(binDir);
421
+ return resolve5(binDir, runtimeRigShellFileName());
422
+ }
423
+ export {
424
+ runtimeGatewayToolNames,
425
+ runtimeFileToolNames,
426
+ runtimeBrowserToolNames,
427
+ materializeRuntimeToolGateway,
428
+ materializeRuntimeFileTools,
429
+ materializeRuntimeBrowserTools
430
+ };
@@ -0,0 +1,2 @@
1
+ export declare function hasEmbeddedNatives(): boolean;
2
+ export declare function extractEmbeddedNative(name: string): string | null;