@h-rig/runtime 0.0.6-alpha.0
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/README.md +27 -0
- package/dist/bin/rig-agent-dispatch.js +9615 -0
- package/dist/bin/rig-agent.js +9512 -0
- package/dist/bin/rig-browser-tool.js +269 -0
- package/dist/src/agent-mode.js +48 -0
- package/dist/src/baked-secrets.js +121 -0
- package/dist/src/binary-build-worker.js +312 -0
- package/dist/src/binary-run.js +540 -0
- package/dist/src/boundaries.js +1 -0
- package/dist/src/build-time-config.js +25 -0
- package/dist/src/control-plane/agent-roles.js +27 -0
- package/dist/src/control-plane/agent-wrapper.js +9621 -0
- package/dist/src/control-plane/authority-files.js +582 -0
- package/dist/src/control-plane/browser-contract.js +135 -0
- package/dist/src/control-plane/controlled-bash.js +1111 -0
- package/dist/src/control-plane/errors.js +13 -0
- package/dist/src/control-plane/harness-main.js +10828 -0
- package/dist/src/control-plane/hook-materializer.js +75 -0
- package/dist/src/control-plane/hooks/audit-trail.js +353 -0
- package/dist/src/control-plane/hooks/completion-verification.js +7552 -0
- package/dist/src/control-plane/hooks/import-guard.js +890 -0
- package/dist/src/control-plane/hooks/inject-context.js +4189 -0
- package/dist/src/control-plane/hooks/post-edit-lint.js +43 -0
- package/dist/src/control-plane/hooks/safety-guard.js +910 -0
- package/dist/src/control-plane/hooks/scope-guard.js +907 -0
- package/dist/src/control-plane/hooks/shared.js +44 -0
- package/dist/src/control-plane/hooks/submodule-branch.js +7797 -0
- package/dist/src/control-plane/hooks/task-runtime-start.js +7799 -0
- package/dist/src/control-plane/hooks/test-integrity-guard.js +891 -0
- package/dist/src/control-plane/materialize-task-config.js +453 -0
- package/dist/src/control-plane/memory-sync/cli.js +2019 -0
- package/dist/src/control-plane/memory-sync/db.js +753 -0
- package/dist/src/control-plane/memory-sync/embed.js +281 -0
- package/dist/src/control-plane/memory-sync/index.js +2049 -0
- package/dist/src/control-plane/memory-sync/query.js +294 -0
- package/dist/src/control-plane/memory-sync/read.js +784 -0
- package/dist/src/control-plane/memory-sync/types.js +6 -0
- package/dist/src/control-plane/memory-sync/write.js +1547 -0
- package/dist/src/control-plane/native/git-native.js +490 -0
- package/dist/src/control-plane/native/git-ops.js +2860 -0
- package/dist/src/control-plane/native/harness-cli.js +9721 -0
- package/dist/src/control-plane/native/pr-automation.js +373 -0
- package/dist/src/control-plane/native/profile-ops.js +481 -0
- package/dist/src/control-plane/native/repo-ops.js +2342 -0
- package/dist/src/control-plane/native/root-resolver.js +66 -0
- package/dist/src/control-plane/native/run-ops.js +3281 -0
- package/dist/src/control-plane/native/runtime-native-sidecar.js +299 -0
- package/dist/src/control-plane/native/runtime-native.js +392 -0
- package/dist/src/control-plane/native/scope-rules.js +17 -0
- package/dist/src/control-plane/native/task-ops.js +6320 -0
- package/dist/src/control-plane/native/task-state.js +1512 -0
- package/dist/src/control-plane/native/utils.js +535 -0
- package/dist/src/control-plane/native/validator-binaries.js +889 -0
- package/dist/src/control-plane/native/validator.js +2197 -0
- package/dist/src/control-plane/native/verifier.js +3249 -0
- package/dist/src/control-plane/native/workspace-ops.js +1635 -0
- package/dist/src/control-plane/plugin-host-context.js +334 -0
- package/dist/src/control-plane/project-main-pre-run-sync.js +630 -0
- package/dist/src/control-plane/provider/claude-stream-records.js +158 -0
- package/dist/src/control-plane/provider/codex-app-server.js +885 -0
- package/dist/src/control-plane/provider/codex-exec-records.js +203 -0
- package/dist/src/control-plane/provider/rig-task-run-skill.js +39 -0
- package/dist/src/control-plane/provider/runtime-instructions.js +96 -0
- package/dist/src/control-plane/remote.js +854 -0
- package/dist/src/control-plane/repos/index.js +473 -0
- package/dist/src/control-plane/repos/layout.js +124 -0
- package/dist/src/control-plane/repos/mirror/bootstrap.js +268 -0
- package/dist/src/control-plane/repos/mirror/refresh.js +398 -0
- package/dist/src/control-plane/repos/mirror/state.js +167 -0
- package/dist/src/control-plane/repos/registry.js +77 -0
- package/dist/src/control-plane/repos/types.js +1 -0
- package/dist/src/control-plane/runtime/agent-mode.js +48 -0
- package/dist/src/control-plane/runtime/baked-secrets.js +120 -0
- package/dist/src/control-plane/runtime/claude-tool-router-binary.js +343 -0
- package/dist/src/control-plane/runtime/claude-tool-router.js +520 -0
- package/dist/src/control-plane/runtime/context.js +216 -0
- package/dist/src/control-plane/runtime/events.js +218 -0
- package/dist/src/control-plane/runtime/guard-types.js +6 -0
- package/dist/src/control-plane/runtime/guard.js +880 -0
- package/dist/src/control-plane/runtime/image/fingerprint-sidecar.js +1194 -0
- package/dist/src/control-plane/runtime/image/index.js +2255 -0
- package/dist/src/control-plane/runtime/image-fingerprint-sidecar.js +1191 -0
- package/dist/src/control-plane/runtime/image.js +2255 -0
- package/dist/src/control-plane/runtime/index.js +8511 -0
- package/dist/src/control-plane/runtime/isolation/discovery.js +599 -0
- package/dist/src/control-plane/runtime/isolation/home.js +1217 -0
- package/dist/src/control-plane/runtime/isolation/index.js +8193 -0
- package/dist/src/control-plane/runtime/isolation/runner.js +2651 -0
- package/dist/src/control-plane/runtime/isolation/shared.js +501 -0
- package/dist/src/control-plane/runtime/isolation/toolchain.js +1892 -0
- package/dist/src/control-plane/runtime/isolation/types.js +1 -0
- package/dist/src/control-plane/runtime/isolation/worktree.js +509 -0
- package/dist/src/control-plane/runtime/isolation.js +8193 -0
- package/dist/src/control-plane/runtime/overlay.js +67 -0
- package/dist/src/control-plane/runtime/plugin-mode.js +41 -0
- package/dist/src/control-plane/runtime/plugins.js +1131 -0
- package/dist/src/control-plane/runtime/provisioning-env.js +220 -0
- package/dist/src/control-plane/runtime/queue.js +8358 -0
- package/dist/src/control-plane/runtime/rig-shell.js +205 -0
- package/dist/src/control-plane/runtime/rig-tools.js +182 -0
- package/dist/src/control-plane/runtime/runner-context.js +1 -0
- package/dist/src/control-plane/runtime/runtime-paths.js +184 -0
- package/dist/src/control-plane/runtime/sandbox/backend-bwrap.js +311 -0
- package/dist/src/control-plane/runtime/sandbox/backend-none.js +21 -0
- package/dist/src/control-plane/runtime/sandbox/backend-seatbelt.js +268 -0
- package/dist/src/control-plane/runtime/sandbox/backend.js +1718 -0
- package/dist/src/control-plane/runtime/sandbox/orchestrator.js +1745 -0
- package/dist/src/control-plane/runtime/sandbox/utils.js +137 -0
- package/dist/src/control-plane/runtime/sandbox-backend-bwrap.js +311 -0
- package/dist/src/control-plane/runtime/sandbox-backend-none.js +21 -0
- package/dist/src/control-plane/runtime/sandbox-backend-seatbelt.js +268 -0
- package/dist/src/control-plane/runtime/sandbox-backend.js +1718 -0
- package/dist/src/control-plane/runtime/sandbox-orchestrator.js +1745 -0
- package/dist/src/control-plane/runtime/sandbox-utils.js +137 -0
- package/dist/src/control-plane/runtime/snapshot/index.js +454 -0
- package/dist/src/control-plane/runtime/snapshot/sidecar.js +502 -0
- package/dist/src/control-plane/runtime/snapshot/task-run.js +1578 -0
- package/dist/src/control-plane/runtime/snapshot-sidecar.js +498 -0
- package/dist/src/control-plane/runtime/snapshot.js +454 -0
- package/dist/src/control-plane/runtime/task-run-snapshot.js +1578 -0
- package/dist/src/control-plane/runtime/tool-gateway.js +422 -0
- package/dist/src/control-plane/runtime/tooling/browser-tools.js +32 -0
- package/dist/src/control-plane/runtime/tooling/claude-router-binary.js +343 -0
- package/dist/src/control-plane/runtime/tooling/claude-router.js +524 -0
- package/dist/src/control-plane/runtime/tooling/file-tools.js +182 -0
- package/dist/src/control-plane/runtime/tooling/gateway.js +422 -0
- package/dist/src/control-plane/runtime/tooling/index.js +1290 -0
- package/dist/src/control-plane/runtime/tooling/shell.js +205 -0
- package/dist/src/control-plane/runtime/types.js +1 -0
- package/dist/src/control-plane/setup-version.js +14 -0
- package/dist/src/control-plane/state-sync/index.js +1509 -0
- package/dist/src/control-plane/state-sync/read.js +856 -0
- package/dist/src/control-plane/state-sync/reconcile.js +260 -0
- package/dist/src/control-plane/state-sync/repo.js +302 -0
- package/dist/src/control-plane/state-sync/types.js +111 -0
- package/dist/src/control-plane/state-sync/write.js +1469 -0
- package/dist/src/control-plane/task-fields.js +38 -0
- package/dist/src/control-plane/task-source-bootstrap.js +46 -0
- package/dist/src/control-plane/task-source.js +30 -0
- package/dist/src/control-plane/tasks/legacy-task-config-source.js +130 -0
- package/dist/src/control-plane/tasks/plugin-task-source.js +103 -0
- package/dist/src/control-plane/tasks/source-aware-task-config-source.js +611 -0
- package/dist/src/control-plane/tasks/source-lifecycle.js +1093 -0
- package/dist/src/control-plane/tasks/task-record-reader.js +9 -0
- package/dist/src/control-plane/validators/boundary/public-apis.js +107 -0
- package/dist/src/control-plane/validators/integration/_shared.js +51 -0
- package/dist/src/control-plane/validators/integration/adm-audit-http.js +85 -0
- package/dist/src/control-plane/validators/integration/adm-auth-http.js +78 -0
- package/dist/src/control-plane/validators/integration/adm-issuer-http.js +80 -0
- package/dist/src/control-plane/validators/integration/adm-migration.js +78 -0
- package/dist/src/control-plane/validators/integration/adm-scaffold.js +78 -0
- package/dist/src/control-plane/validators/runtime-registration.js +64 -0
- package/dist/src/control-plane/validators/shared.js +683 -0
- package/dist/src/events.js +218 -0
- package/dist/src/execution.js +35 -0
- package/dist/src/index.js +1633 -0
- package/dist/src/layout.js +145 -0
- package/dist/src/local-server.js +202 -0
- package/dist/src/plugins.js +329 -0
- package/dist/src/remote-http.js +83 -0
- package/dist/src/runtime-context.js +216 -0
- package/dist/src/types.js +1 -0
- package/native/darwin-arm64/bin/rig-git +0 -0
- package/native/darwin-arm64/bin/rig-shell +0 -0
- package/native/darwin-arm64/bin/rig-tools +0 -0
- package/native/darwin-arm64/lib/runtime-native-darwin-arm64.dylib +0 -0
- package/native/darwin-arm64/lib/runtime-native.dylib +0 -0
- package/native/darwin-arm64/manifest.json +1 -0
- package/native/linux-x64/bin/rig-git +0 -0
- package/native/linux-x64/bin/rig-shell +0 -0
- package/native/linux-x64/bin/rig-tools +0 -0
- package/native/linux-x64/lib/runtime-native-linux-x64.so +0 -0
- package/native/linux-x64/lib/runtime-native.so +0 -0
- package/native/linux-x64/manifest.json +1 -0
- package/package.json +74 -0
- package/skills/rig-task-run.md +71 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/runtime/tooling/gateway.ts
|
|
3
|
+
import { existsSync as existsSync4, rmSync as rmSync3, symlinkSync as symlinkSync3 } from "fs";
|
|
4
|
+
import { resolve as resolve4 } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/runtime/src/control-plane/runtime/tooling/shell.ts
|
|
7
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync } from "fs";
|
|
8
|
+
import { tmpdir } from "os";
|
|
9
|
+
import { basename, dirname, resolve } from "path";
|
|
10
|
+
var sharedNativeShellOutputDir = resolve(tmpdir(), "rig-native");
|
|
11
|
+
var sharedNativeShellOutputPath = resolve(sharedNativeShellOutputDir, `rig-shell-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
12
|
+
function runtimeRigShellFileName() {
|
|
13
|
+
return `rig-shell${process.platform === "win32" ? ".exe" : ""}`;
|
|
14
|
+
}
|
|
15
|
+
async function ensureRigShellBinaryPath(outputPath = sharedNativeShellOutputPath) {
|
|
16
|
+
const sourcePath = resolveRigShellSourcePath();
|
|
17
|
+
if (!sourcePath) {
|
|
18
|
+
const bundledBinary = resolveBundledRigShellBinaryPath();
|
|
19
|
+
if (bundledBinary) {
|
|
20
|
+
return bundledBinary;
|
|
21
|
+
}
|
|
22
|
+
throw new Error("rig-shell.zig source file not found.");
|
|
23
|
+
}
|
|
24
|
+
const zigBinary = Bun.which("zig");
|
|
25
|
+
if (!zigBinary) {
|
|
26
|
+
throw new Error("zig is required to build the native Rig shell.");
|
|
27
|
+
}
|
|
28
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
29
|
+
const sourceDigest = await sha256File(sourcePath);
|
|
30
|
+
const buildKey = JSON.stringify({
|
|
31
|
+
version: 1,
|
|
32
|
+
zigBinary,
|
|
33
|
+
platform: process.platform,
|
|
34
|
+
arch: process.arch,
|
|
35
|
+
sourcePath,
|
|
36
|
+
sourceDigest
|
|
37
|
+
});
|
|
38
|
+
const manifestPath = nativeBuildManifestPath(outputPath);
|
|
39
|
+
const needsBuild = !existsSync(outputPath) || !await hasMatchingNativeBuildManifest(manifestPath, buildKey);
|
|
40
|
+
if (!needsBuild) {
|
|
41
|
+
return outputPath;
|
|
42
|
+
}
|
|
43
|
+
const build = Bun.spawn([
|
|
44
|
+
zigBinary,
|
|
45
|
+
"build-exe",
|
|
46
|
+
sourcePath,
|
|
47
|
+
"-O",
|
|
48
|
+
"ReleaseFast",
|
|
49
|
+
`-femit-bin=${outputPath}`
|
|
50
|
+
], {
|
|
51
|
+
cwd: dirname(sourcePath),
|
|
52
|
+
stdout: "pipe",
|
|
53
|
+
stderr: "pipe"
|
|
54
|
+
});
|
|
55
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
56
|
+
build.exited,
|
|
57
|
+
new Response(build.stdout).text(),
|
|
58
|
+
new Response(build.stderr).text()
|
|
59
|
+
]);
|
|
60
|
+
if (exitCode !== 0 || !existsSync(outputPath)) {
|
|
61
|
+
const details = [stderr.trim(), stdout.trim()].filter(Boolean).join(`
|
|
62
|
+
`);
|
|
63
|
+
throw new Error(`Failed to build native Rig shell: ${details || `zig exited with code ${exitCode}`}`);
|
|
64
|
+
}
|
|
65
|
+
await Bun.write(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
66
|
+
`);
|
|
67
|
+
return outputPath;
|
|
68
|
+
}
|
|
69
|
+
async function materializeRigShellBinary(targetDir) {
|
|
70
|
+
const sourcePath = await ensureRigShellBinaryPath();
|
|
71
|
+
const targetPath = resolve(targetDir, runtimeRigShellFileName());
|
|
72
|
+
mkdirSync(targetDir, { recursive: true });
|
|
73
|
+
const sourceDigest = await sha256File(sourcePath);
|
|
74
|
+
const buildKey = JSON.stringify({
|
|
75
|
+
version: 1,
|
|
76
|
+
sourcePath,
|
|
77
|
+
sourceDigest
|
|
78
|
+
});
|
|
79
|
+
const needsCopy = !existsSync(targetPath) || !await hasMatchingNativeBuildManifest(nativeBuildManifestPath(targetPath), buildKey);
|
|
80
|
+
if (needsCopy) {
|
|
81
|
+
copyFileSync(sourcePath, targetPath);
|
|
82
|
+
chmodSync(targetPath, 493);
|
|
83
|
+
await Bun.write(nativeBuildManifestPath(targetPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
84
|
+
`);
|
|
85
|
+
}
|
|
86
|
+
return targetPath;
|
|
87
|
+
}
|
|
88
|
+
function resolveRigShellSourcePath() {
|
|
89
|
+
for (const candidate of rigShellSourceCandidates()) {
|
|
90
|
+
if (candidate && existsSync(candidate)) {
|
|
91
|
+
return candidate;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function resolveBundledRigShellBinaryPath() {
|
|
97
|
+
for (const candidate of rigShellBinaryCandidates()) {
|
|
98
|
+
if (candidate && existsSync(candidate)) {
|
|
99
|
+
return candidate;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
function rigShellSourceCandidates() {
|
|
105
|
+
const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
|
|
106
|
+
const cwd = process.cwd()?.trim() || "";
|
|
107
|
+
const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
|
|
108
|
+
const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
|
|
109
|
+
return [...new Set([
|
|
110
|
+
process.env.RIG_NATIVE_SHELL_SOURCE?.trim() || "",
|
|
111
|
+
cwd ? resolve(cwd, "packages/runtime/native/rig-shell.zig") : "",
|
|
112
|
+
projectRoot ? resolve(projectRoot, "packages/runtime/native/rig-shell.zig") : "",
|
|
113
|
+
hostProjectRoot ? resolve(hostProjectRoot, "packages/runtime/native/rig-shell.zig") : "",
|
|
114
|
+
execDir ? resolve(execDir, "..", "..", "packages/runtime/native/rig-shell.zig") : "",
|
|
115
|
+
execDir ? resolve(execDir, "..", "native", "rig-shell.zig") : "",
|
|
116
|
+
resolve(import.meta.dir, "../../../../native/rig-shell.zig")
|
|
117
|
+
].filter(Boolean))];
|
|
118
|
+
}
|
|
119
|
+
function nativePackageBinaryCandidates(fromDir, fileName) {
|
|
120
|
+
const candidates = [];
|
|
121
|
+
let cursor = resolve(fromDir);
|
|
122
|
+
for (let index = 0;index < 8; index += 1) {
|
|
123
|
+
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));
|
|
124
|
+
const parent = dirname(cursor);
|
|
125
|
+
if (parent === cursor)
|
|
126
|
+
break;
|
|
127
|
+
cursor = parent;
|
|
128
|
+
}
|
|
129
|
+
return candidates;
|
|
130
|
+
}
|
|
131
|
+
function rigShellBinaryCandidates() {
|
|
132
|
+
const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
|
|
133
|
+
const fileName = runtimeRigShellFileName();
|
|
134
|
+
return [...new Set([
|
|
135
|
+
process.env.RIG_NATIVE_SHELL_BIN?.trim() || "",
|
|
136
|
+
...nativePackageBinaryCandidates(import.meta.dir, fileName),
|
|
137
|
+
execDir ? resolve(execDir, fileName) : "",
|
|
138
|
+
execDir ? resolve(execDir, "..", fileName) : "",
|
|
139
|
+
execDir ? resolve(execDir, "..", "bin", fileName) : ""
|
|
140
|
+
].filter(Boolean))];
|
|
141
|
+
}
|
|
142
|
+
function runtimeToolGatewayNames() {
|
|
143
|
+
return [
|
|
144
|
+
"bash",
|
|
145
|
+
"sh",
|
|
146
|
+
"zsh",
|
|
147
|
+
"git",
|
|
148
|
+
"bun",
|
|
149
|
+
"node",
|
|
150
|
+
"python3",
|
|
151
|
+
"rg",
|
|
152
|
+
"grep",
|
|
153
|
+
"sed",
|
|
154
|
+
"cat",
|
|
155
|
+
"ls",
|
|
156
|
+
"find",
|
|
157
|
+
"tsc",
|
|
158
|
+
"gh",
|
|
159
|
+
"mkdir",
|
|
160
|
+
"rm",
|
|
161
|
+
"mv",
|
|
162
|
+
"cp",
|
|
163
|
+
"touch",
|
|
164
|
+
"pwd",
|
|
165
|
+
"head",
|
|
166
|
+
"tail",
|
|
167
|
+
"wc",
|
|
168
|
+
"sort",
|
|
169
|
+
"uniq",
|
|
170
|
+
"awk",
|
|
171
|
+
"xargs",
|
|
172
|
+
"dirname",
|
|
173
|
+
"basename",
|
|
174
|
+
"realpath",
|
|
175
|
+
"env",
|
|
176
|
+
"jq",
|
|
177
|
+
"tee",
|
|
178
|
+
"which"
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
function nativeBuildManifestPath(outputPath) {
|
|
182
|
+
return `${outputPath}.build-manifest.json`;
|
|
183
|
+
}
|
|
184
|
+
async function hasMatchingNativeBuildManifest(manifestPath, buildKey) {
|
|
185
|
+
if (!existsSync(manifestPath)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const manifest = await Bun.file(manifestPath).json();
|
|
190
|
+
return manifest.version === 1 && manifest.buildKey === buildKey;
|
|
191
|
+
} catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function sha256File(path) {
|
|
196
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
197
|
+
hasher.update(await Bun.file(path).arrayBuffer());
|
|
198
|
+
return hasher.digest("hex");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// packages/runtime/src/control-plane/runtime/tooling/browser-tools.ts
|
|
202
|
+
import { existsSync as existsSync2, rmSync, symlinkSync } from "fs";
|
|
203
|
+
import { resolve as resolve2 } from "path";
|
|
204
|
+
function runtimeBrowserToolBinaryName() {
|
|
205
|
+
return `rig-browser-tool${process.platform === "win32" ? ".exe" : ""}`;
|
|
206
|
+
}
|
|
207
|
+
function runtimeBrowserToolNames() {
|
|
208
|
+
return [
|
|
209
|
+
"rig-browser-launch",
|
|
210
|
+
"rig-browser-check",
|
|
211
|
+
"rig-browser-attach-info",
|
|
212
|
+
"rig-browser-e2e",
|
|
213
|
+
"rig-browser-reset-profile"
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
async function materializeRuntimeBrowserTools(targetDir) {
|
|
217
|
+
const binaryPath = resolve2(targetDir, runtimeBrowserToolBinaryName());
|
|
218
|
+
for (const tool of runtimeBrowserToolNames()) {
|
|
219
|
+
const toolPath = resolve2(targetDir, tool);
|
|
220
|
+
if (existsSync2(toolPath)) {
|
|
221
|
+
rmSync(toolPath, { force: true, recursive: true });
|
|
222
|
+
}
|
|
223
|
+
symlinkSync(binaryPath, toolPath);
|
|
224
|
+
}
|
|
225
|
+
return binaryPath;
|
|
226
|
+
}
|
|
227
|
+
// packages/runtime/src/control-plane/runtime/tooling/file-tools.ts
|
|
228
|
+
import { chmodSync as chmodSync2, copyFileSync as copyFileSync2, existsSync as existsSync3, mkdirSync as mkdirSync2, rmSync as rmSync2, symlinkSync as symlinkSync2 } from "fs";
|
|
229
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
230
|
+
import { basename as basename2, dirname as dirname2, resolve as resolve3 } from "path";
|
|
231
|
+
var sharedNativeToolsOutputDir = resolve3(tmpdir2(), "rig-native");
|
|
232
|
+
var sharedNativeToolsOutputPath = resolve3(sharedNativeToolsOutputDir, `rig-tools-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
233
|
+
function runtimeRigToolsFileName() {
|
|
234
|
+
return `rig-tools${process.platform === "win32" ? ".exe" : ""}`;
|
|
235
|
+
}
|
|
236
|
+
function runtimeFileToolNames() {
|
|
237
|
+
return [
|
|
238
|
+
"rig-read",
|
|
239
|
+
"rig-write",
|
|
240
|
+
"rig-edit",
|
|
241
|
+
"rig-glob",
|
|
242
|
+
"rig-grep"
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
async function ensureRigToolsBinaryPath(outputPath = sharedNativeToolsOutputPath) {
|
|
246
|
+
const sourcePath = resolveRigToolsSourcePath();
|
|
247
|
+
if (!sourcePath) {
|
|
248
|
+
const bundledBinary = resolveBundledRigToolsBinaryPath();
|
|
249
|
+
if (bundledBinary) {
|
|
250
|
+
return bundledBinary;
|
|
251
|
+
}
|
|
252
|
+
throw new Error("rig-tools.zig source file not found.");
|
|
253
|
+
}
|
|
254
|
+
const zigBinary = Bun.which("zig");
|
|
255
|
+
if (!zigBinary) {
|
|
256
|
+
throw new Error("zig is required to build native Rig file tools.");
|
|
257
|
+
}
|
|
258
|
+
mkdirSync2(dirname2(outputPath), { recursive: true });
|
|
259
|
+
const sourceDigest = await sha256File2(sourcePath);
|
|
260
|
+
const buildKey = JSON.stringify({
|
|
261
|
+
version: 1,
|
|
262
|
+
zigBinary,
|
|
263
|
+
platform: process.platform,
|
|
264
|
+
arch: process.arch,
|
|
265
|
+
sourcePath,
|
|
266
|
+
sourceDigest
|
|
267
|
+
});
|
|
268
|
+
const manifestPath = nativeBuildManifestPath2(outputPath);
|
|
269
|
+
const needsBuild = !existsSync3(outputPath) || !await hasMatchingNativeBuildManifest2(manifestPath, buildKey);
|
|
270
|
+
if (!needsBuild) {
|
|
271
|
+
return outputPath;
|
|
272
|
+
}
|
|
273
|
+
const build = Bun.spawn([
|
|
274
|
+
zigBinary,
|
|
275
|
+
"build-exe",
|
|
276
|
+
sourcePath,
|
|
277
|
+
"-O",
|
|
278
|
+
"ReleaseFast",
|
|
279
|
+
`-femit-bin=${outputPath}`
|
|
280
|
+
], {
|
|
281
|
+
cwd: dirname2(sourcePath),
|
|
282
|
+
stdout: "pipe",
|
|
283
|
+
stderr: "pipe"
|
|
284
|
+
});
|
|
285
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
286
|
+
build.exited,
|
|
287
|
+
new Response(build.stdout).text(),
|
|
288
|
+
new Response(build.stderr).text()
|
|
289
|
+
]);
|
|
290
|
+
if (exitCode !== 0 || !existsSync3(outputPath)) {
|
|
291
|
+
const details = [stderr.trim(), stdout.trim()].filter(Boolean).join(`
|
|
292
|
+
`);
|
|
293
|
+
throw new Error(`Failed to build native Rig file tools: ${details || `zig exited with code ${exitCode}`}`);
|
|
294
|
+
}
|
|
295
|
+
await Bun.write(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
296
|
+
`);
|
|
297
|
+
return outputPath;
|
|
298
|
+
}
|
|
299
|
+
async function materializeRuntimeFileTools(targetDir) {
|
|
300
|
+
const sourcePath = await ensureRigToolsBinaryPath();
|
|
301
|
+
const targetPath = resolve3(targetDir, runtimeRigToolsFileName());
|
|
302
|
+
mkdirSync2(targetDir, { recursive: true });
|
|
303
|
+
const sourceDigest = await sha256File2(sourcePath);
|
|
304
|
+
const buildKey = JSON.stringify({
|
|
305
|
+
version: 1,
|
|
306
|
+
sourcePath,
|
|
307
|
+
sourceDigest
|
|
308
|
+
});
|
|
309
|
+
const needsCopy = !existsSync3(targetPath) || !await hasMatchingNativeBuildManifest2(nativeBuildManifestPath2(targetPath), buildKey);
|
|
310
|
+
if (needsCopy) {
|
|
311
|
+
copyFileSync2(sourcePath, targetPath);
|
|
312
|
+
chmodSync2(targetPath, 493);
|
|
313
|
+
await Bun.write(nativeBuildManifestPath2(targetPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
314
|
+
`);
|
|
315
|
+
}
|
|
316
|
+
for (const tool of runtimeFileToolNames()) {
|
|
317
|
+
const toolPath = resolve3(targetDir, tool);
|
|
318
|
+
if (existsSync3(toolPath)) {
|
|
319
|
+
rmSync2(toolPath, { force: true, recursive: true });
|
|
320
|
+
}
|
|
321
|
+
symlinkSync2(targetPath, toolPath);
|
|
322
|
+
}
|
|
323
|
+
return targetPath;
|
|
324
|
+
}
|
|
325
|
+
function resolveRigToolsSourcePath() {
|
|
326
|
+
for (const candidate of rigToolsSourceCandidates()) {
|
|
327
|
+
if (candidate && existsSync3(candidate)) {
|
|
328
|
+
return candidate;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
function resolveBundledRigToolsBinaryPath() {
|
|
334
|
+
for (const candidate of rigToolsBinaryCandidates()) {
|
|
335
|
+
if (candidate && existsSync3(candidate)) {
|
|
336
|
+
return candidate;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
function rigToolsSourceCandidates() {
|
|
342
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
343
|
+
const cwd = process.cwd()?.trim() || "";
|
|
344
|
+
const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
|
|
345
|
+
const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
|
|
346
|
+
return [...new Set([
|
|
347
|
+
process.env.RIG_NATIVE_TOOLS_SOURCE?.trim() || "",
|
|
348
|
+
cwd ? resolve3(cwd, "packages/runtime/native/rig-tools.zig") : "",
|
|
349
|
+
projectRoot ? resolve3(projectRoot, "packages/runtime/native/rig-tools.zig") : "",
|
|
350
|
+
hostProjectRoot ? resolve3(hostProjectRoot, "packages/runtime/native/rig-tools.zig") : "",
|
|
351
|
+
execDir ? resolve3(execDir, "..", "..", "packages/runtime/native/rig-tools.zig") : "",
|
|
352
|
+
execDir ? resolve3(execDir, "..", "native", "rig-tools.zig") : "",
|
|
353
|
+
resolve3(import.meta.dir, "../../../../native/rig-tools.zig")
|
|
354
|
+
].filter(Boolean))];
|
|
355
|
+
}
|
|
356
|
+
function nativePackageBinaryCandidates2(fromDir, fileName) {
|
|
357
|
+
const candidates = [];
|
|
358
|
+
let cursor = resolve3(fromDir);
|
|
359
|
+
for (let index = 0;index < 8; index += 1) {
|
|
360
|
+
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));
|
|
361
|
+
const parent = dirname2(cursor);
|
|
362
|
+
if (parent === cursor)
|
|
363
|
+
break;
|
|
364
|
+
cursor = parent;
|
|
365
|
+
}
|
|
366
|
+
return candidates;
|
|
367
|
+
}
|
|
368
|
+
function rigToolsBinaryCandidates() {
|
|
369
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
370
|
+
const fileName = runtimeRigToolsFileName();
|
|
371
|
+
return [...new Set([
|
|
372
|
+
process.env.RIG_NATIVE_TOOLS_BIN?.trim() || "",
|
|
373
|
+
...nativePackageBinaryCandidates2(import.meta.dir, fileName),
|
|
374
|
+
execDir ? resolve3(execDir, fileName) : "",
|
|
375
|
+
execDir ? resolve3(execDir, "..", fileName) : "",
|
|
376
|
+
execDir ? resolve3(execDir, "..", "bin", fileName) : ""
|
|
377
|
+
].filter(Boolean))];
|
|
378
|
+
}
|
|
379
|
+
function nativeBuildManifestPath2(outputPath) {
|
|
380
|
+
return `${outputPath}.build-manifest.json`;
|
|
381
|
+
}
|
|
382
|
+
async function hasMatchingNativeBuildManifest2(manifestPath, buildKey) {
|
|
383
|
+
if (!existsSync3(manifestPath)) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
const manifest = await Bun.file(manifestPath).json();
|
|
388
|
+
return manifest.version === 1 && manifest.buildKey === buildKey;
|
|
389
|
+
} catch {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async function sha256File2(path) {
|
|
394
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
395
|
+
hasher.update(await Bun.file(path).arrayBuffer());
|
|
396
|
+
return hasher.digest("hex");
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// packages/runtime/src/control-plane/runtime/tooling/gateway.ts
|
|
400
|
+
function runtimeGatewayToolNames() {
|
|
401
|
+
return runtimeToolGatewayNames();
|
|
402
|
+
}
|
|
403
|
+
async function materializeRuntimeToolGateway(binDir) {
|
|
404
|
+
const shellPath = await materializeRigShellBinary(binDir);
|
|
405
|
+
for (const tool of runtimeGatewayToolNames()) {
|
|
406
|
+
const toolPath = resolve4(binDir, tool);
|
|
407
|
+
if (existsSync4(toolPath)) {
|
|
408
|
+
rmSync3(toolPath, { force: true, recursive: true });
|
|
409
|
+
}
|
|
410
|
+
symlinkSync3(shellPath, toolPath);
|
|
411
|
+
}
|
|
412
|
+
await materializeRuntimeBrowserTools(binDir);
|
|
413
|
+
return resolve4(binDir, runtimeRigShellFileName());
|
|
414
|
+
}
|
|
415
|
+
export {
|
|
416
|
+
runtimeGatewayToolNames,
|
|
417
|
+
runtimeFileToolNames,
|
|
418
|
+
runtimeBrowserToolNames,
|
|
419
|
+
materializeRuntimeToolGateway,
|
|
420
|
+
materializeRuntimeFileTools,
|
|
421
|
+
materializeRuntimeBrowserTools
|
|
422
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/runtime/tooling/browser-tools.ts
|
|
3
|
+
import { existsSync, rmSync, symlinkSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
function runtimeBrowserToolBinaryName() {
|
|
6
|
+
return `rig-browser-tool${process.platform === "win32" ? ".exe" : ""}`;
|
|
7
|
+
}
|
|
8
|
+
function runtimeBrowserToolNames() {
|
|
9
|
+
return [
|
|
10
|
+
"rig-browser-launch",
|
|
11
|
+
"rig-browser-check",
|
|
12
|
+
"rig-browser-attach-info",
|
|
13
|
+
"rig-browser-e2e",
|
|
14
|
+
"rig-browser-reset-profile"
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
async function materializeRuntimeBrowserTools(targetDir) {
|
|
18
|
+
const binaryPath = resolve(targetDir, runtimeBrowserToolBinaryName());
|
|
19
|
+
for (const tool of runtimeBrowserToolNames()) {
|
|
20
|
+
const toolPath = resolve(targetDir, tool);
|
|
21
|
+
if (existsSync(toolPath)) {
|
|
22
|
+
rmSync(toolPath, { force: true, recursive: true });
|
|
23
|
+
}
|
|
24
|
+
symlinkSync(binaryPath, toolPath);
|
|
25
|
+
}
|
|
26
|
+
return binaryPath;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
runtimeBrowserToolNames,
|
|
30
|
+
runtimeBrowserToolBinaryName,
|
|
31
|
+
materializeRuntimeBrowserTools
|
|
32
|
+
};
|