@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,269 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// packages/runtime/bin/rig-browser-tool.ts
|
|
5
|
+
import { existsSync as existsSync2, rmSync } from "fs";
|
|
6
|
+
import { basename, dirname as dirname2, resolve as resolve2 } from "path";
|
|
7
|
+
|
|
8
|
+
// packages/runtime/src/control-plane/runtime/context.ts
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
10
|
+
import { dirname, resolve } from "path";
|
|
11
|
+
var runtimeContextStringFields = [
|
|
12
|
+
"runtimeId",
|
|
13
|
+
"taskId",
|
|
14
|
+
"role",
|
|
15
|
+
"workspaceDir",
|
|
16
|
+
"stateDir",
|
|
17
|
+
"logsDir",
|
|
18
|
+
"sessionDir",
|
|
19
|
+
"sessionFile",
|
|
20
|
+
"policyFile",
|
|
21
|
+
"binDir",
|
|
22
|
+
"createdAt"
|
|
23
|
+
];
|
|
24
|
+
var runtimeContextArrayFields = ["scopes", "validation"];
|
|
25
|
+
var runtimeContextOptionalStringFields = [
|
|
26
|
+
"artifactRoot",
|
|
27
|
+
"hostProjectRoot",
|
|
28
|
+
"monorepoMainRoot",
|
|
29
|
+
"monorepoBaseRef",
|
|
30
|
+
"monorepoBaseCommit"
|
|
31
|
+
];
|
|
32
|
+
function loadRuntimeContext(path) {
|
|
33
|
+
const absPath = resolve(path);
|
|
34
|
+
if (!existsSync(absPath)) {
|
|
35
|
+
throw new Error(`RuntimeTaskContext file not found: ${absPath}`);
|
|
36
|
+
}
|
|
37
|
+
let raw;
|
|
38
|
+
try {
|
|
39
|
+
raw = JSON.parse(readFileSync(absPath, "utf8"));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
throw new Error(`Failed to parse RuntimeTaskContext at ${absPath}: ${String(err)}`);
|
|
42
|
+
}
|
|
43
|
+
if (typeof raw !== "object" || raw === null) {
|
|
44
|
+
throw new Error(`RuntimeTaskContext at ${absPath} is not an object`);
|
|
45
|
+
}
|
|
46
|
+
const obj = raw;
|
|
47
|
+
for (const field of runtimeContextStringFields) {
|
|
48
|
+
if (typeof obj[field] !== "string" || obj[field].length === 0) {
|
|
49
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a non-empty string (at ${absPath})`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const field of runtimeContextArrayFields) {
|
|
53
|
+
if (!Array.isArray(obj[field])) {
|
|
54
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be an array (at ${absPath})`);
|
|
55
|
+
}
|
|
56
|
+
if (!obj[field].every((entry) => typeof entry === "string")) {
|
|
57
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string[] (at ${absPath})`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const field of runtimeContextOptionalStringFields) {
|
|
61
|
+
if (field in obj && obj[field] !== undefined && typeof obj[field] !== "string") {
|
|
62
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string when present (at ${absPath})`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (obj.browser !== undefined) {
|
|
66
|
+
if (typeof obj.browser !== "object" || obj.browser === null || Array.isArray(obj.browser)) {
|
|
67
|
+
throw new Error(`RuntimeTaskContext field "browser" must be an object when present (at ${absPath})`);
|
|
68
|
+
}
|
|
69
|
+
const browser = obj.browser;
|
|
70
|
+
for (const field of [
|
|
71
|
+
"preset",
|
|
72
|
+
"mode",
|
|
73
|
+
"stateDir",
|
|
74
|
+
"defaultProfile",
|
|
75
|
+
"effectiveProfile",
|
|
76
|
+
"defaultAttachUrl",
|
|
77
|
+
"effectiveAttachUrl",
|
|
78
|
+
"launchHelper",
|
|
79
|
+
"checkHelper",
|
|
80
|
+
"attachInfoHelper",
|
|
81
|
+
"e2eHelper",
|
|
82
|
+
"resetProfileHelper"
|
|
83
|
+
]) {
|
|
84
|
+
if (typeof browser[field] !== "string" || browser[field].length === 0) {
|
|
85
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a non-empty string (at ${absPath})`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const field of ["devCommand", "launchCommand", "checkCommand", "e2eCommand"]) {
|
|
89
|
+
if (browser[field] !== undefined && typeof browser[field] !== "string") {
|
|
90
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a string when present (at ${absPath})`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (typeof browser.required !== "boolean") {
|
|
94
|
+
throw new Error(`RuntimeTaskContext field "browser.required" must be a boolean (at ${absPath})`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (obj.memory !== undefined) {
|
|
98
|
+
if (typeof obj.memory !== "object" || obj.memory === null || Array.isArray(obj.memory)) {
|
|
99
|
+
throw new Error(`RuntimeTaskContext field "memory" must be an object when present (at ${absPath})`);
|
|
100
|
+
}
|
|
101
|
+
const memory = obj.memory;
|
|
102
|
+
for (const field of ["canonicalPath", "canonicalRef", "canonicalBaseOid", "hydratedPath"]) {
|
|
103
|
+
if (typeof memory[field] !== "string" || memory[field].length === 0) {
|
|
104
|
+
throw new Error(`RuntimeTaskContext field "memory.${field}" must be a non-empty string (at ${absPath})`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (typeof memory.createdFresh !== "boolean") {
|
|
108
|
+
throw new Error(`RuntimeTaskContext field "memory.createdFresh" must be a boolean (at ${absPath})`);
|
|
109
|
+
}
|
|
110
|
+
if (typeof memory.retrieval !== "object" || memory.retrieval === null || Array.isArray(memory.retrieval)) {
|
|
111
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval" must be an object (at ${absPath})`);
|
|
112
|
+
}
|
|
113
|
+
const retrieval = memory.retrieval;
|
|
114
|
+
for (const field of ["topK", "lexicalWeight", "vectorWeight", "recencyWeight", "confidenceWeight"]) {
|
|
115
|
+
if (typeof retrieval[field] !== "number" || Number.isNaN(retrieval[field])) {
|
|
116
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval.${field}" must be a number (at ${absPath})`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (obj.initialDirtyFiles !== undefined) {
|
|
121
|
+
if (typeof obj.initialDirtyFiles !== "object" || obj.initialDirtyFiles === null || Array.isArray(obj.initialDirtyFiles)) {
|
|
122
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles" must be an object when present (at ${absPath})`);
|
|
123
|
+
}
|
|
124
|
+
const dirtyFiles = obj.initialDirtyFiles;
|
|
125
|
+
for (const key of ["project", "monorepo"]) {
|
|
126
|
+
if (dirtyFiles[key] === undefined) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (!Array.isArray(dirtyFiles[key]) || !dirtyFiles[key].every((entry) => typeof entry === "string")) {
|
|
130
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles.${key}" must be a string[] when present (at ${absPath})`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (obj.initialHeadCommits !== undefined) {
|
|
135
|
+
if (typeof obj.initialHeadCommits !== "object" || obj.initialHeadCommits === null || Array.isArray(obj.initialHeadCommits)) {
|
|
136
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits" must be an object when present (at ${absPath})`);
|
|
137
|
+
}
|
|
138
|
+
const headCommits = obj.initialHeadCommits;
|
|
139
|
+
for (const key of ["project", "monorepo"]) {
|
|
140
|
+
if (headCommits[key] === undefined) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (typeof headCommits[key] !== "string") {
|
|
144
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits.${key}" must be a string when present (at ${absPath})`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return obj;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// packages/runtime/bin/rig-browser-tool.ts
|
|
152
|
+
function currentCommand() {
|
|
153
|
+
return basename(process.argv[1] || "");
|
|
154
|
+
}
|
|
155
|
+
function runtimeContextPath() {
|
|
156
|
+
const explicit = process.env.RIG_RUNTIME_CONTEXT_FILE?.trim();
|
|
157
|
+
if (explicit) {
|
|
158
|
+
return explicit;
|
|
159
|
+
}
|
|
160
|
+
return resolve2(dirname2(resolve2(process.argv[1] || "")), "..", "runtime-context.json");
|
|
161
|
+
}
|
|
162
|
+
function loadBrowserContext() {
|
|
163
|
+
const contextPath = runtimeContextPath();
|
|
164
|
+
if (!existsSync2(contextPath)) {
|
|
165
|
+
throw new Error(`Runtime context file not found for ${currentCommand()}: ${contextPath}`);
|
|
166
|
+
}
|
|
167
|
+
const runtimeContext = loadRuntimeContext(contextPath);
|
|
168
|
+
if (!runtimeContext.browser?.required) {
|
|
169
|
+
throw new Error(`No browser contract is configured for ${runtimeContext.taskId}.`);
|
|
170
|
+
}
|
|
171
|
+
if (!runtimeContext.hostProjectRoot) {
|
|
172
|
+
throw new Error(`Runtime browser command ${currentCommand()} requires hostProjectRoot in runtime context.`);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
browser: runtimeContext.browser,
|
|
176
|
+
hostProjectRoot: runtimeContext.hostProjectRoot
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
async function runConfiguredCommand(command, browser, hostProjectRoot) {
|
|
180
|
+
if (!command) {
|
|
181
|
+
throw new Error(`No backing command is configured for ${currentCommand()}.`);
|
|
182
|
+
}
|
|
183
|
+
const attachUrl = new URL(browser.effectiveAttachUrl);
|
|
184
|
+
const child = Bun.spawn({
|
|
185
|
+
cmd: ["/bin/bash", "-lc", command],
|
|
186
|
+
cwd: hostProjectRoot,
|
|
187
|
+
stdin: "inherit",
|
|
188
|
+
stdout: "inherit",
|
|
189
|
+
stderr: "inherit",
|
|
190
|
+
env: {
|
|
191
|
+
...process.env,
|
|
192
|
+
RIG_STATE_DIR: browser.stateDir,
|
|
193
|
+
T3CODE_STATE_DIR: browser.stateDir,
|
|
194
|
+
RIG_BROWSER_PROFILE: browser.effectiveProfile,
|
|
195
|
+
RIG_BROWSER_REMOTE_DEBUGGING_PORT: attachUrl.port,
|
|
196
|
+
RIG_BROWSER_ATTACH_URL: browser.effectiveAttachUrl
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return await child.exited;
|
|
200
|
+
}
|
|
201
|
+
function printAttachInfo(browser, hostProjectRoot) {
|
|
202
|
+
const payload = {
|
|
203
|
+
preset: browser.preset,
|
|
204
|
+
mode: browser.mode,
|
|
205
|
+
stateDir: browser.stateDir,
|
|
206
|
+
hostProjectRoot,
|
|
207
|
+
defaultProfile: browser.defaultProfile,
|
|
208
|
+
effectiveProfile: browser.effectiveProfile,
|
|
209
|
+
defaultAttachUrl: browser.defaultAttachUrl,
|
|
210
|
+
effectiveAttachUrl: browser.effectiveAttachUrl,
|
|
211
|
+
launchHelper: browser.launchHelper,
|
|
212
|
+
checkHelper: browser.checkHelper,
|
|
213
|
+
attachInfoHelper: browser.attachInfoHelper,
|
|
214
|
+
e2eHelper: browser.e2eHelper,
|
|
215
|
+
resetProfileHelper: browser.resetProfileHelper,
|
|
216
|
+
devCommand: browser.devCommand,
|
|
217
|
+
launchCommand: browser.launchCommand,
|
|
218
|
+
checkCommand: browser.checkCommand,
|
|
219
|
+
e2eCommand: browser.e2eCommand
|
|
220
|
+
};
|
|
221
|
+
if (process.argv.includes("--json")) {
|
|
222
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
console.log("Rig Browser");
|
|
226
|
+
console.log(` Preset: ${browser.preset}`);
|
|
227
|
+
console.log(` Mode: ${browser.mode}`);
|
|
228
|
+
console.log(` State dir: ${browser.stateDir}`);
|
|
229
|
+
console.log(` Default profile: ${browser.defaultProfile}`);
|
|
230
|
+
console.log(` Effective profile: ${browser.effectiveProfile}`);
|
|
231
|
+
console.log(` Default attach URL: ${browser.defaultAttachUrl}`);
|
|
232
|
+
console.log(` Effective attach URL: ${browser.effectiveAttachUrl}`);
|
|
233
|
+
console.log(` Launch helper: ${browser.launchHelper}${browser.devCommand ? " [--dev]" : ""}`);
|
|
234
|
+
console.log(` Check helper: ${browser.checkHelper}`);
|
|
235
|
+
console.log(` E2E helper: ${browser.e2eHelper}`);
|
|
236
|
+
console.log(` Reset helper: ${browser.resetProfileHelper}`);
|
|
237
|
+
}
|
|
238
|
+
function resetProfile(browser) {
|
|
239
|
+
const profileRoot = resolve2(browser.stateDir, "browser", "profiles", browser.effectiveProfile);
|
|
240
|
+
rmSync(profileRoot, { recursive: true, force: true });
|
|
241
|
+
console.log(`Removed Rig Browser profile: ${profileRoot}`);
|
|
242
|
+
}
|
|
243
|
+
async function main() {
|
|
244
|
+
const { browser, hostProjectRoot } = loadBrowserContext();
|
|
245
|
+
const command = currentCommand();
|
|
246
|
+
if (command === browser.attachInfoHelper) {
|
|
247
|
+
printAttachInfo(browser, hostProjectRoot);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (command === browser.resetProfileHelper) {
|
|
251
|
+
resetProfile(browser);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (command === browser.launchHelper) {
|
|
255
|
+
const launchCommand = process.argv.includes("--dev") ? browser.devCommand : browser.launchCommand;
|
|
256
|
+
process.exit(await runConfiguredCommand(launchCommand, browser, hostProjectRoot));
|
|
257
|
+
}
|
|
258
|
+
if (command === browser.checkHelper) {
|
|
259
|
+
process.exit(await runConfiguredCommand(browser.checkCommand, browser, hostProjectRoot));
|
|
260
|
+
}
|
|
261
|
+
if (command === browser.e2eHelper) {
|
|
262
|
+
process.exit(await runConfiguredCommand(browser.e2eCommand ?? browser.checkCommand, browser, hostProjectRoot));
|
|
263
|
+
}
|
|
264
|
+
throw new Error(`Unknown Rig Browser helper: ${command}`);
|
|
265
|
+
}
|
|
266
|
+
main().catch((error) => {
|
|
267
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
268
|
+
process.exit(1);
|
|
269
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/agent-mode.ts
|
|
3
|
+
function looksLikeShellInvocation(args, mode = process.env.RIG_AGENT_MODE) {
|
|
4
|
+
if (mode === "shell") {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (mode === "agent") {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (args.length === 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const first = args[0];
|
|
14
|
+
if (!first) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const bashLikeFlags = new Set([
|
|
18
|
+
"-c",
|
|
19
|
+
"-lc",
|
|
20
|
+
"-l",
|
|
21
|
+
"-i",
|
|
22
|
+
"-s",
|
|
23
|
+
"--login",
|
|
24
|
+
"--noprofile",
|
|
25
|
+
"--norc",
|
|
26
|
+
"--posix",
|
|
27
|
+
"--rcfile",
|
|
28
|
+
"--init-file",
|
|
29
|
+
"--restricted",
|
|
30
|
+
"--debug",
|
|
31
|
+
"--debugger",
|
|
32
|
+
"--verbose",
|
|
33
|
+
"--wordexp",
|
|
34
|
+
"--dump-strings",
|
|
35
|
+
"--dump-po-strings",
|
|
36
|
+
"--help"
|
|
37
|
+
]);
|
|
38
|
+
if (bashLikeFlags.has(first)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (!first.startsWith("-")) {
|
|
42
|
+
return first.endsWith(".sh");
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
looksLikeShellInvocation
|
|
48
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/baked-secrets.ts
|
|
3
|
+
import { existsSync, readFileSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
var BAKED_RUNTIME_SECRETS = {
|
|
6
|
+
ANTHROPIC_API_KEY: typeof RIG_BAKED_ANTHROPIC_API_KEY !== "undefined" ? RIG_BAKED_ANTHROPIC_API_KEY : "",
|
|
7
|
+
OPENAI_API_KEY: typeof RIG_BAKED_OPENAI_API_KEY !== "undefined" ? RIG_BAKED_OPENAI_API_KEY : "",
|
|
8
|
+
OPENROUTER_API_KEY: typeof RIG_BAKED_OPENROUTER_API_KEY !== "undefined" ? RIG_BAKED_OPENROUTER_API_KEY : "",
|
|
9
|
+
AI_REVIEW_MODE: typeof RIG_BAKED_AI_REVIEW_MODE !== "undefined" ? RIG_BAKED_AI_REVIEW_MODE : "",
|
|
10
|
+
AI_REVIEW_PROVIDER: typeof RIG_BAKED_AI_REVIEW_PROVIDER !== "undefined" ? RIG_BAKED_AI_REVIEW_PROVIDER : "",
|
|
11
|
+
GREPTILE_API_BASE: typeof RIG_BAKED_GREPTILE_API_BASE !== "undefined" ? RIG_BAKED_GREPTILE_API_BASE : "",
|
|
12
|
+
GREPTILE_REMOTE: typeof RIG_BAKED_GREPTILE_REMOTE !== "undefined" ? RIG_BAKED_GREPTILE_REMOTE : "",
|
|
13
|
+
GREPTILE_REPOSITORY: typeof RIG_BAKED_GREPTILE_REPOSITORY !== "undefined" ? RIG_BAKED_GREPTILE_REPOSITORY : "",
|
|
14
|
+
GREPTILE_CONTEXT_BRANCH: typeof RIG_BAKED_GREPTILE_CONTEXT_BRANCH !== "undefined" ? RIG_BAKED_GREPTILE_CONTEXT_BRANCH : "",
|
|
15
|
+
GREPTILE_DEFAULT_BRANCH: typeof RIG_BAKED_GREPTILE_DEFAULT_BRANCH !== "undefined" ? RIG_BAKED_GREPTILE_DEFAULT_BRANCH : "",
|
|
16
|
+
GREPTILE_API_KEY: typeof RIG_BAKED_GREPTILE_API_KEY !== "undefined" ? RIG_BAKED_GREPTILE_API_KEY : "",
|
|
17
|
+
GREPTILE_GITHUB_TOKEN: typeof RIG_BAKED_GREPTILE_GITHUB_TOKEN !== "undefined" ? RIG_BAKED_GREPTILE_GITHUB_TOKEN : "",
|
|
18
|
+
GREPTILE_POLL_ATTEMPTS: typeof RIG_BAKED_GREPTILE_POLL_ATTEMPTS !== "undefined" ? RIG_BAKED_GREPTILE_POLL_ATTEMPTS : "",
|
|
19
|
+
GREPTILE_POLL_INTERVAL_MS: typeof RIG_BAKED_GREPTILE_POLL_INTERVAL_MS !== "undefined" ? RIG_BAKED_GREPTILE_POLL_INTERVAL_MS : "",
|
|
20
|
+
GH_TOKEN: typeof RIG_BAKED_GITHUB_TOKEN !== "undefined" ? RIG_BAKED_GITHUB_TOKEN : "",
|
|
21
|
+
GITHUB_TOKEN: typeof RIG_BAKED_GITHUB_TOKEN !== "undefined" ? RIG_BAKED_GITHUB_TOKEN : "",
|
|
22
|
+
GITHUB_SSH_KEY: typeof RIG_BAKED_GITHUB_SSH_KEY !== "undefined" ? RIG_BAKED_GITHUB_SSH_KEY : "",
|
|
23
|
+
AWS_ACCESS_KEY_ID: typeof RIG_BAKED_AWS_ACCESS_KEY_ID !== "undefined" ? RIG_BAKED_AWS_ACCESS_KEY_ID : "",
|
|
24
|
+
AWS_SECRET_ACCESS_KEY: typeof RIG_BAKED_AWS_SECRET_ACCESS_KEY !== "undefined" ? RIG_BAKED_AWS_SECRET_ACCESS_KEY : "",
|
|
25
|
+
AWS_REGION: typeof RIG_BAKED_AWS_REGION !== "undefined" ? RIG_BAKED_AWS_REGION : "",
|
|
26
|
+
LINEAR_API_KEY: typeof RIG_BAKED_LINEAR_API_KEY !== "undefined" ? RIG_BAKED_LINEAR_API_KEY : "",
|
|
27
|
+
LINEAR_WEBHOOK_SECRET: typeof RIG_BAKED_LINEAR_WEBHOOK_SECRET !== "undefined" ? RIG_BAKED_LINEAR_WEBHOOK_SECRET : ""
|
|
28
|
+
};
|
|
29
|
+
function resolveRuntimeSecrets(env, baked = BAKED_RUNTIME_SECRETS) {
|
|
30
|
+
const resolved = {};
|
|
31
|
+
const keys = new Set([
|
|
32
|
+
...Object.keys(BAKED_RUNTIME_SECRETS),
|
|
33
|
+
...Object.keys(baked)
|
|
34
|
+
]);
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
const envValue = env[key]?.trim();
|
|
37
|
+
const bakedValue = baked[key]?.trim();
|
|
38
|
+
if (envValue) {
|
|
39
|
+
resolved[key] = envValue;
|
|
40
|
+
} else if (bakedValue) {
|
|
41
|
+
resolved[key] = bakedValue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
46
|
+
function loadDotEnvSecrets(projectRoot, env = process.env) {
|
|
47
|
+
const dotenvPath = resolve(projectRoot, ".env");
|
|
48
|
+
if (!existsSync(dotenvPath)) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
const parsed = {};
|
|
52
|
+
const lines = readFileSync(dotenvPath, "utf-8").split(/\r?\n/);
|
|
53
|
+
for (const rawLine of lines) {
|
|
54
|
+
const line = rawLine.trim();
|
|
55
|
+
if (!line || line.startsWith("#")) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const exportMatch = line.match(/^(?:export\s+)?([A-Z0-9_]+)\s*=\s*(.*)$/);
|
|
59
|
+
if (!exportMatch) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const key = exportMatch[1];
|
|
63
|
+
if (!(key in BAKED_RUNTIME_SECRETS)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const value = expandShellValue(exportMatch[2] ?? "", { ...env, ...parsed });
|
|
67
|
+
if (value) {
|
|
68
|
+
parsed[key] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
function secretDefinesFromEnv(env = process.env, projectRoot) {
|
|
74
|
+
const dotenvSecrets = projectRoot ? loadDotEnvSecrets(projectRoot, env) : {};
|
|
75
|
+
const resolved = resolveRuntimeSecrets(env, {
|
|
76
|
+
...BAKED_RUNTIME_SECRETS,
|
|
77
|
+
...dotenvSecrets
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
RIG_BAKED_ANTHROPIC_API_KEY: resolved.ANTHROPIC_API_KEY || "",
|
|
81
|
+
RIG_BAKED_OPENAI_API_KEY: resolved.OPENAI_API_KEY || "",
|
|
82
|
+
RIG_BAKED_OPENROUTER_API_KEY: resolved.OPENROUTER_API_KEY || "",
|
|
83
|
+
RIG_BAKED_AI_REVIEW_MODE: resolved.AI_REVIEW_MODE || "",
|
|
84
|
+
RIG_BAKED_AI_REVIEW_PROVIDER: resolved.AI_REVIEW_PROVIDER || "",
|
|
85
|
+
RIG_BAKED_GREPTILE_API_BASE: resolved.GREPTILE_API_BASE || "",
|
|
86
|
+
RIG_BAKED_GREPTILE_REMOTE: resolved.GREPTILE_REMOTE || "",
|
|
87
|
+
RIG_BAKED_GREPTILE_REPOSITORY: resolved.GREPTILE_REPOSITORY || "",
|
|
88
|
+
RIG_BAKED_GREPTILE_CONTEXT_BRANCH: resolved.GREPTILE_CONTEXT_BRANCH || "",
|
|
89
|
+
RIG_BAKED_GREPTILE_DEFAULT_BRANCH: resolved.GREPTILE_DEFAULT_BRANCH || "",
|
|
90
|
+
RIG_BAKED_GREPTILE_API_KEY: resolved.GREPTILE_API_KEY || "",
|
|
91
|
+
RIG_BAKED_GREPTILE_GITHUB_TOKEN: resolved.GREPTILE_GITHUB_TOKEN || "",
|
|
92
|
+
RIG_BAKED_GREPTILE_POLL_ATTEMPTS: resolved.GREPTILE_POLL_ATTEMPTS || "",
|
|
93
|
+
RIG_BAKED_GREPTILE_POLL_INTERVAL_MS: resolved.GREPTILE_POLL_INTERVAL_MS || "",
|
|
94
|
+
RIG_BAKED_GITHUB_TOKEN: resolved.GITHUB_TOKEN || resolved.GH_TOKEN || "",
|
|
95
|
+
RIG_BAKED_GITHUB_SSH_KEY: resolved.GITHUB_SSH_KEY || "",
|
|
96
|
+
RIG_BAKED_AWS_ACCESS_KEY_ID: resolved.AWS_ACCESS_KEY_ID || "",
|
|
97
|
+
RIG_BAKED_AWS_SECRET_ACCESS_KEY: resolved.AWS_SECRET_ACCESS_KEY || "",
|
|
98
|
+
RIG_BAKED_AWS_REGION: resolved.AWS_REGION || "",
|
|
99
|
+
RIG_BAKED_LINEAR_API_KEY: resolved.LINEAR_API_KEY || "",
|
|
100
|
+
RIG_BAKED_LINEAR_WEBHOOK_SECRET: resolved.LINEAR_WEBHOOK_SECRET || ""
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function expandShellValue(rawValue, env) {
|
|
104
|
+
let value = rawValue.trim();
|
|
105
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
106
|
+
value = value.slice(1, -1);
|
|
107
|
+
}
|
|
108
|
+
return value.replace(/\$\{([A-Z0-9_]+)(:-([^}]*))?\}/g, (_match, name, _defaultGroup, fallback) => {
|
|
109
|
+
const envValue = env[name]?.trim();
|
|
110
|
+
if (envValue) {
|
|
111
|
+
return envValue;
|
|
112
|
+
}
|
|
113
|
+
return fallback ?? "";
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
secretDefinesFromEnv,
|
|
118
|
+
resolveRuntimeSecrets,
|
|
119
|
+
loadDotEnvSecrets,
|
|
120
|
+
BAKED_RUNTIME_SECRETS
|
|
121
|
+
};
|