@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,9 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/tasks/task-record-reader.ts
3
+ async function findTaskById(reader, id) {
4
+ const tasks = await reader.listTasks();
5
+ return tasks.find((task) => task.id === id) ?? null;
6
+ }
7
+ export {
8
+ findTaskById
9
+ };
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // packages/runtime/src/control-plane/validators/boundary/public-apis.ts
5
+ import { existsSync, readFileSync, readdirSync } from "fs";
6
+ import { join } from "path";
7
+ import { Checker } from "@rig/validator-kit";
8
+ var ID = "boundary:public-apis";
9
+ var checker = new Checker;
10
+ var workspaceRoot = process.cwd();
11
+ var modulesRoots = findModulesRoots(workspaceRoot, 0);
12
+ if (modulesRoots.length === 0) {
13
+ checker.pass("no modules directory present");
14
+ checker.emit(ID);
15
+ }
16
+ var moduleDirs = [];
17
+ for (const modulesRoot of modulesRoots) {
18
+ for (const entry of readdirSync(modulesRoot, { withFileTypes: true })) {
19
+ if (entry.isDirectory()) {
20
+ moduleDirs.push(join(modulesRoot, entry.name));
21
+ }
22
+ }
23
+ }
24
+ for (const moduleDir of moduleDirs) {
25
+ const moduleName = relativeModuleName(workspaceRoot, moduleDir);
26
+ const tsFiles = collectTsFiles(moduleDir);
27
+ if (tsFiles.length === 0) {
28
+ continue;
29
+ }
30
+ const indexPath = join(moduleDir, "index.ts");
31
+ if (!existsSync(indexPath)) {
32
+ checker.fail(moduleName, `missing index.ts in src/modules/${moduleName}/`);
33
+ continue;
34
+ }
35
+ if (!indexHasExports(indexPath)) {
36
+ checker.fail(moduleName, `src/modules/${moduleName}/index.ts has no export statements`);
37
+ continue;
38
+ }
39
+ checker.pass(moduleName);
40
+ }
41
+ checker.emit(ID);
42
+ function findModulesRoots(start, depth, max = 6) {
43
+ const out = [];
44
+ if (depth > max)
45
+ return out;
46
+ if (!existsSync(start))
47
+ return out;
48
+ let entries;
49
+ try {
50
+ entries = readdirSync(start, { withFileTypes: true });
51
+ } catch {
52
+ return out;
53
+ }
54
+ for (const entry of entries) {
55
+ if (!entry.isDirectory())
56
+ continue;
57
+ if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".rig")
58
+ continue;
59
+ if (entry.name === "modules" && depth >= 1) {
60
+ const parts = start.split("/");
61
+ if (parts[parts.length - 1] === "src") {
62
+ out.push(join(start, entry.name));
63
+ continue;
64
+ }
65
+ }
66
+ out.push(...findModulesRoots(join(start, entry.name), depth + 1, max));
67
+ }
68
+ return out;
69
+ }
70
+ function relativeModuleName(workspaceRoot2, moduleDir) {
71
+ const rel = moduleDir.startsWith(workspaceRoot2) ? moduleDir.slice(workspaceRoot2.length + 1) : moduleDir;
72
+ const segments = rel.split("/");
73
+ const idx = segments.lastIndexOf("modules");
74
+ if (idx >= 0 && idx < segments.length - 1) {
75
+ return segments.slice(idx + 1).join("/");
76
+ }
77
+ return rel;
78
+ }
79
+ function collectTsFiles(dir) {
80
+ const out = [];
81
+ const entries = readdirSync(dir, { withFileTypes: true });
82
+ for (const entry of entries) {
83
+ const path = join(dir, entry.name);
84
+ if (entry.isDirectory()) {
85
+ out.push(...collectTsFiles(path));
86
+ } else if (entry.isFile() && entry.name.endsWith(".ts")) {
87
+ out.push(path);
88
+ }
89
+ }
90
+ return out;
91
+ }
92
+ function indexHasExports(indexPath) {
93
+ const lines = readFileSync(indexPath, "utf-8").split(/\r?\n/);
94
+ for (const line of lines) {
95
+ const trimmed = line.trim();
96
+ if (!trimmed)
97
+ continue;
98
+ if (trimmed.startsWith("//"))
99
+ continue;
100
+ if (trimmed.startsWith("/*") || trimmed.startsWith("*"))
101
+ continue;
102
+ if (/^export\b/.test(trimmed)) {
103
+ return true;
104
+ }
105
+ }
106
+ return false;
107
+ }
@@ -0,0 +1,51 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/validators/integration/_shared.ts
3
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
4
+ import { join, resolve } from "path";
5
+ function findAdminServiceRoot(workspaceRoot) {
6
+ const candidates = [
7
+ resolve(workspaceRoot, "microservices", "hp-admin-service")
8
+ ];
9
+ for (const candidate of candidates) {
10
+ if (existsSync(candidate))
11
+ return candidate;
12
+ }
13
+ return findRecursive(workspaceRoot, "hp-admin-service", 0, 6);
14
+ }
15
+ function findRecursive(dir, name, depth, max) {
16
+ if (depth > max || !existsSync(dir))
17
+ return null;
18
+ let entries;
19
+ try {
20
+ entries = readdirSync(dir, { withFileTypes: true });
21
+ } catch {
22
+ return null;
23
+ }
24
+ for (const entry of entries) {
25
+ if (!entry.isDirectory())
26
+ continue;
27
+ if (entry.name === "node_modules" || entry.name === ".git")
28
+ continue;
29
+ if (entry.name === name)
30
+ return join(dir, name);
31
+ const nested = findRecursive(join(dir, entry.name), name, depth + 1, max);
32
+ if (nested)
33
+ return nested;
34
+ }
35
+ return null;
36
+ }
37
+ function readFileOrNull(path) {
38
+ if (!existsSync(path))
39
+ return null;
40
+ try {
41
+ if (!statSync(path).isFile())
42
+ return null;
43
+ return readFileSync(path, "utf-8");
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+ export {
49
+ readFileOrNull,
50
+ findAdminServiceRoot
51
+ };
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // packages/runtime/src/control-plane/validators/integration/adm-audit-http.ts
5
+ import { resolve as resolve2 } from "path";
6
+ import { Checker } from "@rig/validator-kit";
7
+
8
+ // packages/runtime/src/control-plane/validators/integration/_shared.ts
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
10
+ import { join, resolve } from "path";
11
+ function findAdminServiceRoot(workspaceRoot) {
12
+ const candidates = [
13
+ resolve(workspaceRoot, "microservices", "hp-admin-service")
14
+ ];
15
+ for (const candidate of candidates) {
16
+ if (existsSync(candidate))
17
+ return candidate;
18
+ }
19
+ return findRecursive(workspaceRoot, "hp-admin-service", 0, 6);
20
+ }
21
+ function findRecursive(dir, name, depth, max) {
22
+ if (depth > max || !existsSync(dir))
23
+ return null;
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir, { withFileTypes: true });
27
+ } catch {
28
+ return null;
29
+ }
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory())
32
+ continue;
33
+ if (entry.name === "node_modules" || entry.name === ".git")
34
+ continue;
35
+ if (entry.name === name)
36
+ return join(dir, name);
37
+ const nested = findRecursive(join(dir, entry.name), name, depth + 1, max);
38
+ if (nested)
39
+ return nested;
40
+ }
41
+ return null;
42
+ }
43
+ function readFileOrNull(path) {
44
+ if (!existsSync(path))
45
+ return null;
46
+ try {
47
+ if (!statSync(path).isFile())
48
+ return null;
49
+ return readFileSync(path, "utf-8");
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ // packages/runtime/src/control-plane/validators/integration/adm-audit-http.ts
56
+ var ID = "integration:adm-audit-http";
57
+ var checker = new Checker;
58
+ var adminRoot = findAdminServiceRoot(process.cwd());
59
+ if (!adminRoot) {
60
+ checker.fail("hp-admin-service", "missing microservices/hp-admin-service directory");
61
+ checker.emit(ID);
62
+ }
63
+ var routes = readFileOrNull(resolve2(adminRoot, "src", "http", "audit-routes.ts"));
64
+ if (routes === null) {
65
+ checker.fail("audit-routes.ts", "src/http/audit-routes.ts is missing");
66
+ checker.emit(ID);
67
+ }
68
+ if (!/AuditService\.findEvents/.test(routes)) {
69
+ checker.fail("AuditService.findEvents proxy", "audit-routes.ts must proxy to AuditService.findEvents via grpc field");
70
+ } else {
71
+ checker.pass("AuditService.findEvents proxy");
72
+ }
73
+ var expectedQueryFields = ["adminId", "action", "resourceType", "page", "pageSize"];
74
+ var missing = expectedQueryFields.filter((field) => !routes.includes(`"${field}"`));
75
+ if (missing.length > 0) {
76
+ checker.fail("paginated query fields", `audit-routes.ts query is missing fields: ${missing.join(", ")}`);
77
+ } else {
78
+ checker.pass("paginated query fields");
79
+ }
80
+ if (/collection\.\w+\(|\bDb\.collection\(|humanity_AdminAuditLogs\s+collection/.test(routes)) {
81
+ checker.fail("no direct Mongo access", "audit-routes.ts must not access Mongo collections directly; use AuditService.findEvents instead");
82
+ } else {
83
+ checker.pass("no direct Mongo access");
84
+ }
85
+ checker.emit(ID);
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // packages/runtime/src/control-plane/validators/integration/adm-auth-http.ts
5
+ import { resolve as resolve2 } from "path";
6
+ import { Checker } from "@rig/validator-kit";
7
+
8
+ // packages/runtime/src/control-plane/validators/integration/_shared.ts
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
10
+ import { join, resolve } from "path";
11
+ function findAdminServiceRoot(workspaceRoot) {
12
+ const candidates = [
13
+ resolve(workspaceRoot, "microservices", "hp-admin-service")
14
+ ];
15
+ for (const candidate of candidates) {
16
+ if (existsSync(candidate))
17
+ return candidate;
18
+ }
19
+ return findRecursive(workspaceRoot, "hp-admin-service", 0, 6);
20
+ }
21
+ function findRecursive(dir, name, depth, max) {
22
+ if (depth > max || !existsSync(dir))
23
+ return null;
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir, { withFileTypes: true });
27
+ } catch {
28
+ return null;
29
+ }
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory())
32
+ continue;
33
+ if (entry.name === "node_modules" || entry.name === ".git")
34
+ continue;
35
+ if (entry.name === name)
36
+ return join(dir, name);
37
+ const nested = findRecursive(join(dir, entry.name), name, depth + 1, max);
38
+ if (nested)
39
+ return nested;
40
+ }
41
+ return null;
42
+ }
43
+ function readFileOrNull(path) {
44
+ if (!existsSync(path))
45
+ return null;
46
+ try {
47
+ if (!statSync(path).isFile())
48
+ return null;
49
+ return readFileSync(path, "utf-8");
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ // packages/runtime/src/control-plane/validators/integration/adm-auth-http.ts
56
+ var ID = "integration:adm-auth-http";
57
+ var checker = new Checker;
58
+ var adminRoot = findAdminServiceRoot(process.cwd());
59
+ if (!adminRoot) {
60
+ checker.fail("hp-admin-service", "missing microservices/hp-admin-service directory");
61
+ checker.emit(ID);
62
+ }
63
+ var routes = readFileOrNull(resolve2(adminRoot, "src", "http", "auth-routes.ts"));
64
+ if (routes === null) {
65
+ checker.fail("auth-routes.ts", "src/http/auth-routes.ts is missing");
66
+ checker.emit(ID);
67
+ }
68
+ if (!/X-HP-Admin-Key/.test(routes)) {
69
+ checker.fail("X-HP-Admin-Key enforcement", 'auth-routes.ts must declare adminKeyHeader = "X-HP-Admin-Key" enforcement');
70
+ } else {
71
+ checker.pass("X-HP-Admin-Key enforcement");
72
+ }
73
+ if (!/\b(OrgService|ApiKeyService)\.\w+/.test(routes)) {
74
+ checker.fail("auth-routes proxy", "auth-routes.ts must proxy to OrgService.* / ApiKeyService.* gRPC methods");
75
+ } else {
76
+ checker.pass("auth-routes proxy");
77
+ }
78
+ checker.emit(ID);
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // packages/runtime/src/control-plane/validators/integration/adm-issuer-http.ts
5
+ import { resolve as resolve2 } from "path";
6
+ import { Checker } from "@rig/validator-kit";
7
+
8
+ // packages/runtime/src/control-plane/validators/integration/_shared.ts
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
10
+ import { join, resolve } from "path";
11
+ function findAdminServiceRoot(workspaceRoot) {
12
+ const candidates = [
13
+ resolve(workspaceRoot, "microservices", "hp-admin-service")
14
+ ];
15
+ for (const candidate of candidates) {
16
+ if (existsSync(candidate))
17
+ return candidate;
18
+ }
19
+ return findRecursive(workspaceRoot, "hp-admin-service", 0, 6);
20
+ }
21
+ function findRecursive(dir, name, depth, max) {
22
+ if (depth > max || !existsSync(dir))
23
+ return null;
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir, { withFileTypes: true });
27
+ } catch {
28
+ return null;
29
+ }
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory())
32
+ continue;
33
+ if (entry.name === "node_modules" || entry.name === ".git")
34
+ continue;
35
+ if (entry.name === name)
36
+ return join(dir, name);
37
+ const nested = findRecursive(join(dir, entry.name), name, depth + 1, max);
38
+ if (nested)
39
+ return nested;
40
+ }
41
+ return null;
42
+ }
43
+ function readFileOrNull(path) {
44
+ if (!existsSync(path))
45
+ return null;
46
+ try {
47
+ if (!statSync(path).isFile())
48
+ return null;
49
+ return readFileSync(path, "utf-8");
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ // packages/runtime/src/control-plane/validators/integration/adm-issuer-http.ts
56
+ var ID = "integration:adm-issuer-http";
57
+ var checker = new Checker;
58
+ var adminRoot = findAdminServiceRoot(process.cwd());
59
+ if (!adminRoot) {
60
+ checker.fail("hp-admin-service", "missing microservices/hp-admin-service directory");
61
+ checker.emit(ID);
62
+ }
63
+ var routes = readFileOrNull(resolve2(adminRoot, "src", "http", "issuer-routes.ts"));
64
+ if (routes === null) {
65
+ checker.fail("issuer-routes.ts", "src/http/issuer-routes.ts is missing");
66
+ checker.emit(ID);
67
+ }
68
+ if (!/\bIssuerService\.\w+/.test(routes)) {
69
+ checker.fail("issuer-routes routing", "issuer-routes.ts must proxy to IssuerService.* gRPC methods");
70
+ } else {
71
+ checker.pass("issuer-routes routing");
72
+ }
73
+ var forbidden = ["hp-signer", "AWS KMS", "StakingManager"];
74
+ var leaks = forbidden.filter((needle) => routes.includes(needle));
75
+ if (leaks.length > 0) {
76
+ checker.fail("no signer/staking leak", `issuer-routes.ts must not contain ${leaks.join(", ")} \u2014 that logic belongs in hp-issuer-service`);
77
+ } else {
78
+ checker.pass("no signer/staking leak");
79
+ }
80
+ checker.emit(ID);
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // packages/runtime/src/control-plane/validators/integration/adm-migration.ts
5
+ import { resolve as resolve2 } from "path";
6
+ import { Checker } from "@rig/validator-kit";
7
+
8
+ // packages/runtime/src/control-plane/validators/integration/_shared.ts
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
10
+ import { join, resolve } from "path";
11
+ function findAdminServiceRoot(workspaceRoot) {
12
+ const candidates = [
13
+ resolve(workspaceRoot, "microservices", "hp-admin-service")
14
+ ];
15
+ for (const candidate of candidates) {
16
+ if (existsSync(candidate))
17
+ return candidate;
18
+ }
19
+ return findRecursive(workspaceRoot, "hp-admin-service", 0, 6);
20
+ }
21
+ function findRecursive(dir, name, depth, max) {
22
+ if (depth > max || !existsSync(dir))
23
+ return null;
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir, { withFileTypes: true });
27
+ } catch {
28
+ return null;
29
+ }
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory())
32
+ continue;
33
+ if (entry.name === "node_modules" || entry.name === ".git")
34
+ continue;
35
+ if (entry.name === name)
36
+ return join(dir, name);
37
+ const nested = findRecursive(join(dir, entry.name), name, depth + 1, max);
38
+ if (nested)
39
+ return nested;
40
+ }
41
+ return null;
42
+ }
43
+ function readFileOrNull(path) {
44
+ if (!existsSync(path))
45
+ return null;
46
+ try {
47
+ if (!statSync(path).isFile())
48
+ return null;
49
+ return readFileSync(path, "utf-8");
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ // packages/runtime/src/control-plane/validators/integration/adm-migration.ts
56
+ var ID = "integration:adm-migration";
57
+ var checker = new Checker;
58
+ var adminRoot = findAdminServiceRoot(process.cwd());
59
+ if (!adminRoot) {
60
+ checker.fail("hp-admin-service", "missing microservices/hp-admin-service directory");
61
+ checker.emit(ID);
62
+ }
63
+ var migration = readFileOrNull(resolve2(adminRoot, "src", "migrations", "migrate-admin-audit-logs.ts"));
64
+ if (migration === null) {
65
+ checker.fail("migrate-admin-audit-logs.ts", "src/migrations/migrate-admin-audit-logs.ts is missing");
66
+ checker.emit(ID);
67
+ }
68
+ if (!/\bdry-?run\b|\bdryRun\b/i.test(migration)) {
69
+ checker.fail("dry-run support", "migration script must support a dry-run mode (no dry-run parameter found)");
70
+ } else {
71
+ checker.pass("dry-run support");
72
+ }
73
+ if (!/\bidempot/i.test(migration) && !/\bupsert\b/i.test(migration)) {
74
+ checker.fail("idempotency contract", "migration script must declare idempotent behavior (idempotent flag or upsert mode)");
75
+ } else {
76
+ checker.pass("idempotency contract");
77
+ }
78
+ checker.emit(ID);
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // packages/runtime/src/control-plane/validators/integration/adm-scaffold.ts
5
+ import { resolve as resolve2 } from "path";
6
+ import { Checker } from "@rig/validator-kit";
7
+
8
+ // packages/runtime/src/control-plane/validators/integration/_shared.ts
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
10
+ import { join, resolve } from "path";
11
+ function findAdminServiceRoot(workspaceRoot) {
12
+ const candidates = [
13
+ resolve(workspaceRoot, "microservices", "hp-admin-service")
14
+ ];
15
+ for (const candidate of candidates) {
16
+ if (existsSync(candidate))
17
+ return candidate;
18
+ }
19
+ return findRecursive(workspaceRoot, "hp-admin-service", 0, 6);
20
+ }
21
+ function findRecursive(dir, name, depth, max) {
22
+ if (depth > max || !existsSync(dir))
23
+ return null;
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir, { withFileTypes: true });
27
+ } catch {
28
+ return null;
29
+ }
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory())
32
+ continue;
33
+ if (entry.name === "node_modules" || entry.name === ".git")
34
+ continue;
35
+ if (entry.name === name)
36
+ return join(dir, name);
37
+ const nested = findRecursive(join(dir, entry.name), name, depth + 1, max);
38
+ if (nested)
39
+ return nested;
40
+ }
41
+ return null;
42
+ }
43
+ function readFileOrNull(path) {
44
+ if (!existsSync(path))
45
+ return null;
46
+ try {
47
+ if (!statSync(path).isFile())
48
+ return null;
49
+ return readFileSync(path, "utf-8");
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ // packages/runtime/src/control-plane/validators/integration/adm-scaffold.ts
56
+ var ID = "integration:adm-scaffold";
57
+ var checker = new Checker;
58
+ var adminRoot = findAdminServiceRoot(process.cwd());
59
+ if (!adminRoot) {
60
+ checker.fail("hp-admin-service", "missing microservices/hp-admin-service directory");
61
+ checker.emit(ID);
62
+ }
63
+ for (const file of ["package.json", "tsconfig.json", "Dockerfile", "docker-compose.yml"]) {
64
+ if (readFileOrNull(resolve2(adminRoot, file)) === null) {
65
+ checker.fail(file, `missing required file: ${file}`);
66
+ } else {
67
+ checker.pass(file);
68
+ }
69
+ }
70
+ var compose = readFileOrNull(resolve2(adminRoot, "docker-compose.yml"));
71
+ if (compose !== null) {
72
+ if (!/\bmongo\b/i.test(compose)) {
73
+ checker.fail("docker-compose mongo", "docker-compose.yml is missing a mongo service contract");
74
+ } else {
75
+ checker.pass("docker-compose mongo");
76
+ }
77
+ }
78
+ checker.emit(ID);
@@ -0,0 +1,64 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/validators/runtime-registration.ts
3
+ import { existsSync } from "fs";
4
+ import { join } from "path";
5
+ function createValidatorRegistry() {
6
+ const map = new Map;
7
+ const order = [];
8
+ const registry = {
9
+ register(v) {
10
+ if (map.has(v.id))
11
+ throw new Error(`validator already registered: ${v.id}`);
12
+ map.set(v.id, v);
13
+ order.push(v);
14
+ },
15
+ resolve(id) {
16
+ const v = map.get(id);
17
+ if (!v)
18
+ throw new Error(`validator not registered: ${id}`);
19
+ return v;
20
+ },
21
+ list: () => order
22
+ };
23
+ registerBuiltInValidators(registry);
24
+ return registry;
25
+ }
26
+ function registerBuiltInValidators(registry) {
27
+ registry.register({
28
+ id: "std:typecheck",
29
+ category: "custom",
30
+ description: "Runs the package typecheck script when present.",
31
+ run: async (ctx) => runStdTypecheck(ctx)
32
+ });
33
+ }
34
+ async function runStdTypecheck(ctx) {
35
+ const packageJsonPath = join(ctx.workspaceRoot, "package.json");
36
+ if (!existsSync(packageJsonPath)) {
37
+ return {
38
+ id: "std:typecheck",
39
+ passed: false,
40
+ summary: `package.json not found at ${packageJsonPath}`
41
+ };
42
+ }
43
+ const proc = Bun.spawn(["bun", "run", "typecheck"], {
44
+ cwd: ctx.workspaceRoot,
45
+ env: process.env,
46
+ stdout: "pipe",
47
+ stderr: "pipe"
48
+ });
49
+ const [exitCode, stdout, stderr] = await Promise.all([
50
+ proc.exited,
51
+ new Response(proc.stdout).text(),
52
+ new Response(proc.stderr).text()
53
+ ]);
54
+ const output = `${stdout}${stderr}`.trim();
55
+ return {
56
+ id: "std:typecheck",
57
+ passed: exitCode === 0,
58
+ summary: exitCode === 0 ? "typecheck passed" : "typecheck failed",
59
+ ...output ? { details: output.slice(0, 4000) } : {}
60
+ };
61
+ }
62
+ export {
63
+ createValidatorRegistry
64
+ };