@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,535 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/native/utils.ts
|
|
3
|
+
import { ptr as ptr2 } from "bun:ffi";
|
|
4
|
+
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
5
|
+
import { resolve as resolve3 } from "path";
|
|
6
|
+
|
|
7
|
+
// packages/runtime/src/layout.ts
|
|
8
|
+
import { existsSync } from "fs";
|
|
9
|
+
import { basename, dirname, resolve } from "path";
|
|
10
|
+
var RIG_DEFINITION_DIRNAME = "rig";
|
|
11
|
+
var RIG_ARTIFACTS_DIRNAME = "artifacts";
|
|
12
|
+
function resolveMonorepoRoot(projectRoot) {
|
|
13
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
14
|
+
const explicit = process.env.MONOREPO_ROOT?.trim();
|
|
15
|
+
if (explicit) {
|
|
16
|
+
const explicitRoot = resolve(explicit);
|
|
17
|
+
const explicitParent = dirname(explicitRoot);
|
|
18
|
+
if (basename(explicitParent) === ".worktrees") {
|
|
19
|
+
const owner = dirname(explicitParent);
|
|
20
|
+
const ownerHasGit = existsSync(resolve(owner, ".git"));
|
|
21
|
+
const ownerHasTaskConfig = existsSync(resolve(owner, ".rig", "task-config.json"));
|
|
22
|
+
const ownerHasRigConfig = existsSync(resolve(owner, "rig.config.ts"));
|
|
23
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
24
|
+
return owner;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`MONOREPO_ROOT points to worktree ${explicitRoot}, but the owner checkout is incomplete at ${owner}.`);
|
|
27
|
+
}
|
|
28
|
+
if (!existsSync(resolve(explicitRoot, ".git"))) {
|
|
29
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there.`);
|
|
30
|
+
}
|
|
31
|
+
const hasTaskConfig = existsSync(resolve(explicitRoot, ".rig", "task-config.json"));
|
|
32
|
+
const hasRigConfig = existsSync(resolve(explicitRoot, "rig.config.ts"));
|
|
33
|
+
if (!hasTaskConfig && !hasRigConfig) {
|
|
34
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but neither .rig/task-config.json nor rig.config.ts exists there.`);
|
|
35
|
+
}
|
|
36
|
+
return explicitRoot;
|
|
37
|
+
}
|
|
38
|
+
const projectParent = dirname(normalizedProjectRoot);
|
|
39
|
+
if (basename(projectParent) === ".worktrees") {
|
|
40
|
+
const worktreeOwner = dirname(projectParent);
|
|
41
|
+
const ownerHasGit = existsSync(resolve(worktreeOwner, ".git"));
|
|
42
|
+
const ownerHasTaskConfig = existsSync(resolve(worktreeOwner, ".rig", "task-config.json"));
|
|
43
|
+
const ownerHasRigConfig = existsSync(resolve(worktreeOwner, "rig.config.ts"));
|
|
44
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
45
|
+
return worktreeOwner;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return normalizedProjectRoot;
|
|
49
|
+
}
|
|
50
|
+
function resolveRuntimeWorkspaceLayout(workspaceDir) {
|
|
51
|
+
const root = resolve(workspaceDir);
|
|
52
|
+
const rigRoot = resolve(root, ".rig");
|
|
53
|
+
const logsDir = resolve(rigRoot, "logs");
|
|
54
|
+
const stateDir = resolve(rigRoot, "state");
|
|
55
|
+
const runtimeDir = resolve(rigRoot, "runtime");
|
|
56
|
+
const binDir = resolve(rigRoot, "bin");
|
|
57
|
+
return {
|
|
58
|
+
workspaceDir: root,
|
|
59
|
+
rigRoot,
|
|
60
|
+
stateDir,
|
|
61
|
+
logsDir,
|
|
62
|
+
artifactsRoot: resolve(root, RIG_ARTIFACTS_DIRNAME),
|
|
63
|
+
runtimeDir,
|
|
64
|
+
homeDir: resolve(rigRoot, "home"),
|
|
65
|
+
tmpDir: resolve(rigRoot, "tmp"),
|
|
66
|
+
cacheDir: resolve(rigRoot, "cache"),
|
|
67
|
+
sessionDir: resolve(rigRoot, "session"),
|
|
68
|
+
binDir,
|
|
69
|
+
distDir: resolve(rigRoot, "dist"),
|
|
70
|
+
pluginBinDir: resolve(binDir, "plugins"),
|
|
71
|
+
contextPath: resolve(rigRoot, "runtime-context.json"),
|
|
72
|
+
controlPlaneEventsFile: resolve(logsDir, "control-plane.events.jsonl")
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function resolveActiveRuntimeWorkspaceRoot(monorepoRoot) {
|
|
76
|
+
const explicit = process.env.RIG_TASK_WORKSPACE?.trim();
|
|
77
|
+
if (!explicit) {
|
|
78
|
+
throw new Error("No active runtime workspace. Set RIG_TASK_WORKSPACE or provision a task runtime first.");
|
|
79
|
+
}
|
|
80
|
+
return resolve(explicit);
|
|
81
|
+
}
|
|
82
|
+
function resolveRigLayout(projectRoot) {
|
|
83
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
84
|
+
const definitionRoot = resolve(projectRoot, RIG_DEFINITION_DIRNAME);
|
|
85
|
+
const runtimeWorkspaceRoot = resolveActiveRuntimeWorkspaceRoot(monorepoRoot);
|
|
86
|
+
const runtimeLayout = resolveRuntimeWorkspaceLayout(runtimeWorkspaceRoot);
|
|
87
|
+
const policyDir = resolve(definitionRoot, "policy");
|
|
88
|
+
return {
|
|
89
|
+
projectRoot,
|
|
90
|
+
monorepoRoot,
|
|
91
|
+
definitionRoot,
|
|
92
|
+
runtimeWorkspaceRoot,
|
|
93
|
+
stateRoot: runtimeLayout.rigRoot,
|
|
94
|
+
artifactsRoot: runtimeLayout.artifactsRoot,
|
|
95
|
+
configPath: resolve(definitionRoot, "config.sh"),
|
|
96
|
+
taskConfigPath: resolve(runtimeWorkspaceRoot, ".rig", "task-config.json"),
|
|
97
|
+
policyDir,
|
|
98
|
+
policyFile: resolve(policyDir, "policy.json"),
|
|
99
|
+
pluginsDir: resolve(definitionRoot, "plugins"),
|
|
100
|
+
hooksDir: resolve(definitionRoot, "hooks"),
|
|
101
|
+
toolsDir: resolve(definitionRoot, "tools"),
|
|
102
|
+
templatesDir: resolve(definitionRoot, "templates"),
|
|
103
|
+
validationDir: resolve(definitionRoot, "validation"),
|
|
104
|
+
stateDir: runtimeLayout.stateDir,
|
|
105
|
+
logsDir: runtimeLayout.logsDir,
|
|
106
|
+
notificationsDir: resolve(definitionRoot, "notifications"),
|
|
107
|
+
runtimeDir: runtimeLayout.runtimeDir,
|
|
108
|
+
distDir: runtimeLayout.distDir,
|
|
109
|
+
binDir: runtimeLayout.binDir,
|
|
110
|
+
pluginBinDir: runtimeLayout.pluginBinDir,
|
|
111
|
+
keybindingsPath: resolve(definitionRoot, "keybindings.json"),
|
|
112
|
+
controlPlaneEventsFile: runtimeLayout.controlPlaneEventsFile
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// packages/runtime/src/control-plane/native/runtime-native.ts
|
|
117
|
+
import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
|
|
118
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync, renameSync, rmSync, statSync } from "fs";
|
|
119
|
+
import { tmpdir } from "os";
|
|
120
|
+
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
121
|
+
var sharedNativeRuntimeOutputDir = resolve2(tmpdir(), "rig-native");
|
|
122
|
+
var sharedNativeRuntimeOutputPath = resolve2(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
|
|
123
|
+
var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
|
|
124
|
+
var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
|
|
125
|
+
function requireNativeRuntimeLibrary(feature) {
|
|
126
|
+
if (!nativeRuntimeLibrary) {
|
|
127
|
+
throw new Error(`Native Zig runtime is required for ${feature}`);
|
|
128
|
+
}
|
|
129
|
+
return nativeRuntimeLibrary;
|
|
130
|
+
}
|
|
131
|
+
async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
|
|
132
|
+
if (await buildNativeRuntimeLibrary(outputPath, options)) {
|
|
133
|
+
return outputPath;
|
|
134
|
+
}
|
|
135
|
+
return !options.force && existsSync2(outputPath) ? outputPath : null;
|
|
136
|
+
}
|
|
137
|
+
async function loadNativeRuntimeLibrary() {
|
|
138
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
for (const candidate of nativeRuntimeLibraryCandidates()) {
|
|
142
|
+
if (!candidate || !existsSync2(candidate)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const loaded = tryDlopenNativeRuntimeLibrary(candidate);
|
|
146
|
+
if (loaded) {
|
|
147
|
+
return loaded;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
|
|
151
|
+
if (!builtLibraryPath) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
|
|
155
|
+
}
|
|
156
|
+
function nativePackageLibraryCandidates(fromDir, names) {
|
|
157
|
+
const candidates = [];
|
|
158
|
+
let cursor = resolve2(fromDir);
|
|
159
|
+
for (let index = 0;index < 8; index += 1) {
|
|
160
|
+
for (const name of names) {
|
|
161
|
+
candidates.push(resolve2(cursor, "native", `${process.platform}-${process.arch}`, name), resolve2(cursor, "native", `${process.platform}-${process.arch}`, "lib", name), resolve2(cursor, "native", name), resolve2(cursor, "native", "lib", name));
|
|
162
|
+
}
|
|
163
|
+
const parent = dirname2(cursor);
|
|
164
|
+
if (parent === cursor)
|
|
165
|
+
break;
|
|
166
|
+
cursor = parent;
|
|
167
|
+
}
|
|
168
|
+
return candidates;
|
|
169
|
+
}
|
|
170
|
+
function nativeRuntimeLibraryCandidates() {
|
|
171
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
|
|
172
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
173
|
+
const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
|
|
174
|
+
return [...new Set([
|
|
175
|
+
explicit,
|
|
176
|
+
...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
|
|
177
|
+
execDir ? resolve2(execDir, colocatedNativeRuntimeFileName) : "",
|
|
178
|
+
execDir ? resolve2(execDir, platformSpecific) : "",
|
|
179
|
+
execDir ? resolve2(execDir, "..", colocatedNativeRuntimeFileName) : "",
|
|
180
|
+
execDir ? resolve2(execDir, "..", platformSpecific) : "",
|
|
181
|
+
execDir ? resolve2(execDir, "lib", colocatedNativeRuntimeFileName) : "",
|
|
182
|
+
execDir ? resolve2(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
|
|
183
|
+
sharedNativeRuntimeOutputPath
|
|
184
|
+
].filter(Boolean))];
|
|
185
|
+
}
|
|
186
|
+
function resolveNativeRuntimeSourcePath() {
|
|
187
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
|
|
188
|
+
if (explicit && existsSync2(explicit)) {
|
|
189
|
+
return explicit;
|
|
190
|
+
}
|
|
191
|
+
const bundled = resolve2(import.meta.dir, "../../../native/snapshot.zig");
|
|
192
|
+
return existsSync2(bundled) ? bundled : null;
|
|
193
|
+
}
|
|
194
|
+
async function buildNativeRuntimeLibrary(outputPath, options = {}) {
|
|
195
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
const zigBinary = Bun.which("zig");
|
|
199
|
+
const sourcePath = resolveNativeRuntimeSourcePath();
|
|
200
|
+
if (!zigBinary || !sourcePath) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
204
|
+
try {
|
|
205
|
+
mkdirSync(dirname2(outputPath), { recursive: true });
|
|
206
|
+
const needsBuild = options.force === true || !existsSync2(outputPath) || statSync(sourcePath).mtimeMs > statSync(outputPath).mtimeMs;
|
|
207
|
+
if (!needsBuild) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
const build = Bun.spawn([
|
|
211
|
+
zigBinary,
|
|
212
|
+
"build-lib",
|
|
213
|
+
sourcePath,
|
|
214
|
+
"-dynamic",
|
|
215
|
+
"-O",
|
|
216
|
+
"ReleaseFast",
|
|
217
|
+
`-femit-bin=${tempOutputPath}`
|
|
218
|
+
], {
|
|
219
|
+
cwd: import.meta.dir,
|
|
220
|
+
stdout: "pipe",
|
|
221
|
+
stderr: "pipe"
|
|
222
|
+
});
|
|
223
|
+
const exitCode = await build.exited;
|
|
224
|
+
if (exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
225
|
+
rmSync(tempOutputPath, { force: true });
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
renameSync(tempOutputPath, outputPath);
|
|
229
|
+
return true;
|
|
230
|
+
} catch {
|
|
231
|
+
rmSync(tempOutputPath, { force: true });
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function tryDlopenNativeRuntimeLibrary(outputPath) {
|
|
236
|
+
try {
|
|
237
|
+
return dlopen(outputPath, {
|
|
238
|
+
rig_scope_match: {
|
|
239
|
+
args: ["ptr", "ptr"],
|
|
240
|
+
returns: "u8"
|
|
241
|
+
},
|
|
242
|
+
snapshot_capture: {
|
|
243
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
244
|
+
returns: "ptr"
|
|
245
|
+
},
|
|
246
|
+
snapshot_delta: {
|
|
247
|
+
args: ["ptr", "ptr"],
|
|
248
|
+
returns: "ptr"
|
|
249
|
+
},
|
|
250
|
+
snapshot_store_delta: {
|
|
251
|
+
args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
252
|
+
returns: "ptr"
|
|
253
|
+
},
|
|
254
|
+
snapshot_inspect_delta: {
|
|
255
|
+
args: ["ptr", "u64"],
|
|
256
|
+
returns: "ptr"
|
|
257
|
+
},
|
|
258
|
+
snapshot_apply_delta: {
|
|
259
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
260
|
+
returns: "ptr"
|
|
261
|
+
},
|
|
262
|
+
snapshot_release: {
|
|
263
|
+
args: ["ptr"],
|
|
264
|
+
returns: "void"
|
|
265
|
+
},
|
|
266
|
+
runtime_hash_file: {
|
|
267
|
+
args: ["ptr", "u64"],
|
|
268
|
+
returns: "ptr"
|
|
269
|
+
},
|
|
270
|
+
runtime_hash_tree: {
|
|
271
|
+
args: ["ptr", "u64"],
|
|
272
|
+
returns: "ptr"
|
|
273
|
+
},
|
|
274
|
+
runtime_prepare_paths: {
|
|
275
|
+
args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
276
|
+
returns: "ptr"
|
|
277
|
+
},
|
|
278
|
+
runtime_link_dependency_layer: {
|
|
279
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
280
|
+
returns: "ptr"
|
|
281
|
+
},
|
|
282
|
+
runtime_scan_worktrees: {
|
|
283
|
+
args: ["ptr", "u64"],
|
|
284
|
+
returns: "ptr"
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
} catch {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// packages/runtime/src/control-plane/native/scope-rules.ts
|
|
293
|
+
var activeRules = null;
|
|
294
|
+
function getScopeRules() {
|
|
295
|
+
return activeRules;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// packages/runtime/src/control-plane/native/utils.ts
|
|
299
|
+
function resolveMonorepoRoot2(projectRoot) {
|
|
300
|
+
return resolveMonorepoRoot(projectRoot);
|
|
301
|
+
}
|
|
302
|
+
var nativeScopeMatcher = null;
|
|
303
|
+
var scopeRegexCache = new Map;
|
|
304
|
+
function runCapture(command, cwd, env) {
|
|
305
|
+
const result = Bun.spawnSync(command, {
|
|
306
|
+
cwd,
|
|
307
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
308
|
+
stdout: "pipe",
|
|
309
|
+
stderr: "pipe"
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
exitCode: result.exitCode,
|
|
313
|
+
stdout: result.stdout.toString(),
|
|
314
|
+
stderr: result.stderr.toString()
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
var DEFAULT_VALIDATION_TIMEOUT_MS = 30000;
|
|
318
|
+
function getValidationTimeoutMs() {
|
|
319
|
+
const envVal = process.env.RIG_VALIDATION_TIMEOUT_MS;
|
|
320
|
+
if (envVal) {
|
|
321
|
+
const parsed = Number(envVal);
|
|
322
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
323
|
+
return parsed;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return DEFAULT_VALIDATION_TIMEOUT_MS;
|
|
327
|
+
}
|
|
328
|
+
async function runCaptureAsync(command, cwd, env, timeoutMs) {
|
|
329
|
+
const timeout = timeoutMs ?? getValidationTimeoutMs();
|
|
330
|
+
const proc = Bun.spawn(command, {
|
|
331
|
+
cwd,
|
|
332
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
333
|
+
stdout: "pipe",
|
|
334
|
+
stderr: "pipe"
|
|
335
|
+
});
|
|
336
|
+
const stdoutPromise = new Response(proc.stdout).text();
|
|
337
|
+
const stderrPromise = new Response(proc.stderr).text();
|
|
338
|
+
const timeoutResult = Symbol("timeout");
|
|
339
|
+
const exitOrTimeout = await Promise.race([
|
|
340
|
+
proc.exited,
|
|
341
|
+
Bun.sleep(timeout).then(() => timeoutResult)
|
|
342
|
+
]);
|
|
343
|
+
if (exitOrTimeout === timeoutResult) {
|
|
344
|
+
proc.kill("SIGKILL");
|
|
345
|
+
const [stdout2, stderr2] = await Promise.all([
|
|
346
|
+
Promise.race([stdoutPromise, Bun.sleep(2000).then(() => "")]),
|
|
347
|
+
Promise.race([stderrPromise, Bun.sleep(2000).then(() => "")])
|
|
348
|
+
]);
|
|
349
|
+
return {
|
|
350
|
+
exitCode: 124,
|
|
351
|
+
stdout: stdout2,
|
|
352
|
+
stderr: `${stderr2}
|
|
353
|
+
[TIMEOUT] Process killed after ${timeout}ms`
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const [stdout, stderr] = await Promise.all([stdoutPromise, stderrPromise]);
|
|
357
|
+
const exitCode = exitOrTimeout;
|
|
358
|
+
return { exitCode, stdout, stderr };
|
|
359
|
+
}
|
|
360
|
+
function runInherit(command, cwd, env) {
|
|
361
|
+
const proc = Bun.spawnSync(command, {
|
|
362
|
+
cwd,
|
|
363
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
364
|
+
stdin: "inherit",
|
|
365
|
+
stdout: "inherit",
|
|
366
|
+
stderr: "inherit"
|
|
367
|
+
});
|
|
368
|
+
return proc.exitCode;
|
|
369
|
+
}
|
|
370
|
+
function readJsonFile(path, fallback) {
|
|
371
|
+
if (!existsSync3(path)) {
|
|
372
|
+
return fallback;
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
376
|
+
} catch {
|
|
377
|
+
return fallback;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function nowIso() {
|
|
381
|
+
return new Date().toISOString();
|
|
382
|
+
}
|
|
383
|
+
function unique(values) {
|
|
384
|
+
return [...new Set(values)];
|
|
385
|
+
}
|
|
386
|
+
function fileLines(path) {
|
|
387
|
+
if (!existsSync3(path)) {
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
return readFileSync(path, "utf-8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
391
|
+
}
|
|
392
|
+
function resolveHarnessPaths(projectRoot) {
|
|
393
|
+
const hasRuntimeWorkspace = Boolean(process.env.RIG_TASK_WORKSPACE?.trim());
|
|
394
|
+
const monorepoRoot = resolveMonorepoRoot2(projectRoot);
|
|
395
|
+
const harnessRoot = resolve3(projectRoot, "rig");
|
|
396
|
+
const stateRoot = resolve3(projectRoot, ".rig");
|
|
397
|
+
const layout = hasRuntimeWorkspace ? resolveRigLayout(projectRoot) : null;
|
|
398
|
+
const stateDir = layout?.stateDir ?? resolve3(stateRoot, "state");
|
|
399
|
+
const logsDir = layout?.logsDir ?? resolve3(stateRoot, "logs");
|
|
400
|
+
const artifactsDir = layout?.artifactsRoot ?? resolve3(monorepoRoot, "artifacts");
|
|
401
|
+
const taskConfigPath = layout?.taskConfigPath ?? resolve3(monorepoRoot, ".rig", "task-config.json");
|
|
402
|
+
const binDir = layout?.binDir ?? resolve3(stateRoot, "bin");
|
|
403
|
+
return {
|
|
404
|
+
harnessRoot,
|
|
405
|
+
stateDir: process.env.RIG_STATE_DIR || stateDir,
|
|
406
|
+
artifactsDir,
|
|
407
|
+
logsDir: process.env.RIG_LOGS_DIR || logsDir,
|
|
408
|
+
binDir,
|
|
409
|
+
hooksDir: resolve3(harnessRoot, "hooks"),
|
|
410
|
+
validationDir: resolve3(harnessRoot, "validation"),
|
|
411
|
+
taskConfigPath,
|
|
412
|
+
sessionPath: process.env.RIG_SESSION_FILE || resolve3(stateRoot, "session", "session.json"),
|
|
413
|
+
monorepoRoot,
|
|
414
|
+
tsApiTestsDir: process.env.TS_API_TESTS_DIR || resolve3(monorepoRoot, "TSAPITests"),
|
|
415
|
+
taskRepoCommitsPath: resolve3(stateDir, "task-repo-commits.json"),
|
|
416
|
+
baseRepoPinsPath: resolve3(stateDir, "base-repo-pins.json"),
|
|
417
|
+
failedApproachesPath: resolve3(stateDir, "failed_approaches.md"),
|
|
418
|
+
agentProfilePath: resolve3(stateDir, "agent-profile.json"),
|
|
419
|
+
reviewProfilePath: resolve3(stateDir, "review-profile.json")
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function normalizeRelativeScopePath(inputPath) {
|
|
423
|
+
let normalized = inputPath.replace(/^\.\//, "");
|
|
424
|
+
const rules = getScopeRules();
|
|
425
|
+
if (rules?.stripPrefixes) {
|
|
426
|
+
for (const prefix of rules.stripPrefixes) {
|
|
427
|
+
if (normalized.startsWith(prefix)) {
|
|
428
|
+
normalized = normalized.slice(prefix.length);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return normalized;
|
|
433
|
+
}
|
|
434
|
+
function normalizePathToScope(projectRoot, monorepoRoot, inputPath) {
|
|
435
|
+
let normalized = inputPath.replace(/^\.\//, "");
|
|
436
|
+
if (normalized.startsWith(projectRoot + "/")) {
|
|
437
|
+
normalized = normalized.slice(projectRoot.length + 1);
|
|
438
|
+
}
|
|
439
|
+
if (normalized.startsWith(monorepoRoot + "/")) {
|
|
440
|
+
normalized = normalized.slice(monorepoRoot.length + 1);
|
|
441
|
+
}
|
|
442
|
+
return normalizeRelativeScopePath(normalized);
|
|
443
|
+
}
|
|
444
|
+
function monorepoSearchCandidates(inputPath) {
|
|
445
|
+
const normalized = inputPath.replace(/^\.\//, "");
|
|
446
|
+
const candidates = new Set;
|
|
447
|
+
const add = (value) => {
|
|
448
|
+
const trimmed = value.replace(/^\.\//, "");
|
|
449
|
+
if (trimmed) {
|
|
450
|
+
candidates.add(trimmed);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
add(normalized);
|
|
454
|
+
const stripped = normalizeRelativeScopePath(normalized);
|
|
455
|
+
add(stripped);
|
|
456
|
+
const rules = getScopeRules();
|
|
457
|
+
if (rules?.stripPrefixes) {
|
|
458
|
+
for (const prefix of rules.stripPrefixes) {
|
|
459
|
+
if (normalized.startsWith(prefix)) {
|
|
460
|
+
add(normalized.slice(prefix.length));
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (rules?.searchPrefixes) {
|
|
465
|
+
for (const rule of rules.searchPrefixes) {
|
|
466
|
+
const matchesStart = rule.matchStartsWith?.some((p) => stripped.startsWith(p)) ?? false;
|
|
467
|
+
const matchesExact = rule.matchExact?.includes(stripped) ?? false;
|
|
468
|
+
if (matchesStart || matchesExact) {
|
|
469
|
+
add(`${rule.prefix}${stripped}`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return [...candidates];
|
|
474
|
+
}
|
|
475
|
+
function scopeGlobToRegex(glob) {
|
|
476
|
+
const cached = scopeRegexCache.get(glob);
|
|
477
|
+
if (cached) {
|
|
478
|
+
return cached;
|
|
479
|
+
}
|
|
480
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "__GLOBSTAR__").replace(/\*/g, "[^/]*").replace(/__GLOBSTAR__/g, ".*");
|
|
481
|
+
const compiled = new RegExp(`^${escaped}$`);
|
|
482
|
+
scopeRegexCache.set(glob, compiled);
|
|
483
|
+
return compiled;
|
|
484
|
+
}
|
|
485
|
+
function scopeMatches(path, scopes) {
|
|
486
|
+
const matcher = getNativeScopeMatcher();
|
|
487
|
+
const pathVariants = unique([path, normalizeRelativeScopePath(path)]);
|
|
488
|
+
for (const scope of scopes) {
|
|
489
|
+
const scopeVariants = unique([scope, normalizeRelativeScopePath(scope)]);
|
|
490
|
+
for (const candidatePath of pathVariants) {
|
|
491
|
+
for (const candidateScope of scopeVariants) {
|
|
492
|
+
if (candidatePath === candidateScope) {
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
if (matcher.match(candidateScope, candidatePath)) {
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
function getNativeScopeMatcher() {
|
|
504
|
+
if (nativeScopeMatcher) {
|
|
505
|
+
return nativeScopeMatcher;
|
|
506
|
+
}
|
|
507
|
+
nativeScopeMatcher = createNativeScopeMatcher();
|
|
508
|
+
return nativeScopeMatcher;
|
|
509
|
+
}
|
|
510
|
+
function createNativeScopeMatcher() {
|
|
511
|
+
const library = requireNativeRuntimeLibrary("scope matching");
|
|
512
|
+
return {
|
|
513
|
+
match: (pattern, path) => {
|
|
514
|
+
const patternBuffer = Buffer.from(`${pattern}\x00`);
|
|
515
|
+
const pathBuffer = Buffer.from(`${path}\x00`);
|
|
516
|
+
return library.symbols.rig_scope_match(Number(ptr2(patternBuffer)), Number(ptr2(pathBuffer))) !== 0;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
export {
|
|
521
|
+
unique,
|
|
522
|
+
scopeMatches,
|
|
523
|
+
scopeGlobToRegex,
|
|
524
|
+
runInherit,
|
|
525
|
+
runCaptureAsync,
|
|
526
|
+
runCapture,
|
|
527
|
+
resolveMonorepoRoot2 as resolveMonorepoRoot,
|
|
528
|
+
resolveHarnessPaths,
|
|
529
|
+
readJsonFile,
|
|
530
|
+
nowIso,
|
|
531
|
+
normalizePathToScope,
|
|
532
|
+
monorepoSearchCandidates,
|
|
533
|
+
getValidationTimeoutMs,
|
|
534
|
+
fileLines
|
|
535
|
+
};
|