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

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,125 @@
1
+ /**
2
+ * Deprecated compatibility subpath. Remote transport configuration, registry /
3
+ * relay defaults, managed endpoints, dispatch placement, and owner namespace
4
+ * resolution are owned by @rig/transport-plugin. Core must not implement this
5
+ * product behavior.
6
+ */
7
+ export declare const DEFAULT_REMOTE_PORT = 7890;
8
+ export declare const REMOTES_CONFIG_PATH = "";
9
+ export declare class RemoteCliError extends Error {
10
+ readonly code: string;
11
+ readonly exitCode: number;
12
+ readonly details: Record<string, unknown> | undefined;
13
+ constructor(code: string, message: string, exitCode?: number, details?: Record<string, unknown>);
14
+ }
15
+ export type RemoteConfigEntry = {
16
+ host?: string;
17
+ port?: number;
18
+ token?: string;
19
+ addedAt?: string;
20
+ lastConnected?: string;
21
+ };
22
+ export type RemotesToml = {
23
+ version?: number;
24
+ remotes?: Record<string, RemoteConfigEntry>;
25
+ };
26
+ export type AuthorityRemoteEndpointRecord = {
27
+ id: string;
28
+ alias: string;
29
+ host: string;
30
+ port: number;
31
+ transport: string;
32
+ auto_connect: boolean;
33
+ labels: string[];
34
+ capabilities: string[];
35
+ secret_ref: string;
36
+ created_at: string;
37
+ updated_at: string;
38
+ last_connected_at?: string | null;
39
+ };
40
+ export type AuthorityRemoteEndpointsToml = {
41
+ version?: number;
42
+ endpoints?: Record<string, AuthorityRemoteEndpointRecord>;
43
+ };
44
+ export type AuthorityRemoteSecretsToml = {
45
+ version?: number;
46
+ secrets?: Record<string, string>;
47
+ };
48
+ export type AuthorityMaterializedRemoteEndpoint = {
49
+ id: string;
50
+ alias: string;
51
+ host: string;
52
+ port: number;
53
+ token: string;
54
+ autoConnect: boolean;
55
+ addedAt: string;
56
+ updatedAt: string;
57
+ lastConnectedAt: string | null;
58
+ labels: string[];
59
+ capabilities: string[];
60
+ transport: string;
61
+ secretRef: string;
62
+ };
63
+ export type ManagedRemoteEndpoint = {
64
+ id: string;
65
+ alias: string;
66
+ host: string;
67
+ port: number;
68
+ token: string;
69
+ addedAt: string | null;
70
+ lastConnected: string | null;
71
+ };
72
+ export type SelectedRemote = {
73
+ alias: string;
74
+ host: string;
75
+ port: number;
76
+ sshTarget: string;
77
+ checkout: string | null;
78
+ registryBaseUrl: string | null;
79
+ secretRef: string | null;
80
+ };
81
+ export type DispatchTransportPlacement = {
82
+ readonly kind: "local";
83
+ readonly alias: "local";
84
+ readonly sshTarget: null;
85
+ readonly selected: null;
86
+ } | {
87
+ readonly kind: "remote";
88
+ readonly alias: string;
89
+ readonly sshTarget: string;
90
+ readonly selected: SelectedRemote | null;
91
+ };
92
+ export declare function registerBackboneDefaults(_defaults: {
93
+ relayUrl?: string;
94
+ registryBaseUrl?: string;
95
+ sshTarget?: string;
96
+ }): void;
97
+ export declare function resolveRelayUrl(_env?: NodeJS.ProcessEnv): string;
98
+ export declare function resolveSshTarget(_env?: NodeJS.ProcessEnv): string;
99
+ export declare function loadRemotesConfig(_configPath?: string): RemotesToml;
100
+ export declare function listManagedRemoteEndpoints(_configPath?: string, _projectRoot?: string): ManagedRemoteEndpoint[];
101
+ export declare function resolveManagedRemoteEndpoint(_alias: string, _configPath?: string, _projectRoot?: string): SelectedRemote | null;
102
+ export declare function upsertManagedRemoteEndpoint(_input: {
103
+ alias: string;
104
+ host: string;
105
+ port: number;
106
+ token?: string;
107
+ }, _configPath?: string, _projectRoot?: string): ManagedRemoteEndpoint;
108
+ export declare function updateAuthorityRemoteEndpoint(_projectRoot: string, _input: {
109
+ endpointId?: string;
110
+ alias?: string;
111
+ host?: string;
112
+ port?: number;
113
+ token?: string;
114
+ autoConnect?: boolean;
115
+ transport?: string;
116
+ labels?: string[];
117
+ capabilities?: string[];
118
+ }): AuthorityMaterializedRemoteEndpoint | null;
119
+ export declare function removeManagedRemoteEndpoint(_alias: string, _configPath?: string, _projectRoot?: string): boolean;
120
+ export declare function resolveSelectedRemote(_projectRoot: string, _env?: NodeJS.ProcessEnv): SelectedRemote | null;
121
+ export declare function resolveDispatchTransportPlacement(_projectRoot: string, _env?: NodeJS.ProcessEnv): DispatchTransportPlacement;
122
+ export declare function resolveRegistryBaseUrl(_projectRoot: string, _env?: NodeJS.ProcessEnv): string;
123
+ export declare function resolveOwnerNamespaceKey(_projectRoot: string, _env?: NodeJS.ProcessEnv): string | undefined;
124
+ export declare function resolveRigOmpConfigOverlayPath(_projectRoot?: string): string;
125
+ export declare function materializeRigOmpConfigOverlay(_projectRoot: string, _env?: NodeJS.ProcessEnv): string;
@@ -0,0 +1,85 @@
1
+ // @bun
2
+ // packages/core/src/remote-config.ts
3
+ var DEFAULT_REMOTE_PORT = 7890;
4
+ var REMOTES_CONFIG_PATH = "";
5
+
6
+ class RemoteCliError extends Error {
7
+ code;
8
+ exitCode;
9
+ details;
10
+ constructor(code, message, exitCode = 1, details) {
11
+ super(message);
12
+ this.name = "RemoteCliError";
13
+ this.code = code;
14
+ this.exitCode = exitCode;
15
+ this.details = details;
16
+ }
17
+ }
18
+ function remoteConfigOwnerRequired() {
19
+ throw new Error("This remote config compatibility API is deprecated. Resolve transport-owned remote config through the TRANSPORT_CONFIG capability.");
20
+ }
21
+ function registerBackboneDefaults(_defaults) {
22
+ remoteConfigOwnerRequired();
23
+ }
24
+ function resolveRelayUrl(_env = process.env) {
25
+ return remoteConfigOwnerRequired();
26
+ }
27
+ function resolveSshTarget(_env = process.env) {
28
+ return remoteConfigOwnerRequired();
29
+ }
30
+ function loadRemotesConfig(_configPath) {
31
+ return remoteConfigOwnerRequired();
32
+ }
33
+ function listManagedRemoteEndpoints(_configPath, _projectRoot) {
34
+ return remoteConfigOwnerRequired();
35
+ }
36
+ function resolveManagedRemoteEndpoint(_alias, _configPath, _projectRoot) {
37
+ return remoteConfigOwnerRequired();
38
+ }
39
+ function upsertManagedRemoteEndpoint(_input, _configPath, _projectRoot) {
40
+ return remoteConfigOwnerRequired();
41
+ }
42
+ function updateAuthorityRemoteEndpoint(_projectRoot, _input) {
43
+ return remoteConfigOwnerRequired();
44
+ }
45
+ function removeManagedRemoteEndpoint(_alias, _configPath, _projectRoot) {
46
+ return remoteConfigOwnerRequired();
47
+ }
48
+ function resolveSelectedRemote(_projectRoot, _env = process.env) {
49
+ return remoteConfigOwnerRequired();
50
+ }
51
+ function resolveDispatchTransportPlacement(_projectRoot, _env = process.env) {
52
+ return remoteConfigOwnerRequired();
53
+ }
54
+ function resolveRegistryBaseUrl(_projectRoot, _env = process.env) {
55
+ return remoteConfigOwnerRequired();
56
+ }
57
+ function resolveOwnerNamespaceKey(_projectRoot, _env = process.env) {
58
+ return remoteConfigOwnerRequired();
59
+ }
60
+ function resolveRigOmpConfigOverlayPath(_projectRoot = process.cwd()) {
61
+ return remoteConfigOwnerRequired();
62
+ }
63
+ function materializeRigOmpConfigOverlay(_projectRoot, _env = process.env) {
64
+ return remoteConfigOwnerRequired();
65
+ }
66
+ export {
67
+ upsertManagedRemoteEndpoint,
68
+ updateAuthorityRemoteEndpoint,
69
+ resolveSshTarget,
70
+ resolveSelectedRemote,
71
+ resolveRigOmpConfigOverlayPath,
72
+ resolveRelayUrl,
73
+ resolveRegistryBaseUrl,
74
+ resolveOwnerNamespaceKey,
75
+ resolveManagedRemoteEndpoint,
76
+ resolveDispatchTransportPlacement,
77
+ removeManagedRemoteEndpoint,
78
+ registerBackboneDefaults,
79
+ materializeRigOmpConfigOverlay,
80
+ loadRemotesConfig,
81
+ listManagedRemoteEndpoints,
82
+ RemoteCliError,
83
+ REMOTES_CONFIG_PATH,
84
+ DEFAULT_REMOTE_PORT
85
+ };
@@ -0,0 +1,5 @@
1
+ export declare function resolveProjectRoot(options?: {
2
+ cwd?: string;
3
+ projectRootEnv?: string;
4
+ fallbackFromDir?: string;
5
+ }): string;
@@ -0,0 +1,68 @@
1
+ // @bun
2
+ // packages/core/src/root-resolver.ts
3
+ import { existsSync, readFileSync } from "fs";
4
+ import { dirname, parse, resolve } from "path";
5
+
6
+ // packages/core/src/layout.ts
7
+ import {
8
+ RIG_DEFINITION_DIRNAME,
9
+ RIG_STATE_DIRNAME
10
+ } from "@rig/contracts";
11
+
12
+ // packages/core/src/root-resolver.ts
13
+ function hasProjectMarker(candidate) {
14
+ return existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME));
15
+ }
16
+ function resolveProjectRoot(options) {
17
+ const cwd = options?.cwd || process.cwd();
18
+ const envRoot = options?.projectRootEnv || process.env.PROJECT_RIG_ROOT || "";
19
+ const fallbackFromDir = options?.fallbackFromDir || cwd;
20
+ if (envRoot && hasProjectMarker(envRoot)) {
21
+ return envRoot;
22
+ }
23
+ const walked = walkUpForRoot(cwd);
24
+ if (walked) {
25
+ return walked;
26
+ }
27
+ const configRoot = readConfiguredRoot();
28
+ if (configRoot && hasProjectMarker(configRoot)) {
29
+ return configRoot;
30
+ }
31
+ let fileDir = resolve(fallbackFromDir);
32
+ for (let i = 0;i < 5; i += 1) {
33
+ if (hasProjectMarker(fileDir)) {
34
+ return fileDir;
35
+ }
36
+ fileDir = dirname(fileDir);
37
+ }
38
+ return cwd;
39
+ }
40
+ function walkUpForRoot(start) {
41
+ let searchDir = resolve(start);
42
+ const root = parse(searchDir).root || "/";
43
+ while (searchDir !== root) {
44
+ if (hasProjectMarker(searchDir)) {
45
+ return searchDir;
46
+ }
47
+ searchDir = dirname(searchDir);
48
+ }
49
+ if (hasProjectMarker(root)) {
50
+ return root;
51
+ }
52
+ return "";
53
+ }
54
+ function readConfiguredRoot() {
55
+ const configPath = resolve(process.env.HOME || "~", ".config", "project-rig", "root");
56
+ if (!existsSync(configPath)) {
57
+ return "";
58
+ }
59
+ try {
60
+ const value = readFileSync(configPath, "utf-8").split(/\r?\n/)[0]?.trim() || "";
61
+ return value;
62
+ } catch {
63
+ return "";
64
+ }
65
+ }
66
+ export {
67
+ resolveProjectRoot
68
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Deprecated compatibility subpath. Run launch/provisioning behavior is owned
3
+ * outside @rig/core (transport/run-host). Resolve the typed owner services or
4
+ * import the owner plugin's run-provisioning helper instead.
5
+ */
6
+ import type { EnsureAgentRuntimeOptions } from "@rig/contracts";
7
+ export type RunWorkspaceProvisioningOptions = Pick<EnsureAgentRuntimeOptions, "projectRoot" | "id" | "taskId" | "mode" | "provider">;
8
+ export type RigRunLaunchOptions = {
9
+ readonly taskId: string;
10
+ readonly title?: string | null | undefined;
11
+ readonly model?: string | null | undefined;
12
+ readonly prompt?: string | null | undefined;
13
+ readonly forceSteerOnce?: boolean | undefined;
14
+ };
15
+ export declare function buildRunWorkspaceProvisioningOptions(_input: {
16
+ readonly projectRoot: string;
17
+ readonly runId: string;
18
+ readonly taskId: string;
19
+ readonly mode: EnsureAgentRuntimeOptions["mode"];
20
+ readonly provider?: EnsureAgentRuntimeOptions["provider"];
21
+ }): RunWorkspaceProvisioningOptions;
22
+ export declare function buildRigRunLaunchArgs(_input: RigRunLaunchOptions, _runId: string, _projectRoot: string): string[];
23
+ export declare function isCompiledBunBinary(_importMetaUrl: string): boolean;
24
+ export declare function resolveCompiledSiblingPath(_execPath: string, _siblingBinaryName: string, _platform?: NodeJS.Platform): string;
25
+ export declare function ensureSiblingBinaryCurrent(_sourceBin: string, _siblingBin: string): void;
26
+ export declare function resolveLocalDispatchRigRunBin(_input: {
27
+ readonly importMetaUrl: string;
28
+ readonly sourceRigRunPath: string;
29
+ readonly compiledSiblingName: string;
30
+ readonly execPath?: string;
31
+ readonly platform?: NodeJS.Platform;
32
+ }): string;
33
+ export declare function resolveInProcessRigRunBin(_input: {
34
+ readonly importMetaUrl: string;
35
+ readonly sourceRigRunPath: string;
36
+ readonly execPath?: string;
37
+ }): string;
@@ -0,0 +1,35 @@
1
+ // @bun
2
+ // packages/core/src/run-provisioning.ts
3
+ function runProvisioningOwnerRequired() {
4
+ throw new Error("This run provisioning compatibility API is deprecated. Resolve run provisioning through the owning transport/run-host boundary instead.");
5
+ }
6
+ function buildRunWorkspaceProvisioningOptions(_input) {
7
+ return runProvisioningOwnerRequired();
8
+ }
9
+ function buildRigRunLaunchArgs(_input, _runId, _projectRoot) {
10
+ return runProvisioningOwnerRequired();
11
+ }
12
+ function isCompiledBunBinary(_importMetaUrl) {
13
+ return runProvisioningOwnerRequired();
14
+ }
15
+ function resolveCompiledSiblingPath(_execPath, _siblingBinaryName, _platform = process.platform) {
16
+ return runProvisioningOwnerRequired();
17
+ }
18
+ function ensureSiblingBinaryCurrent(_sourceBin, _siblingBin) {
19
+ runProvisioningOwnerRequired();
20
+ }
21
+ function resolveLocalDispatchRigRunBin(_input) {
22
+ return runProvisioningOwnerRequired();
23
+ }
24
+ function resolveInProcessRigRunBin(_input) {
25
+ return runProvisioningOwnerRequired();
26
+ }
27
+ export {
28
+ resolveLocalDispatchRigRunBin,
29
+ resolveInProcessRigRunBin,
30
+ resolveCompiledSiblingPath,
31
+ isCompiledBunBinary,
32
+ ensureSiblingBinaryCurrent,
33
+ buildRunWorkspaceProvisioningOptions,
34
+ buildRigRunLaunchArgs
35
+ };
@@ -0,0 +1,20 @@
1
+ import type { RuntimeBrowserContext, RuntimeMemoryRetrievalConfig, RuntimeTaskContext } from "@rig/contracts";
2
+ export type { RuntimeBrowserContext, RuntimeMemoryRetrievalConfig, RuntimeMemoryContext, RuntimeSourceTaskContract, RuntimeTaskContext, } from "@rig/contracts";
3
+ export declare const RUNTIME_CONTEXT_ENV = "RIG_RUNTIME_CONTEXT_FILE";
4
+ export declare const DEFAULT_RUNTIME_MEMORY_RETRIEVAL: RuntimeMemoryRetrievalConfig;
5
+ export declare const runtimeContextStringFields: readonly (keyof RuntimeTaskContext)[];
6
+ export declare const runtimeContextArrayFields: readonly (keyof RuntimeTaskContext)[];
7
+ export declare const runtimeContextOptionalStringFields: readonly (keyof RuntimeTaskContext)[];
8
+ export declare function writeRuntimeContext(path: string, ctx: RuntimeTaskContext): void;
9
+ export declare function loadRuntimeContext(path: string): RuntimeTaskContext;
10
+ export declare function runtimeMemoryEnvFromContext(ctx: RuntimeTaskContext | null | undefined): Record<string, string>;
11
+ /**
12
+ * Serialize an already-resolved browser context into the RIG_BROWSER_* env wire
13
+ * contract read by rig-agent and rig-browser-tool. This is dumb substrate
14
+ * plumbing (a flat projection of the resolved context's own fields) — the
15
+ * browser DOMAIN resolution that produced this context lives in
16
+ * @rig/browser-plugin, resolved via browser-contract-port.ts. Mirrors
17
+ * runtimeMemoryEnvFromContext above.
18
+ */
19
+ export declare function browserEnvFromContext(browser: RuntimeBrowserContext | undefined): Record<string, string>;
20
+ export declare function loadRuntimeContextFromEnv(env?: NodeJS.ProcessEnv): RuntimeTaskContext | null;
@@ -0,0 +1,257 @@
1
+ // @bun
2
+ // packages/core/src/runtime-context.ts
3
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
4
+ import { dirname, resolve } from "path";
5
+ var RUNTIME_CONTEXT_ENV = "RIG_RUNTIME_CONTEXT_FILE";
6
+ var DEFAULT_RUNTIME_MEMORY_RETRIEVAL = {
7
+ topK: 5,
8
+ lexicalWeight: 0.35,
9
+ vectorWeight: 0.45,
10
+ recencyWeight: 0.1,
11
+ confidenceWeight: 0.1
12
+ };
13
+ var runtimeContextStringFields = [
14
+ "runtimeId",
15
+ "taskId",
16
+ "role",
17
+ "workspaceDir",
18
+ "stateDir",
19
+ "logsDir",
20
+ "sessionDir",
21
+ "sessionFile",
22
+ "policyFile",
23
+ "binDir",
24
+ "createdAt"
25
+ ];
26
+ var runtimeContextArrayFields = ["scopes", "validation"];
27
+ var runtimeContextOptionalStringFields = [
28
+ "artifactRoot",
29
+ "hostProjectRoot",
30
+ "monorepoMainRoot",
31
+ "monorepoBaseRef",
32
+ "monorepoBaseCommit"
33
+ ];
34
+ function writeRuntimeContext(path, ctx) {
35
+ const absPath = resolve(path);
36
+ const dir = dirname(absPath);
37
+ if (!existsSync(dir)) {
38
+ mkdirSync(dir, { recursive: true });
39
+ }
40
+ writeFileSync(absPath, JSON.stringify(ctx, null, 2), "utf8");
41
+ }
42
+ function loadRuntimeContext(path) {
43
+ const absPath = resolve(path);
44
+ if (!existsSync(absPath)) {
45
+ throw new Error(`RuntimeTaskContext file not found: ${absPath}`);
46
+ }
47
+ let raw;
48
+ try {
49
+ raw = JSON.parse(readFileSync(absPath, "utf8"));
50
+ } catch (err) {
51
+ throw new Error(`Failed to parse RuntimeTaskContext at ${absPath}: ${String(err)}`);
52
+ }
53
+ if (typeof raw !== "object" || raw === null) {
54
+ throw new Error(`RuntimeTaskContext at ${absPath} is not an object`);
55
+ }
56
+ const obj = raw;
57
+ for (const field of runtimeContextStringFields) {
58
+ if (typeof obj[field] !== "string" || obj[field].length === 0) {
59
+ throw new Error(`RuntimeTaskContext field "${field}" must be a non-empty string (at ${absPath})`);
60
+ }
61
+ }
62
+ for (const field of runtimeContextArrayFields) {
63
+ if (!Array.isArray(obj[field])) {
64
+ throw new Error(`RuntimeTaskContext field "${field}" must be an array (at ${absPath})`);
65
+ }
66
+ if (!obj[field].every((entry) => typeof entry === "string")) {
67
+ throw new Error(`RuntimeTaskContext field "${field}" must be a string[] (at ${absPath})`);
68
+ }
69
+ }
70
+ for (const field of runtimeContextOptionalStringFields) {
71
+ if (field in obj && obj[field] !== undefined && typeof obj[field] !== "string") {
72
+ throw new Error(`RuntimeTaskContext field "${field}" must be a string when present (at ${absPath})`);
73
+ }
74
+ }
75
+ if (obj.browser !== undefined) {
76
+ if (typeof obj.browser !== "object" || obj.browser === null || Array.isArray(obj.browser)) {
77
+ throw new Error(`RuntimeTaskContext field "browser" must be an object when present (at ${absPath})`);
78
+ }
79
+ const browser = obj.browser;
80
+ for (const field of [
81
+ "preset",
82
+ "mode",
83
+ "stateDir",
84
+ "defaultProfile",
85
+ "effectiveProfile",
86
+ "defaultAttachUrl",
87
+ "effectiveAttachUrl",
88
+ "launchHelper",
89
+ "checkHelper",
90
+ "attachInfoHelper",
91
+ "e2eHelper",
92
+ "resetProfileHelper"
93
+ ]) {
94
+ if (typeof browser[field] !== "string" || browser[field].length === 0) {
95
+ throw new Error(`RuntimeTaskContext field "browser.${field}" must be a non-empty string (at ${absPath})`);
96
+ }
97
+ }
98
+ for (const field of ["devCommand", "launchCommand", "checkCommand", "e2eCommand"]) {
99
+ if (browser[field] !== undefined && typeof browser[field] !== "string") {
100
+ throw new Error(`RuntimeTaskContext field "browser.${field}" must be a string when present (at ${absPath})`);
101
+ }
102
+ }
103
+ if (typeof browser.required !== "boolean") {
104
+ throw new Error(`RuntimeTaskContext field "browser.required" must be a boolean (at ${absPath})`);
105
+ }
106
+ }
107
+ if (obj.memory !== undefined) {
108
+ if (typeof obj.memory !== "object" || obj.memory === null || Array.isArray(obj.memory)) {
109
+ throw new Error(`RuntimeTaskContext field "memory" must be an object when present (at ${absPath})`);
110
+ }
111
+ const memory = obj.memory;
112
+ for (const field of ["canonicalPath", "canonicalRef", "hydratedPath"]) {
113
+ if (typeof memory[field] !== "string" || memory[field].length === 0) {
114
+ throw new Error(`RuntimeTaskContext field "memory.${field}" must be a non-empty string (at ${absPath})`);
115
+ }
116
+ }
117
+ if (typeof memory.createdFresh !== "boolean") {
118
+ throw new Error(`RuntimeTaskContext field "memory.createdFresh" must be a boolean (at ${absPath})`);
119
+ }
120
+ const hasCanonicalBaseOid = typeof memory.canonicalBaseOid === "string" && memory.canonicalBaseOid.length > 0;
121
+ if (memory.canonicalBaseOid !== undefined && !hasCanonicalBaseOid) {
122
+ throw new Error(`RuntimeTaskContext field "memory.canonicalBaseOid" must be a non-empty string when present (at ${absPath})`);
123
+ }
124
+ if (!memory.createdFresh && !hasCanonicalBaseOid) {
125
+ throw new Error(`RuntimeTaskContext field "memory.canonicalBaseOid" must be a non-empty string when memory.createdFresh is false (at ${absPath})`);
126
+ }
127
+ if (typeof memory.retrieval !== "object" || memory.retrieval === null || Array.isArray(memory.retrieval)) {
128
+ throw new Error(`RuntimeTaskContext field "memory.retrieval" must be an object (at ${absPath})`);
129
+ }
130
+ const retrieval = memory.retrieval;
131
+ for (const field of ["topK", "lexicalWeight", "vectorWeight", "recencyWeight", "confidenceWeight"]) {
132
+ if (typeof retrieval[field] !== "number" || Number.isNaN(retrieval[field])) {
133
+ throw new Error(`RuntimeTaskContext field "memory.retrieval.${field}" must be a number (at ${absPath})`);
134
+ }
135
+ }
136
+ }
137
+ if (obj.initialDirtyFiles !== undefined) {
138
+ if (typeof obj.initialDirtyFiles !== "object" || obj.initialDirtyFiles === null || Array.isArray(obj.initialDirtyFiles)) {
139
+ throw new Error(`RuntimeTaskContext field "initialDirtyFiles" must be an object when present (at ${absPath})`);
140
+ }
141
+ const dirtyFiles = obj.initialDirtyFiles;
142
+ for (const key of ["project", "monorepo"]) {
143
+ if (dirtyFiles[key] === undefined) {
144
+ continue;
145
+ }
146
+ if (!Array.isArray(dirtyFiles[key]) || !dirtyFiles[key].every((entry) => typeof entry === "string")) {
147
+ throw new Error(`RuntimeTaskContext field "initialDirtyFiles.${key}" must be a string[] when present (at ${absPath})`);
148
+ }
149
+ }
150
+ }
151
+ if (obj.initialHeadCommits !== undefined) {
152
+ if (typeof obj.initialHeadCommits !== "object" || obj.initialHeadCommits === null || Array.isArray(obj.initialHeadCommits)) {
153
+ throw new Error(`RuntimeTaskContext field "initialHeadCommits" must be an object when present (at ${absPath})`);
154
+ }
155
+ const headCommits = obj.initialHeadCommits;
156
+ for (const key of ["project", "monorepo"]) {
157
+ if (headCommits[key] === undefined) {
158
+ continue;
159
+ }
160
+ if (typeof headCommits[key] !== "string") {
161
+ throw new Error(`RuntimeTaskContext field "initialHeadCommits.${key}" must be a string when present (at ${absPath})`);
162
+ }
163
+ }
164
+ }
165
+ return obj;
166
+ }
167
+ function runtimeMemoryEnvFromContext(ctx) {
168
+ if (!ctx?.memory) {
169
+ return {};
170
+ }
171
+ return {
172
+ RIG_MEMORY_DB_PATH: ctx.memory.hydratedPath,
173
+ RIG_MEMORY_CANONICAL_PATH: ctx.memory.canonicalPath,
174
+ RIG_MEMORY_CANONICAL_REF: ctx.memory.canonicalRef,
175
+ ...ctx.memory.canonicalBaseOid ? { RIG_MEMORY_CANONICAL_BASE_OID: ctx.memory.canonicalBaseOid } : {},
176
+ RIG_MEMORY_CREATED_FRESH: ctx.memory.createdFresh ? "1" : "0",
177
+ RIG_MEMORY_RETRIEVAL_TOP_K: String(ctx.memory.retrieval.topK),
178
+ RIG_MEMORY_RETRIEVAL_LEXICAL_WEIGHT: String(ctx.memory.retrieval.lexicalWeight),
179
+ RIG_MEMORY_RETRIEVAL_VECTOR_WEIGHT: String(ctx.memory.retrieval.vectorWeight),
180
+ RIG_MEMORY_RETRIEVAL_RECENCY_WEIGHT: String(ctx.memory.retrieval.recencyWeight),
181
+ RIG_MEMORY_RETRIEVAL_CONFIDENCE_WEIGHT: String(ctx.memory.retrieval.confidenceWeight)
182
+ };
183
+ }
184
+ function browserEnvFromContext(browser) {
185
+ if (!browser?.required) {
186
+ return {};
187
+ }
188
+ const env = {
189
+ RIG_BROWSER_REQUIRED: "1",
190
+ RIG_BROWSER_PRESET: browser.preset,
191
+ RIG_BROWSER_MODE: browser.mode,
192
+ RIG_BROWSER_STATE_DIR: browser.stateDir,
193
+ RIG_BROWSER_PROFILE: browser.effectiveProfile,
194
+ RIG_BROWSER_BASE_PROFILE: browser.defaultProfile,
195
+ RIG_BROWSER_ATTACH_URL: browser.effectiveAttachUrl,
196
+ RIG_BROWSER_DEFAULT_ATTACH_URL: browser.defaultAttachUrl,
197
+ RIG_BROWSER_LAUNCH_HELPER: browser.launchHelper,
198
+ RIG_BROWSER_CHECK_HELPER: browser.checkHelper,
199
+ RIG_BROWSER_ATTACH_INFO_HELPER: browser.attachInfoHelper,
200
+ RIG_BROWSER_E2E_HELPER: browser.e2eHelper,
201
+ RIG_BROWSER_RESET_HELPER: browser.resetProfileHelper
202
+ };
203
+ if (browser.devCommand) {
204
+ env.RIG_BROWSER_DEV_COMMAND = browser.devCommand;
205
+ }
206
+ if (browser.launchCommand) {
207
+ env.RIG_BROWSER_LAUNCH_COMMAND = browser.launchCommand;
208
+ }
209
+ if (browser.checkCommand) {
210
+ env.RIG_BROWSER_CHECK_COMMAND = browser.checkCommand;
211
+ }
212
+ if (browser.e2eCommand) {
213
+ env.RIG_BROWSER_E2E_COMMAND = browser.e2eCommand;
214
+ }
215
+ return env;
216
+ }
217
+ function loadRuntimeContextFromEnv(env = process.env) {
218
+ const contextFile = env[RUNTIME_CONTEXT_ENV];
219
+ if (contextFile) {
220
+ return loadRuntimeContext(contextFile);
221
+ }
222
+ const inferred = findRuntimeContextFile(process.cwd());
223
+ if (!inferred) {
224
+ return null;
225
+ }
226
+ return loadRuntimeContext(inferred);
227
+ }
228
+ function findRuntimeContextFile(startPath) {
229
+ let current = resolve(startPath);
230
+ while (true) {
231
+ const candidate = resolve(current, "runtime-context.json");
232
+ if (existsSync(candidate) && isAgentRuntimeContextPath(candidate)) {
233
+ return candidate;
234
+ }
235
+ const parent = dirname(current);
236
+ if (parent === current) {
237
+ return "";
238
+ }
239
+ current = parent;
240
+ }
241
+ }
242
+ function isAgentRuntimeContextPath(path) {
243
+ const normalized = path.replace(/\\/g, "/");
244
+ return /\/\.rig\/runtime-context\.json$/.test(normalized);
245
+ }
246
+ export {
247
+ writeRuntimeContext,
248
+ runtimeMemoryEnvFromContext,
249
+ runtimeContextStringFields,
250
+ runtimeContextOptionalStringFields,
251
+ runtimeContextArrayFields,
252
+ loadRuntimeContextFromEnv,
253
+ loadRuntimeContext,
254
+ browserEnvFromContext,
255
+ RUNTIME_CONTEXT_ENV,
256
+ DEFAULT_RUNTIME_MEMORY_RETRIEVAL
257
+ };
@@ -0,0 +1,44 @@
1
+ import type { HarnessEvent, HarnessEventType } from "@rig/contracts";
2
+ export type EventBusLike = {
3
+ getRunId(): string;
4
+ getEventsFile(): string;
5
+ getMemoryEvents(): HarnessEvent[];
6
+ emit<TPayload extends Record<string, unknown>>(type: HarnessEventType, payload: TPayload): Promise<HarnessEvent<TPayload>>;
7
+ attachRuntimeBus(runtimeBus: RuntimeEventBus): Promise<void>;
8
+ attachRuntimeWorkspace(projectRoot: string): Promise<RuntimeEventBus>;
9
+ };
10
+ export declare class RuntimeEventBus implements EventBusLike {
11
+ private readonly runId;
12
+ private readonly eventsFile;
13
+ private readonly memoryEvents;
14
+ constructor(options: {
15
+ projectRoot: string;
16
+ runId?: string;
17
+ eventsFile?: string;
18
+ });
19
+ getRunId(): string;
20
+ getEventsFile(): string;
21
+ getMemoryEvents(): HarnessEvent[];
22
+ attachRuntimeBus(runtimeBus: RuntimeEventBus): Promise<void>;
23
+ attachRuntimeWorkspace(projectRoot: string): Promise<RuntimeEventBus>;
24
+ ingest(event: HarnessEvent): Promise<void>;
25
+ emit<TPayload extends Record<string, unknown>>(type: HarnessEventType, payload: TPayload): Promise<HarnessEvent<TPayload>>;
26
+ }
27
+ export declare class GeneralCliEventBus implements EventBusLike {
28
+ private readonly runId;
29
+ private readonly eventsFile;
30
+ private readonly memoryEvents;
31
+ private readonly runtimeBuses;
32
+ constructor(options: {
33
+ projectRoot: string;
34
+ runId?: string;
35
+ eventsFile?: string;
36
+ });
37
+ getRunId(): string;
38
+ getEventsFile(): string;
39
+ getMemoryEvents(): HarnessEvent[];
40
+ attachRuntimeBus(runtimeBus: RuntimeEventBus): Promise<void>;
41
+ attachRuntimeWorkspace(projectRoot: string): Promise<RuntimeEventBus>;
42
+ emit<TPayload extends Record<string, unknown>>(type: HarnessEventType, payload: TPayload): Promise<HarnessEvent<TPayload>>;
43
+ }
44
+ export { GeneralCliEventBus as EventBus };