@h-rig/core 0.0.6-alpha.18 → 0.0.6-alpha.180

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 (105) hide show
  1. package/dist/src/agent-role-registry.d.ts +4 -0
  2. package/dist/src/agent-role-registry.js +27 -0
  3. package/dist/src/authority-paths.d.ts +15 -0
  4. package/dist/src/authority-paths.js +80 -0
  5. package/dist/src/baked-secrets.d.ts +3 -0
  6. package/dist/src/baked-secrets.js +63 -0
  7. package/dist/src/build-time-config.d.ts +12 -0
  8. package/dist/src/build-time-config.js +25 -0
  9. package/dist/src/build-time-config.macro.d.ts +1 -0
  10. package/dist/src/capability-loaders.d.ts +51 -0
  11. package/dist/src/capability-loaders.js +870 -0
  12. package/dist/src/capability.d.ts +79 -0
  13. package/dist/src/capability.js +63 -0
  14. package/dist/src/checkout-root.d.ts +1 -0
  15. package/dist/src/checkout-root.js +30 -0
  16. package/dist/src/config-env.d.ts +4 -0
  17. package/dist/src/config-env.js +23 -0
  18. package/dist/src/config.d.ts +3 -0
  19. package/dist/src/config.js +44 -0
  20. package/dist/src/declarative-config.d.ts +14 -0
  21. package/dist/src/declarative-config.js +85 -0
  22. package/dist/src/default-kernel.d.ts +1 -0
  23. package/dist/src/default-kernel.js +12 -0
  24. package/dist/src/define-config.d.ts +20 -0
  25. package/dist/src/define-config.js +28 -15
  26. package/dist/src/define-plugin.d.ts +13 -0
  27. package/dist/src/define-plugin.js +4 -43
  28. package/dist/src/embedded-plugins.d.ts +59 -0
  29. package/dist/src/embedded-plugins.js +22 -0
  30. package/dist/src/exec.d.ts +13 -0
  31. package/dist/src/exec.js +101 -0
  32. package/dist/src/harness-paths.d.ts +9 -0
  33. package/dist/src/harness-paths.js +126 -0
  34. package/dist/src/hook-materializer.d.ts +21 -0
  35. package/dist/src/hook-materializer.js +152 -0
  36. package/dist/src/hook-protocol.d.ts +2 -0
  37. package/dist/src/hook-protocol.js +432 -0
  38. package/dist/src/hook-runner.d.ts +48 -0
  39. package/dist/src/hook-runner.js +868 -0
  40. package/dist/src/hook-runtime.d.ts +52 -0
  41. package/dist/src/hook-runtime.js +432 -0
  42. package/dist/src/index.d.ts +8 -0
  43. package/dist/src/index.js +210 -2499
  44. package/dist/src/json-files.d.ts +9 -0
  45. package/dist/src/json-files.js +124 -0
  46. package/dist/src/kernel-boot.d.ts +2 -0
  47. package/dist/src/kernel-boot.js +10 -0
  48. package/dist/src/kernel-entrypoint.d.ts +22 -0
  49. package/dist/src/kernel-entrypoint.js +660 -0
  50. package/dist/src/kernel-plugin-abi.d.ts +1 -0
  51. package/dist/src/kernel-plugin-abi.js +1 -0
  52. package/dist/src/kernel-resolver.d.ts +2 -0
  53. package/dist/src/kernel-resolver.js +6 -0
  54. package/dist/src/layout.d.ts +10 -0
  55. package/dist/src/layout.js +138 -0
  56. package/dist/src/load-config.d.ts +2 -0
  57. package/dist/src/load-config.js +535 -30
  58. package/dist/src/placement.d.ts +58 -0
  59. package/dist/src/placement.js +53 -0
  60. package/dist/src/plugin-host-context.d.ts +65 -0
  61. package/dist/src/plugin-host-context.js +1171 -0
  62. package/dist/src/plugin-host-registries.d.ts +31 -0
  63. package/dist/src/plugin-host-registries.js +79 -0
  64. package/dist/src/plugin-host.d.ts +77 -0
  65. package/dist/src/plugin-host.js +127 -63
  66. package/dist/src/plugin-runtime.d.ts +173 -0
  67. package/dist/src/project-plugins.d.ts +63 -0
  68. package/dist/src/project-plugins.js +905 -0
  69. package/dist/src/remote-config.d.ts +125 -0
  70. package/dist/src/remote-config.js +85 -0
  71. package/dist/src/root-resolver.d.ts +5 -0
  72. package/dist/src/root-resolver.js +68 -0
  73. package/dist/src/run-provisioning.d.ts +37 -0
  74. package/dist/src/run-provisioning.js +35 -0
  75. package/dist/src/runtime-context.d.ts +20 -0
  76. package/dist/src/runtime-context.js +257 -0
  77. package/dist/src/runtime-events.d.ts +44 -0
  78. package/dist/src/runtime-events.js +208 -0
  79. package/dist/src/runtime-overlay.d.ts +11 -0
  80. package/dist/src/runtime-overlay.js +69 -0
  81. package/dist/src/runtime-paths.d.ts +21 -0
  82. package/dist/src/runtime-paths.js +181 -0
  83. package/dist/src/runtime-provisioning-env.d.ts +5 -0
  84. package/dist/src/runtime-provisioning-env.js +217 -0
  85. package/dist/src/runtime-runner-context.d.ts +12 -0
  86. package/dist/src/runtime-runner-context.js +1 -0
  87. package/dist/src/safe-identifiers.d.ts +44 -0
  88. package/dist/src/safe-identifiers.js +96 -0
  89. package/dist/src/scope-rules.d.ts +4 -0
  90. package/dist/src/scope-rules.js +21 -0
  91. package/dist/src/server-paths.d.ts +22 -0
  92. package/dist/src/server-paths.js +219 -0
  93. package/dist/src/setup-version.d.ts +3 -0
  94. package/dist/src/setup-version.js +14 -0
  95. package/dist/src/task-record-reader.d.ts +3 -0
  96. package/dist/src/task-record-reader.js +9 -0
  97. package/dist/src/validator-registry.d.ts +27 -0
  98. package/dist/src/validator-registry.js +64 -0
  99. package/package.json +162 -10
  100. package/dist/src/engineReadModelReducer.js +0 -1780
  101. package/dist/src/rig-init-builder.js +0 -57
  102. package/dist/src/rigSelectors.js +0 -293
  103. package/dist/src/taskGraph.js +0 -64
  104. package/dist/src/taskGraphCodes.js +0 -26
  105. package/dist/src/taskGraphLayout.js +0 -374
@@ -0,0 +1,4 @@
1
+ import type { AgentRoleRegistration, AgentRoleRegistry } from "@rig/contracts";
2
+ export declare function createAgentRoleRegistry(pluginRoles: readonly AgentRoleRegistration[], configOverrides?: Record<string, {
3
+ model?: string;
4
+ }>): AgentRoleRegistry;
@@ -0,0 +1,27 @@
1
+ // @bun
2
+ // packages/core/src/agent-role-registry.ts
3
+ function createAgentRoleRegistry(pluginRoles, configOverrides) {
4
+ const map = new Map;
5
+ for (const r of pluginRoles) {
6
+ if (map.has(r.id))
7
+ throw new Error(`agent role already registered: ${r.id}`);
8
+ const override = configOverrides?.[r.id];
9
+ const model = override?.model ?? r.defaultModel;
10
+ if (!model) {
11
+ throw new Error(`agent role "${r.id}" has no model \u2014 provide defaultModel in plugin or model in config.runtime.agentRoles.${r.id}`);
12
+ }
13
+ map.set(r.id, { ...r, model });
14
+ }
15
+ return {
16
+ resolve(id) {
17
+ const r = map.get(id);
18
+ if (!r)
19
+ throw new Error(`agent role not registered: ${id}`);
20
+ return r;
21
+ },
22
+ list: () => Array.from(map.values())
23
+ };
24
+ }
25
+ export {
26
+ createAgentRoleRegistry
27
+ };
@@ -0,0 +1,15 @@
1
+ export type AuthorityPaths = {
2
+ projectRoot: string;
3
+ harnessRoot: string;
4
+ runsDir: string;
5
+ remoteDir: string;
6
+ stateDir: string;
7
+ remoteEndpointsPath: string;
8
+ remoteSecretsPath: string;
9
+ };
10
+ export declare function normalizeOptionalString(value: string | undefined | null): string | null;
11
+ export declare function normalizeOptionalBoolean(value: string | undefined | null, fallback: boolean): boolean;
12
+ export declare function resolveAuthorityPaths(projectRoot: string): AuthorityPaths;
13
+ export declare function resolveAuthorityStateRoot(projectRoot: string): string;
14
+ export declare function resolveAuthorityStateDir(projectRoot: string): string;
15
+ export declare function resolveAuthorityProjectStateDir(projectRoot: string): string;
@@ -0,0 +1,80 @@
1
+ // @bun
2
+ // packages/core/src/authority-paths.ts
3
+ import { existsSync } from "fs";
4
+ import { dirname, resolve } from "path";
5
+ function normalizeOptionalString(value) {
6
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
7
+ }
8
+ function normalizeOptionalBoolean(value, fallback) {
9
+ if (typeof value !== "string") {
10
+ return fallback;
11
+ }
12
+ const normalized = value.trim().toLowerCase();
13
+ if (["1", "true", "yes", "on"].includes(normalized)) {
14
+ return true;
15
+ }
16
+ if (["0", "false", "no", "off"].includes(normalized)) {
17
+ return false;
18
+ }
19
+ return fallback;
20
+ }
21
+ function resolveAuthorityPaths(projectRoot) {
22
+ const normalizedRoot = resolve(projectRoot);
23
+ const stateRoot = resolveAuthorityStateRoot(normalizedRoot);
24
+ const stateDir = resolveAuthorityStateDir(normalizedRoot);
25
+ return {
26
+ projectRoot: normalizedRoot,
27
+ harnessRoot: resolve(normalizedRoot, "rig"),
28
+ runsDir: resolve(stateRoot, "runs"),
29
+ remoteDir: resolve(stateRoot, "remote"),
30
+ stateDir,
31
+ remoteEndpointsPath: resolve(stateRoot, "remote", "endpoints.toml"),
32
+ remoteSecretsPath: resolve(stateDir, "remote-secrets.toml")
33
+ };
34
+ }
35
+ function resolveAuthorityStateRoot(projectRoot) {
36
+ const normalizedRoot = resolve(projectRoot);
37
+ const taskWorkspace = normalizeOptionalString(process.env.RIG_TASK_WORKSPACE);
38
+ if (taskWorkspace) {
39
+ return resolve(taskWorkspace, ".rig");
40
+ }
41
+ const stateDir = normalizeOptionalString(process.env.RIG_STATE_DIR);
42
+ if (stateDir) {
43
+ return dirname(resolve(stateDir));
44
+ }
45
+ const logsDir = normalizeOptionalString(process.env.RIG_LOGS_DIR);
46
+ if (logsDir) {
47
+ return dirname(resolve(logsDir));
48
+ }
49
+ const sessionFile = normalizeOptionalString(process.env.RIG_SESSION_FILE);
50
+ if (sessionFile) {
51
+ return dirname(dirname(resolve(sessionFile)));
52
+ }
53
+ const projectStateRoot = resolve(normalizedRoot, ".rig");
54
+ if (existsSync(projectStateRoot)) {
55
+ return projectStateRoot;
56
+ }
57
+ return resolve(normalizedRoot, ".rig");
58
+ }
59
+ function resolveAuthorityStateDir(projectRoot) {
60
+ const explicit = normalizeOptionalString(process.env.RIG_STATE_DIR);
61
+ if (explicit) {
62
+ return resolve(explicit);
63
+ }
64
+ return resolve(resolveAuthorityStateRoot(projectRoot), "state");
65
+ }
66
+ function resolveAuthorityProjectStateDir(projectRoot) {
67
+ const explicit = normalizeOptionalString(process.env.RIG_STATE_DIR);
68
+ if (explicit) {
69
+ return resolve(explicit);
70
+ }
71
+ return resolve(resolve(projectRoot), ".rig", "state");
72
+ }
73
+ export {
74
+ resolveAuthorityStateRoot,
75
+ resolveAuthorityStateDir,
76
+ resolveAuthorityProjectStateDir,
77
+ resolveAuthorityPaths,
78
+ normalizeOptionalString,
79
+ normalizeOptionalBoolean
80
+ };
@@ -0,0 +1,3 @@
1
+ export type RuntimeConfigValues = Record<string, string>;
2
+ export declare function resolveRuntimeConfigValues(env: Record<string, string | undefined>, keys: Iterable<string>, baked?: Record<string, string | undefined>): RuntimeConfigValues;
3
+ export declare function loadDotEnvValues(projectRoot: string, keys: Iterable<string>, env?: Record<string, string | undefined>): RuntimeConfigValues;
@@ -0,0 +1,63 @@
1
+ // @bun
2
+ // packages/core/src/baked-secrets.ts
3
+ import { existsSync, readFileSync } from "fs";
4
+ import { resolve } from "path";
5
+ function resolveRuntimeConfigValues(env, keys, baked = {}) {
6
+ const resolved = {};
7
+ const allKeys = new Set([...keys, ...Object.keys(baked)]);
8
+ for (const key of allKeys) {
9
+ const envValue = env[key]?.trim();
10
+ const bakedValue = baked[key]?.trim();
11
+ if (envValue) {
12
+ resolved[key] = envValue;
13
+ } else if (bakedValue) {
14
+ resolved[key] = bakedValue;
15
+ }
16
+ }
17
+ return resolved;
18
+ }
19
+ function loadDotEnvValues(projectRoot, keys, env = process.env) {
20
+ const dotenvPath = resolve(projectRoot, ".env");
21
+ if (!existsSync(dotenvPath)) {
22
+ return {};
23
+ }
24
+ const allowedKeys = new Set(keys);
25
+ const parsed = {};
26
+ const lines = readFileSync(dotenvPath, "utf-8").split(/\r?\n/);
27
+ for (const rawLine of lines) {
28
+ const line = rawLine.trim();
29
+ if (!line || line.startsWith("#")) {
30
+ continue;
31
+ }
32
+ const exportMatch = line.match(/^(?:export\s+)?([A-Z0-9_]+)\s*=\s*(.*)$/);
33
+ if (!exportMatch) {
34
+ continue;
35
+ }
36
+ const key = exportMatch[1] ?? "";
37
+ if (!allowedKeys.has(key)) {
38
+ continue;
39
+ }
40
+ const value = expandShellValue(exportMatch[2] ?? "", { ...env, ...parsed });
41
+ if (value) {
42
+ parsed[key] = value;
43
+ }
44
+ }
45
+ return parsed;
46
+ }
47
+ function expandShellValue(rawValue, env) {
48
+ let value = rawValue.trim();
49
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
50
+ value = value.slice(1, -1);
51
+ }
52
+ return value.replace(/\$\{([A-Z0-9_]+)(:-([^}]*))?\}/g, (_match, name, _defaultGroup, fallback) => {
53
+ const envValue = env[name]?.trim();
54
+ if (envValue) {
55
+ return envValue;
56
+ }
57
+ return fallback ?? "";
58
+ });
59
+ }
60
+ export {
61
+ resolveRuntimeConfigValues,
62
+ loadDotEnvValues
63
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Runtime fallback for build-time config.
3
+ *
4
+ * Compiled binaries use `build-time-config.macro.ts` with Bun's macro import
5
+ * (`with { type: "macro" }`) to inline config constants at build time.
6
+ *
7
+ * This module provides the same interface for non-compiled execution paths
8
+ * (e.g. `bun run`, tests, CLI dev mode) where macro expansion does not run.
9
+ * It reads from the `__RIG_BUILD_CONFIG__` global (if the compiled binary sets
10
+ * it) and falls back to the `RIG_BUILD_CONFIG_JSON` environment variable.
11
+ */
12
+ export declare function readBuildConfig(): Record<string, string>;
@@ -0,0 +1,25 @@
1
+ // @bun
2
+ // packages/core/src/build-time-config.ts
3
+ function normalizeBuildConfig(value) {
4
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
5
+ return {};
6
+ }
7
+ return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
8
+ }
9
+ function readBuildConfig() {
10
+ if (typeof __RIG_BUILD_CONFIG__ !== "undefined") {
11
+ return normalizeBuildConfig(__RIG_BUILD_CONFIG__);
12
+ }
13
+ const raw = process.env.RIG_BUILD_CONFIG_JSON?.trim();
14
+ if (!raw) {
15
+ return {};
16
+ }
17
+ try {
18
+ return normalizeBuildConfig(JSON.parse(raw));
19
+ } catch {
20
+ return {};
21
+ }
22
+ }
23
+ export {
24
+ readBuildConfig
25
+ };
@@ -0,0 +1 @@
1
+ export declare function readBuildConfig(): Record<string, string>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * capability-loaders.ts — generic project-root capability resolution + a typed
3
+ * installed-capability holder.
4
+ *
5
+ * These are the substrate-neutral helpers that the dissolved
6
+ * `@rig/runtime/control-plane/*-port` modules used to provide. Each per-capability
7
+ * port (doctor / memory / isolation / browser / provider-instruction /
8
+ * managed-repo / lifecycle) collapsed into three things that already exist:
9
+ *
10
+ * 1. the capability id + interface in `@rig/contracts` (pure vocab),
11
+ * 2. the `defineCapability(id)` seam in `@rig/core/capability`, and
12
+ * 3. these two GENERIC helpers — `loadCapabilityForRoot` /
13
+ * `requireCapabilityForRoot` plus an installed-singleton holder.
14
+ *
15
+ * Consumers resolve a capability off a project's plugin host (or read a
16
+ * boot-installed singleton) WITHOUT importing any provider plugin, so no
17
+ * floor->plugin / cross-plugin import cycle is introduced. The single
18
+ * `unknown -> T` cast for capability resolution still lives once inside
19
+ * `defineCapability.resolve`; the holder cast below is the lone exception, kept
20
+ * local to this typed accessor.
21
+ */
22
+ import type { Capability } from "./capability";
23
+ import type { PluginHost } from "./plugin-host";
24
+ /**
25
+ * Build a plugin host from a project's rig.config. Returns null when no config
26
+ * is loadable (legacy projects) so callers can decide their own fallback.
27
+ */
28
+ export declare function buildProjectPluginHost(projectRoot: string): Promise<PluginHost | null>;
29
+ /**
30
+ * Resolve a capability off a project root. Returns null when no config loads or
31
+ * no plugin provides the capability, so callers degrade gracefully.
32
+ */
33
+ export declare function loadCapabilityForRoot<T>(projectRoot: string, capability: Capability<T>): Promise<T | null>;
34
+ /**
35
+ * Resolve a capability off a project root, or throw a precise, actionable error
36
+ * (`message`) when no provider is registered.
37
+ */
38
+ export declare function requireCapabilityForRoot<T>(projectRoot: string, capability: Capability<T>, message: string): Promise<T>;
39
+ /** Install a resolved capability impl for synchronous cross-package reads. */
40
+ export declare function installCapability<T>(capability: Capability<T>, impl: T): void;
41
+ /** Clear an installed capability impl (test / reset hook). */
42
+ export declare function clearInstalledCapability<T>(capability: Capability<T>): void;
43
+ /** Read a boot-installed capability impl, or null when none is installed. */
44
+ export declare function getInstalledCapability<T>(capability: Capability<T>): T | null;
45
+ /**
46
+ * Read a boot-installed capability impl, or throw a precise `message` when none
47
+ * is installed. For synchronous substrate consumers that resolve a capability
48
+ * the boot wiring installs once (e.g. task-data) and cannot re-resolve a plugin
49
+ * host on every call.
50
+ */
51
+ export declare function requireInstalledCapability<T>(capability: Capability<T>, message: string): T;