@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,453 @@
1
+ // @bun
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
16
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
+
18
+ // packages/runtime/src/control-plane/task-source.ts
19
+ function createTaskSourceRegistry() {
20
+ const byId = new Map;
21
+ const order = [];
22
+ return {
23
+ register(s) {
24
+ if (byId.has(s.id))
25
+ throw new Error(`task source already registered: ${s.id}`);
26
+ byId.set(s.id, s);
27
+ order.push(s);
28
+ },
29
+ resolveById(id) {
30
+ const s = byId.get(id);
31
+ if (!s)
32
+ throw new Error(`task source not registered: ${id}`);
33
+ return s;
34
+ },
35
+ resolveByKind(kind) {
36
+ for (const s of order)
37
+ if (s.kind === kind)
38
+ return s;
39
+ throw new Error(`no task source registered for kind: ${kind}`);
40
+ },
41
+ list: () => order
42
+ };
43
+ }
44
+
45
+ // packages/runtime/src/control-plane/task-source-bootstrap.ts
46
+ function formatRegisteredKinds(pluginHost) {
47
+ const kinds = pluginHost ? pluginHost.listExecutableTaskSources().map((source) => source.kind) : [];
48
+ return kinds.length > 0 ? kinds.join(", ") : "none";
49
+ }
50
+ function buildTaskSourceRegistry(config, pluginHost) {
51
+ const registry = createTaskSourceRegistry();
52
+ const taskSourceConfig = config.taskSource;
53
+ const factory = pluginHost?.resolveTaskSourceFactoryByKind(taskSourceConfig.kind);
54
+ if (!factory) {
55
+ throw new Error(`No task source factory registered for kind "${taskSourceConfig.kind}". ` + `Registered kinds: ${formatRegisteredKinds(pluginHost)}. ` + "Load a plugin that contributes an executable task source factory for this kind.");
56
+ }
57
+ registry.register(factory.factory(taskSourceConfig));
58
+ return registry;
59
+ }
60
+ var init_task_source_bootstrap = () => {};
61
+
62
+ // packages/runtime/src/control-plane/repos/registry.ts
63
+ function createRepoRegistry(entries) {
64
+ const map = new Map;
65
+ for (const e of entries) {
66
+ if (map.has(e.id))
67
+ throw new Error(`repo already registered: ${e.id}`);
68
+ map.set(e.id, { ...e });
69
+ }
70
+ const ordered = Array.from(map.values());
71
+ return {
72
+ getById: (id) => map.get(id),
73
+ list: () => ordered
74
+ };
75
+ }
76
+ function setManagedRepos(entries) {
77
+ const next = new Map;
78
+ for (const e of entries) {
79
+ if (next.has(e.id)) {
80
+ throw new Error(`managed repo already registered: ${e.id}`);
81
+ }
82
+ next.set(e.id, e);
83
+ }
84
+ MANAGED_REPOS = next;
85
+ }
86
+ function repoRegistrationToManagedEntry(reg) {
87
+ if (!reg.defaultBranch) {
88
+ return null;
89
+ }
90
+ return {
91
+ id: reg.id,
92
+ alias: reg.defaultPath ?? reg.id,
93
+ defaultBranch: reg.defaultBranch,
94
+ defaultRemoteUrl: reg.url,
95
+ remoteEnvVar: reg.remoteEnvVar,
96
+ checkoutEnvVar: reg.checkoutEnvVar
97
+ };
98
+ }
99
+ var MANAGED_REPOS;
100
+ var init_registry = __esm(() => {
101
+ MANAGED_REPOS = new Map;
102
+ });
103
+
104
+ // packages/runtime/src/control-plane/agent-roles.ts
105
+ function createAgentRoleRegistry(pluginRoles, configOverrides) {
106
+ const map = new Map;
107
+ for (const r of pluginRoles) {
108
+ if (map.has(r.id))
109
+ throw new Error(`agent role already registered: ${r.id}`);
110
+ const override = configOverrides?.[r.id];
111
+ const model = override?.model ?? r.defaultModel;
112
+ if (!model) {
113
+ throw new Error(`agent role "${r.id}" has no model \u2014 provide defaultModel in plugin or model in config.runtime.agentRoles.${r.id}`);
114
+ }
115
+ map.set(r.id, { ...r, model });
116
+ }
117
+ return {
118
+ resolve(id) {
119
+ const r = map.get(id);
120
+ if (!r)
121
+ throw new Error(`agent role not registered: ${id}`);
122
+ return r;
123
+ },
124
+ list: () => Array.from(map.values())
125
+ };
126
+ }
127
+
128
+ // packages/runtime/src/control-plane/task-fields.ts
129
+ function createTaskFieldRegistry(extensions) {
130
+ const byId = new Map;
131
+ for (const e of extensions) {
132
+ if (byId.has(e.id))
133
+ throw new Error(`task field extension already registered: ${e.id}`);
134
+ byId.set(e.id, e);
135
+ }
136
+ return {
137
+ get: (id) => byId.get(id),
138
+ list: () => Array.from(byId.values()),
139
+ fieldNames: () => Array.from(byId.values()).map((e) => e.fieldName),
140
+ validateTaskFields(task) {
141
+ const errors = [];
142
+ for (const ext of byId.values()) {
143
+ let schema;
144
+ try {
145
+ schema = JSON.parse(ext.schemaJson);
146
+ } catch {
147
+ errors.push(`task field "${ext.id}": schemaJson is not valid JSON`);
148
+ continue;
149
+ }
150
+ const isRequired = typeof schema === "object" && schema !== null && schema.required === true;
151
+ if (!isRequired)
152
+ continue;
153
+ const value = task[ext.fieldName];
154
+ if (value === undefined || value === null || value === "") {
155
+ errors.push(`task field "${ext.fieldName}" (from extension "${ext.id}") is required but missing`);
156
+ }
157
+ }
158
+ return errors.length === 0 ? { ok: true } : { ok: false, errors };
159
+ }
160
+ };
161
+ }
162
+
163
+ // packages/runtime/src/control-plane/validators/runtime-registration.ts
164
+ import { existsSync } from "fs";
165
+ import { join } from "path";
166
+ function createValidatorRegistry() {
167
+ const map = new Map;
168
+ const order = [];
169
+ const registry = {
170
+ register(v) {
171
+ if (map.has(v.id))
172
+ throw new Error(`validator already registered: ${v.id}`);
173
+ map.set(v.id, v);
174
+ order.push(v);
175
+ },
176
+ resolve(id) {
177
+ const v = map.get(id);
178
+ if (!v)
179
+ throw new Error(`validator not registered: ${id}`);
180
+ return v;
181
+ },
182
+ list: () => order
183
+ };
184
+ registerBuiltInValidators(registry);
185
+ return registry;
186
+ }
187
+ function registerBuiltInValidators(registry) {
188
+ registry.register({
189
+ id: "std:typecheck",
190
+ category: "custom",
191
+ description: "Runs the package typecheck script when present.",
192
+ run: async (ctx) => runStdTypecheck(ctx)
193
+ });
194
+ }
195
+ async function runStdTypecheck(ctx) {
196
+ const packageJsonPath = join(ctx.workspaceRoot, "package.json");
197
+ if (!existsSync(packageJsonPath)) {
198
+ return {
199
+ id: "std:typecheck",
200
+ passed: false,
201
+ summary: `package.json not found at ${packageJsonPath}`
202
+ };
203
+ }
204
+ const proc = Bun.spawn(["bun", "run", "typecheck"], {
205
+ cwd: ctx.workspaceRoot,
206
+ env: process.env,
207
+ stdout: "pipe",
208
+ stderr: "pipe"
209
+ });
210
+ const [exitCode, stdout, stderr] = await Promise.all([
211
+ proc.exited,
212
+ new Response(proc.stdout).text(),
213
+ new Response(proc.stderr).text()
214
+ ]);
215
+ const output = `${stdout}${stderr}`.trim();
216
+ return {
217
+ id: "std:typecheck",
218
+ passed: exitCode === 0,
219
+ summary: exitCode === 0 ? "typecheck passed" : "typecheck failed",
220
+ ...output ? { details: output.slice(0, 4000) } : {}
221
+ };
222
+ }
223
+ var init_runtime_registration = () => {};
224
+
225
+ // packages/runtime/src/control-plane/native/scope-rules.ts
226
+ function setScopeRules(rules) {
227
+ activeRules = rules ?? null;
228
+ }
229
+ var activeRules = null;
230
+
231
+ // packages/runtime/src/control-plane/hook-materializer.ts
232
+ import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
233
+ import { dirname, resolve } from "path";
234
+ function matcherToString(matcher) {
235
+ if (matcher.kind === "all")
236
+ return;
237
+ if (matcher.kind === "tool")
238
+ return matcher.name;
239
+ return matcher.pattern;
240
+ }
241
+ function isPluginOwned(cmd) {
242
+ return typeof cmd[MARKER_PLUGIN] === "string";
243
+ }
244
+ function materializeHooks(projectRoot, entries) {
245
+ const settingsPath = resolve(projectRoot, ".claude", "settings.json");
246
+ const existing = existsSync2(settingsPath) ? safeReadJson(settingsPath) : {};
247
+ const hooks = existing.hooks ?? {};
248
+ for (const event of Object.keys(hooks)) {
249
+ const groups = hooks[event] ?? [];
250
+ const cleaned = [];
251
+ for (const group of groups) {
252
+ const operatorHooks = group.hooks.filter((h) => !isPluginOwned(h));
253
+ if (operatorHooks.length > 0) {
254
+ cleaned.push({ ...group, hooks: operatorHooks });
255
+ }
256
+ }
257
+ if (cleaned.length > 0) {
258
+ hooks[event] = cleaned;
259
+ } else {
260
+ delete hooks[event];
261
+ }
262
+ }
263
+ for (const { pluginName, hook } of entries) {
264
+ if (!hook.command) {
265
+ continue;
266
+ }
267
+ const event = hook.event;
268
+ const matcherString = matcherToString(hook.matcher);
269
+ const groups = hooks[event] ??= [];
270
+ let group = groups.find((g) => g.matcher === matcherString);
271
+ if (!group) {
272
+ group = matcherString === undefined ? { hooks: [] } : { matcher: matcherString, hooks: [] };
273
+ groups.push(group);
274
+ }
275
+ group.hooks.push({
276
+ type: "command",
277
+ command: hook.command,
278
+ [MARKER_PLUGIN]: pluginName,
279
+ [MARKER_HOOK_ID]: hook.id
280
+ });
281
+ }
282
+ const next = { ...existing };
283
+ if (Object.keys(hooks).length > 0) {
284
+ next.hooks = hooks;
285
+ } else {
286
+ delete next.hooks;
287
+ }
288
+ mkdirSync(dirname(settingsPath), { recursive: true });
289
+ writeFileSync(settingsPath, `${JSON.stringify(next, null, 2)}
290
+ `, "utf-8");
291
+ return settingsPath;
292
+ }
293
+ function safeReadJson(path) {
294
+ try {
295
+ return JSON.parse(readFileSync(path, "utf-8"));
296
+ } catch {
297
+ return {};
298
+ }
299
+ }
300
+ var MARKER_PLUGIN = "_rigPlugin", MARKER_HOOK_ID = "_rigHookId";
301
+ var init_hook_materializer = () => {};
302
+
303
+ // packages/runtime/src/control-plane/plugin-host-context.ts
304
+ var exports_plugin_host_context = {};
305
+ __export(exports_plugin_host_context, {
306
+ buildPluginHostContext: () => buildPluginHostContext
307
+ });
308
+ import { createPluginHost } from "@rig/core";
309
+ import { loadConfig } from "@rig/core/load-config";
310
+ async function buildPluginHostContext(projectRoot) {
311
+ let config;
312
+ try {
313
+ config = await loadConfig(projectRoot);
314
+ } catch (err) {
315
+ const msg = err instanceof Error ? err.message : String(err);
316
+ if (msg.includes("no rig.config")) {
317
+ return null;
318
+ }
319
+ throw err;
320
+ }
321
+ const pluginHost = createPluginHost(config.plugins);
322
+ setScopeRules(config.workspace.scopeNormalization);
323
+ const validatorRegistry = createValidatorRegistry();
324
+ for (const impl of pluginHost.listExecutableValidators()) {
325
+ validatorRegistry.register(impl);
326
+ }
327
+ const taskSourceRegistry = buildTaskSourceRegistry(config, pluginHost);
328
+ const repoRegistry = createRepoRegistry(pluginHost.listRepoSources());
329
+ const managedEntries = pluginHost.listRepoSources().map(repoRegistrationToManagedEntry).filter((e) => e !== null);
330
+ setManagedRepos(managedEntries);
331
+ const configRoleOverrides = config.runtime?.agentRoles;
332
+ const agentRoleRegistry = createAgentRoleRegistry(pluginHost.listAgentRoles(), configRoleOverrides);
333
+ const taskFieldRegistry = createTaskFieldRegistry(pluginHost.listTaskFieldExtensions());
334
+ try {
335
+ const hookEntries = config.plugins.flatMap((plugin) => (plugin.contributes?.hooks ?? []).map((hook) => ({
336
+ pluginName: plugin.name,
337
+ hook
338
+ })));
339
+ if (hookEntries.length > 0) {
340
+ materializeHooks(projectRoot, hookEntries);
341
+ }
342
+ } catch (err) {
343
+ console.warn(`[plugin-host] hook materialization failed: ${err instanceof Error ? err.message : err}`);
344
+ }
345
+ return {
346
+ config,
347
+ pluginHost,
348
+ validatorRegistry,
349
+ taskSourceRegistry,
350
+ repoRegistry,
351
+ agentRoleRegistry,
352
+ taskFieldRegistry
353
+ };
354
+ }
355
+ var init_plugin_host_context = __esm(() => {
356
+ init_task_source_bootstrap();
357
+ init_registry();
358
+ init_runtime_registration();
359
+ init_hook_materializer();
360
+ });
361
+
362
+ // packages/runtime/src/control-plane/materialize-task-config.ts
363
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
364
+ import { dirname as dirname2, resolve as resolve2 } from "path";
365
+ async function materializePluginHostTaskConfig(projectRoot) {
366
+ const hasConfig = existsSync3(resolve2(projectRoot, "rig.config.ts")) || existsSync3(resolve2(projectRoot, "rig.config.json"));
367
+ if (!hasConfig)
368
+ return null;
369
+ const { buildPluginHostContext: buildPluginHostContext2 } = await Promise.resolve().then(() => (init_plugin_host_context(), exports_plugin_host_context));
370
+ let ctx;
371
+ try {
372
+ ctx = await buildPluginHostContext2(projectRoot);
373
+ } catch (err) {
374
+ console.warn(`[materialize-task-config] plugin host build failed (treating as legacy path): ${err instanceof Error ? err.message : String(err)}`);
375
+ return null;
376
+ }
377
+ if (!ctx)
378
+ return null;
379
+ const sources = ctx.taskSourceRegistry.list();
380
+ if (sources.length === 0)
381
+ return null;
382
+ const source = sources[0];
383
+ const tasks = await source.list();
384
+ if (tasks.length === 0)
385
+ return null;
386
+ const configPath = resolve2(projectRoot, ".rig", "task-config.json");
387
+ const existing = existsSync3(configPath) ? safeJsonRead(configPath) : {};
388
+ const merged = { ...existing };
389
+ let syncedCount = 0;
390
+ for (const task of tasks) {
391
+ const t = task;
392
+ const id = typeof t.id === "string" ? t.id.trim() : "";
393
+ if (!id)
394
+ continue;
395
+ const existingEntry = merged[id];
396
+ const existingIsOperatorEdit = existingEntry !== undefined && typeof existingEntry === "object" && existingEntry !== null && existingEntry.auto_synced !== true;
397
+ if (existingIsOperatorEdit) {
398
+ continue;
399
+ }
400
+ merged[id] = synthesizeEntry(t, ctx.config.taskSource);
401
+ syncedCount += 1;
402
+ }
403
+ mkdirSync2(dirname2(configPath), { recursive: true });
404
+ writeFileSync2(configPath, `${JSON.stringify(merged, null, 2)}
405
+ `, "utf-8");
406
+ return { configPath, syncedCount };
407
+ }
408
+ function synthesizeEntry(t, taskSource) {
409
+ const role = typeof t.role === "string" ? t.role : undefined;
410
+ const scope = Array.isArray(t.scope) ? t.scope.filter((s) => typeof s === "string") : [];
411
+ const validation = Array.isArray(t.validators) ? t.validators.filter((v) => typeof v === "string") : Array.isArray(t.validation) ? t.validation.filter((v) => typeof v === "string") : [];
412
+ const description = typeof t.description === "string" ? t.description : typeof t.body === "string" ? t.body : undefined;
413
+ const acceptance = typeof t.acceptanceCriteria === "string" ? t.acceptanceCriteria : undefined;
414
+ const title = typeof t.title === "string" ? t.title : undefined;
415
+ const status = typeof t.status === "string" ? t.status : undefined;
416
+ const sourceIssueId = typeof t.sourceIssueId === "string" ? t.sourceIssueId : taskSource.kind === "github-issues" && taskSource.owner && taskSource.repo ? `${taskSource.owner}/${taskSource.repo}#${String(t.id)}` : undefined;
417
+ return {
418
+ auto_synced: true,
419
+ _rig: {
420
+ taskSource: materializedTaskSource(taskSource),
421
+ ...sourceIssueId ? { sourceIssueId } : {}
422
+ },
423
+ ...title ? { title } : {},
424
+ ...status ? { status } : {},
425
+ ...sourceIssueId ? { sourceIssueId } : {},
426
+ ...role ? { role } : {},
427
+ scope,
428
+ validation,
429
+ ...description ? { description } : {},
430
+ ...acceptance ? { acceptance_criteria: acceptance } : {}
431
+ };
432
+ }
433
+ function materializedTaskSource(taskSource) {
434
+ return {
435
+ kind: taskSource.kind,
436
+ ...taskSource.path ? { path: taskSource.path } : {},
437
+ ...taskSource.owner ? { owner: taskSource.owner } : {},
438
+ ...taskSource.repo ? { repo: taskSource.repo } : {},
439
+ ...taskSource.labels ? { labels: taskSource.labels } : {},
440
+ ...taskSource.state ? { state: taskSource.state } : {}
441
+ };
442
+ }
443
+ function safeJsonRead(path) {
444
+ try {
445
+ const parsed = JSON.parse(readFileSync2(path, "utf-8"));
446
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
447
+ } catch {
448
+ return {};
449
+ }
450
+ }
451
+ export {
452
+ materializePluginHostTaskConfig
453
+ };