@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,599 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/runtime/isolation/discovery.ts
|
|
3
|
+
import { existsSync as existsSync4 } from "fs";
|
|
4
|
+
import { resolve as resolve8 } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/runtime/src/layout.ts
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
import { basename, dirname, resolve } from "path";
|
|
9
|
+
var RIG_ARTIFACTS_DIRNAME = "artifacts";
|
|
10
|
+
function resolveMonorepoRoot(projectRoot) {
|
|
11
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
12
|
+
const explicit = process.env.MONOREPO_ROOT?.trim();
|
|
13
|
+
if (explicit) {
|
|
14
|
+
const explicitRoot = resolve(explicit);
|
|
15
|
+
const explicitParent = dirname(explicitRoot);
|
|
16
|
+
if (basename(explicitParent) === ".worktrees") {
|
|
17
|
+
const owner = dirname(explicitParent);
|
|
18
|
+
const ownerHasGit = existsSync(resolve(owner, ".git"));
|
|
19
|
+
const ownerHasTaskConfig = existsSync(resolve(owner, ".rig", "task-config.json"));
|
|
20
|
+
const ownerHasRigConfig = existsSync(resolve(owner, "rig.config.ts"));
|
|
21
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
22
|
+
return owner;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`MONOREPO_ROOT points to worktree ${explicitRoot}, but the owner checkout is incomplete at ${owner}.`);
|
|
25
|
+
}
|
|
26
|
+
if (!existsSync(resolve(explicitRoot, ".git"))) {
|
|
27
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there.`);
|
|
28
|
+
}
|
|
29
|
+
const hasTaskConfig = existsSync(resolve(explicitRoot, ".rig", "task-config.json"));
|
|
30
|
+
const hasRigConfig = existsSync(resolve(explicitRoot, "rig.config.ts"));
|
|
31
|
+
if (!hasTaskConfig && !hasRigConfig) {
|
|
32
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but neither .rig/task-config.json nor rig.config.ts exists there.`);
|
|
33
|
+
}
|
|
34
|
+
return explicitRoot;
|
|
35
|
+
}
|
|
36
|
+
const projectParent = dirname(normalizedProjectRoot);
|
|
37
|
+
if (basename(projectParent) === ".worktrees") {
|
|
38
|
+
const worktreeOwner = dirname(projectParent);
|
|
39
|
+
const ownerHasGit = existsSync(resolve(worktreeOwner, ".git"));
|
|
40
|
+
const ownerHasTaskConfig = existsSync(resolve(worktreeOwner, ".rig", "task-config.json"));
|
|
41
|
+
const ownerHasRigConfig = existsSync(resolve(worktreeOwner, "rig.config.ts"));
|
|
42
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
43
|
+
return worktreeOwner;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return normalizedProjectRoot;
|
|
47
|
+
}
|
|
48
|
+
function resolveRuntimeWorkspaceLayout(workspaceDir) {
|
|
49
|
+
const root = resolve(workspaceDir);
|
|
50
|
+
const rigRoot = resolve(root, ".rig");
|
|
51
|
+
const logsDir = resolve(rigRoot, "logs");
|
|
52
|
+
const stateDir = resolve(rigRoot, "state");
|
|
53
|
+
const runtimeDir = resolve(rigRoot, "runtime");
|
|
54
|
+
const binDir = resolve(rigRoot, "bin");
|
|
55
|
+
return {
|
|
56
|
+
workspaceDir: root,
|
|
57
|
+
rigRoot,
|
|
58
|
+
stateDir,
|
|
59
|
+
logsDir,
|
|
60
|
+
artifactsRoot: resolve(root, RIG_ARTIFACTS_DIRNAME),
|
|
61
|
+
runtimeDir,
|
|
62
|
+
homeDir: resolve(rigRoot, "home"),
|
|
63
|
+
tmpDir: resolve(rigRoot, "tmp"),
|
|
64
|
+
cacheDir: resolve(rigRoot, "cache"),
|
|
65
|
+
sessionDir: resolve(rigRoot, "session"),
|
|
66
|
+
binDir,
|
|
67
|
+
distDir: resolve(rigRoot, "dist"),
|
|
68
|
+
pluginBinDir: resolve(binDir, "plugins"),
|
|
69
|
+
contextPath: resolve(rigRoot, "runtime-context.json"),
|
|
70
|
+
controlPlaneEventsFile: resolve(logsDir, "control-plane.events.jsonl")
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// packages/runtime/src/control-plane/native/runtime-native.ts
|
|
75
|
+
import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
|
|
76
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync, renameSync, rmSync, statSync } from "fs";
|
|
77
|
+
import { tmpdir } from "os";
|
|
78
|
+
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
79
|
+
var sharedNativeRuntimeOutputDir = resolve2(tmpdir(), "rig-native");
|
|
80
|
+
var sharedNativeRuntimeOutputPath = resolve2(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
|
|
81
|
+
var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
|
|
82
|
+
var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
|
|
83
|
+
function runtimeScanWorktreesNative(worktreesRoot) {
|
|
84
|
+
const response = runNativeRuntimeSidecar({
|
|
85
|
+
op: "scan-worktrees",
|
|
86
|
+
input: { worktreesRoot }
|
|
87
|
+
});
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
throw new Error(response.error);
|
|
90
|
+
}
|
|
91
|
+
return response.entries ?? [];
|
|
92
|
+
}
|
|
93
|
+
async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
|
|
94
|
+
if (await buildNativeRuntimeLibrary(outputPath, options)) {
|
|
95
|
+
return outputPath;
|
|
96
|
+
}
|
|
97
|
+
return !options.force && existsSync2(outputPath) ? outputPath : null;
|
|
98
|
+
}
|
|
99
|
+
async function loadNativeRuntimeLibrary() {
|
|
100
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
for (const candidate of nativeRuntimeLibraryCandidates()) {
|
|
104
|
+
if (!candidate || !existsSync2(candidate)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const loaded = tryDlopenNativeRuntimeLibrary(candidate);
|
|
108
|
+
if (loaded) {
|
|
109
|
+
return loaded;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
|
|
113
|
+
if (!builtLibraryPath) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
|
|
117
|
+
}
|
|
118
|
+
function nativePackageLibraryCandidates(fromDir, names) {
|
|
119
|
+
const candidates = [];
|
|
120
|
+
let cursor = resolve2(fromDir);
|
|
121
|
+
for (let index = 0;index < 8; index += 1) {
|
|
122
|
+
for (const name of names) {
|
|
123
|
+
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));
|
|
124
|
+
}
|
|
125
|
+
const parent = dirname2(cursor);
|
|
126
|
+
if (parent === cursor)
|
|
127
|
+
break;
|
|
128
|
+
cursor = parent;
|
|
129
|
+
}
|
|
130
|
+
return candidates;
|
|
131
|
+
}
|
|
132
|
+
function nativeRuntimeLibraryCandidates() {
|
|
133
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
|
|
134
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
135
|
+
const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
|
|
136
|
+
return [...new Set([
|
|
137
|
+
explicit,
|
|
138
|
+
...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
|
|
139
|
+
execDir ? resolve2(execDir, colocatedNativeRuntimeFileName) : "",
|
|
140
|
+
execDir ? resolve2(execDir, platformSpecific) : "",
|
|
141
|
+
execDir ? resolve2(execDir, "..", colocatedNativeRuntimeFileName) : "",
|
|
142
|
+
execDir ? resolve2(execDir, "..", platformSpecific) : "",
|
|
143
|
+
execDir ? resolve2(execDir, "lib", colocatedNativeRuntimeFileName) : "",
|
|
144
|
+
execDir ? resolve2(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
|
|
145
|
+
sharedNativeRuntimeOutputPath
|
|
146
|
+
].filter(Boolean))];
|
|
147
|
+
}
|
|
148
|
+
function resolveNativeRuntimeSourcePath() {
|
|
149
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
|
|
150
|
+
if (explicit && existsSync2(explicit)) {
|
|
151
|
+
return explicit;
|
|
152
|
+
}
|
|
153
|
+
const bundled = resolve2(import.meta.dir, "../../../native/snapshot.zig");
|
|
154
|
+
return existsSync2(bundled) ? bundled : null;
|
|
155
|
+
}
|
|
156
|
+
function resolveNativeRuntimeSidecarSourcePath() {
|
|
157
|
+
const envRoots = [
|
|
158
|
+
process.cwd()?.trim(),
|
|
159
|
+
process.env.RIG_HOST_PROJECT_ROOT?.trim(),
|
|
160
|
+
process.env.PROJECT_RIG_ROOT?.trim()
|
|
161
|
+
].filter(Boolean);
|
|
162
|
+
for (const root of envRoots) {
|
|
163
|
+
for (const relative of [
|
|
164
|
+
"packages/runtime/src/control-plane/native/runtime-native-sidecar.ts",
|
|
165
|
+
"packages/runtime/dist/src/control-plane/native/runtime-native-sidecar.js"
|
|
166
|
+
]) {
|
|
167
|
+
const candidate = resolve2(root, relative);
|
|
168
|
+
if (existsSync2(candidate)) {
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const localCandidate of [
|
|
174
|
+
resolve2(import.meta.dir, "runtime-native-sidecar.js"),
|
|
175
|
+
resolve2(import.meta.dir, "runtime-native-sidecar.ts")
|
|
176
|
+
]) {
|
|
177
|
+
if (existsSync2(localCandidate))
|
|
178
|
+
return localCandidate;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
async function buildNativeRuntimeLibrary(outputPath, options = {}) {
|
|
183
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
const zigBinary = Bun.which("zig");
|
|
187
|
+
const sourcePath = resolveNativeRuntimeSourcePath();
|
|
188
|
+
if (!zigBinary || !sourcePath) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
192
|
+
try {
|
|
193
|
+
mkdirSync(dirname2(outputPath), { recursive: true });
|
|
194
|
+
const needsBuild = options.force === true || !existsSync2(outputPath) || statSync(sourcePath).mtimeMs > statSync(outputPath).mtimeMs;
|
|
195
|
+
if (!needsBuild) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
const build = Bun.spawn([
|
|
199
|
+
zigBinary,
|
|
200
|
+
"build-lib",
|
|
201
|
+
sourcePath,
|
|
202
|
+
"-dynamic",
|
|
203
|
+
"-O",
|
|
204
|
+
"ReleaseFast",
|
|
205
|
+
`-femit-bin=${tempOutputPath}`
|
|
206
|
+
], {
|
|
207
|
+
cwd: import.meta.dir,
|
|
208
|
+
stdout: "pipe",
|
|
209
|
+
stderr: "pipe"
|
|
210
|
+
});
|
|
211
|
+
const exitCode = await build.exited;
|
|
212
|
+
if (exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
213
|
+
rmSync(tempOutputPath, { force: true });
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
renameSync(tempOutputPath, outputPath);
|
|
217
|
+
return true;
|
|
218
|
+
} catch {
|
|
219
|
+
rmSync(tempOutputPath, { force: true });
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function tryDlopenNativeRuntimeLibrary(outputPath) {
|
|
224
|
+
try {
|
|
225
|
+
return dlopen(outputPath, {
|
|
226
|
+
rig_scope_match: {
|
|
227
|
+
args: ["ptr", "ptr"],
|
|
228
|
+
returns: "u8"
|
|
229
|
+
},
|
|
230
|
+
snapshot_capture: {
|
|
231
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
232
|
+
returns: "ptr"
|
|
233
|
+
},
|
|
234
|
+
snapshot_delta: {
|
|
235
|
+
args: ["ptr", "ptr"],
|
|
236
|
+
returns: "ptr"
|
|
237
|
+
},
|
|
238
|
+
snapshot_store_delta: {
|
|
239
|
+
args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
240
|
+
returns: "ptr"
|
|
241
|
+
},
|
|
242
|
+
snapshot_inspect_delta: {
|
|
243
|
+
args: ["ptr", "u64"],
|
|
244
|
+
returns: "ptr"
|
|
245
|
+
},
|
|
246
|
+
snapshot_apply_delta: {
|
|
247
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
248
|
+
returns: "ptr"
|
|
249
|
+
},
|
|
250
|
+
snapshot_release: {
|
|
251
|
+
args: ["ptr"],
|
|
252
|
+
returns: "void"
|
|
253
|
+
},
|
|
254
|
+
runtime_hash_file: {
|
|
255
|
+
args: ["ptr", "u64"],
|
|
256
|
+
returns: "ptr"
|
|
257
|
+
},
|
|
258
|
+
runtime_hash_tree: {
|
|
259
|
+
args: ["ptr", "u64"],
|
|
260
|
+
returns: "ptr"
|
|
261
|
+
},
|
|
262
|
+
runtime_prepare_paths: {
|
|
263
|
+
args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
264
|
+
returns: "ptr"
|
|
265
|
+
},
|
|
266
|
+
runtime_link_dependency_layer: {
|
|
267
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
268
|
+
returns: "ptr"
|
|
269
|
+
},
|
|
270
|
+
runtime_scan_worktrees: {
|
|
271
|
+
args: ["ptr", "u64"],
|
|
272
|
+
returns: "ptr"
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
} catch {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function runNativeRuntimeSidecar(request) {
|
|
280
|
+
const sidecarSourcePath = resolveNativeRuntimeSidecarSourcePath();
|
|
281
|
+
if (!sidecarSourcePath) {
|
|
282
|
+
throw new Error("runtime-native-sidecar.ts source file not found.");
|
|
283
|
+
}
|
|
284
|
+
const bunCli = resolveNativeRuntimeSidecarInvocation();
|
|
285
|
+
const proc = Bun.spawnSync([bunCli.command, sidecarSourcePath, JSON.stringify(request)], {
|
|
286
|
+
cwd: process.env.RIG_HOST_PROJECT_ROOT?.trim() || process.cwd(),
|
|
287
|
+
stdout: "pipe",
|
|
288
|
+
stderr: "pipe",
|
|
289
|
+
env: {
|
|
290
|
+
...process.env,
|
|
291
|
+
...bunCli.env,
|
|
292
|
+
RIG_NATIVE_RUNTIME_SIDECAR: "1"
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
if (proc.exitCode !== 0) {
|
|
296
|
+
throw new Error(proc.stderr.toString() || proc.stdout.toString() || `runtime native sidecar exited ${proc.exitCode}`);
|
|
297
|
+
}
|
|
298
|
+
const stdout = proc.stdout.toString().trim();
|
|
299
|
+
if (!stdout) {
|
|
300
|
+
throw new Error("runtime native sidecar returned empty output.");
|
|
301
|
+
}
|
|
302
|
+
return JSON.parse(stdout);
|
|
303
|
+
}
|
|
304
|
+
function resolveNativeRuntimeSidecarInvocation() {
|
|
305
|
+
const bunPath = Bun.which("bun");
|
|
306
|
+
if (bunPath) {
|
|
307
|
+
return { command: bunPath, env: {} };
|
|
308
|
+
}
|
|
309
|
+
if (process.execPath?.trim()) {
|
|
310
|
+
return {
|
|
311
|
+
command: process.execPath,
|
|
312
|
+
env: { BUN_BE_BUN: "1" }
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
throw new Error("bun is required to run the runtime native sidecar.");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// packages/runtime/src/control-plane/runtime/context.ts
|
|
319
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync, writeFileSync } from "fs";
|
|
320
|
+
import { dirname as dirname3, resolve as resolve3 } from "path";
|
|
321
|
+
var runtimeContextStringFields = [
|
|
322
|
+
"runtimeId",
|
|
323
|
+
"taskId",
|
|
324
|
+
"role",
|
|
325
|
+
"workspaceDir",
|
|
326
|
+
"stateDir",
|
|
327
|
+
"logsDir",
|
|
328
|
+
"sessionDir",
|
|
329
|
+
"sessionFile",
|
|
330
|
+
"policyFile",
|
|
331
|
+
"binDir",
|
|
332
|
+
"createdAt"
|
|
333
|
+
];
|
|
334
|
+
var runtimeContextArrayFields = ["scopes", "validation"];
|
|
335
|
+
var runtimeContextOptionalStringFields = [
|
|
336
|
+
"artifactRoot",
|
|
337
|
+
"hostProjectRoot",
|
|
338
|
+
"monorepoMainRoot",
|
|
339
|
+
"monorepoBaseRef",
|
|
340
|
+
"monorepoBaseCommit"
|
|
341
|
+
];
|
|
342
|
+
function loadRuntimeContext(path) {
|
|
343
|
+
const absPath = resolve3(path);
|
|
344
|
+
if (!existsSync3(absPath)) {
|
|
345
|
+
throw new Error(`RuntimeTaskContext file not found: ${absPath}`);
|
|
346
|
+
}
|
|
347
|
+
let raw;
|
|
348
|
+
try {
|
|
349
|
+
raw = JSON.parse(readFileSync(absPath, "utf8"));
|
|
350
|
+
} catch (err) {
|
|
351
|
+
throw new Error(`Failed to parse RuntimeTaskContext at ${absPath}: ${String(err)}`);
|
|
352
|
+
}
|
|
353
|
+
if (typeof raw !== "object" || raw === null) {
|
|
354
|
+
throw new Error(`RuntimeTaskContext at ${absPath} is not an object`);
|
|
355
|
+
}
|
|
356
|
+
const obj = raw;
|
|
357
|
+
for (const field of runtimeContextStringFields) {
|
|
358
|
+
if (typeof obj[field] !== "string" || obj[field].length === 0) {
|
|
359
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a non-empty string (at ${absPath})`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
for (const field of runtimeContextArrayFields) {
|
|
363
|
+
if (!Array.isArray(obj[field])) {
|
|
364
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be an array (at ${absPath})`);
|
|
365
|
+
}
|
|
366
|
+
if (!obj[field].every((entry) => typeof entry === "string")) {
|
|
367
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string[] (at ${absPath})`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
for (const field of runtimeContextOptionalStringFields) {
|
|
371
|
+
if (field in obj && obj[field] !== undefined && typeof obj[field] !== "string") {
|
|
372
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string when present (at ${absPath})`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (obj.browser !== undefined) {
|
|
376
|
+
if (typeof obj.browser !== "object" || obj.browser === null || Array.isArray(obj.browser)) {
|
|
377
|
+
throw new Error(`RuntimeTaskContext field "browser" must be an object when present (at ${absPath})`);
|
|
378
|
+
}
|
|
379
|
+
const browser = obj.browser;
|
|
380
|
+
for (const field of [
|
|
381
|
+
"preset",
|
|
382
|
+
"mode",
|
|
383
|
+
"stateDir",
|
|
384
|
+
"defaultProfile",
|
|
385
|
+
"effectiveProfile",
|
|
386
|
+
"defaultAttachUrl",
|
|
387
|
+
"effectiveAttachUrl",
|
|
388
|
+
"launchHelper",
|
|
389
|
+
"checkHelper",
|
|
390
|
+
"attachInfoHelper",
|
|
391
|
+
"e2eHelper",
|
|
392
|
+
"resetProfileHelper"
|
|
393
|
+
]) {
|
|
394
|
+
if (typeof browser[field] !== "string" || browser[field].length === 0) {
|
|
395
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a non-empty string (at ${absPath})`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
for (const field of ["devCommand", "launchCommand", "checkCommand", "e2eCommand"]) {
|
|
399
|
+
if (browser[field] !== undefined && typeof browser[field] !== "string") {
|
|
400
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a string when present (at ${absPath})`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (typeof browser.required !== "boolean") {
|
|
404
|
+
throw new Error(`RuntimeTaskContext field "browser.required" must be a boolean (at ${absPath})`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (obj.memory !== undefined) {
|
|
408
|
+
if (typeof obj.memory !== "object" || obj.memory === null || Array.isArray(obj.memory)) {
|
|
409
|
+
throw new Error(`RuntimeTaskContext field "memory" must be an object when present (at ${absPath})`);
|
|
410
|
+
}
|
|
411
|
+
const memory = obj.memory;
|
|
412
|
+
for (const field of ["canonicalPath", "canonicalRef", "canonicalBaseOid", "hydratedPath"]) {
|
|
413
|
+
if (typeof memory[field] !== "string" || memory[field].length === 0) {
|
|
414
|
+
throw new Error(`RuntimeTaskContext field "memory.${field}" must be a non-empty string (at ${absPath})`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (typeof memory.createdFresh !== "boolean") {
|
|
418
|
+
throw new Error(`RuntimeTaskContext field "memory.createdFresh" must be a boolean (at ${absPath})`);
|
|
419
|
+
}
|
|
420
|
+
if (typeof memory.retrieval !== "object" || memory.retrieval === null || Array.isArray(memory.retrieval)) {
|
|
421
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval" must be an object (at ${absPath})`);
|
|
422
|
+
}
|
|
423
|
+
const retrieval = memory.retrieval;
|
|
424
|
+
for (const field of ["topK", "lexicalWeight", "vectorWeight", "recencyWeight", "confidenceWeight"]) {
|
|
425
|
+
if (typeof retrieval[field] !== "number" || Number.isNaN(retrieval[field])) {
|
|
426
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval.${field}" must be a number (at ${absPath})`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (obj.initialDirtyFiles !== undefined) {
|
|
431
|
+
if (typeof obj.initialDirtyFiles !== "object" || obj.initialDirtyFiles === null || Array.isArray(obj.initialDirtyFiles)) {
|
|
432
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles" must be an object when present (at ${absPath})`);
|
|
433
|
+
}
|
|
434
|
+
const dirtyFiles = obj.initialDirtyFiles;
|
|
435
|
+
for (const key of ["project", "monorepo"]) {
|
|
436
|
+
if (dirtyFiles[key] === undefined) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (!Array.isArray(dirtyFiles[key]) || !dirtyFiles[key].every((entry) => typeof entry === "string")) {
|
|
440
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles.${key}" must be a string[] when present (at ${absPath})`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (obj.initialHeadCommits !== undefined) {
|
|
445
|
+
if (typeof obj.initialHeadCommits !== "object" || obj.initialHeadCommits === null || Array.isArray(obj.initialHeadCommits)) {
|
|
446
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits" must be an object when present (at ${absPath})`);
|
|
447
|
+
}
|
|
448
|
+
const headCommits = obj.initialHeadCommits;
|
|
449
|
+
for (const key of ["project", "monorepo"]) {
|
|
450
|
+
if (headCommits[key] === undefined) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (typeof headCommits[key] !== "string") {
|
|
454
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits.${key}" must be a string when present (at ${absPath})`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return obj;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// packages/runtime/src/control-plane/native/utils.ts
|
|
462
|
+
function resolveMonorepoRoot2(projectRoot) {
|
|
463
|
+
return resolveMonorepoRoot(projectRoot);
|
|
464
|
+
}
|
|
465
|
+
var scopeRegexCache = new Map;
|
|
466
|
+
|
|
467
|
+
// packages/runtime/src/control-plane/runtime/isolation/shared.ts
|
|
468
|
+
var generatedCredentialFiles = new Set;
|
|
469
|
+
function resolveMonorepoRoot3(projectRoot) {
|
|
470
|
+
return resolveMonorepoRoot2(projectRoot);
|
|
471
|
+
}
|
|
472
|
+
function sanitizeRuntimeRefSegment(value) {
|
|
473
|
+
const sanitized = value.trim().replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
474
|
+
return (sanitized || "runtime").slice(0, 64);
|
|
475
|
+
}
|
|
476
|
+
function taskRuntimeId(taskId) {
|
|
477
|
+
return `task-${taskId}`;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// packages/runtime/src/control-plane/runtime/isolation/worktree.ts
|
|
481
|
+
function runtimeWorktreeNameFromRuntimeId(runtimeId) {
|
|
482
|
+
return sanitizeRuntimeRefSegment(runtimeId.replace(/^task-/, ""));
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// packages/runtime/src/binary-run.ts
|
|
486
|
+
var runtimeBinaryBuildQueue = Promise.resolve();
|
|
487
|
+
|
|
488
|
+
// packages/runtime/src/control-plane/native/git-native.ts
|
|
489
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
490
|
+
import { dirname as dirname4, isAbsolute, resolve as resolve4 } from "path";
|
|
491
|
+
var sharedGitNativeOutputDir = resolve4(tmpdir2(), "rig-native");
|
|
492
|
+
var sharedGitNativeOutputPath = resolve4(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
493
|
+
// packages/runtime/src/control-plane/runtime/tooling/shell.ts
|
|
494
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
495
|
+
import { basename as basename2, dirname as dirname5, resolve as resolve5 } from "path";
|
|
496
|
+
var sharedNativeShellOutputDir = resolve5(tmpdir3(), "rig-native");
|
|
497
|
+
var sharedNativeShellOutputPath = resolve5(sharedNativeShellOutputDir, `rig-shell-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
498
|
+
// packages/runtime/src/control-plane/runtime/tooling/file-tools.ts
|
|
499
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
500
|
+
import { basename as basename3, dirname as dirname6, resolve as resolve6 } from "path";
|
|
501
|
+
var sharedNativeToolsOutputDir = resolve6(tmpdir4(), "rig-native");
|
|
502
|
+
var sharedNativeToolsOutputPath = resolve6(sharedNativeToolsOutputDir, `rig-tools-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
503
|
+
// packages/runtime/src/control-plane/runtime/tooling/claude-router-binary.ts
|
|
504
|
+
import { tmpdir as tmpdir5 } from "os";
|
|
505
|
+
import { dirname as dirname7, resolve as resolve7 } from "path";
|
|
506
|
+
var sharedRouterOutputDir = resolve7(tmpdir5(), "rig-native");
|
|
507
|
+
var sharedRouterOutputPath = resolve7(sharedRouterOutputDir, `rig-tool-router-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
508
|
+
// packages/runtime/src/control-plane/runtime/isolation/toolchain.ts
|
|
509
|
+
function runtimeWorktreeId(workspaceDir) {
|
|
510
|
+
return workspaceDir.split("/").at(-1) || "runtime";
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// packages/runtime/src/control-plane/runtime/isolation/discovery.ts
|
|
514
|
+
async function readRuntimeMetadata(metadataPath) {
|
|
515
|
+
if (!existsSync4(metadataPath)) {
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
return await Bun.file(metadataPath).json();
|
|
520
|
+
} catch {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
async function listAgentRuntimes(projectRoot) {
|
|
525
|
+
const runtimes = [];
|
|
526
|
+
const monorepoRoot = resolveMonorepoRoot3(projectRoot);
|
|
527
|
+
const worktreesRoot = resolve8(monorepoRoot, ".worktrees");
|
|
528
|
+
if (!existsSync4(worktreesRoot)) {
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
531
|
+
const workspaces = runtimeScanWorktreesNative(worktreesRoot);
|
|
532
|
+
for (let scan of workspaces) {
|
|
533
|
+
let workspacePath = scan.workspaceDir;
|
|
534
|
+
const workspaceLayout = resolveRuntimeWorkspaceLayout(workspacePath);
|
|
535
|
+
const rootDir = scan.runtimeDir || workspaceLayout.runtimeDir;
|
|
536
|
+
const metadataPath = scan.metadataPath || resolve8(rootDir, "runtime.json");
|
|
537
|
+
const contextFile = scan.contextPath || workspaceLayout.contextPath;
|
|
538
|
+
let mode = "worktree";
|
|
539
|
+
let createdAt = new Date().toISOString();
|
|
540
|
+
let taskId = "";
|
|
541
|
+
let runtimeId = "";
|
|
542
|
+
let binDir = workspaceLayout.binDir;
|
|
543
|
+
let logsDir = workspaceLayout.logsDir;
|
|
544
|
+
let stateDir = workspaceLayout.stateDir;
|
|
545
|
+
let sessionDir = workspaceLayout.sessionDir;
|
|
546
|
+
const metadata = await readRuntimeMetadata(metadataPath);
|
|
547
|
+
if (metadata) {
|
|
548
|
+
runtimeId = metadata.id;
|
|
549
|
+
mode = metadata.mode;
|
|
550
|
+
createdAt = metadata.createdAt;
|
|
551
|
+
}
|
|
552
|
+
if (existsSync4(contextFile)) {
|
|
553
|
+
try {
|
|
554
|
+
const ctx = loadRuntimeContext(contextFile);
|
|
555
|
+
taskId = ctx.taskId;
|
|
556
|
+
workspacePath = ctx.workspaceDir;
|
|
557
|
+
binDir = ctx.binDir;
|
|
558
|
+
logsDir = ctx.logsDir;
|
|
559
|
+
stateDir = ctx.stateDir;
|
|
560
|
+
sessionDir = ctx.sessionDir;
|
|
561
|
+
} catch {}
|
|
562
|
+
}
|
|
563
|
+
if (!runtimeId) {
|
|
564
|
+
runtimeId = taskRuntimeId(taskId || runtimeWorktreeId(workspacePath));
|
|
565
|
+
}
|
|
566
|
+
runtimes.push({
|
|
567
|
+
id: runtimeId,
|
|
568
|
+
taskId,
|
|
569
|
+
mode,
|
|
570
|
+
rootDir,
|
|
571
|
+
workspaceDir: workspacePath,
|
|
572
|
+
homeDir: resolve8(rootDir, "home"),
|
|
573
|
+
tmpDir: resolve8(rootDir, "tmp"),
|
|
574
|
+
cacheDir: resolve8(rootDir, "cache"),
|
|
575
|
+
logsDir,
|
|
576
|
+
stateDir,
|
|
577
|
+
sessionDir,
|
|
578
|
+
claudeHomeDir: resolve8(rootDir, "home", ".claude"),
|
|
579
|
+
contextFile,
|
|
580
|
+
binDir,
|
|
581
|
+
createdAt
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
return runtimes;
|
|
585
|
+
}
|
|
586
|
+
function runtimeRootForCleanup(projectRoot, runtimeId) {
|
|
587
|
+
let monorepoRoot = null;
|
|
588
|
+
try {
|
|
589
|
+
monorepoRoot = resolveMonorepoRoot3(projectRoot);
|
|
590
|
+
} catch {}
|
|
591
|
+
const workspaceRootCandidate = monorepoRoot ?? projectRoot;
|
|
592
|
+
const initialWorkspaceDir = resolve8(workspaceRootCandidate, ".worktrees", runtimeWorktreeNameFromRuntimeId(runtimeId));
|
|
593
|
+
const runtimeRoot = resolveRuntimeWorkspaceLayout(initialWorkspaceDir).runtimeDir;
|
|
594
|
+
return { monorepoRoot, initialWorkspaceDir, runtimeRoot };
|
|
595
|
+
}
|
|
596
|
+
export {
|
|
597
|
+
runtimeRootForCleanup,
|
|
598
|
+
listAgentRuntimes
|
|
599
|
+
};
|