@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.
Files changed (176) hide show
  1. package/README.md +27 -0
  2. package/dist/bin/rig-agent-dispatch.js +9615 -0
  3. package/dist/bin/rig-agent.js +9512 -0
  4. package/dist/bin/rig-browser-tool.js +269 -0
  5. package/dist/src/agent-mode.js +48 -0
  6. package/dist/src/baked-secrets.js +121 -0
  7. package/dist/src/binary-build-worker.js +312 -0
  8. package/dist/src/binary-run.js +540 -0
  9. package/dist/src/boundaries.js +1 -0
  10. package/dist/src/build-time-config.js +25 -0
  11. package/dist/src/control-plane/agent-roles.js +27 -0
  12. package/dist/src/control-plane/agent-wrapper.js +9621 -0
  13. package/dist/src/control-plane/authority-files.js +582 -0
  14. package/dist/src/control-plane/browser-contract.js +135 -0
  15. package/dist/src/control-plane/controlled-bash.js +1111 -0
  16. package/dist/src/control-plane/errors.js +13 -0
  17. package/dist/src/control-plane/harness-main.js +10828 -0
  18. package/dist/src/control-plane/hook-materializer.js +75 -0
  19. package/dist/src/control-plane/hooks/audit-trail.js +353 -0
  20. package/dist/src/control-plane/hooks/completion-verification.js +7552 -0
  21. package/dist/src/control-plane/hooks/import-guard.js +890 -0
  22. package/dist/src/control-plane/hooks/inject-context.js +4189 -0
  23. package/dist/src/control-plane/hooks/post-edit-lint.js +43 -0
  24. package/dist/src/control-plane/hooks/safety-guard.js +910 -0
  25. package/dist/src/control-plane/hooks/scope-guard.js +907 -0
  26. package/dist/src/control-plane/hooks/shared.js +44 -0
  27. package/dist/src/control-plane/hooks/submodule-branch.js +7797 -0
  28. package/dist/src/control-plane/hooks/task-runtime-start.js +7799 -0
  29. package/dist/src/control-plane/hooks/test-integrity-guard.js +891 -0
  30. package/dist/src/control-plane/materialize-task-config.js +453 -0
  31. package/dist/src/control-plane/memory-sync/cli.js +2019 -0
  32. package/dist/src/control-plane/memory-sync/db.js +753 -0
  33. package/dist/src/control-plane/memory-sync/embed.js +281 -0
  34. package/dist/src/control-plane/memory-sync/index.js +2049 -0
  35. package/dist/src/control-plane/memory-sync/query.js +294 -0
  36. package/dist/src/control-plane/memory-sync/read.js +784 -0
  37. package/dist/src/control-plane/memory-sync/types.js +6 -0
  38. package/dist/src/control-plane/memory-sync/write.js +1547 -0
  39. package/dist/src/control-plane/native/git-native.js +490 -0
  40. package/dist/src/control-plane/native/git-ops.js +2860 -0
  41. package/dist/src/control-plane/native/harness-cli.js +9721 -0
  42. package/dist/src/control-plane/native/pr-automation.js +373 -0
  43. package/dist/src/control-plane/native/profile-ops.js +481 -0
  44. package/dist/src/control-plane/native/repo-ops.js +2342 -0
  45. package/dist/src/control-plane/native/root-resolver.js +66 -0
  46. package/dist/src/control-plane/native/run-ops.js +3281 -0
  47. package/dist/src/control-plane/native/runtime-native-sidecar.js +299 -0
  48. package/dist/src/control-plane/native/runtime-native.js +392 -0
  49. package/dist/src/control-plane/native/scope-rules.js +17 -0
  50. package/dist/src/control-plane/native/task-ops.js +6320 -0
  51. package/dist/src/control-plane/native/task-state.js +1512 -0
  52. package/dist/src/control-plane/native/utils.js +535 -0
  53. package/dist/src/control-plane/native/validator-binaries.js +889 -0
  54. package/dist/src/control-plane/native/validator.js +2197 -0
  55. package/dist/src/control-plane/native/verifier.js +3249 -0
  56. package/dist/src/control-plane/native/workspace-ops.js +1635 -0
  57. package/dist/src/control-plane/plugin-host-context.js +334 -0
  58. package/dist/src/control-plane/project-main-pre-run-sync.js +630 -0
  59. package/dist/src/control-plane/provider/claude-stream-records.js +158 -0
  60. package/dist/src/control-plane/provider/codex-app-server.js +885 -0
  61. package/dist/src/control-plane/provider/codex-exec-records.js +203 -0
  62. package/dist/src/control-plane/provider/rig-task-run-skill.js +39 -0
  63. package/dist/src/control-plane/provider/runtime-instructions.js +96 -0
  64. package/dist/src/control-plane/remote.js +854 -0
  65. package/dist/src/control-plane/repos/index.js +473 -0
  66. package/dist/src/control-plane/repos/layout.js +124 -0
  67. package/dist/src/control-plane/repos/mirror/bootstrap.js +268 -0
  68. package/dist/src/control-plane/repos/mirror/refresh.js +398 -0
  69. package/dist/src/control-plane/repos/mirror/state.js +167 -0
  70. package/dist/src/control-plane/repos/registry.js +77 -0
  71. package/dist/src/control-plane/repos/types.js +1 -0
  72. package/dist/src/control-plane/runtime/agent-mode.js +48 -0
  73. package/dist/src/control-plane/runtime/baked-secrets.js +120 -0
  74. package/dist/src/control-plane/runtime/claude-tool-router-binary.js +343 -0
  75. package/dist/src/control-plane/runtime/claude-tool-router.js +520 -0
  76. package/dist/src/control-plane/runtime/context.js +216 -0
  77. package/dist/src/control-plane/runtime/events.js +218 -0
  78. package/dist/src/control-plane/runtime/guard-types.js +6 -0
  79. package/dist/src/control-plane/runtime/guard.js +880 -0
  80. package/dist/src/control-plane/runtime/image/fingerprint-sidecar.js +1194 -0
  81. package/dist/src/control-plane/runtime/image/index.js +2255 -0
  82. package/dist/src/control-plane/runtime/image-fingerprint-sidecar.js +1191 -0
  83. package/dist/src/control-plane/runtime/image.js +2255 -0
  84. package/dist/src/control-plane/runtime/index.js +8511 -0
  85. package/dist/src/control-plane/runtime/isolation/discovery.js +599 -0
  86. package/dist/src/control-plane/runtime/isolation/home.js +1217 -0
  87. package/dist/src/control-plane/runtime/isolation/index.js +8193 -0
  88. package/dist/src/control-plane/runtime/isolation/runner.js +2651 -0
  89. package/dist/src/control-plane/runtime/isolation/shared.js +501 -0
  90. package/dist/src/control-plane/runtime/isolation/toolchain.js +1892 -0
  91. package/dist/src/control-plane/runtime/isolation/types.js +1 -0
  92. package/dist/src/control-plane/runtime/isolation/worktree.js +509 -0
  93. package/dist/src/control-plane/runtime/isolation.js +8193 -0
  94. package/dist/src/control-plane/runtime/overlay.js +67 -0
  95. package/dist/src/control-plane/runtime/plugin-mode.js +41 -0
  96. package/dist/src/control-plane/runtime/plugins.js +1131 -0
  97. package/dist/src/control-plane/runtime/provisioning-env.js +220 -0
  98. package/dist/src/control-plane/runtime/queue.js +8358 -0
  99. package/dist/src/control-plane/runtime/rig-shell.js +205 -0
  100. package/dist/src/control-plane/runtime/rig-tools.js +182 -0
  101. package/dist/src/control-plane/runtime/runner-context.js +1 -0
  102. package/dist/src/control-plane/runtime/runtime-paths.js +184 -0
  103. package/dist/src/control-plane/runtime/sandbox/backend-bwrap.js +311 -0
  104. package/dist/src/control-plane/runtime/sandbox/backend-none.js +21 -0
  105. package/dist/src/control-plane/runtime/sandbox/backend-seatbelt.js +268 -0
  106. package/dist/src/control-plane/runtime/sandbox/backend.js +1718 -0
  107. package/dist/src/control-plane/runtime/sandbox/orchestrator.js +1745 -0
  108. package/dist/src/control-plane/runtime/sandbox/utils.js +137 -0
  109. package/dist/src/control-plane/runtime/sandbox-backend-bwrap.js +311 -0
  110. package/dist/src/control-plane/runtime/sandbox-backend-none.js +21 -0
  111. package/dist/src/control-plane/runtime/sandbox-backend-seatbelt.js +268 -0
  112. package/dist/src/control-plane/runtime/sandbox-backend.js +1718 -0
  113. package/dist/src/control-plane/runtime/sandbox-orchestrator.js +1745 -0
  114. package/dist/src/control-plane/runtime/sandbox-utils.js +137 -0
  115. package/dist/src/control-plane/runtime/snapshot/index.js +454 -0
  116. package/dist/src/control-plane/runtime/snapshot/sidecar.js +502 -0
  117. package/dist/src/control-plane/runtime/snapshot/task-run.js +1578 -0
  118. package/dist/src/control-plane/runtime/snapshot-sidecar.js +498 -0
  119. package/dist/src/control-plane/runtime/snapshot.js +454 -0
  120. package/dist/src/control-plane/runtime/task-run-snapshot.js +1578 -0
  121. package/dist/src/control-plane/runtime/tool-gateway.js +422 -0
  122. package/dist/src/control-plane/runtime/tooling/browser-tools.js +32 -0
  123. package/dist/src/control-plane/runtime/tooling/claude-router-binary.js +343 -0
  124. package/dist/src/control-plane/runtime/tooling/claude-router.js +524 -0
  125. package/dist/src/control-plane/runtime/tooling/file-tools.js +182 -0
  126. package/dist/src/control-plane/runtime/tooling/gateway.js +422 -0
  127. package/dist/src/control-plane/runtime/tooling/index.js +1290 -0
  128. package/dist/src/control-plane/runtime/tooling/shell.js +205 -0
  129. package/dist/src/control-plane/runtime/types.js +1 -0
  130. package/dist/src/control-plane/setup-version.js +14 -0
  131. package/dist/src/control-plane/state-sync/index.js +1509 -0
  132. package/dist/src/control-plane/state-sync/read.js +856 -0
  133. package/dist/src/control-plane/state-sync/reconcile.js +260 -0
  134. package/dist/src/control-plane/state-sync/repo.js +302 -0
  135. package/dist/src/control-plane/state-sync/types.js +111 -0
  136. package/dist/src/control-plane/state-sync/write.js +1469 -0
  137. package/dist/src/control-plane/task-fields.js +38 -0
  138. package/dist/src/control-plane/task-source-bootstrap.js +46 -0
  139. package/dist/src/control-plane/task-source.js +30 -0
  140. package/dist/src/control-plane/tasks/legacy-task-config-source.js +130 -0
  141. package/dist/src/control-plane/tasks/plugin-task-source.js +103 -0
  142. package/dist/src/control-plane/tasks/source-aware-task-config-source.js +611 -0
  143. package/dist/src/control-plane/tasks/source-lifecycle.js +1093 -0
  144. package/dist/src/control-plane/tasks/task-record-reader.js +9 -0
  145. package/dist/src/control-plane/validators/boundary/public-apis.js +107 -0
  146. package/dist/src/control-plane/validators/integration/_shared.js +51 -0
  147. package/dist/src/control-plane/validators/integration/adm-audit-http.js +85 -0
  148. package/dist/src/control-plane/validators/integration/adm-auth-http.js +78 -0
  149. package/dist/src/control-plane/validators/integration/adm-issuer-http.js +80 -0
  150. package/dist/src/control-plane/validators/integration/adm-migration.js +78 -0
  151. package/dist/src/control-plane/validators/integration/adm-scaffold.js +78 -0
  152. package/dist/src/control-plane/validators/runtime-registration.js +64 -0
  153. package/dist/src/control-plane/validators/shared.js +683 -0
  154. package/dist/src/events.js +218 -0
  155. package/dist/src/execution.js +35 -0
  156. package/dist/src/index.js +1633 -0
  157. package/dist/src/layout.js +145 -0
  158. package/dist/src/local-server.js +202 -0
  159. package/dist/src/plugins.js +329 -0
  160. package/dist/src/remote-http.js +83 -0
  161. package/dist/src/runtime-context.js +216 -0
  162. package/dist/src/types.js +1 -0
  163. package/native/darwin-arm64/bin/rig-git +0 -0
  164. package/native/darwin-arm64/bin/rig-shell +0 -0
  165. package/native/darwin-arm64/bin/rig-tools +0 -0
  166. package/native/darwin-arm64/lib/runtime-native-darwin-arm64.dylib +0 -0
  167. package/native/darwin-arm64/lib/runtime-native.dylib +0 -0
  168. package/native/darwin-arm64/manifest.json +1 -0
  169. package/native/linux-x64/bin/rig-git +0 -0
  170. package/native/linux-x64/bin/rig-shell +0 -0
  171. package/native/linux-x64/bin/rig-tools +0 -0
  172. package/native/linux-x64/lib/runtime-native-linux-x64.so +0 -0
  173. package/native/linux-x64/lib/runtime-native.so +0 -0
  174. package/native/linux-x64/manifest.json +1 -0
  175. package/package.json +74 -0
  176. package/skills/rig-task-run.md +71 -0
@@ -0,0 +1,167 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/authority-files.ts
3
+ import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync, appendFileSync, copyFileSync, statSync, readdirSync, chmodSync } from "fs";
4
+ import { dirname as dirname2, join, relative, resolve as resolve2 } from "path";
5
+ import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
6
+
7
+ // packages/runtime/src/layout.ts
8
+ import { existsSync } from "fs";
9
+ import { basename, dirname, resolve } from "path";
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
+
49
+ // packages/runtime/src/control-plane/authority-files.ts
50
+ function resolveAuthorityProjectStateDir(projectRoot) {
51
+ const explicit = process.env.RIG_STATE_DIR?.trim();
52
+ if (explicit) {
53
+ return resolve2(explicit);
54
+ }
55
+ return resolve2(resolve2(projectRoot), ".rig", "state");
56
+ }
57
+ function readJsonAtPath(path, fallback) {
58
+ if (!existsSync2(path)) {
59
+ return fallback;
60
+ }
61
+ try {
62
+ return JSON.parse(readFileSync(path, "utf-8"));
63
+ } catch {
64
+ return fallback;
65
+ }
66
+ }
67
+ function writeJsonAtPath(path, value) {
68
+ mkdirSync(dirname2(path), { recursive: true });
69
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
70
+ `, "utf8");
71
+ return path;
72
+ }
73
+ function readAuthorityProjectStateJson(projectRoot, relativePath, fallback) {
74
+ return readJsonAtPath(resolve2(resolveAuthorityProjectStateDir(projectRoot), relativePath), fallback);
75
+ }
76
+ function writeAuthorityProjectStateJson(projectRoot, relativePath, value) {
77
+ return writeJsonAtPath(resolve2(resolveAuthorityProjectStateDir(projectRoot), relativePath), value);
78
+ }
79
+
80
+ // packages/runtime/src/control-plane/repos/layout.ts
81
+ import { existsSync as existsSync3 } from "fs";
82
+ import { basename as basename2, dirname as dirname3, join as join2, resolve as resolve3 } from "path";
83
+
84
+ // packages/runtime/src/control-plane/repos/registry.ts
85
+ var MANAGED_REPOS = new Map;
86
+ function getManagedRepoEntry(repoId) {
87
+ const entry = MANAGED_REPOS.get(repoId);
88
+ if (!entry) {
89
+ throw new Error(`managed repo not registered: ${repoId}. Plugins contribute repos via RigPlugin.contributes.repoSources; ` + `make sure a plugin declares this id and the plugin host has been initialized.`);
90
+ }
91
+ return entry;
92
+ }
93
+ function listManagedRepoEntries() {
94
+ return Array.from(MANAGED_REPOS.values());
95
+ }
96
+
97
+ // packages/runtime/src/control-plane/repos/layout.ts
98
+ function resolveRepoStateDir(projectRoot) {
99
+ const normalizedProjectRoot = resolve3(projectRoot);
100
+ const projectParent = dirname3(normalizedProjectRoot);
101
+ if (basename2(projectParent) === ".worktrees") {
102
+ const ownerRoot = dirname3(projectParent);
103
+ const ownerHasRepoMarkers = existsSync3(resolve3(ownerRoot, ".git")) || existsSync3(resolve3(ownerRoot, ".rig", "state"));
104
+ if (ownerHasRepoMarkers) {
105
+ return resolve3(ownerRoot, ".rig", "state");
106
+ }
107
+ }
108
+ return resolve3(projectRoot, ".rig", "state");
109
+ }
110
+ function resolveManagedRepoLayout(projectRoot, repoId) {
111
+ const normalizedProjectRoot = resolve3(projectRoot);
112
+ const entry = getManagedRepoEntry(repoId);
113
+ const stateDir = resolveRepoStateDir(normalizedProjectRoot);
114
+ const metadataRelativePath = join2("repos", entry.id);
115
+ const metadataRoot = resolve3(stateDir, metadataRelativePath);
116
+ const runtimeWorkspace = process.env.RIG_TASK_WORKSPACE?.trim();
117
+ const runsInsideTaskWorktree = runtimeWorkspace && resolve3(runtimeWorkspace) === normalizedProjectRoot || basename2(dirname3(normalizedProjectRoot)) === ".worktrees";
118
+ const isPrimaryManagedRepo = listManagedRepoEntries()[0]?.id === repoId;
119
+ const checkoutRoot = isPrimaryManagedRepo && runsInsideTaskWorktree ? resolveMonorepoRoot(normalizedProjectRoot) : entry.checkoutEnvVar && process.env[entry.checkoutEnvVar]?.trim() ? resolve3(process.env[entry.checkoutEnvVar].trim()) : resolve3(normalizedProjectRoot, entry.alias);
120
+ return {
121
+ projectRoot: normalizedProjectRoot,
122
+ repoId: entry.id,
123
+ alias: entry.alias,
124
+ defaultBranch: entry.defaultBranch,
125
+ remoteUrl: entry.remoteEnvVar && process.env[entry.remoteEnvVar]?.trim() ? process.env[entry.remoteEnvVar].trim() : entry.defaultRemoteUrl,
126
+ checkoutRoot,
127
+ worktreesRoot: resolve3(checkoutRoot, ".worktrees"),
128
+ stateDir,
129
+ metadataRoot,
130
+ metadataRelativePath,
131
+ mirrorRoot: resolve3(metadataRoot, "mirror.git"),
132
+ mirrorStatePath: resolve3(metadataRoot, "mirror-state.json"),
133
+ mirrorStateRelativePath: join2(metadataRelativePath, "mirror-state.json")
134
+ };
135
+ }
136
+
137
+ // packages/runtime/src/control-plane/repos/mirror/state.ts
138
+ var STATE_VERSION = 1;
139
+ function defaultMirrorState(projectRoot, repoId) {
140
+ const layout = resolveManagedRepoLayout(projectRoot, repoId);
141
+ return {
142
+ version: STATE_VERSION,
143
+ repoId,
144
+ remoteUrl: layout.remoteUrl,
145
+ defaultBranch: layout.defaultBranch
146
+ };
147
+ }
148
+ function readManagedRepoMirrorState(projectRoot, repoId) {
149
+ const layout = resolveManagedRepoLayout(projectRoot, repoId);
150
+ return readAuthorityProjectStateJson(projectRoot, layout.mirrorStateRelativePath, null);
151
+ }
152
+ function writeManagedRepoMirrorState(projectRoot, repoId, patch) {
153
+ const current = readManagedRepoMirrorState(projectRoot, repoId) || defaultMirrorState(projectRoot, repoId);
154
+ const next = {
155
+ ...current,
156
+ ...patch,
157
+ version: STATE_VERSION,
158
+ repoId
159
+ };
160
+ const layout = resolveManagedRepoLayout(projectRoot, repoId);
161
+ writeAuthorityProjectStateJson(projectRoot, layout.mirrorStateRelativePath, next);
162
+ return next;
163
+ }
164
+ export {
165
+ writeManagedRepoMirrorState,
166
+ readManagedRepoMirrorState
167
+ };
@@ -0,0 +1,77 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/repos/registry.ts
3
+ function createRepoRegistry(entries) {
4
+ const map = new Map;
5
+ for (const e of entries) {
6
+ if (map.has(e.id))
7
+ throw new Error(`repo already registered: ${e.id}`);
8
+ map.set(e.id, { ...e });
9
+ }
10
+ const ordered = Array.from(map.values());
11
+ return {
12
+ getById: (id) => map.get(id),
13
+ list: () => ordered
14
+ };
15
+ }
16
+ var MANAGED_REPOS = new Map;
17
+ function setManagedRepos(entries) {
18
+ const next = new Map;
19
+ for (const e of entries) {
20
+ if (next.has(e.id)) {
21
+ throw new Error(`managed repo already registered: ${e.id}`);
22
+ }
23
+ next.set(e.id, e);
24
+ }
25
+ MANAGED_REPOS = next;
26
+ }
27
+ function clearManagedRepos() {
28
+ MANAGED_REPOS = new Map;
29
+ }
30
+ function getManagedRepoEntry(repoId) {
31
+ const entry = MANAGED_REPOS.get(repoId);
32
+ if (!entry) {
33
+ throw new Error(`managed repo not registered: ${repoId}. Plugins contribute repos via RigPlugin.contributes.repoSources; ` + `make sure a plugin declares this id and the plugin host has been initialized.`);
34
+ }
35
+ return entry;
36
+ }
37
+ function tryGetManagedRepoEntry(repoId) {
38
+ return MANAGED_REPOS.get(repoId);
39
+ }
40
+ function listManagedRepoEntries() {
41
+ return Array.from(MANAGED_REPOS.values());
42
+ }
43
+ function resolveManagedRepoIdByAlias(alias) {
44
+ for (const entry of MANAGED_REPOS.values()) {
45
+ if (entry.alias === alias) {
46
+ return entry.id;
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ function isManagedRepoAlias(alias) {
52
+ return resolveManagedRepoIdByAlias(alias) !== null;
53
+ }
54
+ function repoRegistrationToManagedEntry(reg) {
55
+ if (!reg.defaultBranch) {
56
+ return null;
57
+ }
58
+ return {
59
+ id: reg.id,
60
+ alias: reg.defaultPath ?? reg.id,
61
+ defaultBranch: reg.defaultBranch,
62
+ defaultRemoteUrl: reg.url,
63
+ remoteEnvVar: reg.remoteEnvVar,
64
+ checkoutEnvVar: reg.checkoutEnvVar
65
+ };
66
+ }
67
+ export {
68
+ tryGetManagedRepoEntry,
69
+ setManagedRepos,
70
+ resolveManagedRepoIdByAlias,
71
+ repoRegistrationToManagedEntry,
72
+ listManagedRepoEntries,
73
+ isManagedRepoAlias,
74
+ getManagedRepoEntry,
75
+ createRepoRegistry,
76
+ clearManagedRepos
77
+ };
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,48 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/runtime/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,120 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/runtime/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_API_KEY: resolved.GREPTILE_API_KEY || "",
90
+ RIG_BAKED_GREPTILE_GITHUB_TOKEN: resolved.GREPTILE_GITHUB_TOKEN || "",
91
+ RIG_BAKED_GREPTILE_POLL_ATTEMPTS: resolved.GREPTILE_POLL_ATTEMPTS || "",
92
+ RIG_BAKED_GREPTILE_POLL_INTERVAL_MS: resolved.GREPTILE_POLL_INTERVAL_MS || "",
93
+ RIG_BAKED_GITHUB_TOKEN: resolved.GITHUB_TOKEN || resolved.GH_TOKEN || "",
94
+ RIG_BAKED_GITHUB_SSH_KEY: resolved.GITHUB_SSH_KEY || "",
95
+ RIG_BAKED_AWS_ACCESS_KEY_ID: resolved.AWS_ACCESS_KEY_ID || "",
96
+ RIG_BAKED_AWS_SECRET_ACCESS_KEY: resolved.AWS_SECRET_ACCESS_KEY || "",
97
+ RIG_BAKED_AWS_REGION: resolved.AWS_REGION || "",
98
+ RIG_BAKED_LINEAR_API_KEY: resolved.LINEAR_API_KEY || "",
99
+ RIG_BAKED_LINEAR_WEBHOOK_SECRET: resolved.LINEAR_WEBHOOK_SECRET || ""
100
+ };
101
+ }
102
+ function expandShellValue(rawValue, env) {
103
+ let value = rawValue.trim();
104
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
105
+ value = value.slice(1, -1);
106
+ }
107
+ return value.replace(/\$\{([A-Z0-9_]+)(:-([^}]*))?\}/g, (_match, name, _defaultGroup, fallback) => {
108
+ const envValue = env[name]?.trim();
109
+ if (envValue) {
110
+ return envValue;
111
+ }
112
+ return fallback ?? "";
113
+ });
114
+ }
115
+ export {
116
+ secretDefinesFromEnv,
117
+ resolveRuntimeSecrets,
118
+ loadDotEnvSecrets,
119
+ BAKED_RUNTIME_SECRETS
120
+ };