@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
@@ -1,48 +1,553 @@
1
1
  // @bun
2
2
  // packages/core/src/load-config.ts
3
- import { existsSync, readFileSync } from "fs";
4
- import { join } from "path";
3
+ import { existsSync as existsSync2, mkdirSync, mkdtempSync, readFileSync as readFileSync2, readdirSync, rmSync, statSync } from "fs";
4
+ import { isBuiltin } from "module";
5
+ import { basename, dirname, isAbsolute, join as join2, relative, resolve } from "path";
5
6
  import { pathToFileURL } from "url";
7
+ import { Schema as Schema3 } from "effect";
8
+ import { RigConfig as RigConfig3 } from "@rig/contracts";
9
+
10
+ // packages/core/src/define-config.ts
6
11
  import { Schema } from "effect";
7
12
  import { RigConfig } from "@rig/contracts";
8
- var TS_NAMES = ["rig.config.ts", "rig.config.mts"];
9
- var JSON_NAMES = ["rig.config.json"];
13
+ function normalizeWorkspaceConfig(raw) {
14
+ const workspace = raw && typeof raw === "object" && !Array.isArray(raw) ? { ...raw } : {};
15
+ if (workspace.mainRepo === undefined)
16
+ workspace.mainRepo = ".";
17
+ if (workspace.checkout === undefined && workspace.isolation !== undefined)
18
+ workspace.checkout = workspace.isolation;
19
+ if (workspace.isolation === undefined && workspace.checkout !== undefined)
20
+ workspace.isolation = workspace.checkout;
21
+ return workspace;
22
+ }
23
+ function applyConfigDefaults(raw) {
24
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
25
+ return raw;
26
+ const record = raw;
27
+ return {
28
+ ...record,
29
+ plugins: Array.isArray(record.plugins) ? record.plugins.flat() : [],
30
+ workspace: normalizeWorkspaceConfig(record.workspace)
31
+ };
32
+ }
33
+
34
+ // packages/core/src/declarative-config.ts
35
+ import { existsSync, readFileSync } from "fs";
36
+ import { join } from "path";
37
+ import { parse as parseToml } from "smol-toml";
38
+ import { Schema as Schema2 } from "effect";
39
+ import { RigConfig as RigConfig2 } from "@rig/contracts";
40
+
41
+ // packages/core/src/embedded-plugins.ts
42
+ var registered = null;
43
+ function getStandardPluginsResolver() {
44
+ return registered;
45
+ }
46
+ var bakedProjectConfig = null;
47
+ function getEmbeddedProjectConfig() {
48
+ return bakedProjectConfig;
49
+ }
50
+
51
+ // packages/core/src/declarative-config.ts
52
+ var DECLARATIVE_CONFIG_NAMES = ["rigfig.toml", "rigfig.json"];
53
+ function findDeclarativeConfigPath(cwd) {
54
+ const dir = join(cwd, ".rig");
55
+ for (const name of DECLARATIVE_CONFIG_NAMES) {
56
+ const candidate = join(dir, name);
57
+ if (existsSync(candidate))
58
+ return candidate;
59
+ }
60
+ return null;
61
+ }
62
+ function parseDeclarativeFile(path) {
63
+ const raw = readFileSync(path, "utf8");
64
+ const parsed = path.endsWith(".json") ? JSON.parse(raw) : parseToml(raw);
65
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
66
+ throw new Error(`Declarative config ${path} must parse to an object.`);
67
+ }
68
+ return parsed;
69
+ }
70
+ function loadDeclarativeConfig(path) {
71
+ const data = parseDeclarativeFile(path);
72
+ const standardSection = data.standard && typeof data.standard === "object" && !Array.isArray(data.standard) ? data.standard : null;
73
+ if (standardSection?.enabled !== true && standardSection?.enabled !== false) {
74
+ throw new Error(`Declarative config ${path} must explicitly set [standard] enabled = true or false.`);
75
+ }
76
+ const useStandard = standardSection.enabled === true;
77
+ let plugins = [];
78
+ if (useStandard) {
79
+ const resolver = getStandardPluginsResolver();
80
+ if (!resolver) {
81
+ throw new Error(`Declarative config ${path} needs the embedded standard plugins, but none were registered. ` + `This is a seed/boot wiring error (the binary entrypoint must import the standard-plugin registration).`);
82
+ }
83
+ plugins = resolver(data);
84
+ }
85
+ const { standard: _standardDirective, ...configFields } = data;
86
+ const withDefaults = applyConfigDefaults({ ...configFields, plugins });
87
+ const explicitPlugins = Array.isArray(withDefaults.plugins) ? [...withDefaults.plugins] : [];
88
+ const decoded = Schema2.decodeUnknownSync(RigConfig2)({
89
+ ...withDefaults,
90
+ plugins: explicitPlugins
91
+ });
92
+ return { ...decoded, plugins: explicitPlugins };
93
+ }
94
+
95
+ // packages/core/src/load-config.ts
96
+ var TS_NAMES = [".rig/rig.config.ts", ".rig/rig.config.mts"];
97
+ var JSON_NAMES = [".rig/rig.config.json"];
98
+ function isModuleResolutionError(error) {
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ return message.includes("Cannot find module") || message.includes("Could not resolve");
101
+ }
102
+ function runningFromCompiledBinary() {
103
+ return import.meta.url.includes("$bunfs");
104
+ }
105
+ function packageNameAndSubpath(specifier) {
106
+ if (specifier.startsWith(".") || specifier.startsWith("/") || /^[a-zA-Z]+:/.test(specifier))
107
+ return null;
108
+ const parts = specifier.split("/");
109
+ const packageName = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
110
+ if (!packageName)
111
+ return null;
112
+ const rest = parts.slice(specifier.startsWith("@") ? 2 : 1).join("/");
113
+ return { packageName, subpath: rest ? `./${rest}` : "." };
114
+ }
115
+ function exportTargetFromEntry(entry) {
116
+ if (typeof entry === "string")
117
+ return entry;
118
+ if (Array.isArray(entry)) {
119
+ for (const candidate of entry) {
120
+ const target = exportTargetFromEntry(candidate);
121
+ if (target)
122
+ return target;
123
+ }
124
+ return null;
125
+ }
126
+ if (entry && typeof entry === "object") {
127
+ const conditions = entry;
128
+ for (const key of ["bun", "node", "import", "default", "require"]) {
129
+ const target = exportTargetFromEntry(conditions[key]);
130
+ if (target)
131
+ return target;
132
+ }
133
+ }
134
+ return null;
135
+ }
136
+ function patternExportTarget(record, subpath) {
137
+ const entries = Object.entries(record).filter(([pattern]) => pattern.includes("*")).sort(([a], [b]) => b.replace("*", "").length - a.replace("*", "").length);
138
+ for (const [pattern, entry] of entries) {
139
+ const [prefix = "", suffix = ""] = pattern.split("*");
140
+ if (!subpath.startsWith(prefix) || !subpath.endsWith(suffix))
141
+ continue;
142
+ const replacement = subpath.slice(prefix.length, subpath.length - suffix.length);
143
+ const target = exportTargetFromEntry(entry);
144
+ if (target)
145
+ return target.replace("*", replacement);
146
+ }
147
+ return null;
148
+ }
149
+ function exportTargetFromPackageJson(pkg, subpath) {
150
+ const exportsField = pkg.exports;
151
+ const target = (() => {
152
+ if (typeof exportsField === "string" && subpath === ".")
153
+ return exportsField;
154
+ if (!exportsField || typeof exportsField !== "object" || Array.isArray(exportsField))
155
+ return null;
156
+ const record = exportsField;
157
+ return exportTargetFromEntry(record[subpath] ?? (subpath === "." ? record["."] : undefined)) ?? patternExportTarget(record, subpath);
158
+ })();
159
+ if (target)
160
+ return target;
161
+ return subpath === "." && typeof pkg.module === "string" ? pkg.module : subpath === "." && typeof pkg.main === "string" ? pkg.main : null;
162
+ }
163
+ function patternImportTarget(record, specifier) {
164
+ for (const [pattern, entry] of Object.entries(record)) {
165
+ if (!pattern.includes("*"))
166
+ continue;
167
+ const [prefix = "", suffix = ""] = pattern.split("*");
168
+ if (!specifier.startsWith(prefix) || !specifier.endsWith(suffix))
169
+ continue;
170
+ const replacement = specifier.slice(prefix.length, specifier.length - suffix.length);
171
+ const target = exportTargetFromEntry(entry);
172
+ if (target)
173
+ return target.replace("*", replacement);
174
+ }
175
+ return null;
176
+ }
177
+ function resolvePackagePrivateImport(specifier, importer, projectRoot) {
178
+ if (!specifier.startsWith("#") || !importer || !isAbsolute(importer))
179
+ return null;
180
+ let dir = dirname(importer);
181
+ const stop = resolve(projectRoot);
182
+ while (isWithinDir(dir, stop)) {
183
+ const packageJsonPath = join2(dir, "package.json");
184
+ if (existsSync2(packageJsonPath)) {
185
+ try {
186
+ const pkg = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
187
+ const imports = pkg.imports;
188
+ if (imports && typeof imports === "object" && !Array.isArray(imports)) {
189
+ const record = imports;
190
+ const target = exportTargetFromEntry(record[specifier]) ?? patternImportTarget(record, specifier);
191
+ if (target)
192
+ return resolveModulePath(join2(dir, target));
193
+ }
194
+ } catch {
195
+ return null;
196
+ }
197
+ return null;
198
+ }
199
+ const parent = dirname(dir);
200
+ if (parent === dir)
201
+ return null;
202
+ dir = parent;
203
+ }
204
+ return null;
205
+ }
206
+ function resolvePackageDirFromBunStore(packageName, nodeModulesDir) {
207
+ const storeDir = join2(nodeModulesDir, ".bun");
208
+ if (!existsSync2(storeDir))
209
+ return null;
210
+ const encoded = packageName.replace("/", "+");
211
+ try {
212
+ const candidates = readdirSync(storeDir).filter((entry) => entry.startsWith(`${encoded}@`)).map((entry) => {
213
+ const candidateDir = join2(storeDir, entry, "node_modules", packageName);
214
+ const packageJsonPath = join2(candidateDir, "package.json");
215
+ if (!existsSync2(packageJsonPath))
216
+ return null;
217
+ try {
218
+ const pkg = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
219
+ return {
220
+ dir: candidateDir,
221
+ sortKey: pkg.version?.trim() || entry
222
+ };
223
+ } catch {
224
+ return {
225
+ dir: candidateDir,
226
+ sortKey: entry
227
+ };
228
+ }
229
+ }).filter((candidate) => candidate !== null).sort((a, b) => b.sortKey.localeCompare(a.sortKey, undefined, { numeric: true, sensitivity: "base" }));
230
+ return candidates[0]?.dir ?? null;
231
+ } catch {
232
+ return null;
233
+ }
234
+ }
235
+ function resolveDirectoryModulePath(directoryPath) {
236
+ const packageJsonPath = join2(directoryPath, "package.json");
237
+ if (existsSync2(packageJsonPath)) {
238
+ try {
239
+ const pkg = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
240
+ const target = exportTargetFromPackageJson(pkg, ".");
241
+ if (target) {
242
+ const resolved = resolveModulePath(join2(directoryPath, target));
243
+ if (resolved)
244
+ return resolved;
245
+ }
246
+ } catch {}
247
+ }
248
+ for (const candidate of ["index.js", "index.mjs", "index.cjs", "index.ts", "index.json"]) {
249
+ const resolved = resolveModulePath(join2(directoryPath, candidate));
250
+ if (resolved)
251
+ return resolved;
252
+ }
253
+ return null;
254
+ }
255
+ function resolveModulePath(candidatePath) {
256
+ if (!existsSync2(candidatePath)) {
257
+ for (const extension of [".ts", ".mts", ".tsx", ".js", ".mjs", ".cjs", ".json"]) {
258
+ const withExtension = `${candidatePath}${extension}`;
259
+ if (existsSync2(withExtension))
260
+ return resolveModulePath(withExtension);
261
+ }
262
+ return null;
263
+ }
264
+ try {
265
+ const stat = statSync(candidatePath);
266
+ if (stat.isFile())
267
+ return candidatePath;
268
+ if (stat.isDirectory())
269
+ return resolveDirectoryModulePath(candidatePath);
270
+ } catch {
271
+ return null;
272
+ }
273
+ return null;
274
+ }
275
+ function resolvePackageExportFromDir(packageDir, subpath) {
276
+ const packageJsonPath = join2(packageDir, "package.json");
277
+ if (existsSync2(packageJsonPath)) {
278
+ try {
279
+ const pkg = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
280
+ const targets = [
281
+ exportTargetFromPackageJson(pkg, subpath),
282
+ ...subpath === "." ? [typeof pkg.module === "string" ? pkg.module : null, typeof pkg.main === "string" ? pkg.main : null] : []
283
+ ];
284
+ const seen = new Set;
285
+ for (const target of targets) {
286
+ if (!target || seen.has(target))
287
+ continue;
288
+ seen.add(target);
289
+ const resolved = resolveModulePath(join2(packageDir, target));
290
+ if (resolved)
291
+ return resolved;
292
+ }
293
+ } catch {
294
+ return null;
295
+ }
296
+ }
297
+ if (subpath !== ".") {
298
+ const legacySubpath = subpath.replace(/^\.\//, "");
299
+ for (const candidate of [
300
+ join2(packageDir, legacySubpath),
301
+ join2(packageDir, `${legacySubpath}.js`),
302
+ join2(packageDir, `${legacySubpath}.mjs`),
303
+ join2(packageDir, `${legacySubpath}.cjs`),
304
+ join2(packageDir, `${legacySubpath}.ts`),
305
+ join2(packageDir, `${legacySubpath}.json`)
306
+ ]) {
307
+ const resolved = resolveModulePath(candidate);
308
+ if (resolved)
309
+ return resolved;
310
+ }
311
+ }
312
+ return subpath === "." ? resolveDirectoryModulePath(packageDir) : null;
313
+ }
314
+ var runtimeBundleQueue = Promise.resolve();
315
+ function enqueueRuntimeBundle(operation) {
316
+ const next = runtimeBundleQueue.then(operation, operation);
317
+ runtimeBundleQueue = next.then(() => {
318
+ return;
319
+ }, () => {
320
+ return;
321
+ });
322
+ return next;
323
+ }
324
+ function isWithinDir(candidatePath, rootPath) {
325
+ const rel = relative(resolve(rootPath), resolve(candidatePath));
326
+ return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
327
+ }
328
+ function resolvedFilePath(path, rootPath) {
329
+ if (!path || !isAbsolute(path))
330
+ return null;
331
+ const resolved = resolveModulePath(path);
332
+ if (!resolved)
333
+ return null;
334
+ return rootPath && !isWithinDir(resolved, rootPath) ? null : resolved;
335
+ }
336
+ function resolveProjectPackageImport(specifier, configDir) {
337
+ const parsed = packageNameAndSubpath(specifier);
338
+ if (!parsed)
339
+ return null;
340
+ const nodeModulesDir = join2(configDir, "node_modules");
341
+ const directPackageDir = join2(nodeModulesDir, parsed.packageName);
342
+ const packageDir = existsSync2(join2(directPackageDir, "package.json")) ? directPackageDir : resolvePackageDirFromBunStore(parsed.packageName, nodeModulesDir);
343
+ return packageDir ? resolvePackageExportFromDir(packageDir, parsed.subpath) : null;
344
+ }
345
+ function canImportRigWorkspacePackagesDirectly(source, configDir) {
346
+ const packageNames = new Set;
347
+ for (const match of source.matchAll(/(?:from\s*|import\s*\(\s*|import\s*)["'](@rig\/[^"']+)["']/g)) {
348
+ const parsed = packageNameAndSubpath(match[1] ?? "");
349
+ if (parsed?.packageName)
350
+ packageNames.add(parsed.packageName);
351
+ }
352
+ if (packageNames.size === 0)
353
+ return false;
354
+ for (const packageName of packageNames) {
355
+ const shortName = packageName.replace(/^@rig\//, "");
356
+ const manifestPath = join2(configDir, "packages", shortName, "package.json");
357
+ if (!existsSync2(manifestPath))
358
+ return false;
359
+ try {
360
+ const parsed = JSON.parse(readFileSync2(manifestPath, "utf8"));
361
+ if (parsed.name !== packageName)
362
+ return false;
363
+ } catch {
364
+ return false;
365
+ }
366
+ }
367
+ return true;
368
+ }
369
+ async function importConfigViaRuntimeBundleUnserialized(configPath) {
370
+ const bun = globalThis.Bun;
371
+ if (!bun?.build) {
372
+ throw new Error(`Failed to import ${configPath}: bare imports could not be resolved and no Bun.build runtime bundler is available.`);
373
+ }
374
+ const RUNTIME_ONLY_EXTERNAL_PACKAGES = new Set(["effect", "mupdf", "fastembed", "onnxruntime-node", "markit-ai"]);
375
+ const configDir = dirname(configPath);
376
+ const configProjectRoot = basename(configDir) === ".rig" ? dirname(configDir) : configDir;
377
+ const UNRESOLVED_NAMESPACE = "rig-config-unresolved";
378
+ const ABSOLUTE_EXTERNAL_NAMESPACE = "rig-config-absolute-external";
379
+ const unresolvedLocalPlugin = {
380
+ name: "rig-config-unresolved-local",
381
+ setup(build) {
382
+ build.onLoad({ filter: /[\\/]@oh-my-pi[\\/]pi-coding-agent[\\/]src[\\/]export[\\/]html[\\/](?:template\.css|template\.html|template\.js|tool-views\.generated\.js)$/ }, (args) => ({
383
+ loader: "js",
384
+ contents: `export default ${JSON.stringify(readFileSync2(args.path, "utf8"))};
385
+ `
386
+ }));
387
+ build.onLoad({ filter: /\.(?:html|txt)$/ }, (args) => ({
388
+ loader: "js",
389
+ contents: `export default ${JSON.stringify(readFileSync2(args.path, "utf8"))};
390
+ `
391
+ }));
392
+ build.onResolve({ filter: /.*/ }, (args) => {
393
+ const directFilePath = resolvedFilePath(args.path, configDir);
394
+ if (directFilePath)
395
+ return { path: directFilePath };
396
+ if (args.path.startsWith("#")) {
397
+ const packagePrivatePath = resolvePackagePrivateImport(args.path, args.importer, configProjectRoot);
398
+ if (packagePrivatePath)
399
+ return { path: packagePrivatePath };
400
+ try {
401
+ const parent2 = args.importer && isAbsolute(args.importer) ? dirname(args.importer) : configProjectRoot;
402
+ const resolved = bun.resolveSync?.(args.path, parent2);
403
+ const filePath = resolvedFilePath(resolved, configProjectRoot);
404
+ if (filePath)
405
+ return { path: filePath };
406
+ } catch {}
407
+ return;
408
+ }
409
+ const packageImport = packageNameAndSubpath(args.path);
410
+ if (packageImport?.packageName === "uhyphen" && packageImport.subpath === ".") {
411
+ const uhyphenPath = resolveProjectPackageImport("uhyphen", configProjectRoot);
412
+ if (uhyphenPath)
413
+ return { path: uhyphenPath };
414
+ }
415
+ if (packageImport && packageImport.packageName !== "uhyphen") {
416
+ try {
417
+ const parent2 = args.importer && isAbsolute(args.importer) ? dirname(args.importer) : configProjectRoot;
418
+ const resolved = bun.resolveSync?.(args.path, parent2);
419
+ const filePath = resolvedFilePath(resolved, configProjectRoot);
420
+ if (filePath)
421
+ return { path: filePath };
422
+ } catch {}
423
+ }
424
+ const projectPackagePath = packageImport ? resolveProjectPackageImport(args.path, configProjectRoot) : null;
425
+ if (projectPackagePath)
426
+ return { path: projectPackagePath };
427
+ if (packageImport && (packageImport.packageName.startsWith("@rig/") || RUNTIME_ONLY_EXTERNAL_PACKAGES.has(packageImport.packageName))) {
428
+ return { path: args.path, external: true };
429
+ }
430
+ if (/^(?:node|bun):/.test(args.path) || isBuiltin(args.path))
431
+ return;
432
+ if (packageImport)
433
+ return { path: args.path, external: true };
434
+ const importerDir = args.importer && isAbsolute(args.importer) ? dirname(args.importer) : null;
435
+ if (args.path.startsWith(".") && importerDir) {
436
+ const fromImporter = resolveModulePath(resolve(importerDir, args.path));
437
+ if (fromImporter)
438
+ return { path: fromImporter };
439
+ if (/[\\/]node_modules[\\/]/.test(args.importer ?? ""))
440
+ return;
441
+ }
442
+ const parentCandidates = args.path.startsWith(".") ? [importerDir, configDir].filter((value) => Boolean(value)) : [importerDir ?? configDir];
443
+ for (const parent2 of parentCandidates) {
444
+ const filePath = resolvedFilePath(resolve(parent2, args.path), configProjectRoot);
445
+ if (filePath)
446
+ return { path: filePath };
447
+ }
448
+ const parent = parentCandidates[0] ?? configDir;
449
+ try {
450
+ const resolved = bun.resolveSync?.(args.path, parent) ?? resolve(parent, args.path);
451
+ const filePath = resolvedFilePath(resolved, configProjectRoot);
452
+ if (filePath)
453
+ return { path: filePath };
454
+ } catch {}
455
+ return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
456
+ });
457
+ build.onLoad({ filter: /.*/, namespace: ABSOLUTE_EXTERNAL_NAMESPACE }, (args) => {
458
+ const href = pathToFileURL(args.path).href;
459
+ return {
460
+ loader: "js",
461
+ contents: `export * from ${JSON.stringify(href)};
462
+ const mod = await import(${JSON.stringify(href)});
463
+ export default (mod && "default" in mod) ? mod.default : mod;
464
+ `
465
+ };
466
+ });
467
+ build.onLoad({ filter: /.*/, namespace: UNRESOLVED_NAMESPACE }, (args) => ({
468
+ loader: "js",
469
+ contents: `module.exports = {};
470
+ throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not resolve local import "${args.path}". Maybe you need to fix a relative import in rig.config.ts or install project deps.`)});
471
+ `
472
+ }));
473
+ }
474
+ };
475
+ const result = await bun.build({
476
+ entrypoints: [configPath],
477
+ target: "bun",
478
+ format: "esm",
479
+ throw: false,
480
+ packages: "bundle",
481
+ plugins: [unresolvedLocalPlugin]
482
+ });
483
+ if (!result.success || !result.outputs[0]) {
484
+ const detail = result.logs.map((log) => String(log)).join(`
485
+ `);
486
+ throw new Error(`Failed to bundle ${configPath}: ${detail || "unknown bundler error"}`);
487
+ }
488
+ const bundleParentDir = join2(configProjectRoot, ".rig", "tmp");
489
+ mkdirSync(bundleParentDir, { recursive: true });
490
+ const dir = mkdtempSync(join2(bundleParentDir, "rig-config-bundle-"));
491
+ try {
492
+ const bundledPath = join2(dir, "rig.config.bundled.js");
493
+ await bun.write(bundledPath, await result.outputs[0].text());
494
+ return await import(pathToFileURL(bundledPath).href);
495
+ } finally {
496
+ try {
497
+ rmSync(dir, { recursive: true, force: true });
498
+ } catch {}
499
+ }
500
+ }
10
501
  async function loadConfig(cwd) {
502
+ const baked = getEmbeddedProjectConfig();
503
+ if (baked && resolve(baked.projectRoot) === resolve(cwd)) {
504
+ return decodeExplicitPluginConfig(baked.raw);
505
+ }
11
506
  for (const name of TS_NAMES) {
12
- const p = join(cwd, name);
13
- if (existsSync(p)) {
14
- const mod = await import(pathToFileURL(p).href);
507
+ const p = join2(cwd, name);
508
+ if (existsSync2(p)) {
509
+ const mod = await enqueueRuntimeBundle(async () => {
510
+ if (runningFromCompiledBinary()) {
511
+ return importConfigViaRuntimeBundleUnserialized(p);
512
+ }
513
+ const source = readFileSync2(p, "utf8");
514
+ const importsRigHostPackages = /(?:import\s+[^;]*?from\s*|import\s*\()\s*["']@rig\//.test(source);
515
+ if (importsRigHostPackages && !canImportRigWorkspacePackagesDirectly(source, cwd)) {
516
+ return importConfigViaRuntimeBundleUnserialized(p);
517
+ }
518
+ try {
519
+ return await import(pathToFileURL(p).href);
520
+ } catch (error) {
521
+ if (!isModuleResolutionError(error))
522
+ throw error;
523
+ return importConfigViaRuntimeBundleUnserialized(p);
524
+ }
525
+ });
15
526
  const raw = mod.default ?? mod.config;
16
- return decodePreservingRuntime(raw);
527
+ return decodeExplicitPluginConfig(raw);
17
528
  }
18
529
  }
530
+ const declarativePath = findDeclarativeConfigPath(cwd);
531
+ if (declarativePath) {
532
+ return loadDeclarativeConfig(declarativePath);
533
+ }
19
534
  for (const name of JSON_NAMES) {
20
- const p = join(cwd, name);
21
- if (existsSync(p)) {
22
- const raw = JSON.parse(readFileSync(p, "utf-8"));
23
- return decodePreservingRuntime(raw);
535
+ const p = join2(cwd, name);
536
+ if (existsSync2(p)) {
537
+ const raw = JSON.parse(readFileSync2(p, "utf-8"));
538
+ return decodeExplicitPluginConfig(raw);
24
539
  }
25
540
  }
26
- throw new Error(`no rig.config.{ts,mts,json} found in ${cwd}`);
541
+ throw new Error(`no .rig/rig.config.{ts,mts,json} or .rig/rigfig.{toml,json} found in ${cwd}`);
27
542
  }
28
- function decodePreservingRuntime(raw) {
29
- const runtimeByName = new Map;
30
- const cfgIn = raw;
31
- if (Array.isArray(cfgIn?.plugins)) {
32
- for (const plugin of cfgIn.plugins) {
33
- if (plugin?.__runtime) {
34
- runtimeByName.set(plugin.name, plugin.__runtime);
35
- }
36
- }
37
- }
38
- const decoded = Schema.decodeUnknownSync(RigConfig)(raw);
39
- const plugins = decoded.plugins.map((p) => {
40
- const runtime = runtimeByName.get(p.name);
41
- if (!runtime)
42
- return p;
43
- return { ...p, __runtime: runtime };
543
+ function decodeExplicitPluginConfig(raw) {
544
+ const withDefaults = applyConfigDefaults(raw);
545
+ const explicitPlugins = Array.isArray(withDefaults.plugins) ? [...withDefaults.plugins] : [];
546
+ const decoded = Schema3.decodeUnknownSync(RigConfig3)({
547
+ ...withDefaults,
548
+ plugins: explicitPlugins
44
549
  });
45
- return { ...decoded, plugins };
550
+ return { ...decoded, plugins: explicitPlugins };
46
551
  }
47
552
  export {
48
553
  loadConfig
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Deprecated compatibility subpath. Placement behavior is owned by
3
+ * @rig/transport-plugin and exposed through PLACEMENT_SERVICE.
4
+ *
5
+ * Core intentionally does not implement read/list/select/add/remove placement
6
+ * state; callers should resolve the typed capability from their project plugin
7
+ * host. These stubs remain only to make accidental direct imports fail loudly.
8
+ */
9
+ export type PlacementKind = "local" | "remote";
10
+ export type Placement = {
11
+ readonly alias: string;
12
+ readonly kind: PlacementKind;
13
+ readonly host?: string | null;
14
+ readonly port?: number | null;
15
+ readonly baseUrl?: string | null;
16
+ readonly projectRoot?: string | null;
17
+ readonly status?: string | null;
18
+ readonly taskSource?: string | null;
19
+ };
20
+ export type RepoConnectionState = {
21
+ selected: string;
22
+ project?: string;
23
+ linkedAt?: string;
24
+ serverProjectRoot?: string;
25
+ serverProjectRootAlias?: string;
26
+ serverProjectRootBaseUrl?: string;
27
+ };
28
+ export type AddPlacementInput = {
29
+ readonly alias: string;
30
+ readonly host: string;
31
+ readonly port?: number;
32
+ readonly token?: string | null;
33
+ readonly select?: boolean;
34
+ };
35
+ export declare function resolveRepoConnectionPath(_projectRoot: string): string;
36
+ export declare function readSelection(_projectRoot: string): RepoConnectionState | null;
37
+ export declare const readRepoConnection: typeof readSelection;
38
+ export declare function writeSelection(_projectRoot: string, _state: RepoConnectionState): void;
39
+ export declare const writeRepoConnection: typeof writeSelection;
40
+ export declare function readPlacement(_projectRoot: string, _env?: NodeJS.ProcessEnv): Promise<Placement>;
41
+ export declare const readSelectedTarget: typeof readPlacement;
42
+ export declare function listPlacements(_projectRoot: string): Placement[];
43
+ export declare const listServerTargets: typeof listPlacements;
44
+ export declare function selectPlacement(_projectRoot: string, _alias: string, _options?: {
45
+ dryRun?: boolean;
46
+ }): Placement;
47
+ export declare const selectServerTarget: typeof selectPlacement;
48
+ export declare function addPlacement(_projectRoot: string, _input: AddPlacementInput, _options?: {
49
+ dryRun?: boolean;
50
+ }): Placement;
51
+ export declare const addRemoteTarget: typeof addPlacement;
52
+ export declare function removePlacement(_projectRoot: string, _alias: string, _options?: {
53
+ dryRun?: boolean;
54
+ }): {
55
+ readonly alias: string;
56
+ readonly removed: boolean;
57
+ };
58
+ export declare const removeServerTarget: typeof removePlacement;
@@ -0,0 +1,53 @@
1
+ // @bun
2
+ // packages/core/src/placement.ts
3
+ function placementServiceRequired() {
4
+ throw new Error("@rig/core/placement is deprecated. Resolve PLACEMENT_SERVICE from @rig/transport-plugin instead.");
5
+ }
6
+ function resolveRepoConnectionPath(_projectRoot) {
7
+ return placementServiceRequired();
8
+ }
9
+ function readSelection(_projectRoot) {
10
+ return placementServiceRequired();
11
+ }
12
+ var readRepoConnection = readSelection;
13
+ function writeSelection(_projectRoot, _state) {
14
+ placementServiceRequired();
15
+ }
16
+ var writeRepoConnection = writeSelection;
17
+ async function readPlacement(_projectRoot, _env = process.env) {
18
+ return placementServiceRequired();
19
+ }
20
+ var readSelectedTarget = readPlacement;
21
+ function listPlacements(_projectRoot) {
22
+ return placementServiceRequired();
23
+ }
24
+ var listServerTargets = listPlacements;
25
+ function selectPlacement(_projectRoot, _alias, _options = {}) {
26
+ return placementServiceRequired();
27
+ }
28
+ var selectServerTarget = selectPlacement;
29
+ function addPlacement(_projectRoot, _input, _options = {}) {
30
+ return placementServiceRequired();
31
+ }
32
+ var addRemoteTarget = addPlacement;
33
+ function removePlacement(_projectRoot, _alias, _options = {}) {
34
+ return placementServiceRequired();
35
+ }
36
+ var removeServerTarget = removePlacement;
37
+ export {
38
+ writeSelection,
39
+ writeRepoConnection,
40
+ selectServerTarget,
41
+ selectPlacement,
42
+ resolveRepoConnectionPath,
43
+ removeServerTarget,
44
+ removePlacement,
45
+ readSelection,
46
+ readSelectedTarget,
47
+ readRepoConnection,
48
+ readPlacement,
49
+ listServerTargets,
50
+ listPlacements,
51
+ addRemoteTarget,
52
+ addPlacement
53
+ };