@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,75 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/hook-materializer.ts
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { dirname, resolve } from "path";
|
|
5
|
+
var MARKER_PLUGIN = "_rigPlugin";
|
|
6
|
+
var MARKER_HOOK_ID = "_rigHookId";
|
|
7
|
+
function matcherToString(matcher) {
|
|
8
|
+
if (matcher.kind === "all")
|
|
9
|
+
return;
|
|
10
|
+
if (matcher.kind === "tool")
|
|
11
|
+
return matcher.name;
|
|
12
|
+
return matcher.pattern;
|
|
13
|
+
}
|
|
14
|
+
function isPluginOwned(cmd) {
|
|
15
|
+
return typeof cmd[MARKER_PLUGIN] === "string";
|
|
16
|
+
}
|
|
17
|
+
function materializeHooks(projectRoot, entries) {
|
|
18
|
+
const settingsPath = resolve(projectRoot, ".claude", "settings.json");
|
|
19
|
+
const existing = existsSync(settingsPath) ? safeReadJson(settingsPath) : {};
|
|
20
|
+
const hooks = existing.hooks ?? {};
|
|
21
|
+
for (const event of Object.keys(hooks)) {
|
|
22
|
+
const groups = hooks[event] ?? [];
|
|
23
|
+
const cleaned = [];
|
|
24
|
+
for (const group of groups) {
|
|
25
|
+
const operatorHooks = group.hooks.filter((h) => !isPluginOwned(h));
|
|
26
|
+
if (operatorHooks.length > 0) {
|
|
27
|
+
cleaned.push({ ...group, hooks: operatorHooks });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (cleaned.length > 0) {
|
|
31
|
+
hooks[event] = cleaned;
|
|
32
|
+
} else {
|
|
33
|
+
delete hooks[event];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const { pluginName, hook } of entries) {
|
|
37
|
+
if (!hook.command) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const event = hook.event;
|
|
41
|
+
const matcherString = matcherToString(hook.matcher);
|
|
42
|
+
const groups = hooks[event] ??= [];
|
|
43
|
+
let group = groups.find((g) => g.matcher === matcherString);
|
|
44
|
+
if (!group) {
|
|
45
|
+
group = matcherString === undefined ? { hooks: [] } : { matcher: matcherString, hooks: [] };
|
|
46
|
+
groups.push(group);
|
|
47
|
+
}
|
|
48
|
+
group.hooks.push({
|
|
49
|
+
type: "command",
|
|
50
|
+
command: hook.command,
|
|
51
|
+
[MARKER_PLUGIN]: pluginName,
|
|
52
|
+
[MARKER_HOOK_ID]: hook.id
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const next = { ...existing };
|
|
56
|
+
if (Object.keys(hooks).length > 0) {
|
|
57
|
+
next.hooks = hooks;
|
|
58
|
+
} else {
|
|
59
|
+
delete next.hooks;
|
|
60
|
+
}
|
|
61
|
+
mkdirSync(dirname(settingsPath), { recursive: true });
|
|
62
|
+
writeFileSync(settingsPath, `${JSON.stringify(next, null, 2)}
|
|
63
|
+
`, "utf-8");
|
|
64
|
+
return settingsPath;
|
|
65
|
+
}
|
|
66
|
+
function safeReadJson(path) {
|
|
67
|
+
try {
|
|
68
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
69
|
+
} catch {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
materializeHooks
|
|
75
|
+
};
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// packages/runtime/src/control-plane/hooks/audit-trail.ts
|
|
5
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
6
|
+
import { resolve as resolve4 } from "path";
|
|
7
|
+
import { readHookInput, resolveProjectRoot, resolveTaskIdForHook } from "@rig/hook-kit";
|
|
8
|
+
|
|
9
|
+
// packages/runtime/src/control-plane/native/utils.ts
|
|
10
|
+
import { resolve as resolve3 } from "path";
|
|
11
|
+
|
|
12
|
+
// packages/runtime/src/layout.ts
|
|
13
|
+
import { existsSync } from "fs";
|
|
14
|
+
import { basename, dirname, resolve } from "path";
|
|
15
|
+
var RIG_DEFINITION_DIRNAME = "rig";
|
|
16
|
+
var RIG_ARTIFACTS_DIRNAME = "artifacts";
|
|
17
|
+
function resolveMonorepoRoot(projectRoot) {
|
|
18
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
19
|
+
const explicit = process.env.MONOREPO_ROOT?.trim();
|
|
20
|
+
if (explicit) {
|
|
21
|
+
const explicitRoot = resolve(explicit);
|
|
22
|
+
const explicitParent = dirname(explicitRoot);
|
|
23
|
+
if (basename(explicitParent) === ".worktrees") {
|
|
24
|
+
const owner = dirname(explicitParent);
|
|
25
|
+
const ownerHasGit = existsSync(resolve(owner, ".git"));
|
|
26
|
+
const ownerHasTaskConfig = existsSync(resolve(owner, ".rig", "task-config.json"));
|
|
27
|
+
const ownerHasRigConfig = existsSync(resolve(owner, "rig.config.ts"));
|
|
28
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
29
|
+
return owner;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`MONOREPO_ROOT points to worktree ${explicitRoot}, but the owner checkout is incomplete at ${owner}.`);
|
|
32
|
+
}
|
|
33
|
+
if (!existsSync(resolve(explicitRoot, ".git"))) {
|
|
34
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there.`);
|
|
35
|
+
}
|
|
36
|
+
const hasTaskConfig = existsSync(resolve(explicitRoot, ".rig", "task-config.json"));
|
|
37
|
+
const hasRigConfig = existsSync(resolve(explicitRoot, "rig.config.ts"));
|
|
38
|
+
if (!hasTaskConfig && !hasRigConfig) {
|
|
39
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but neither .rig/task-config.json nor rig.config.ts exists there.`);
|
|
40
|
+
}
|
|
41
|
+
return explicitRoot;
|
|
42
|
+
}
|
|
43
|
+
const projectParent = dirname(normalizedProjectRoot);
|
|
44
|
+
if (basename(projectParent) === ".worktrees") {
|
|
45
|
+
const worktreeOwner = dirname(projectParent);
|
|
46
|
+
const ownerHasGit = existsSync(resolve(worktreeOwner, ".git"));
|
|
47
|
+
const ownerHasTaskConfig = existsSync(resolve(worktreeOwner, ".rig", "task-config.json"));
|
|
48
|
+
const ownerHasRigConfig = existsSync(resolve(worktreeOwner, "rig.config.ts"));
|
|
49
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
50
|
+
return worktreeOwner;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return normalizedProjectRoot;
|
|
54
|
+
}
|
|
55
|
+
function resolveRuntimeWorkspaceLayout(workspaceDir) {
|
|
56
|
+
const root = resolve(workspaceDir);
|
|
57
|
+
const rigRoot = resolve(root, ".rig");
|
|
58
|
+
const logsDir = resolve(rigRoot, "logs");
|
|
59
|
+
const stateDir = resolve(rigRoot, "state");
|
|
60
|
+
const runtimeDir = resolve(rigRoot, "runtime");
|
|
61
|
+
const binDir = resolve(rigRoot, "bin");
|
|
62
|
+
return {
|
|
63
|
+
workspaceDir: root,
|
|
64
|
+
rigRoot,
|
|
65
|
+
stateDir,
|
|
66
|
+
logsDir,
|
|
67
|
+
artifactsRoot: resolve(root, RIG_ARTIFACTS_DIRNAME),
|
|
68
|
+
runtimeDir,
|
|
69
|
+
homeDir: resolve(rigRoot, "home"),
|
|
70
|
+
tmpDir: resolve(rigRoot, "tmp"),
|
|
71
|
+
cacheDir: resolve(rigRoot, "cache"),
|
|
72
|
+
sessionDir: resolve(rigRoot, "session"),
|
|
73
|
+
binDir,
|
|
74
|
+
distDir: resolve(rigRoot, "dist"),
|
|
75
|
+
pluginBinDir: resolve(binDir, "plugins"),
|
|
76
|
+
contextPath: resolve(rigRoot, "runtime-context.json"),
|
|
77
|
+
controlPlaneEventsFile: resolve(logsDir, "control-plane.events.jsonl")
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function resolveActiveRuntimeWorkspaceRoot(monorepoRoot) {
|
|
81
|
+
const explicit = process.env.RIG_TASK_WORKSPACE?.trim();
|
|
82
|
+
if (!explicit) {
|
|
83
|
+
throw new Error("No active runtime workspace. Set RIG_TASK_WORKSPACE or provision a task runtime first.");
|
|
84
|
+
}
|
|
85
|
+
return resolve(explicit);
|
|
86
|
+
}
|
|
87
|
+
function resolveRigLayout(projectRoot) {
|
|
88
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
89
|
+
const definitionRoot = resolve(projectRoot, RIG_DEFINITION_DIRNAME);
|
|
90
|
+
const runtimeWorkspaceRoot = resolveActiveRuntimeWorkspaceRoot(monorepoRoot);
|
|
91
|
+
const runtimeLayout = resolveRuntimeWorkspaceLayout(runtimeWorkspaceRoot);
|
|
92
|
+
const policyDir = resolve(definitionRoot, "policy");
|
|
93
|
+
return {
|
|
94
|
+
projectRoot,
|
|
95
|
+
monorepoRoot,
|
|
96
|
+
definitionRoot,
|
|
97
|
+
runtimeWorkspaceRoot,
|
|
98
|
+
stateRoot: runtimeLayout.rigRoot,
|
|
99
|
+
artifactsRoot: runtimeLayout.artifactsRoot,
|
|
100
|
+
configPath: resolve(definitionRoot, "config.sh"),
|
|
101
|
+
taskConfigPath: resolve(runtimeWorkspaceRoot, ".rig", "task-config.json"),
|
|
102
|
+
policyDir,
|
|
103
|
+
policyFile: resolve(policyDir, "policy.json"),
|
|
104
|
+
pluginsDir: resolve(definitionRoot, "plugins"),
|
|
105
|
+
hooksDir: resolve(definitionRoot, "hooks"),
|
|
106
|
+
toolsDir: resolve(definitionRoot, "tools"),
|
|
107
|
+
templatesDir: resolve(definitionRoot, "templates"),
|
|
108
|
+
validationDir: resolve(definitionRoot, "validation"),
|
|
109
|
+
stateDir: runtimeLayout.stateDir,
|
|
110
|
+
logsDir: runtimeLayout.logsDir,
|
|
111
|
+
notificationsDir: resolve(definitionRoot, "notifications"),
|
|
112
|
+
runtimeDir: runtimeLayout.runtimeDir,
|
|
113
|
+
distDir: runtimeLayout.distDir,
|
|
114
|
+
binDir: runtimeLayout.binDir,
|
|
115
|
+
pluginBinDir: runtimeLayout.pluginBinDir,
|
|
116
|
+
keybindingsPath: resolve(definitionRoot, "keybindings.json"),
|
|
117
|
+
controlPlaneEventsFile: runtimeLayout.controlPlaneEventsFile
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// packages/runtime/src/control-plane/native/runtime-native.ts
|
|
122
|
+
import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
|
|
123
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync, renameSync, rmSync, statSync } from "fs";
|
|
124
|
+
import { tmpdir } from "os";
|
|
125
|
+
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
126
|
+
var sharedNativeRuntimeOutputDir = resolve2(tmpdir(), "rig-native");
|
|
127
|
+
var sharedNativeRuntimeOutputPath = resolve2(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
|
|
128
|
+
var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
|
|
129
|
+
var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
|
|
130
|
+
async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
|
|
131
|
+
if (await buildNativeRuntimeLibrary(outputPath, options)) {
|
|
132
|
+
return outputPath;
|
|
133
|
+
}
|
|
134
|
+
return !options.force && existsSync2(outputPath) ? outputPath : null;
|
|
135
|
+
}
|
|
136
|
+
async function loadNativeRuntimeLibrary() {
|
|
137
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
for (const candidate of nativeRuntimeLibraryCandidates()) {
|
|
141
|
+
if (!candidate || !existsSync2(candidate)) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const loaded = tryDlopenNativeRuntimeLibrary(candidate);
|
|
145
|
+
if (loaded) {
|
|
146
|
+
return loaded;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
|
|
150
|
+
if (!builtLibraryPath) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
|
|
154
|
+
}
|
|
155
|
+
function nativePackageLibraryCandidates(fromDir, names) {
|
|
156
|
+
const candidates = [];
|
|
157
|
+
let cursor = resolve2(fromDir);
|
|
158
|
+
for (let index = 0;index < 8; index += 1) {
|
|
159
|
+
for (const name of names) {
|
|
160
|
+
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));
|
|
161
|
+
}
|
|
162
|
+
const parent = dirname2(cursor);
|
|
163
|
+
if (parent === cursor)
|
|
164
|
+
break;
|
|
165
|
+
cursor = parent;
|
|
166
|
+
}
|
|
167
|
+
return candidates;
|
|
168
|
+
}
|
|
169
|
+
function nativeRuntimeLibraryCandidates() {
|
|
170
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
|
|
171
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
172
|
+
const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
|
|
173
|
+
return [...new Set([
|
|
174
|
+
explicit,
|
|
175
|
+
...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
|
|
176
|
+
execDir ? resolve2(execDir, colocatedNativeRuntimeFileName) : "",
|
|
177
|
+
execDir ? resolve2(execDir, platformSpecific) : "",
|
|
178
|
+
execDir ? resolve2(execDir, "..", colocatedNativeRuntimeFileName) : "",
|
|
179
|
+
execDir ? resolve2(execDir, "..", platformSpecific) : "",
|
|
180
|
+
execDir ? resolve2(execDir, "lib", colocatedNativeRuntimeFileName) : "",
|
|
181
|
+
execDir ? resolve2(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
|
|
182
|
+
sharedNativeRuntimeOutputPath
|
|
183
|
+
].filter(Boolean))];
|
|
184
|
+
}
|
|
185
|
+
function resolveNativeRuntimeSourcePath() {
|
|
186
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
|
|
187
|
+
if (explicit && existsSync2(explicit)) {
|
|
188
|
+
return explicit;
|
|
189
|
+
}
|
|
190
|
+
const bundled = resolve2(import.meta.dir, "../../../native/snapshot.zig");
|
|
191
|
+
return existsSync2(bundled) ? bundled : null;
|
|
192
|
+
}
|
|
193
|
+
async function buildNativeRuntimeLibrary(outputPath, options = {}) {
|
|
194
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
const zigBinary = Bun.which("zig");
|
|
198
|
+
const sourcePath = resolveNativeRuntimeSourcePath();
|
|
199
|
+
if (!zigBinary || !sourcePath) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
203
|
+
try {
|
|
204
|
+
mkdirSync(dirname2(outputPath), { recursive: true });
|
|
205
|
+
const needsBuild = options.force === true || !existsSync2(outputPath) || statSync(sourcePath).mtimeMs > statSync(outputPath).mtimeMs;
|
|
206
|
+
if (!needsBuild) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
const build = Bun.spawn([
|
|
210
|
+
zigBinary,
|
|
211
|
+
"build-lib",
|
|
212
|
+
sourcePath,
|
|
213
|
+
"-dynamic",
|
|
214
|
+
"-O",
|
|
215
|
+
"ReleaseFast",
|
|
216
|
+
`-femit-bin=${tempOutputPath}`
|
|
217
|
+
], {
|
|
218
|
+
cwd: import.meta.dir,
|
|
219
|
+
stdout: "pipe",
|
|
220
|
+
stderr: "pipe"
|
|
221
|
+
});
|
|
222
|
+
const exitCode = await build.exited;
|
|
223
|
+
if (exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
224
|
+
rmSync(tempOutputPath, { force: true });
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
renameSync(tempOutputPath, outputPath);
|
|
228
|
+
return true;
|
|
229
|
+
} catch {
|
|
230
|
+
rmSync(tempOutputPath, { force: true });
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function tryDlopenNativeRuntimeLibrary(outputPath) {
|
|
235
|
+
try {
|
|
236
|
+
return dlopen(outputPath, {
|
|
237
|
+
rig_scope_match: {
|
|
238
|
+
args: ["ptr", "ptr"],
|
|
239
|
+
returns: "u8"
|
|
240
|
+
},
|
|
241
|
+
snapshot_capture: {
|
|
242
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
243
|
+
returns: "ptr"
|
|
244
|
+
},
|
|
245
|
+
snapshot_delta: {
|
|
246
|
+
args: ["ptr", "ptr"],
|
|
247
|
+
returns: "ptr"
|
|
248
|
+
},
|
|
249
|
+
snapshot_store_delta: {
|
|
250
|
+
args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
251
|
+
returns: "ptr"
|
|
252
|
+
},
|
|
253
|
+
snapshot_inspect_delta: {
|
|
254
|
+
args: ["ptr", "u64"],
|
|
255
|
+
returns: "ptr"
|
|
256
|
+
},
|
|
257
|
+
snapshot_apply_delta: {
|
|
258
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
259
|
+
returns: "ptr"
|
|
260
|
+
},
|
|
261
|
+
snapshot_release: {
|
|
262
|
+
args: ["ptr"],
|
|
263
|
+
returns: "void"
|
|
264
|
+
},
|
|
265
|
+
runtime_hash_file: {
|
|
266
|
+
args: ["ptr", "u64"],
|
|
267
|
+
returns: "ptr"
|
|
268
|
+
},
|
|
269
|
+
runtime_hash_tree: {
|
|
270
|
+
args: ["ptr", "u64"],
|
|
271
|
+
returns: "ptr"
|
|
272
|
+
},
|
|
273
|
+
runtime_prepare_paths: {
|
|
274
|
+
args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
275
|
+
returns: "ptr"
|
|
276
|
+
},
|
|
277
|
+
runtime_link_dependency_layer: {
|
|
278
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
279
|
+
returns: "ptr"
|
|
280
|
+
},
|
|
281
|
+
runtime_scan_worktrees: {
|
|
282
|
+
args: ["ptr", "u64"],
|
|
283
|
+
returns: "ptr"
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
} catch {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// packages/runtime/src/control-plane/native/utils.ts
|
|
292
|
+
function resolveMonorepoRoot2(projectRoot) {
|
|
293
|
+
return resolveMonorepoRoot(projectRoot);
|
|
294
|
+
}
|
|
295
|
+
var scopeRegexCache = new Map;
|
|
296
|
+
function resolveHarnessPaths(projectRoot) {
|
|
297
|
+
const hasRuntimeWorkspace = Boolean(process.env.RIG_TASK_WORKSPACE?.trim());
|
|
298
|
+
const monorepoRoot = resolveMonorepoRoot2(projectRoot);
|
|
299
|
+
const harnessRoot = resolve3(projectRoot, "rig");
|
|
300
|
+
const stateRoot = resolve3(projectRoot, ".rig");
|
|
301
|
+
const layout = hasRuntimeWorkspace ? resolveRigLayout(projectRoot) : null;
|
|
302
|
+
const stateDir = layout?.stateDir ?? resolve3(stateRoot, "state");
|
|
303
|
+
const logsDir = layout?.logsDir ?? resolve3(stateRoot, "logs");
|
|
304
|
+
const artifactsDir = layout?.artifactsRoot ?? resolve3(monorepoRoot, "artifacts");
|
|
305
|
+
const taskConfigPath = layout?.taskConfigPath ?? resolve3(monorepoRoot, ".rig", "task-config.json");
|
|
306
|
+
const binDir = layout?.binDir ?? resolve3(stateRoot, "bin");
|
|
307
|
+
return {
|
|
308
|
+
harnessRoot,
|
|
309
|
+
stateDir: process.env.RIG_STATE_DIR || stateDir,
|
|
310
|
+
artifactsDir,
|
|
311
|
+
logsDir: process.env.RIG_LOGS_DIR || logsDir,
|
|
312
|
+
binDir,
|
|
313
|
+
hooksDir: resolve3(harnessRoot, "hooks"),
|
|
314
|
+
validationDir: resolve3(harnessRoot, "validation"),
|
|
315
|
+
taskConfigPath,
|
|
316
|
+
sessionPath: process.env.RIG_SESSION_FILE || resolve3(stateRoot, "session", "session.json"),
|
|
317
|
+
monorepoRoot,
|
|
318
|
+
tsApiTestsDir: process.env.TS_API_TESTS_DIR || resolve3(monorepoRoot, "TSAPITests"),
|
|
319
|
+
taskRepoCommitsPath: resolve3(stateDir, "task-repo-commits.json"),
|
|
320
|
+
baseRepoPinsPath: resolve3(stateDir, "base-repo-pins.json"),
|
|
321
|
+
failedApproachesPath: resolve3(stateDir, "failed_approaches.md"),
|
|
322
|
+
agentProfilePath: resolve3(stateDir, "agent-profile.json"),
|
|
323
|
+
reviewProfilePath: resolve3(stateDir, "review-profile.json")
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// packages/runtime/src/control-plane/hooks/audit-trail.ts
|
|
328
|
+
async function main() {
|
|
329
|
+
const projectRoot = resolveProjectRoot();
|
|
330
|
+
const parsed = await readHookInput();
|
|
331
|
+
const input = parsed.input;
|
|
332
|
+
const paths = resolveHarnessPaths(projectRoot);
|
|
333
|
+
mkdirSync2(paths.logsDir, { recursive: true });
|
|
334
|
+
const taskId = resolveTaskIdForHook(projectRoot) || "unknown";
|
|
335
|
+
const tool = String(input.tool_name || "unknown");
|
|
336
|
+
const filePath = String(input.tool_input?.file_path || input.tool_input?.path || "none");
|
|
337
|
+
const command = String(input.tool_input?.command || input.tool_input?.cmd || "").slice(0, 180);
|
|
338
|
+
const payload = {
|
|
339
|
+
timestamp: new Date().toISOString(),
|
|
340
|
+
task: taskId,
|
|
341
|
+
tool,
|
|
342
|
+
path: filePath
|
|
343
|
+
};
|
|
344
|
+
if (tool === "Bash" && command) {
|
|
345
|
+
payload.command_preview = command;
|
|
346
|
+
}
|
|
347
|
+
appendFileSync(resolve4(paths.logsDir, "audit.jsonl"), `${JSON.stringify(payload)}
|
|
348
|
+
`, "utf-8");
|
|
349
|
+
}
|
|
350
|
+
main().catch((error) => {
|
|
351
|
+
console.error(error);
|
|
352
|
+
process.exit(1);
|
|
353
|
+
});
|