@h-rig/core 0.0.6-alpha.6 → 0.0.6-alpha.60

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.
@@ -2,6 +2,16 @@
2
2
  // packages/core/src/define-config.ts
3
3
  import { Schema } from "effect";
4
4
  import { RigConfig } from "@rig/contracts";
5
+ function applyConfigDefaults(raw) {
6
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
7
+ return raw;
8
+ const record = raw;
9
+ return {
10
+ ...record,
11
+ plugins: Array.isArray(record.plugins) ? record.plugins : [],
12
+ workspace: record.workspace && typeof record.workspace === "object" && !Array.isArray(record.workspace) ? record.workspace : { mainRepo: ".", isolation: "worktree" }
13
+ };
14
+ }
5
15
  function defineConfig(cfg) {
6
16
  const runtimeByName = new Map;
7
17
  const plugins = cfg.plugins ?? [];
@@ -10,7 +20,7 @@ function defineConfig(cfg) {
10
20
  runtimeByName.set(plugin.name, plugin.__runtime);
11
21
  }
12
22
  }
13
- const decoded = Schema.decodeUnknownSync(RigConfig)(cfg);
23
+ const decoded = Schema.decodeUnknownSync(RigConfig)(applyConfigDefaults(cfg));
14
24
  const decodedPlugins = decoded.plugins.map((p) => {
15
25
  const runtime = runtimeByName.get(p.name);
16
26
  if (!runtime)
@@ -20,5 +30,6 @@ function defineConfig(cfg) {
20
30
  return { ...decoded, plugins: decodedPlugins };
21
31
  }
22
32
  export {
23
- defineConfig
33
+ defineConfig,
34
+ applyConfigDefaults
24
35
  };
package/dist/src/index.js CHANGED
@@ -48,6 +48,16 @@ function definePlugin(meta, runtime) {
48
48
  // packages/core/src/define-config.ts
49
49
  import { Schema as Schema2 } from "effect";
50
50
  import { RigConfig } from "@rig/contracts";
51
+ function applyConfigDefaults(raw) {
52
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
53
+ return raw;
54
+ const record = raw;
55
+ return {
56
+ ...record,
57
+ plugins: Array.isArray(record.plugins) ? record.plugins : [],
58
+ workspace: record.workspace && typeof record.workspace === "object" && !Array.isArray(record.workspace) ? record.workspace : { mainRepo: ".", isolation: "worktree" }
59
+ };
60
+ }
51
61
  function defineConfig(cfg) {
52
62
  const runtimeByName = new Map;
53
63
  const plugins = cfg.plugins ?? [];
@@ -56,7 +66,7 @@ function defineConfig(cfg) {
56
66
  runtimeByName.set(plugin.name, plugin.__runtime);
57
67
  }
58
68
  }
59
- const decoded = Schema2.decodeUnknownSync(RigConfig)(cfg);
69
+ const decoded = Schema2.decodeUnknownSync(RigConfig)(applyConfigDefaults(cfg));
60
70
  const decodedPlugins = decoded.plugins.map((p) => {
61
71
  const runtime = runtimeByName.get(p.name);
62
72
  if (!runtime)
@@ -263,7 +273,7 @@ function buildRigInitConfigSource(input) {
263
273
  lines.push(` issueUpdates: "lifecycle",`);
264
274
  lines.push(` projects: { enabled: false },`);
265
275
  lines.push(` },`);
266
- lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations: 30 },`);
276
+ lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations: 100500 },`);
267
277
  lines.push(` pr: { mode: "auto", watchChecks: true, autoFixChecks: true, autoFixReview: true },`);
268
278
  lines.push(` merge: { mode: "auto", method: "repo-default", deleteBranch: "repo-default", bypass: false },`);
269
279
  lines.push(` issueAnalysis: { enabled: true, harness: "pi", mode: "continuous" },`);
@@ -1,17 +1,108 @@
1
1
  // @bun
2
2
  // packages/core/src/load-config.ts
3
- import { existsSync, readFileSync } from "fs";
4
- import { join } from "path";
5
- import { pathToFileURL } from "url";
3
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "fs";
4
+ import { tmpdir } from "os";
5
+ import { dirname, join } from "path";
6
+ import { fileURLToPath, pathToFileURL } from "url";
7
+ import { Schema as Schema2 } from "effect";
8
+ import { RigConfig as RigConfig2 } from "@rig/contracts";
9
+
10
+ // packages/core/src/define-config.ts
6
11
  import { Schema } from "effect";
7
12
  import { RigConfig } from "@rig/contracts";
13
+ function applyConfigDefaults(raw) {
14
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
15
+ return raw;
16
+ const record = raw;
17
+ return {
18
+ ...record,
19
+ plugins: Array.isArray(record.plugins) ? record.plugins : [],
20
+ workspace: record.workspace && typeof record.workspace === "object" && !Array.isArray(record.workspace) ? record.workspace : { mainRepo: ".", isolation: "worktree" }
21
+ };
22
+ }
23
+
24
+ // packages/core/src/load-config.ts
8
25
  var TS_NAMES = ["rig.config.ts", "rig.config.mts"];
9
26
  var JSON_NAMES = ["rig.config.json"];
27
+ function isModuleResolutionError(error) {
28
+ const message = error instanceof Error ? error.message : String(error);
29
+ return message.includes("Cannot find module") || message.includes("Could not resolve");
30
+ }
31
+ function runningFromCompiledBinary() {
32
+ return import.meta.url.includes("$bunfs");
33
+ }
34
+ async function importConfigViaRuntimeBundle(configPath) {
35
+ const bun = globalThis.Bun;
36
+ if (!bun?.build) {
37
+ throw new Error(`Failed to import ${configPath}: bare imports could not be resolved and no Bun.build runtime bundler is available.`);
38
+ }
39
+ const hostDir = (() => {
40
+ try {
41
+ return dirname(fileURLToPath(import.meta.url));
42
+ } catch {
43
+ return process.cwd();
44
+ }
45
+ })();
46
+ const configDir = dirname(configPath);
47
+ const hostResolverPlugin = {
48
+ name: "rig-host-package-resolver",
49
+ setup(build) {
50
+ build.onResolve({ filter: /^@rig\// }, (args) => {
51
+ const candidates = [
52
+ [args.path, configDir],
53
+ [args.path, hostDir],
54
+ [args.path.replace(/^@rig\//, "@h-rig/"), hostDir]
55
+ ];
56
+ for (const [specifier, parent] of candidates) {
57
+ try {
58
+ const resolved = bun.resolveSync?.(specifier, parent);
59
+ if (resolved)
60
+ return { path: resolved };
61
+ } catch {}
62
+ }
63
+ return;
64
+ });
65
+ }
66
+ };
67
+ const result = await bun.build({
68
+ entrypoints: [configPath],
69
+ target: "bun",
70
+ format: "esm",
71
+ throw: false,
72
+ plugins: [hostResolverPlugin]
73
+ });
74
+ if (!result.success || !result.outputs[0]) {
75
+ const detail = result.logs.map((log) => String(log)).join(`
76
+ `);
77
+ throw new Error(`Failed to bundle ${configPath}: ${detail || "unknown bundler error"}`);
78
+ }
79
+ const dir = mkdtempSync(join(tmpdir(), "rig-config-bundle-"));
80
+ try {
81
+ const bundledPath = join(dir, "rig.config.bundled.js");
82
+ await bun.write(bundledPath, await result.outputs[0].text());
83
+ return await import(pathToFileURL(bundledPath).href);
84
+ } finally {
85
+ try {
86
+ rmSync(dir, { recursive: true, force: true });
87
+ } catch {}
88
+ }
89
+ }
10
90
  async function loadConfig(cwd) {
11
91
  for (const name of TS_NAMES) {
12
92
  const p = join(cwd, name);
13
93
  if (existsSync(p)) {
14
- const mod = await import(pathToFileURL(p).href);
94
+ let mod;
95
+ if (runningFromCompiledBinary()) {
96
+ mod = await importConfigViaRuntimeBundle(p);
97
+ } else {
98
+ try {
99
+ mod = await import(pathToFileURL(p).href);
100
+ } catch (error) {
101
+ if (!isModuleResolutionError(error))
102
+ throw error;
103
+ mod = await importConfigViaRuntimeBundle(p);
104
+ }
105
+ }
15
106
  const raw = mod.default ?? mod.config;
16
107
  return decodePreservingRuntime(raw);
17
108
  }
@@ -35,7 +126,7 @@ function decodePreservingRuntime(raw) {
35
126
  }
36
127
  }
37
128
  }
38
- const decoded = Schema.decodeUnknownSync(RigConfig)(raw);
129
+ const decoded = Schema2.decodeUnknownSync(RigConfig2)(applyConfigDefaults(raw));
39
130
  const plugins = decoded.plugins.map((p) => {
40
131
  const runtime = runtimeByName.get(p.name);
41
132
  if (!runtime)
@@ -43,7 +43,7 @@ function buildRigInitConfigSource(input) {
43
43
  lines.push(` issueUpdates: "lifecycle",`);
44
44
  lines.push(` projects: { enabled: false },`);
45
45
  lines.push(` },`);
46
- lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations: 30 },`);
46
+ lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations: 100500 },`);
47
47
  lines.push(` pr: { mode: "auto", watchChecks: true, autoFixChecks: true, autoFixReview: true },`);
48
48
  lines.push(` merge: { mode: "auto", method: "repo-default", deleteBranch: "repo-default", bypass: false },`);
49
49
  lines.push(` issueAnalysis: { enabled: true, harness: "pi", mode: "continuous" },`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/core",
3
- "version": "0.0.6-alpha.6",
3
+ "version": "0.0.6-alpha.60",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",
@@ -31,7 +31,7 @@
31
31
  "main": "./dist/src/index.js",
32
32
  "module": "./dist/src/index.js",
33
33
  "dependencies": {
34
- "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.6",
34
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.60",
35
35
  "effect": "4.0.0-beta.78"
36
36
  }
37
37
  }