@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,683 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/validators/shared.ts
|
|
3
|
+
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
4
|
+
import { resolve as resolve5 } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/runtime/src/build-time-config.ts
|
|
7
|
+
function normalizeBuildConfig(value) {
|
|
8
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
12
|
+
}
|
|
13
|
+
function readBuildConfig() {
|
|
14
|
+
if (typeof __RIG_BUILD_CONFIG__ !== "undefined") {
|
|
15
|
+
return normalizeBuildConfig(__RIG_BUILD_CONFIG__);
|
|
16
|
+
}
|
|
17
|
+
const raw = process.env.RIG_BUILD_CONFIG_JSON?.trim();
|
|
18
|
+
if (!raw) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return normalizeBuildConfig(JSON.parse(raw));
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// packages/runtime/src/control-plane/runtime/context.ts
|
|
29
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
30
|
+
import { dirname, resolve } from "path";
|
|
31
|
+
var RUNTIME_CONTEXT_ENV = "RIG_RUNTIME_CONTEXT_FILE";
|
|
32
|
+
var runtimeContextStringFields = [
|
|
33
|
+
"runtimeId",
|
|
34
|
+
"taskId",
|
|
35
|
+
"role",
|
|
36
|
+
"workspaceDir",
|
|
37
|
+
"stateDir",
|
|
38
|
+
"logsDir",
|
|
39
|
+
"sessionDir",
|
|
40
|
+
"sessionFile",
|
|
41
|
+
"policyFile",
|
|
42
|
+
"binDir",
|
|
43
|
+
"createdAt"
|
|
44
|
+
];
|
|
45
|
+
var runtimeContextArrayFields = ["scopes", "validation"];
|
|
46
|
+
var runtimeContextOptionalStringFields = [
|
|
47
|
+
"artifactRoot",
|
|
48
|
+
"hostProjectRoot",
|
|
49
|
+
"monorepoMainRoot",
|
|
50
|
+
"monorepoBaseRef",
|
|
51
|
+
"monorepoBaseCommit"
|
|
52
|
+
];
|
|
53
|
+
function loadRuntimeContext(path) {
|
|
54
|
+
const absPath = resolve(path);
|
|
55
|
+
if (!existsSync(absPath)) {
|
|
56
|
+
throw new Error(`RuntimeTaskContext file not found: ${absPath}`);
|
|
57
|
+
}
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(readFileSync(absPath, "utf8"));
|
|
61
|
+
} catch (err) {
|
|
62
|
+
throw new Error(`Failed to parse RuntimeTaskContext at ${absPath}: ${String(err)}`);
|
|
63
|
+
}
|
|
64
|
+
if (typeof raw !== "object" || raw === null) {
|
|
65
|
+
throw new Error(`RuntimeTaskContext at ${absPath} is not an object`);
|
|
66
|
+
}
|
|
67
|
+
const obj = raw;
|
|
68
|
+
for (const field of runtimeContextStringFields) {
|
|
69
|
+
if (typeof obj[field] !== "string" || obj[field].length === 0) {
|
|
70
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a non-empty string (at ${absPath})`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const field of runtimeContextArrayFields) {
|
|
74
|
+
if (!Array.isArray(obj[field])) {
|
|
75
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be an array (at ${absPath})`);
|
|
76
|
+
}
|
|
77
|
+
if (!obj[field].every((entry) => typeof entry === "string")) {
|
|
78
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string[] (at ${absPath})`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const field of runtimeContextOptionalStringFields) {
|
|
82
|
+
if (field in obj && obj[field] !== undefined && typeof obj[field] !== "string") {
|
|
83
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string when present (at ${absPath})`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (obj.browser !== undefined) {
|
|
87
|
+
if (typeof obj.browser !== "object" || obj.browser === null || Array.isArray(obj.browser)) {
|
|
88
|
+
throw new Error(`RuntimeTaskContext field "browser" must be an object when present (at ${absPath})`);
|
|
89
|
+
}
|
|
90
|
+
const browser = obj.browser;
|
|
91
|
+
for (const field of [
|
|
92
|
+
"preset",
|
|
93
|
+
"mode",
|
|
94
|
+
"stateDir",
|
|
95
|
+
"defaultProfile",
|
|
96
|
+
"effectiveProfile",
|
|
97
|
+
"defaultAttachUrl",
|
|
98
|
+
"effectiveAttachUrl",
|
|
99
|
+
"launchHelper",
|
|
100
|
+
"checkHelper",
|
|
101
|
+
"attachInfoHelper",
|
|
102
|
+
"e2eHelper",
|
|
103
|
+
"resetProfileHelper"
|
|
104
|
+
]) {
|
|
105
|
+
if (typeof browser[field] !== "string" || browser[field].length === 0) {
|
|
106
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a non-empty string (at ${absPath})`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const field of ["devCommand", "launchCommand", "checkCommand", "e2eCommand"]) {
|
|
110
|
+
if (browser[field] !== undefined && typeof browser[field] !== "string") {
|
|
111
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a string when present (at ${absPath})`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (typeof browser.required !== "boolean") {
|
|
115
|
+
throw new Error(`RuntimeTaskContext field "browser.required" must be a boolean (at ${absPath})`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (obj.memory !== undefined) {
|
|
119
|
+
if (typeof obj.memory !== "object" || obj.memory === null || Array.isArray(obj.memory)) {
|
|
120
|
+
throw new Error(`RuntimeTaskContext field "memory" must be an object when present (at ${absPath})`);
|
|
121
|
+
}
|
|
122
|
+
const memory = obj.memory;
|
|
123
|
+
for (const field of ["canonicalPath", "canonicalRef", "canonicalBaseOid", "hydratedPath"]) {
|
|
124
|
+
if (typeof memory[field] !== "string" || memory[field].length === 0) {
|
|
125
|
+
throw new Error(`RuntimeTaskContext field "memory.${field}" must be a non-empty string (at ${absPath})`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (typeof memory.createdFresh !== "boolean") {
|
|
129
|
+
throw new Error(`RuntimeTaskContext field "memory.createdFresh" must be a boolean (at ${absPath})`);
|
|
130
|
+
}
|
|
131
|
+
if (typeof memory.retrieval !== "object" || memory.retrieval === null || Array.isArray(memory.retrieval)) {
|
|
132
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval" must be an object (at ${absPath})`);
|
|
133
|
+
}
|
|
134
|
+
const retrieval = memory.retrieval;
|
|
135
|
+
for (const field of ["topK", "lexicalWeight", "vectorWeight", "recencyWeight", "confidenceWeight"]) {
|
|
136
|
+
if (typeof retrieval[field] !== "number" || Number.isNaN(retrieval[field])) {
|
|
137
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval.${field}" must be a number (at ${absPath})`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (obj.initialDirtyFiles !== undefined) {
|
|
142
|
+
if (typeof obj.initialDirtyFiles !== "object" || obj.initialDirtyFiles === null || Array.isArray(obj.initialDirtyFiles)) {
|
|
143
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles" must be an object when present (at ${absPath})`);
|
|
144
|
+
}
|
|
145
|
+
const dirtyFiles = obj.initialDirtyFiles;
|
|
146
|
+
for (const key of ["project", "monorepo"]) {
|
|
147
|
+
if (dirtyFiles[key] === undefined) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (!Array.isArray(dirtyFiles[key]) || !dirtyFiles[key].every((entry) => typeof entry === "string")) {
|
|
151
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles.${key}" must be a string[] when present (at ${absPath})`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (obj.initialHeadCommits !== undefined) {
|
|
156
|
+
if (typeof obj.initialHeadCommits !== "object" || obj.initialHeadCommits === null || Array.isArray(obj.initialHeadCommits)) {
|
|
157
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits" must be an object when present (at ${absPath})`);
|
|
158
|
+
}
|
|
159
|
+
const headCommits = obj.initialHeadCommits;
|
|
160
|
+
for (const key of ["project", "monorepo"]) {
|
|
161
|
+
if (headCommits[key] === undefined) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (typeof headCommits[key] !== "string") {
|
|
165
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits.${key}" must be a string when present (at ${absPath})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return obj;
|
|
170
|
+
}
|
|
171
|
+
function loadRuntimeContextFromEnv(env = process.env) {
|
|
172
|
+
const contextFile = env[RUNTIME_CONTEXT_ENV];
|
|
173
|
+
if (contextFile) {
|
|
174
|
+
return loadRuntimeContext(contextFile);
|
|
175
|
+
}
|
|
176
|
+
const inferred = findRuntimeContextFile(process.cwd());
|
|
177
|
+
if (!inferred) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return loadRuntimeContext(inferred);
|
|
181
|
+
}
|
|
182
|
+
function findRuntimeContextFile(startPath) {
|
|
183
|
+
let current = resolve(startPath);
|
|
184
|
+
while (true) {
|
|
185
|
+
const candidate = resolve(current, "runtime-context.json");
|
|
186
|
+
if (existsSync(candidate) && isAgentRuntimeContextPath(candidate)) {
|
|
187
|
+
return candidate;
|
|
188
|
+
}
|
|
189
|
+
const parent = dirname(current);
|
|
190
|
+
if (parent === current) {
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
current = parent;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function isAgentRuntimeContextPath(path) {
|
|
197
|
+
const normalized = path.replace(/\\/g, "/");
|
|
198
|
+
return /\/\.rig\/runtime-context\.json$/.test(normalized);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// packages/runtime/src/control-plane/runtime/runtime-paths.ts
|
|
202
|
+
import { existsSync as existsSync3, readdirSync, realpathSync } from "fs";
|
|
203
|
+
import { resolve as resolve3 } from "path";
|
|
204
|
+
|
|
205
|
+
// packages/runtime/src/layout.ts
|
|
206
|
+
import { existsSync as existsSync2 } from "fs";
|
|
207
|
+
import { basename, dirname as dirname2, resolve as resolve2 } from "path";
|
|
208
|
+
function resolveMonorepoRoot(projectRoot) {
|
|
209
|
+
const normalizedProjectRoot = resolve2(projectRoot);
|
|
210
|
+
const explicit = process.env.MONOREPO_ROOT?.trim();
|
|
211
|
+
if (explicit) {
|
|
212
|
+
const explicitRoot = resolve2(explicit);
|
|
213
|
+
const explicitParent = dirname2(explicitRoot);
|
|
214
|
+
if (basename(explicitParent) === ".worktrees") {
|
|
215
|
+
const owner = dirname2(explicitParent);
|
|
216
|
+
const ownerHasGit = existsSync2(resolve2(owner, ".git"));
|
|
217
|
+
const ownerHasTaskConfig = existsSync2(resolve2(owner, ".rig", "task-config.json"));
|
|
218
|
+
const ownerHasRigConfig = existsSync2(resolve2(owner, "rig.config.ts"));
|
|
219
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
220
|
+
return owner;
|
|
221
|
+
}
|
|
222
|
+
throw new Error(`MONOREPO_ROOT points to worktree ${explicitRoot}, but the owner checkout is incomplete at ${owner}.`);
|
|
223
|
+
}
|
|
224
|
+
if (!existsSync2(resolve2(explicitRoot, ".git"))) {
|
|
225
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there.`);
|
|
226
|
+
}
|
|
227
|
+
const hasTaskConfig = existsSync2(resolve2(explicitRoot, ".rig", "task-config.json"));
|
|
228
|
+
const hasRigConfig = existsSync2(resolve2(explicitRoot, "rig.config.ts"));
|
|
229
|
+
if (!hasTaskConfig && !hasRigConfig) {
|
|
230
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but neither .rig/task-config.json nor rig.config.ts exists there.`);
|
|
231
|
+
}
|
|
232
|
+
return explicitRoot;
|
|
233
|
+
}
|
|
234
|
+
const projectParent = dirname2(normalizedProjectRoot);
|
|
235
|
+
if (basename(projectParent) === ".worktrees") {
|
|
236
|
+
const worktreeOwner = dirname2(projectParent);
|
|
237
|
+
const ownerHasGit = existsSync2(resolve2(worktreeOwner, ".git"));
|
|
238
|
+
const ownerHasTaskConfig = existsSync2(resolve2(worktreeOwner, ".rig", "task-config.json"));
|
|
239
|
+
const ownerHasRigConfig = existsSync2(resolve2(worktreeOwner, "rig.config.ts"));
|
|
240
|
+
if (ownerHasGit && (ownerHasTaskConfig || ownerHasRigConfig)) {
|
|
241
|
+
return worktreeOwner;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return normalizedProjectRoot;
|
|
245
|
+
}
|
|
246
|
+
// packages/runtime/src/control-plane/runtime/runtime-paths.ts
|
|
247
|
+
function resolveBunBinaryPath() {
|
|
248
|
+
const explicit = normalizeExecutablePath(process.env.RIG_BUN_PATH?.trim());
|
|
249
|
+
if (explicit) {
|
|
250
|
+
return explicit;
|
|
251
|
+
}
|
|
252
|
+
const pathBun = normalizeExecutablePath(Bun.which("bun")?.trim());
|
|
253
|
+
if (pathBun && !looksLikeRuntimeGateway(pathBun)) {
|
|
254
|
+
return pathBun;
|
|
255
|
+
}
|
|
256
|
+
const home = process.env.HOME?.trim();
|
|
257
|
+
const fallbackCandidates = [
|
|
258
|
+
home ? resolve3(home, ".bun/bin/bun") : "",
|
|
259
|
+
"/opt/homebrew/bin/bun",
|
|
260
|
+
"/usr/local/bin/bun",
|
|
261
|
+
"/usr/bin/bun"
|
|
262
|
+
];
|
|
263
|
+
for (const candidate of fallbackCandidates) {
|
|
264
|
+
const normalized = normalizeExecutablePath(candidate);
|
|
265
|
+
if (normalized) {
|
|
266
|
+
return normalized;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const execPath = normalizeExecutablePath(process.execPath?.trim());
|
|
270
|
+
if (execPath && !looksLikeRuntimeGateway(execPath)) {
|
|
271
|
+
return execPath;
|
|
272
|
+
}
|
|
273
|
+
throw new Error("bun not found in PATH");
|
|
274
|
+
}
|
|
275
|
+
function normalizeExecutablePath(candidate) {
|
|
276
|
+
if (!candidate) {
|
|
277
|
+
return "";
|
|
278
|
+
}
|
|
279
|
+
const normalized = resolve3(candidate);
|
|
280
|
+
if (!existsSync3(normalized)) {
|
|
281
|
+
return "";
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
return realpathSync(normalized);
|
|
285
|
+
} catch {
|
|
286
|
+
return normalized;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function looksLikeRuntimeGateway(candidate) {
|
|
290
|
+
const normalized = resolve3(candidate).replace(/\\/g, "/");
|
|
291
|
+
return normalized.includes("/.rig/bin/") || normalized.endsWith("/rig-shell") || normalized.endsWith("/rig-agent");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// packages/runtime/src/control-plane/native/runtime-native.ts
|
|
295
|
+
import { dlopen, ptr, suffix, toBuffer } from "bun:ffi";
|
|
296
|
+
import { copyFileSync, existsSync as existsSync4, mkdirSync as mkdirSync2, renameSync, rmSync, statSync } from "fs";
|
|
297
|
+
import { tmpdir } from "os";
|
|
298
|
+
import { dirname as dirname3, resolve as resolve4 } from "path";
|
|
299
|
+
var sharedNativeRuntimeOutputDir = resolve4(tmpdir(), "rig-native");
|
|
300
|
+
var sharedNativeRuntimeOutputPath = resolve4(sharedNativeRuntimeOutputDir, `runtime-native-${process.platform}-${process.arch}.${suffix}`);
|
|
301
|
+
var colocatedNativeRuntimeFileName = `runtime-native.${suffix}`;
|
|
302
|
+
var nativeRuntimeLibrary = await loadNativeRuntimeLibrary();
|
|
303
|
+
async function ensureNativeRuntimeLibraryPath(outputPath = sharedNativeRuntimeOutputPath, options = {}) {
|
|
304
|
+
if (await buildNativeRuntimeLibrary(outputPath, options)) {
|
|
305
|
+
return outputPath;
|
|
306
|
+
}
|
|
307
|
+
return !options.force && existsSync4(outputPath) ? outputPath : null;
|
|
308
|
+
}
|
|
309
|
+
async function loadNativeRuntimeLibrary() {
|
|
310
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
for (const candidate of nativeRuntimeLibraryCandidates()) {
|
|
314
|
+
if (!candidate || !existsSync4(candidate)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const loaded = tryDlopenNativeRuntimeLibrary(candidate);
|
|
318
|
+
if (loaded) {
|
|
319
|
+
return loaded;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const builtLibraryPath = await ensureNativeRuntimeLibraryPath(sharedNativeRuntimeOutputPath, { force: true });
|
|
323
|
+
if (!builtLibraryPath) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
return tryDlopenNativeRuntimeLibrary(builtLibraryPath);
|
|
327
|
+
}
|
|
328
|
+
function nativePackageLibraryCandidates(fromDir, names) {
|
|
329
|
+
const candidates = [];
|
|
330
|
+
let cursor = resolve4(fromDir);
|
|
331
|
+
for (let index = 0;index < 8; index += 1) {
|
|
332
|
+
for (const name of names) {
|
|
333
|
+
candidates.push(resolve4(cursor, "native", `${process.platform}-${process.arch}`, name), resolve4(cursor, "native", `${process.platform}-${process.arch}`, "lib", name), resolve4(cursor, "native", name), resolve4(cursor, "native", "lib", name));
|
|
334
|
+
}
|
|
335
|
+
const parent = dirname3(cursor);
|
|
336
|
+
if (parent === cursor)
|
|
337
|
+
break;
|
|
338
|
+
cursor = parent;
|
|
339
|
+
}
|
|
340
|
+
return candidates;
|
|
341
|
+
}
|
|
342
|
+
function nativeRuntimeLibraryCandidates() {
|
|
343
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_LIB?.trim() || "";
|
|
344
|
+
const execDir = process.execPath?.trim() ? dirname3(process.execPath.trim()) : "";
|
|
345
|
+
const platformSpecific = `runtime-native-${process.platform}-${process.arch}.${suffix}`;
|
|
346
|
+
return [...new Set([
|
|
347
|
+
explicit,
|
|
348
|
+
...nativePackageLibraryCandidates(import.meta.dir, [colocatedNativeRuntimeFileName, platformSpecific]),
|
|
349
|
+
execDir ? resolve4(execDir, colocatedNativeRuntimeFileName) : "",
|
|
350
|
+
execDir ? resolve4(execDir, platformSpecific) : "",
|
|
351
|
+
execDir ? resolve4(execDir, "..", colocatedNativeRuntimeFileName) : "",
|
|
352
|
+
execDir ? resolve4(execDir, "..", platformSpecific) : "",
|
|
353
|
+
execDir ? resolve4(execDir, "lib", colocatedNativeRuntimeFileName) : "",
|
|
354
|
+
execDir ? resolve4(execDir, "..", "lib", colocatedNativeRuntimeFileName) : "",
|
|
355
|
+
sharedNativeRuntimeOutputPath
|
|
356
|
+
].filter(Boolean))];
|
|
357
|
+
}
|
|
358
|
+
function resolveNativeRuntimeSourcePath() {
|
|
359
|
+
const explicit = process.env.RIG_NATIVE_RUNTIME_SOURCE?.trim();
|
|
360
|
+
if (explicit && existsSync4(explicit)) {
|
|
361
|
+
return explicit;
|
|
362
|
+
}
|
|
363
|
+
const bundled = resolve4(import.meta.dir, "../../../native/snapshot.zig");
|
|
364
|
+
return existsSync4(bundled) ? bundled : null;
|
|
365
|
+
}
|
|
366
|
+
async function buildNativeRuntimeLibrary(outputPath, options = {}) {
|
|
367
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
const zigBinary = Bun.which("zig");
|
|
371
|
+
const sourcePath = resolveNativeRuntimeSourcePath();
|
|
372
|
+
if (!zigBinary || !sourcePath) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
const tempOutputPath = `${outputPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
376
|
+
try {
|
|
377
|
+
mkdirSync2(dirname3(outputPath), { recursive: true });
|
|
378
|
+
const needsBuild = options.force === true || !existsSync4(outputPath) || statSync(sourcePath).mtimeMs > statSync(outputPath).mtimeMs;
|
|
379
|
+
if (!needsBuild) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
const build = Bun.spawn([
|
|
383
|
+
zigBinary,
|
|
384
|
+
"build-lib",
|
|
385
|
+
sourcePath,
|
|
386
|
+
"-dynamic",
|
|
387
|
+
"-O",
|
|
388
|
+
"ReleaseFast",
|
|
389
|
+
`-femit-bin=${tempOutputPath}`
|
|
390
|
+
], {
|
|
391
|
+
cwd: import.meta.dir,
|
|
392
|
+
stdout: "pipe",
|
|
393
|
+
stderr: "pipe"
|
|
394
|
+
});
|
|
395
|
+
const exitCode = await build.exited;
|
|
396
|
+
if (exitCode !== 0 || !existsSync4(tempOutputPath)) {
|
|
397
|
+
rmSync(tempOutputPath, { force: true });
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
renameSync(tempOutputPath, outputPath);
|
|
401
|
+
return true;
|
|
402
|
+
} catch {
|
|
403
|
+
rmSync(tempOutputPath, { force: true });
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function tryDlopenNativeRuntimeLibrary(outputPath) {
|
|
408
|
+
try {
|
|
409
|
+
return dlopen(outputPath, {
|
|
410
|
+
rig_scope_match: {
|
|
411
|
+
args: ["ptr", "ptr"],
|
|
412
|
+
returns: "u8"
|
|
413
|
+
},
|
|
414
|
+
snapshot_capture: {
|
|
415
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
416
|
+
returns: "ptr"
|
|
417
|
+
},
|
|
418
|
+
snapshot_delta: {
|
|
419
|
+
args: ["ptr", "ptr"],
|
|
420
|
+
returns: "ptr"
|
|
421
|
+
},
|
|
422
|
+
snapshot_store_delta: {
|
|
423
|
+
args: ["ptr", "ptr", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
424
|
+
returns: "ptr"
|
|
425
|
+
},
|
|
426
|
+
snapshot_inspect_delta: {
|
|
427
|
+
args: ["ptr", "u64"],
|
|
428
|
+
returns: "ptr"
|
|
429
|
+
},
|
|
430
|
+
snapshot_apply_delta: {
|
|
431
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
432
|
+
returns: "ptr"
|
|
433
|
+
},
|
|
434
|
+
snapshot_release: {
|
|
435
|
+
args: ["ptr"],
|
|
436
|
+
returns: "void"
|
|
437
|
+
},
|
|
438
|
+
runtime_hash_file: {
|
|
439
|
+
args: ["ptr", "u64"],
|
|
440
|
+
returns: "ptr"
|
|
441
|
+
},
|
|
442
|
+
runtime_hash_tree: {
|
|
443
|
+
args: ["ptr", "u64"],
|
|
444
|
+
returns: "ptr"
|
|
445
|
+
},
|
|
446
|
+
runtime_prepare_paths: {
|
|
447
|
+
args: ["ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64", "ptr", "u64"],
|
|
448
|
+
returns: "ptr"
|
|
449
|
+
},
|
|
450
|
+
runtime_link_dependency_layer: {
|
|
451
|
+
args: ["ptr", "u64", "ptr", "u64"],
|
|
452
|
+
returns: "ptr"
|
|
453
|
+
},
|
|
454
|
+
runtime_scan_worktrees: {
|
|
455
|
+
args: ["ptr", "u64"],
|
|
456
|
+
returns: "ptr"
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
} catch {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// packages/runtime/src/control-plane/native/utils.ts
|
|
465
|
+
function resolveMonorepoRoot2(projectRoot) {
|
|
466
|
+
return resolveMonorepoRoot(projectRoot);
|
|
467
|
+
}
|
|
468
|
+
var scopeRegexCache = new Map;
|
|
469
|
+
|
|
470
|
+
// packages/runtime/src/control-plane/validators/shared.ts
|
|
471
|
+
import { pass, fail, error, Checker } from "@rig/validator-kit";
|
|
472
|
+
import {
|
|
473
|
+
findFirstFile,
|
|
474
|
+
readFileSafe,
|
|
475
|
+
requireFile,
|
|
476
|
+
fileContains,
|
|
477
|
+
walkDir,
|
|
478
|
+
listSubdirs,
|
|
479
|
+
countTsFiles,
|
|
480
|
+
countTestFiles,
|
|
481
|
+
findFirstDir,
|
|
482
|
+
findFilesByName
|
|
483
|
+
} from "@rig/validator-kit";
|
|
484
|
+
import { grepFiles, grepCount, grepLines } from "@rig/validator-kit";
|
|
485
|
+
import { requireMarkdownSections, requireTerms, requireJsonKeys } from "@rig/validator-kit";
|
|
486
|
+
import {
|
|
487
|
+
requireFileCheck,
|
|
488
|
+
requireDirCheck,
|
|
489
|
+
requirePackageStructure,
|
|
490
|
+
checkTestsExist
|
|
491
|
+
} from "@rig/validator-kit";
|
|
492
|
+
var BUILD_CONFIG = readBuildConfig();
|
|
493
|
+
var BAKED_BUN_PATH = BUILD_CONFIG.AGENT_BUN_PATH ?? "";
|
|
494
|
+
var RUNTIME_CONTEXT = loadRuntimeContextFromEnv();
|
|
495
|
+
var PROJECT_ROOT = BUILD_CONFIG.AGENT_PROJECT_ROOT ? BUILD_CONFIG.AGENT_PROJECT_ROOT : RUNTIME_CONTEXT?.hostProjectRoot ? RUNTIME_CONTEXT.hostProjectRoot : process.env.RIG_HOST_PROJECT_ROOT || process.env.PROJECT_RIG_ROOT || process.cwd();
|
|
496
|
+
var TASK_ID = BUILD_CONFIG.AGENT_TASK_ID ? BUILD_CONFIG.AGENT_TASK_ID : process.env.RIG_TASK_ID || "";
|
|
497
|
+
function tryResolveMonorepoRoot(projectRoot) {
|
|
498
|
+
try {
|
|
499
|
+
return resolveMonorepoRoot2(projectRoot);
|
|
500
|
+
} catch {
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
var FALLBACK_MONOREPO_ROOT = tryResolveMonorepoRoot(PROJECT_ROOT);
|
|
505
|
+
var WORKSPACE = RUNTIME_CONTEXT?.workspaceDir || process.env.RIG_TASK_WORKSPACE?.trim() || process.env.MONOREPO_ROOT?.trim() || FALLBACK_MONOREPO_ROOT || PROJECT_ROOT;
|
|
506
|
+
var MONOREPO_ROOT = process.env.MONOREPO_ROOT?.trim() || WORKSPACE;
|
|
507
|
+
var MONOREPO_MAIN_ROOT = RUNTIME_CONTEXT?.monorepoMainRoot || process.env.MONOREPO_MAIN_ROOT?.trim() || FALLBACK_MONOREPO_ROOT || MONOREPO_ROOT;
|
|
508
|
+
var HP_BACKEND = resolve5(WORKSPACE, "humoongate/humanity/hp-backend-ts");
|
|
509
|
+
var MOONGATE_CORE = resolve5(WORKSPACE, "humoongate/moongate/core-app");
|
|
510
|
+
var ARTIFACTS_DIR = resolve5(WORKSPACE, "artifacts");
|
|
511
|
+
var TASK_CONFIG_PATH = existsSync5(resolve5(WORKSPACE, ".rig", "task-config.json")) ? resolve5(WORKSPACE, ".rig", "task-config.json") : resolve5(MONOREPO_MAIN_ROOT, ".rig", "task-config.json");
|
|
512
|
+
var TS_API_TESTS_DIR = process.env.TS_API_TESTS_DIR || resolve5(WORKSPACE, "TSAPITests");
|
|
513
|
+
var STATE_DIR = resolve5(WORKSPACE, ".rig", "state");
|
|
514
|
+
var PACKAGES_DIR = resolve5(WORKSPACE, "packages");
|
|
515
|
+
var CI_WORKFLOWS_DIR = resolve5(WORKSPACE, ".github/workflows");
|
|
516
|
+
function resolveBunCli() {
|
|
517
|
+
return resolveBunCliInvocation().command;
|
|
518
|
+
}
|
|
519
|
+
function resolveBunCliInvocation() {
|
|
520
|
+
if (BAKED_BUN_PATH) {
|
|
521
|
+
return {
|
|
522
|
+
command: BAKED_BUN_PATH,
|
|
523
|
+
env: {}
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
if (process.env.RIG_BUN_PATH?.trim()) {
|
|
527
|
+
return {
|
|
528
|
+
command: process.env.RIG_BUN_PATH.trim(),
|
|
529
|
+
env: {}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
try {
|
|
533
|
+
const systemBun = resolveBunBinaryPath();
|
|
534
|
+
return {
|
|
535
|
+
command: systemBun,
|
|
536
|
+
env: {}
|
|
537
|
+
};
|
|
538
|
+
} catch {}
|
|
539
|
+
if (process.execPath?.trim()) {
|
|
540
|
+
return {
|
|
541
|
+
command: process.execPath,
|
|
542
|
+
env: { BUN_BE_BUN: "1" }
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
return { command: "bun", env: {} };
|
|
546
|
+
}
|
|
547
|
+
function artifactDirForId(id) {
|
|
548
|
+
return resolve5(ARTIFACTS_DIR, id);
|
|
549
|
+
}
|
|
550
|
+
function artifactDir() {
|
|
551
|
+
return resolve5(ARTIFACTS_DIR, TASK_ID);
|
|
552
|
+
}
|
|
553
|
+
function requireArtifact(checker, taskId, ...files) {
|
|
554
|
+
const dir = artifactDirForId(taskId);
|
|
555
|
+
if (!existsSync5(dir) || !statSync2(dir).isDirectory()) {
|
|
556
|
+
checker.fail(`${taskId}-artifact-dir`, `artifact directory missing: ${dir}`);
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
checker.pass(`${taskId}-artifact-dir`);
|
|
560
|
+
for (const file of files) {
|
|
561
|
+
const full = resolve5(dir, file);
|
|
562
|
+
if (existsSync5(full)) {
|
|
563
|
+
checker.pass(`${taskId}/${file}`);
|
|
564
|
+
} else {
|
|
565
|
+
checker.fail(`${taskId}/${file}`, `required artifact file missing: ${full}`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return dir;
|
|
569
|
+
}
|
|
570
|
+
async function runCommand(cmd, cwd) {
|
|
571
|
+
const bunCli = resolveBunCliInvocation();
|
|
572
|
+
const env = {
|
|
573
|
+
...process.env,
|
|
574
|
+
...bunCli.env,
|
|
575
|
+
PWD: cwd,
|
|
576
|
+
INIT_CWD: cwd
|
|
577
|
+
};
|
|
578
|
+
if (cmd[0] === "bun" || cmd[0] === "bunx") {
|
|
579
|
+
const normalized = cmd[0] === "bunx" ? [bunCli.command, "x", ...cmd.slice(1)] : [bunCli.command, ...cmd.slice(1)];
|
|
580
|
+
const proc2 = Bun.spawn(normalized, { cwd, stdout: "pipe", stderr: "pipe", env });
|
|
581
|
+
const exitCode2 = await proc2.exited;
|
|
582
|
+
return {
|
|
583
|
+
exitCode: exitCode2,
|
|
584
|
+
stdout: await new Response(proc2.stdout).text(),
|
|
585
|
+
stderr: await new Response(proc2.stderr).text()
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const proc = Bun.spawn(cmd, { cwd, stdout: "pipe", stderr: "pipe", env });
|
|
589
|
+
const exitCode = await proc.exited;
|
|
590
|
+
const stdout = await new Response(proc.stdout).text();
|
|
591
|
+
const stderr = await new Response(proc.stderr).text();
|
|
592
|
+
return { exitCode, stdout, stderr };
|
|
593
|
+
}
|
|
594
|
+
function resolveTypescriptCommand(projectDir) {
|
|
595
|
+
const tsconfigPath = resolve5(projectDir, "tsconfig.json");
|
|
596
|
+
const bunCli = resolveBunCli();
|
|
597
|
+
const candidates = [
|
|
598
|
+
resolve5(projectDir, "node_modules", "typescript", "lib", "tsc.js"),
|
|
599
|
+
resolve5(projectDir, "..", "node_modules", "typescript", "lib", "tsc.js"),
|
|
600
|
+
resolve5(projectDir, "..", "..", "node_modules", "typescript", "lib", "tsc.js"),
|
|
601
|
+
resolve5(projectDir, "..", "..", "..", "node_modules", "typescript", "lib", "tsc.js")
|
|
602
|
+
];
|
|
603
|
+
for (const candidate of candidates) {
|
|
604
|
+
if (existsSync5(candidate)) {
|
|
605
|
+
return [bunCli, candidate, "--noEmit", "--project", tsconfigPath];
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return ["bunx", "tsc", "--noEmit", "--project", tsconfigPath];
|
|
609
|
+
}
|
|
610
|
+
async function checkTypescriptCompiles(checker, projectDir, checkName) {
|
|
611
|
+
if (!existsSync5(resolve5(projectDir, "tsconfig.json"))) {
|
|
612
|
+
checker.fail(checkName, "no tsconfig.json found");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const command = resolveTypescriptCommand(projectDir);
|
|
616
|
+
const transientRetryDelaysMs = [250, 500, 1000, 1500];
|
|
617
|
+
let result = await runCommand(command, projectDir);
|
|
618
|
+
let combined = result.stdout + result.stderr;
|
|
619
|
+
let errorCount = combined.split(`
|
|
620
|
+
`).filter((l) => l.includes("error TS")).length;
|
|
621
|
+
for (const delayMs of transientRetryDelaysMs) {
|
|
622
|
+
if (result.exitCode === 0 || errorCount > 0) {
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
await Bun.sleep(delayMs);
|
|
626
|
+
result = await runCommand(command, projectDir);
|
|
627
|
+
combined = result.stdout + result.stderr;
|
|
628
|
+
errorCount = combined.split(`
|
|
629
|
+
`).filter((l) => l.includes("error TS")).length;
|
|
630
|
+
}
|
|
631
|
+
if (result.exitCode === 0) {
|
|
632
|
+
checker.pass(checkName);
|
|
633
|
+
} else {
|
|
634
|
+
const detail = errorCount > 0 ? `${errorCount} TypeScript errors` : `TypeScript command exited ${result.exitCode} without TS diagnostics`;
|
|
635
|
+
checker.fail(checkName, detail);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
export {
|
|
639
|
+
walkDir,
|
|
640
|
+
runCommand,
|
|
641
|
+
resolveBunCliInvocation,
|
|
642
|
+
resolveBunCli,
|
|
643
|
+
requireTerms,
|
|
644
|
+
requirePackageStructure,
|
|
645
|
+
requireMarkdownSections,
|
|
646
|
+
requireJsonKeys,
|
|
647
|
+
requireFileCheck,
|
|
648
|
+
requireFile,
|
|
649
|
+
requireDirCheck,
|
|
650
|
+
requireArtifact,
|
|
651
|
+
readFileSafe,
|
|
652
|
+
pass,
|
|
653
|
+
listSubdirs,
|
|
654
|
+
grepLines,
|
|
655
|
+
grepFiles,
|
|
656
|
+
grepCount,
|
|
657
|
+
findFirstFile,
|
|
658
|
+
findFirstDir,
|
|
659
|
+
findFilesByName,
|
|
660
|
+
fileContains,
|
|
661
|
+
fail,
|
|
662
|
+
error,
|
|
663
|
+
countTsFiles,
|
|
664
|
+
countTestFiles,
|
|
665
|
+
checkTypescriptCompiles,
|
|
666
|
+
checkTestsExist,
|
|
667
|
+
artifactDirForId,
|
|
668
|
+
artifactDir,
|
|
669
|
+
WORKSPACE,
|
|
670
|
+
TS_API_TESTS_DIR,
|
|
671
|
+
TASK_ID,
|
|
672
|
+
TASK_CONFIG_PATH,
|
|
673
|
+
STATE_DIR,
|
|
674
|
+
PROJECT_ROOT,
|
|
675
|
+
PACKAGES_DIR,
|
|
676
|
+
MOONGATE_CORE,
|
|
677
|
+
MONOREPO_ROOT,
|
|
678
|
+
MONOREPO_MAIN_ROOT,
|
|
679
|
+
HP_BACKEND,
|
|
680
|
+
Checker,
|
|
681
|
+
CI_WORKFLOWS_DIR,
|
|
682
|
+
ARTIFACTS_DIR
|
|
683
|
+
};
|