@h-rig/harness-plugin 0.0.6-alpha.186

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