@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,343 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/runtime/tooling/claude-router-binary.ts
|
|
3
|
+
import { chmodSync as chmodSync2, copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, statSync } from "fs";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
6
|
+
|
|
7
|
+
// packages/runtime/src/binary-run.ts
|
|
8
|
+
import { chmodSync, cpSync, existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from "fs";
|
|
9
|
+
import { basename, dirname, resolve } from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import { drainMicrotasks, gcAndSweep } from "bun:jsc";
|
|
12
|
+
var runtimeBinaryBuildQueue = Promise.resolve();
|
|
13
|
+
async function buildRuntimeBinary(options) {
|
|
14
|
+
return runSerializedRuntimeBinaryBuild(async () => {
|
|
15
|
+
const resolved = resolveRuntimeBinaryBuildOptions(options);
|
|
16
|
+
runBestEffortBuildGc();
|
|
17
|
+
const manifestPath = runtimeBinaryCacheManifestPath(resolved.outputPath);
|
|
18
|
+
const buildKey = createRuntimeBinaryBuildKey({
|
|
19
|
+
entrypoint: resolved.entrypoint,
|
|
20
|
+
define: resolved.define,
|
|
21
|
+
env: resolved.env
|
|
22
|
+
});
|
|
23
|
+
if (await isRuntimeBinaryBuildFresh({ outputPath: resolved.outputPath, manifestPath, buildKey })) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (shouldUseRuntimeBinaryBuildWorker()) {
|
|
27
|
+
await buildRuntimeBinaryViaWorker(resolved);
|
|
28
|
+
} else {
|
|
29
|
+
await buildRuntimeBinaryInProcess(resolved, { manifestPath, buildKey });
|
|
30
|
+
}
|
|
31
|
+
runBestEffortBuildGc();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function buildRuntimeBinaryInProcess(options, manifest) {
|
|
35
|
+
const tempBuildDir = resolve(dirname(options.outputPath), `.bun-build-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
36
|
+
const tempOutputPath = resolve(tempBuildDir, basename(options.outputPath));
|
|
37
|
+
mkdirSync(tempBuildDir, { recursive: true });
|
|
38
|
+
await withTemporaryEnv({
|
|
39
|
+
...options.env,
|
|
40
|
+
...options.define ? { RIG_BUILD_CONFIG_JSON: JSON.stringify(options.define) } : {}
|
|
41
|
+
}, async () => withTemporaryCwd(tempBuildDir, async () => {
|
|
42
|
+
const buildResult = await Bun.build({
|
|
43
|
+
entrypoints: [options.entrypoint],
|
|
44
|
+
compile: {
|
|
45
|
+
target: currentCompileTarget(),
|
|
46
|
+
outfile: tempOutputPath
|
|
47
|
+
},
|
|
48
|
+
target: "bun",
|
|
49
|
+
format: "esm",
|
|
50
|
+
minify: true,
|
|
51
|
+
bytecode: true,
|
|
52
|
+
metafile: true,
|
|
53
|
+
define: options.define ? {
|
|
54
|
+
__RIG_BUILD_CONFIG__: JSON.stringify(options.define)
|
|
55
|
+
} : undefined
|
|
56
|
+
});
|
|
57
|
+
if (!buildResult.success) {
|
|
58
|
+
const details = buildResult.logs.map((log) => [log.message, log.position?.file ? `${log.position.file}:${log.position.line}:${log.position.column}` : ""].filter(Boolean).join(" ")).filter(Boolean).join(`
|
|
59
|
+
`);
|
|
60
|
+
throw new Error(`Failed to build ${options.entrypoint}: ${details || "Bun.build() returned errors"}`);
|
|
61
|
+
}
|
|
62
|
+
if (!existsSync(tempOutputPath)) {
|
|
63
|
+
const emitted = buildResult.outputs.map((output) => output.path).join(", ") || "(none)";
|
|
64
|
+
throw new Error(`Failed to build ${options.entrypoint}: Bun.build() did not emit ${tempOutputPath}. Emitted: ${emitted}`);
|
|
65
|
+
}
|
|
66
|
+
renameSync(tempOutputPath, options.outputPath);
|
|
67
|
+
chmodSync(options.outputPath, 493);
|
|
68
|
+
if (manifest) {
|
|
69
|
+
await writeRuntimeBinaryCacheManifest({
|
|
70
|
+
manifestPath: manifest.manifestPath,
|
|
71
|
+
buildKey: manifest.buildKey,
|
|
72
|
+
cwd: tempBuildDir,
|
|
73
|
+
metafile: buildResult.metafile
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
})).finally(() => {
|
|
77
|
+
rmSync(tempBuildDir, { recursive: true, force: true });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function runBestEffortBuildGc() {
|
|
81
|
+
try {
|
|
82
|
+
drainMicrotasks();
|
|
83
|
+
} catch {}
|
|
84
|
+
try {
|
|
85
|
+
gcAndSweep();
|
|
86
|
+
} catch {}
|
|
87
|
+
}
|
|
88
|
+
function runtimeBinaryCacheManifestPath(outputPath) {
|
|
89
|
+
return `${outputPath}.build-manifest.json`;
|
|
90
|
+
}
|
|
91
|
+
function resolveRuntimeBinaryBuildOptions(options) {
|
|
92
|
+
return {
|
|
93
|
+
...options,
|
|
94
|
+
entrypoint: resolve(options.cwd, options.sourcePath),
|
|
95
|
+
outputPath: resolve(options.outputPath)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function shouldUseRuntimeBinaryBuildWorker() {
|
|
99
|
+
if (process.env.RIG_RUNTIME_BUILD_WORKER === "1") {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (process.env.RIG_RUNTIME_BUILD_IN_PROCESS === "1") {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
async function buildRuntimeBinaryViaWorker(options) {
|
|
108
|
+
const workerSourcePath = resolveRuntimeBinaryBuildWorkerSourcePath(options);
|
|
109
|
+
if (!workerSourcePath || !existsSync(workerSourcePath)) {
|
|
110
|
+
await buildRuntimeBinaryInProcess(options, {
|
|
111
|
+
manifestPath: runtimeBinaryCacheManifestPath(options.outputPath),
|
|
112
|
+
buildKey: createRuntimeBinaryBuildKey({
|
|
113
|
+
entrypoint: options.entrypoint,
|
|
114
|
+
define: options.define,
|
|
115
|
+
env: options.env
|
|
116
|
+
})
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const payloadPath = createRuntimeBinaryBuildWorkerPayloadPath(options.outputPath);
|
|
121
|
+
const bunCli = resolveRuntimeBinaryBuildWorkerInvocation();
|
|
122
|
+
await Bun.write(payloadPath, `${JSON.stringify(options)}
|
|
123
|
+
`);
|
|
124
|
+
const build = Bun.spawn([bunCli.command, workerSourcePath, payloadPath], {
|
|
125
|
+
cwd: options.cwd,
|
|
126
|
+
stdout: "pipe",
|
|
127
|
+
stderr: "pipe",
|
|
128
|
+
env: {
|
|
129
|
+
...process.env,
|
|
130
|
+
...options.env,
|
|
131
|
+
...bunCli.env,
|
|
132
|
+
RIG_RUNTIME_BUILD_WORKER: "1"
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
136
|
+
build.exited,
|
|
137
|
+
new Response(build.stdout).text(),
|
|
138
|
+
new Response(build.stderr).text()
|
|
139
|
+
]);
|
|
140
|
+
rmSync(payloadPath, { force: true });
|
|
141
|
+
if (exitCode !== 0) {
|
|
142
|
+
throw new Error(`Failed to build ${options.entrypoint}: ${(stderr || stdout || `worker exited ${exitCode}`).trim()}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function createRuntimeBinaryBuildWorkerPayloadPath(outputPath) {
|
|
146
|
+
return resolve(dirname(outputPath), `.bun-build-worker-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
|
|
147
|
+
}
|
|
148
|
+
function resolveRuntimeBinaryBuildWorkerSourcePath(options) {
|
|
149
|
+
const envRoots = [
|
|
150
|
+
options.cwd?.trim(),
|
|
151
|
+
process.env.RIG_HOST_PROJECT_ROOT?.trim(),
|
|
152
|
+
process.env.PROJECT_RIG_ROOT?.trim()
|
|
153
|
+
].filter(Boolean);
|
|
154
|
+
for (const root of envRoots) {
|
|
155
|
+
const candidate = resolve(root, "packages/runtime/src/binary-build-worker.ts");
|
|
156
|
+
if (existsSync(candidate)) {
|
|
157
|
+
return candidate;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const localCandidate = resolve(import.meta.dir, "binary-build-worker.ts");
|
|
161
|
+
return existsSync(localCandidate) ? localCandidate : null;
|
|
162
|
+
}
|
|
163
|
+
function resolveRuntimeBinaryBuildWorkerInvocation() {
|
|
164
|
+
const bunPath = Bun.which("bun");
|
|
165
|
+
if (bunPath) {
|
|
166
|
+
return { command: bunPath, env: {} };
|
|
167
|
+
}
|
|
168
|
+
if (process.execPath?.trim()) {
|
|
169
|
+
return {
|
|
170
|
+
command: process.execPath,
|
|
171
|
+
env: { BUN_BE_BUN: "1" }
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
throw new Error("bun is required to run the runtime binary build worker.");
|
|
175
|
+
}
|
|
176
|
+
function currentCompileTarget() {
|
|
177
|
+
if (process.platform === "darwin") {
|
|
178
|
+
return process.arch === "arm64" ? "bun-darwin-arm64" : "bun-darwin-x64";
|
|
179
|
+
}
|
|
180
|
+
if (process.platform === "linux") {
|
|
181
|
+
return process.arch === "arm64" ? "bun-linux-arm64" : "bun-linux-x64";
|
|
182
|
+
}
|
|
183
|
+
return "bun-windows-x64";
|
|
184
|
+
}
|
|
185
|
+
function createRuntimeBinaryBuildKey(input) {
|
|
186
|
+
return JSON.stringify({
|
|
187
|
+
version: 1,
|
|
188
|
+
bunVersion: Bun.version,
|
|
189
|
+
platform: process.platform,
|
|
190
|
+
arch: process.arch,
|
|
191
|
+
entrypoint: input.entrypoint,
|
|
192
|
+
define: sortRecord(input.define),
|
|
193
|
+
env: sortRecord(input.env)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async function isRuntimeBinaryBuildFresh(input) {
|
|
197
|
+
if (!existsSync(input.outputPath) || !existsSync(input.manifestPath)) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
let manifest = null;
|
|
201
|
+
try {
|
|
202
|
+
manifest = await Bun.file(input.manifestPath).json();
|
|
203
|
+
} catch {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (!manifest || manifest.version !== 1 || manifest.buildKey !== input.buildKey) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
for (const [filePath, expectedDigest] of Object.entries(manifest.inputs || {})) {
|
|
210
|
+
if (!existsSync(filePath)) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
if (await sha256File(filePath) !== expectedDigest) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
async function writeRuntimeBinaryCacheManifest(input) {
|
|
220
|
+
const inputs = {};
|
|
221
|
+
for (const inputPath of Object.keys(input.metafile?.inputs || {}).sort()) {
|
|
222
|
+
const normalized = normalizeBuildInputPath(input.cwd, inputPath);
|
|
223
|
+
if (!normalized || !existsSync(normalized)) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
inputs[normalized] = await sha256File(normalized);
|
|
227
|
+
}
|
|
228
|
+
const manifest = {
|
|
229
|
+
version: 1,
|
|
230
|
+
buildKey: input.buildKey,
|
|
231
|
+
inputs
|
|
232
|
+
};
|
|
233
|
+
await Bun.write(input.manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
234
|
+
`);
|
|
235
|
+
}
|
|
236
|
+
function normalizeBuildInputPath(cwd, inputPath) {
|
|
237
|
+
if (!inputPath) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
if (inputPath.startsWith("file://")) {
|
|
241
|
+
return fileURLToPath(inputPath);
|
|
242
|
+
}
|
|
243
|
+
if (inputPath.startsWith("<")) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
return resolve(cwd, inputPath);
|
|
247
|
+
}
|
|
248
|
+
async function sha256File(path) {
|
|
249
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
250
|
+
hasher.update(await Bun.file(path).arrayBuffer());
|
|
251
|
+
return hasher.digest("hex");
|
|
252
|
+
}
|
|
253
|
+
function sortRecord(value) {
|
|
254
|
+
if (!value) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)));
|
|
258
|
+
}
|
|
259
|
+
async function runSerializedRuntimeBinaryBuild(action) {
|
|
260
|
+
const previous = runtimeBinaryBuildQueue;
|
|
261
|
+
let release;
|
|
262
|
+
runtimeBinaryBuildQueue = new Promise((resolve2) => {
|
|
263
|
+
release = resolve2;
|
|
264
|
+
});
|
|
265
|
+
await previous;
|
|
266
|
+
try {
|
|
267
|
+
return await action();
|
|
268
|
+
} finally {
|
|
269
|
+
release();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function withTemporaryEnv(env, action) {
|
|
273
|
+
if (!env) {
|
|
274
|
+
return action();
|
|
275
|
+
}
|
|
276
|
+
const previousValues = new Map;
|
|
277
|
+
for (const [key, value] of Object.entries(env)) {
|
|
278
|
+
previousValues.set(key, process.env[key]);
|
|
279
|
+
if (value === undefined) {
|
|
280
|
+
delete process.env[key];
|
|
281
|
+
} else {
|
|
282
|
+
process.env[key] = value;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
return await action();
|
|
287
|
+
} finally {
|
|
288
|
+
for (const [key, value] of previousValues.entries()) {
|
|
289
|
+
if (value === undefined) {
|
|
290
|
+
delete process.env[key];
|
|
291
|
+
} else {
|
|
292
|
+
process.env[key] = value;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async function withTemporaryCwd(cwd, action) {
|
|
298
|
+
const previousCwd = process.cwd();
|
|
299
|
+
process.chdir(cwd);
|
|
300
|
+
try {
|
|
301
|
+
return await action();
|
|
302
|
+
} finally {
|
|
303
|
+
process.chdir(previousCwd);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// packages/runtime/src/control-plane/runtime/tooling/claude-router-binary.ts
|
|
308
|
+
var sharedRouterOutputDir = resolve2(tmpdir(), "rig-native");
|
|
309
|
+
var sharedRouterOutputPath = resolve2(sharedRouterOutputDir, `rig-tool-router-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
310
|
+
function runtimeClaudeToolRouterFileName() {
|
|
311
|
+
return `rig-tool-router${process.platform === "win32" ? ".exe" : ""}`;
|
|
312
|
+
}
|
|
313
|
+
async function ensureClaudeToolRouterBinaryPath(projectRoot, outputPath = sharedRouterOutputPath) {
|
|
314
|
+
const sourcePath = resolve2(projectRoot, "packages/runtime/src/control-plane/runtime/tooling/claude-router.ts");
|
|
315
|
+
mkdirSync2(dirname2(outputPath), { recursive: true });
|
|
316
|
+
const needsBuild = !existsSync2(outputPath) || statSync(sourcePath).mtimeMs > statSync(outputPath).mtimeMs;
|
|
317
|
+
if (!needsBuild) {
|
|
318
|
+
return outputPath;
|
|
319
|
+
}
|
|
320
|
+
await buildRuntimeBinary({
|
|
321
|
+
sourcePath: "packages/runtime/src/control-plane/runtime/tooling/claude-router.ts",
|
|
322
|
+
outputPath,
|
|
323
|
+
cwd: projectRoot
|
|
324
|
+
});
|
|
325
|
+
chmodSync2(outputPath, 493);
|
|
326
|
+
return outputPath;
|
|
327
|
+
}
|
|
328
|
+
async function materializeClaudeToolRouterBinary(projectRoot, targetDir) {
|
|
329
|
+
const sourcePath = await ensureClaudeToolRouterBinaryPath(projectRoot);
|
|
330
|
+
const targetPath = resolve2(targetDir, runtimeClaudeToolRouterFileName());
|
|
331
|
+
mkdirSync2(targetDir, { recursive: true });
|
|
332
|
+
const needsCopy = !existsSync2(targetPath) || statSync(sourcePath).mtimeMs > statSync(targetPath).mtimeMs;
|
|
333
|
+
if (needsCopy) {
|
|
334
|
+
copyFileSync(sourcePath, targetPath);
|
|
335
|
+
chmodSync2(targetPath, 493);
|
|
336
|
+
}
|
|
337
|
+
return targetPath;
|
|
338
|
+
}
|
|
339
|
+
export {
|
|
340
|
+
runtimeClaudeToolRouterFileName,
|
|
341
|
+
materializeClaudeToolRouterBinary,
|
|
342
|
+
ensureClaudeToolRouterBinaryPath
|
|
343
|
+
};
|