@h-rig/core 0.0.6-alpha.17 → 0.0.6-alpha.170

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 (107) 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 +6 -0
  6. package/dist/src/baked-secrets.js +121 -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 +758 -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 +82 -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 +18 -0
  33. package/dist/src/harness-paths.js +141 -0
  34. package/dist/src/hook-materializer.d.ts +72 -0
  35. package/dist/src/hook-materializer.js +281 -0
  36. package/dist/src/hook-protocol.d.ts +2 -0
  37. package/dist/src/hook-protocol.js +462 -0
  38. package/dist/src/hook-runner.d.ts +48 -0
  39. package/dist/src/hook-runner.js +756 -0
  40. package/dist/src/hook-runtime.d.ts +52 -0
  41. package/dist/src/hook-runtime.js +462 -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 +125 -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 +548 -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 +144 -0
  56. package/dist/src/load-config.d.ts +2 -0
  57. package/dist/src/load-config.js +423 -30
  58. package/dist/src/placement.d.ts +50 -0
  59. package/dist/src/placement.js +996 -0
  60. package/dist/src/plugin-host-context.d.ts +66 -0
  61. package/dist/src/plugin-host-context.js +1292 -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/profile-ops.d.ts +9 -0
  68. package/dist/src/profile-ops.js +252 -0
  69. package/dist/src/project-plugins.d.ts +63 -0
  70. package/dist/src/project-plugins.js +793 -0
  71. package/dist/src/remote-config.d.ts +183 -0
  72. package/dist/src/remote-config.js +574 -0
  73. package/dist/src/root-resolver.d.ts +5 -0
  74. package/dist/src/root-resolver.js +69 -0
  75. package/dist/src/run-provisioning.d.ts +58 -0
  76. package/dist/src/run-provisioning.js +128 -0
  77. package/dist/src/runtime-context.d.ts +20 -0
  78. package/dist/src/runtime-context.js +257 -0
  79. package/dist/src/runtime-events.d.ts +44 -0
  80. package/dist/src/runtime-events.js +212 -0
  81. package/dist/src/runtime-overlay.d.ts +11 -0
  82. package/dist/src/runtime-overlay.js +71 -0
  83. package/dist/src/runtime-paths.d.ts +21 -0
  84. package/dist/src/runtime-paths.js +181 -0
  85. package/dist/src/runtime-provisioning-env.d.ts +5 -0
  86. package/dist/src/runtime-provisioning-env.js +217 -0
  87. package/dist/src/runtime-runner-context.d.ts +12 -0
  88. package/dist/src/runtime-runner-context.js +1 -0
  89. package/dist/src/safe-identifiers.d.ts +44 -0
  90. package/dist/src/safe-identifiers.js +96 -0
  91. package/dist/src/scope-rules.d.ts +4 -0
  92. package/dist/src/scope-rules.js +21 -0
  93. package/dist/src/server-paths.d.ts +26 -0
  94. package/dist/src/server-paths.js +308 -0
  95. package/dist/src/setup-version.d.ts +3 -0
  96. package/dist/src/setup-version.js +14 -0
  97. package/dist/src/task-record-reader.d.ts +3 -0
  98. package/dist/src/task-record-reader.js +9 -0
  99. package/dist/src/validator-registry.d.ts +27 -0
  100. package/dist/src/validator-registry.js +64 -0
  101. package/package.json +166 -10
  102. package/dist/src/engineReadModelReducer.js +0 -1780
  103. package/dist/src/rig-init-builder.js +0 -57
  104. package/dist/src/rigSelectors.js +0 -293
  105. package/dist/src/taskGraph.js +0 -64
  106. package/dist/src/taskGraphCodes.js +0 -26
  107. package/dist/src/taskGraphLayout.js +0 -374
@@ -0,0 +1,252 @@
1
+ // @bun
2
+ // packages/core/src/profile-ops.ts
3
+ import { existsSync as existsSync2, mkdirSync, writeFileSync } from "fs";
4
+
5
+ // packages/core/src/harness-paths.ts
6
+ import { resolve as resolve3 } from "path";
7
+
8
+ // packages/core/src/layout.ts
9
+ import { resolve as resolve2 } from "path";
10
+ import {
11
+ RIG_ARTIFACTS_DIRNAME,
12
+ RIG_DEFINITION_DIRNAME,
13
+ RIG_STATE_DIRNAME
14
+ } from "@rig/contracts";
15
+
16
+ // packages/core/src/checkout-root.ts
17
+ import { dirname, resolve } from "path";
18
+ import { existsSync } from "fs";
19
+ function findNearestGitCheckoutRoot(startDir) {
20
+ let current = resolve(startDir);
21
+ for (;; ) {
22
+ if (existsSync(resolve(current, ".git")))
23
+ return current;
24
+ const parent = dirname(current);
25
+ if (parent === current)
26
+ return null;
27
+ current = parent;
28
+ }
29
+ }
30
+ function resolveCheckoutRoot(projectRoot) {
31
+ const normalizedProjectRoot = resolve(projectRoot);
32
+ const explicit = process.env.MONOREPO_ROOT?.trim();
33
+ if (explicit) {
34
+ const explicitRoot = resolve(explicit);
35
+ const gitRoot = findNearestGitCheckoutRoot(explicitRoot);
36
+ if (gitRoot)
37
+ return gitRoot;
38
+ throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there or above it.`);
39
+ }
40
+ return findNearestGitCheckoutRoot(normalizedProjectRoot) ?? normalizedProjectRoot;
41
+ }
42
+
43
+ // packages/core/src/layout.ts
44
+ var resolveMonorepoRoot = resolveCheckoutRoot;
45
+ function resolveRuntimeWorkspaceLayout(workspaceDir) {
46
+ const root = resolve2(workspaceDir);
47
+ const rigRoot = resolve2(root, ".rig");
48
+ const logsDir = resolve2(rigRoot, "logs");
49
+ const stateDir = resolve2(rigRoot, "state");
50
+ const runtimeDir = resolve2(rigRoot, "runtime");
51
+ const binDir = resolve2(rigRoot, "bin");
52
+ return {
53
+ workspaceDir: root,
54
+ rigRoot,
55
+ stateDir,
56
+ logsDir,
57
+ artifactsRoot: resolve2(root, RIG_ARTIFACTS_DIRNAME),
58
+ runtimeDir,
59
+ homeDir: resolve2(rigRoot, "home"),
60
+ tmpDir: resolve2(rigRoot, "tmp"),
61
+ cacheDir: resolve2(rigRoot, "cache"),
62
+ sessionDir: resolve2(rigRoot, "session"),
63
+ binDir,
64
+ distDir: resolve2(rigRoot, "dist"),
65
+ pluginBinDir: resolve2(binDir, "plugins"),
66
+ contextPath: resolve2(rigRoot, "runtime-context.json"),
67
+ controlPlaneEventsFile: resolve2(logsDir, "control-plane.events.jsonl")
68
+ };
69
+ }
70
+ function resolveActiveRuntimeWorkspaceRoot(_monorepoRoot) {
71
+ const explicit = process.env.RIG_TASK_WORKSPACE?.trim();
72
+ if (!explicit) {
73
+ throw new Error("No active runtime workspace. Set RIG_TASK_WORKSPACE or provision a task runtime first.");
74
+ }
75
+ return resolve2(explicit);
76
+ }
77
+ function resolveRigLayout(projectRoot) {
78
+ const monorepoRoot = resolveMonorepoRoot(projectRoot);
79
+ const definitionRoot = resolve2(projectRoot, RIG_DEFINITION_DIRNAME);
80
+ const runtimeWorkspaceRoot = resolveActiveRuntimeWorkspaceRoot(monorepoRoot);
81
+ const runtimeLayout = resolveRuntimeWorkspaceLayout(runtimeWorkspaceRoot);
82
+ const policyDir = resolve2(definitionRoot, "policy");
83
+ return {
84
+ projectRoot,
85
+ monorepoRoot,
86
+ definitionRoot,
87
+ runtimeWorkspaceRoot,
88
+ stateRoot: runtimeLayout.rigRoot,
89
+ artifactsRoot: runtimeLayout.artifactsRoot,
90
+ configPath: resolve2(definitionRoot, "config.sh"),
91
+ taskConfigPath: resolve2(runtimeWorkspaceRoot, ".rig", "task-config.json"),
92
+ policyDir,
93
+ policyFile: resolve2(policyDir, "policy.json"),
94
+ pluginsDir: resolve2(definitionRoot, "plugins"),
95
+ hooksDir: resolve2(definitionRoot, "hooks"),
96
+ toolsDir: resolve2(definitionRoot, "tools"),
97
+ templatesDir: resolve2(definitionRoot, "templates"),
98
+ validationDir: resolve2(definitionRoot, "validation"),
99
+ stateDir: runtimeLayout.stateDir,
100
+ logsDir: runtimeLayout.logsDir,
101
+ notificationsDir: resolve2(definitionRoot, "notifications"),
102
+ runtimeDir: runtimeLayout.runtimeDir,
103
+ distDir: runtimeLayout.distDir,
104
+ binDir: runtimeLayout.binDir,
105
+ pluginBinDir: runtimeLayout.pluginBinDir,
106
+ keybindingsPath: resolve2(definitionRoot, "keybindings.json"),
107
+ controlPlaneEventsFile: runtimeLayout.controlPlaneEventsFile
108
+ };
109
+ }
110
+
111
+ // packages/core/src/harness-paths.ts
112
+ function resolveHarnessPaths(projectRoot) {
113
+ const hasRuntimeWorkspace = Boolean(process.env.RIG_TASK_WORKSPACE?.trim());
114
+ const monorepoRoot = resolveCheckoutRoot(projectRoot);
115
+ const harnessRoot = resolve3(projectRoot, "rig");
116
+ const stateRoot = resolve3(projectRoot, ".rig");
117
+ const layout = hasRuntimeWorkspace ? resolveRigLayout(projectRoot) : null;
118
+ const stateDir = layout?.stateDir ?? resolve3(stateRoot, "state");
119
+ const logsDir = layout?.logsDir ?? resolve3(stateRoot, "logs");
120
+ const artifactsDir = layout?.artifactsRoot ?? resolve3(monorepoRoot, "artifacts");
121
+ const taskConfigPath = layout?.taskConfigPath ?? resolve3(monorepoRoot, ".rig", "task-config.json");
122
+ const binDir = layout?.binDir ?? resolve3(stateRoot, "bin");
123
+ return {
124
+ harnessRoot,
125
+ stateDir: process.env.RIG_STATE_DIR || stateDir,
126
+ artifactsDir,
127
+ logsDir: process.env.RIG_LOGS_DIR || logsDir,
128
+ binDir,
129
+ hooksDir: resolve3(harnessRoot, "hooks"),
130
+ validationDir: resolve3(harnessRoot, "validation"),
131
+ taskConfigPath,
132
+ sessionPath: process.env.RIG_SESSION_FILE || resolve3(stateRoot, "session", "session.json"),
133
+ monorepoRoot,
134
+ tsApiTestsDir: process.env.TS_API_TESTS_DIR || resolve3(monorepoRoot, "TSAPITests"),
135
+ taskRepoCommitsPath: resolve3(stateDir, "task-repo-commits.json"),
136
+ baseRepoPinsPath: resolve3(stateDir, "base-repo-pins.json"),
137
+ failedApproachesPath: resolve3(stateDir, "failed_approaches.md"),
138
+ agentProfilePath: resolve3(stateDir, "agent-profile.json"),
139
+ reviewProfilePath: resolve3(stateDir, "review-profile.json")
140
+ };
141
+ }
142
+
143
+ // packages/core/src/profile-ops.ts
144
+ var DEFAULTS = {
145
+ model: "pi",
146
+ runtime: "pi",
147
+ plugin: "pi",
148
+ reviewMode: parseEnvOrDefault(process.env.AI_REVIEW_MODE, ["off", "advisory", "required"], "advisory"),
149
+ reviewProvider: parseEnvOrDefault(process.env.AI_REVIEW_PROVIDER, ["greptile", "github"], "github")
150
+ };
151
+ function parseEnvOrDefault(value, allowed, fallback) {
152
+ if (!value) {
153
+ return fallback;
154
+ }
155
+ return allowed.includes(value) ? value : fallback;
156
+ }
157
+ async function readProfileFile(path) {
158
+ if (!existsSync2(path)) {
159
+ return null;
160
+ }
161
+ try {
162
+ return await Bun.file(path).json();
163
+ } catch {
164
+ return null;
165
+ }
166
+ }
167
+ async function showProfile(projectRoot, compact = false) {
168
+ const paths = resolveHarnessPaths(projectRoot);
169
+ const profile = await loadProfile(paths.agentProfilePath);
170
+ if (compact) {
171
+ console.log(`model=${profile.model} runtime=${profile.runtime} plugin=${profile.agent_plugin}`);
172
+ return;
173
+ }
174
+ console.log("Execution Profile:");
175
+ console.log(` model: ${profile.model}`);
176
+ console.log(` runtime: ${profile.runtime}`);
177
+ console.log(` plugin: ${profile.agent_plugin}`);
178
+ }
179
+ async function setProfile(projectRoot, options) {
180
+ const invalid = [options.model, options.runtime, options.plugin, options.preset].filter((value) => typeof value === "string" && value.trim().length > 0 && value.trim() !== "pi");
181
+ if (invalid.length > 0) {
182
+ throw new Error("Only the Pi runtime profile is supported by this Rig substrate.");
183
+ }
184
+ const paths = resolveHarnessPaths(projectRoot);
185
+ mkdirSync(paths.stateDir, { recursive: true });
186
+ const next = {
187
+ model: "pi",
188
+ runtime: "pi",
189
+ agent_plugin: "pi",
190
+ updated_at: new Date().toISOString()
191
+ };
192
+ writeFileSync(paths.agentProfilePath, `${JSON.stringify(next, null, 2)}
193
+ `, "utf-8");
194
+ await showProfile(projectRoot, false);
195
+ }
196
+ async function showReviewProfile(projectRoot) {
197
+ const paths = resolveHarnessPaths(projectRoot);
198
+ const profile = await loadReviewProfile(paths.reviewProfilePath);
199
+ console.log("AI Review Profile:");
200
+ console.log(` mode: ${profile.mode}`);
201
+ console.log(` provider: ${profile.provider}`);
202
+ console.log(` file: ${paths.reviewProfilePath}`);
203
+ }
204
+ async function setReviewProfile(projectRoot, mode, provider) {
205
+ if (mode !== "off" && mode !== "advisory" && mode !== "required") {
206
+ throw new Error(`Invalid mode: ${mode}. Use off|advisory|required.`);
207
+ }
208
+ const resolvedProvider = provider || DEFAULTS.reviewProvider;
209
+ if (resolvedProvider !== "greptile" && resolvedProvider !== "github") {
210
+ throw new Error(`Invalid provider: ${resolvedProvider}. Supported: github|greptile.`);
211
+ }
212
+ const paths = resolveHarnessPaths(projectRoot);
213
+ mkdirSync(paths.stateDir, { recursive: true });
214
+ const next = {
215
+ mode,
216
+ provider: resolvedProvider,
217
+ updated_at: new Date().toISOString()
218
+ };
219
+ writeFileSync(paths.reviewProfilePath, `${JSON.stringify(next, null, 2)}
220
+ `, "utf-8");
221
+ await showReviewProfile(projectRoot);
222
+ }
223
+ async function loadProfile(path) {
224
+ const parsed = await readProfileFile(path);
225
+ return {
226
+ model: "pi",
227
+ runtime: "pi",
228
+ agent_plugin: "pi",
229
+ updated_at: parsed?.updated_at || new Date().toISOString()
230
+ };
231
+ }
232
+ async function loadReviewProfile(path) {
233
+ const parsed = await readProfileFile(path);
234
+ if (parsed) {
235
+ return {
236
+ mode: parsed.mode || DEFAULTS.reviewMode,
237
+ provider: parsed.provider || DEFAULTS.reviewProvider,
238
+ updated_at: parsed.updated_at || new Date().toISOString()
239
+ };
240
+ }
241
+ return {
242
+ mode: DEFAULTS.reviewMode,
243
+ provider: DEFAULTS.reviewProvider,
244
+ updated_at: new Date().toISOString()
245
+ };
246
+ }
247
+ export {
248
+ showReviewProfile,
249
+ showProfile,
250
+ setReviewProfile,
251
+ setProfile
252
+ };
@@ -0,0 +1,63 @@
1
+ import type { RigConfig } from "@rig/contracts";
2
+ import { type PluginHost } from "./plugin-host";
3
+ import type { RigPlugin } from "./plugin-runtime";
4
+ export type ProjectPluginResolutionMode = "strict-config-only";
5
+ export type ProjectConfigPresence = {
6
+ readonly status: "loaded";
7
+ readonly path: string | null;
8
+ } | {
9
+ readonly status: "missing";
10
+ readonly path: null;
11
+ };
12
+ export type ProjectPluginResolution = {
13
+ readonly mode: ProjectPluginResolutionMode;
14
+ readonly projectRoot: string;
15
+ readonly configPresence: ProjectConfigPresence;
16
+ readonly config: RigConfig | null;
17
+ readonly plugins: readonly RigPlugin[];
18
+ };
19
+ export type ProjectPluginHostResult = {
20
+ readonly host: PluginHost;
21
+ readonly resolved: ProjectPluginResolution;
22
+ };
23
+ export type LoadProjectConfig = (projectRoot: string) => Promise<RigConfig>;
24
+ export type LoadProjectPluginSetOptions = {
25
+ readonly mode?: ProjectPluginResolutionMode;
26
+ readonly load?: LoadProjectConfig;
27
+ };
28
+ export type ProjectPluginResolutionOptions = Omit<LoadProjectPluginSetOptions, "mode"> & {
29
+ readonly projectRoot: string;
30
+ readonly mode: ProjectPluginResolutionMode;
31
+ };
32
+ export declare function loadProjectPluginSet(options: ProjectPluginResolutionOptions): Promise<ProjectPluginResolution>;
33
+ export declare function loadProjectPluginSet(projectRoot: string, options?: LoadProjectPluginSetOptions): Promise<ProjectPluginResolution>;
34
+ export type ResolvedPluginHost = {
35
+ readonly host: PluginHost;
36
+ readonly config: RigConfig;
37
+ };
38
+ export type ResolvePluginHostOptions = {
39
+ readonly load?: LoadProjectConfig;
40
+ };
41
+ /**
42
+ * The single cached plugin-host resolver. Returns the resolved host plus the
43
+ * loaded config for a project root, memoized per normalized root and validated
44
+ * by the rig.config file mtime — an edited config rebuilds the host (preserving
45
+ * loadConfig's mtime-cache semantics) while every other consumer in the same
46
+ * generation shares one resolved host.
47
+ *
48
+ * It propagates loadConfig's throw on a missing/broken config; each consumer
49
+ * keeps its own try/catch so per-call-site degradation (graceful-null vs
50
+ * surfaced error) is unchanged. A custom `load` bypasses the shared cache so it
51
+ * cannot poison the canonical on-disk host other consumers read.
52
+ */
53
+ export declare function resolvePluginHost(projectRoot: string, options?: ResolvePluginHostOptions): Promise<ResolvedPluginHost>;
54
+ /**
55
+ * Resolve the plugin host for a project root, returning the host plus the full
56
+ * resolution shape. This delegates to the single cached `resolvePluginHost`
57
+ * memo so every consumer in a process SHARES one resolved host for a root
58
+ * instead of re-evaluating rig.config.ts and constructing an independent host
59
+ * (architecture-reference §18: one resolved host per process/root). Graceful
60
+ * missing-config degradation and the custom-`load` bypass are preserved.
61
+ */
62
+ export declare function createProjectPluginHost(options: ProjectPluginResolutionOptions): Promise<ProjectPluginHostResult>;
63
+ export declare function createProjectPluginHost(projectRoot: string, options?: LoadProjectPluginSetOptions): Promise<ProjectPluginHostResult>;