@h-rig/runtime 0.0.6-alpha.0 → 0.0.6-alpha.10

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 (42) hide show
  1. package/dist/bin/rig-agent-dispatch.js +133 -14
  2. package/dist/bin/rig-agent.js +83 -26
  3. package/dist/src/control-plane/agent-wrapper.js +133 -14
  4. package/dist/src/control-plane/harness-main.js +83 -26
  5. package/dist/src/control-plane/hooks/completion-verification.js +85 -28
  6. package/dist/src/control-plane/hooks/inject-context.js +2 -2
  7. package/dist/src/control-plane/hooks/submodule-branch.js +26 -3
  8. package/dist/src/control-plane/hooks/task-runtime-start.js +26 -3
  9. package/dist/src/control-plane/native/git-ops.js +81 -24
  10. package/dist/src/control-plane/native/harness-cli.js +83 -26
  11. package/dist/src/control-plane/native/pr-automation.js +88 -17
  12. package/dist/src/control-plane/native/run-ops.js +23 -6
  13. package/dist/src/control-plane/native/task-ops.js +2 -2
  14. package/dist/src/control-plane/native/validator.js +2 -2
  15. package/dist/src/control-plane/native/verifier.js +2 -2
  16. package/dist/src/control-plane/runtime/index.js +38 -9
  17. package/dist/src/control-plane/runtime/isolation/home.js +31 -6
  18. package/dist/src/control-plane/runtime/isolation/index.js +38 -9
  19. package/dist/src/control-plane/runtime/isolation/runner.js +31 -6
  20. package/dist/src/control-plane/runtime/isolation/shared.js +9 -6
  21. package/dist/src/control-plane/runtime/isolation.js +38 -9
  22. package/dist/src/control-plane/runtime/queue.js +38 -9
  23. package/dist/src/control-plane/tasks/source-aware-task-config-source.js +14 -2
  24. package/dist/src/control-plane/tasks/source-lifecycle.js +2 -2
  25. package/dist/src/index.js +15 -13
  26. package/dist/src/local-server.js +20 -14
  27. package/native/darwin-arm64/{bin/rig-git → rig-git} +0 -0
  28. package/native/darwin-arm64/rig-git.build-manifest.json +4 -0
  29. package/native/darwin-arm64/{bin/rig-shell → rig-shell} +0 -0
  30. package/native/darwin-arm64/rig-shell.build-manifest.json +4 -0
  31. package/native/darwin-arm64/{bin/rig-tools → rig-tools} +0 -0
  32. package/native/darwin-arm64/rig-tools.build-manifest.json +4 -0
  33. package/native/darwin-arm64/{lib/runtime-native.dylib → runtime-native.dylib} +0 -0
  34. package/package.json +8 -7
  35. package/native/darwin-arm64/lib/runtime-native-darwin-arm64.dylib +0 -0
  36. package/native/darwin-arm64/manifest.json +0 -1
  37. package/native/linux-x64/bin/rig-git +0 -0
  38. package/native/linux-x64/bin/rig-shell +0 -0
  39. package/native/linux-x64/bin/rig-tools +0 -0
  40. package/native/linux-x64/lib/runtime-native-linux-x64.so +0 -0
  41. package/native/linux-x64/lib/runtime-native.so +0 -0
  42. package/native/linux-x64/manifest.json +0 -1
@@ -3148,8 +3148,8 @@ function githubStatusFor(issue) {
3148
3148
  return "open";
3149
3149
  }
3150
3150
  function selectedGitHubEnv() {
3151
- const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() ?? "";
3152
- return { GH_TOKEN: token, GITHUB_TOKEN: token };
3151
+ const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() || process.env.RIG_GITHUB_TOKEN?.trim() || "";
3152
+ return { GH_TOKEN: token, GITHUB_TOKEN: token, RIG_GITHUB_TOKEN: token };
3153
3153
  }
3154
3154
  function ghSpawnOptions() {
3155
3155
  return { encoding: "utf-8", env: { ...process.env, ...selectedGitHubEnv() } };
@@ -5454,20 +5454,23 @@ function hashProjectPath(workspaceDir) {
5454
5454
  }
5455
5455
  function resolveGithubCliBinaryPath() {
5456
5456
  const explicit = process.env.RIG_GH_BIN?.trim();
5457
- if (explicit && existsSync23(explicit)) {
5457
+ if (explicit && existsSync23(explicit) && !isRuntimeGatewayGhPath(explicit)) {
5458
5458
  return explicit;
5459
5459
  }
5460
- const bunResolved = Bun.which("gh");
5461
- if (bunResolved && existsSync23(bunResolved)) {
5462
- return bunResolved;
5463
- }
5464
- for (const candidate of ["/opt/homebrew/bin/gh", "/usr/local/bin/gh", "/usr/bin/gh"]) {
5460
+ for (const candidate of ["/usr/bin/gh", "/opt/homebrew/bin/gh", "/usr/local/bin/gh"]) {
5465
5461
  if (existsSync23(candidate)) {
5466
5462
  return candidate;
5467
5463
  }
5468
5464
  }
5465
+ const bunResolved = Bun.which("gh");
5466
+ if (bunResolved && existsSync23(bunResolved) && !isRuntimeGatewayGhPath(bunResolved)) {
5467
+ return bunResolved;
5468
+ }
5469
5469
  return "";
5470
5470
  }
5471
+ function isRuntimeGatewayGhPath(candidate) {
5472
+ return /\/\.rig\/bin\/gh$/.test(candidate.replace(/\\/g, "/"));
5473
+ }
5471
5474
  async function resolveGithubCliAuthToken(ghBinary = "") {
5472
5475
  const gh = ghBinary || resolveGithubCliBinaryPath();
5473
5476
  if (!gh) {
@@ -5568,6 +5571,8 @@ async function runtimeEnv(projectRoot, runtime) {
5568
5571
  XDG_CACHE_HOME: runtime.cacheDir,
5569
5572
  XDG_STATE_HOME: runtime.stateDir,
5570
5573
  RIG_AGENT_ID: runtime.id,
5574
+ ...process.env.RIG_RUN_ID?.trim() ? { RIG_RUN_ID: process.env.RIG_RUN_ID.trim() } : {},
5575
+ ...process.env.RIG_SERVER_RUN_ID?.trim() ? { RIG_SERVER_RUN_ID: process.env.RIG_SERVER_RUN_ID.trim() } : {},
5571
5576
  RIG_TASK_ID: runtime.taskId,
5572
5577
  RIG_TASK_RUNTIME_ID: runtime.id,
5573
5578
  RIG_TASK_WORKSPACE: runtime.workspaceDir,
@@ -5631,6 +5636,10 @@ async function runtimeEnv(projectRoot, runtime) {
5631
5636
  env[key] = value;
5632
5637
  }
5633
5638
  }
5639
+ const rigGithubToken = process.env.RIG_GITHUB_TOKEN?.trim() || "";
5640
+ if (rigGithubToken && !env.GITHUB_TOKEN && !env.GH_TOKEN) {
5641
+ env.GITHUB_TOKEN = rigGithubToken;
5642
+ }
5634
5643
  const fallbackGithubToken = !env.GITHUB_TOKEN && !env.GH_TOKEN ? await resolveGithubCliAuthToken(hostGhBinary) : "";
5635
5644
  if (fallbackGithubToken) {
5636
5645
  env.GITHUB_TOKEN = fallbackGithubToken;
@@ -5641,6 +5650,13 @@ async function runtimeEnv(projectRoot, runtime) {
5641
5650
  if (!env.GH_TOKEN && env.GITHUB_TOKEN) {
5642
5651
  env.GH_TOKEN = env.GITHUB_TOKEN;
5643
5652
  }
5653
+ const gitHubToken = env.GITHUB_TOKEN || env.GH_TOKEN || rigGithubToken;
5654
+ if (gitHubToken) {
5655
+ env.RIG_GITHUB_TOKEN = gitHubToken;
5656
+ env.GITHUB_TOKEN = env.GITHUB_TOKEN || gitHubToken;
5657
+ env.GH_TOKEN = env.GH_TOKEN || gitHubToken;
5658
+ applyGitHubCredentialHelperEnv(env);
5659
+ }
5644
5660
  if (!env.GREPTILE_GITHUB_TOKEN && env.GITHUB_TOKEN) {
5645
5661
  env.GREPTILE_GITHUB_TOKEN = env.GITHUB_TOKEN;
5646
5662
  }
@@ -5736,12 +5752,21 @@ async function materializeRuntimeCertBundle(runtime) {
5736
5752
  }
5737
5753
  return targetPath;
5738
5754
  }
5755
+ function applyGitHubCredentialHelperEnv(env) {
5756
+ env.GIT_TERMINAL_PROMPT = "0";
5757
+ env.GIT_CONFIG_COUNT = "2";
5758
+ env.GIT_CONFIG_KEY_0 = "credential.helper";
5759
+ env.GIT_CONFIG_VALUE_0 = "";
5760
+ env.GIT_CONFIG_KEY_1 = "credential.helper";
5761
+ env.GIT_CONFIG_VALUE_1 = '!f() { test "$1" = get || exit 0; token="${GITHUB_TOKEN:-${GH_TOKEN:-${RIG_GITHUB_TOKEN:-}}}"; test -n "$token" || exit 0; echo username=x-access-token; echo password="$token"; }; f';
5762
+ }
5739
5763
  function persistRuntimeSecrets(runtimeRoot, env) {
5740
5764
  const secretsPath = resolve25(runtimeRoot, "runtime-secrets.json");
5741
5765
  const persisted = {};
5742
5766
  for (const key of [
5743
5767
  "GITHUB_TOKEN",
5744
5768
  "GH_TOKEN",
5769
+ "RIG_GITHUB_TOKEN",
5745
5770
  "GREPTILE_GITHUB_TOKEN",
5746
5771
  "GREPTILE_API_KEY",
5747
5772
  "AI_REVIEW_MODE",
@@ -8060,7 +8085,11 @@ async function ensureAgentRuntime(options) {
8060
8085
  mkdirSync18(runtime.binDir, { recursive: true });
8061
8086
  mkdirSync18(workspaceLayout.distDir, { recursive: true });
8062
8087
  prepareRuntimeWorkspace(options.projectRoot, workspaceDir);
8063
- await resetEphemeralTaskArtifacts(workspaceDir, options.taskId);
8088
+ if (options.preserveTaskArtifacts) {
8089
+ console.log(`[rig-agent] Preserving runtime task artifacts for resume of ${options.taskId}.`);
8090
+ } else {
8091
+ await resetEphemeralTaskArtifacts(workspaceDir, options.taskId);
8092
+ }
8064
8093
  const ctx = {
8065
8094
  runtimeId: options.id,
8066
8095
  taskId: options.taskId,
@@ -2091,20 +2091,23 @@ function taskRuntimeId(taskId) {
2091
2091
  }
2092
2092
  function resolveGithubCliBinaryPath() {
2093
2093
  const explicit = process.env.RIG_GH_BIN?.trim();
2094
- if (explicit && existsSync8(explicit)) {
2094
+ if (explicit && existsSync8(explicit) && !isRuntimeGatewayGhPath(explicit)) {
2095
2095
  return explicit;
2096
2096
  }
2097
- const bunResolved = Bun.which("gh");
2098
- if (bunResolved && existsSync8(bunResolved)) {
2099
- return bunResolved;
2100
- }
2101
- for (const candidate of ["/opt/homebrew/bin/gh", "/usr/local/bin/gh", "/usr/bin/gh"]) {
2097
+ for (const candidate of ["/usr/bin/gh", "/opt/homebrew/bin/gh", "/usr/local/bin/gh"]) {
2102
2098
  if (existsSync8(candidate)) {
2103
2099
  return candidate;
2104
2100
  }
2105
2101
  }
2102
+ const bunResolved = Bun.which("gh");
2103
+ if (bunResolved && existsSync8(bunResolved) && !isRuntimeGatewayGhPath(bunResolved)) {
2104
+ return bunResolved;
2105
+ }
2106
2106
  return "";
2107
2107
  }
2108
+ function isRuntimeGatewayGhPath(candidate) {
2109
+ return /\/\.rig\/bin\/gh$/.test(candidate.replace(/\\/g, "/"));
2110
+ }
2108
2111
  async function resolveGithubCliAuthToken(ghBinary = "") {
2109
2112
  const gh = ghBinary || resolveGithubCliBinaryPath();
2110
2113
  if (!gh) {
@@ -2198,6 +2201,8 @@ async function runtimeEnv(projectRoot, runtime) {
2198
2201
  XDG_CACHE_HOME: runtime.cacheDir,
2199
2202
  XDG_STATE_HOME: runtime.stateDir,
2200
2203
  RIG_AGENT_ID: runtime.id,
2204
+ ...process.env.RIG_RUN_ID?.trim() ? { RIG_RUN_ID: process.env.RIG_RUN_ID.trim() } : {},
2205
+ ...process.env.RIG_SERVER_RUN_ID?.trim() ? { RIG_SERVER_RUN_ID: process.env.RIG_SERVER_RUN_ID.trim() } : {},
2201
2206
  RIG_TASK_ID: runtime.taskId,
2202
2207
  RIG_TASK_RUNTIME_ID: runtime.id,
2203
2208
  RIG_TASK_WORKSPACE: runtime.workspaceDir,
@@ -2261,6 +2266,10 @@ async function runtimeEnv(projectRoot, runtime) {
2261
2266
  env[key] = value;
2262
2267
  }
2263
2268
  }
2269
+ const rigGithubToken = process.env.RIG_GITHUB_TOKEN?.trim() || "";
2270
+ if (rigGithubToken && !env.GITHUB_TOKEN && !env.GH_TOKEN) {
2271
+ env.GITHUB_TOKEN = rigGithubToken;
2272
+ }
2264
2273
  const fallbackGithubToken = !env.GITHUB_TOKEN && !env.GH_TOKEN ? await resolveGithubCliAuthToken(hostGhBinary) : "";
2265
2274
  if (fallbackGithubToken) {
2266
2275
  env.GITHUB_TOKEN = fallbackGithubToken;
@@ -2271,6 +2280,13 @@ async function runtimeEnv(projectRoot, runtime) {
2271
2280
  if (!env.GH_TOKEN && env.GITHUB_TOKEN) {
2272
2281
  env.GH_TOKEN = env.GITHUB_TOKEN;
2273
2282
  }
2283
+ const gitHubToken = env.GITHUB_TOKEN || env.GH_TOKEN || rigGithubToken;
2284
+ if (gitHubToken) {
2285
+ env.RIG_GITHUB_TOKEN = gitHubToken;
2286
+ env.GITHUB_TOKEN = env.GITHUB_TOKEN || gitHubToken;
2287
+ env.GH_TOKEN = env.GH_TOKEN || gitHubToken;
2288
+ applyGitHubCredentialHelperEnv(env);
2289
+ }
2274
2290
  if (!env.GREPTILE_GITHUB_TOKEN && env.GITHUB_TOKEN) {
2275
2291
  env.GREPTILE_GITHUB_TOKEN = env.GITHUB_TOKEN;
2276
2292
  }
@@ -2318,12 +2334,21 @@ async function materializeRuntimeCertBundle(runtime) {
2318
2334
  }
2319
2335
  return targetPath;
2320
2336
  }
2337
+ function applyGitHubCredentialHelperEnv(env) {
2338
+ env.GIT_TERMINAL_PROMPT = "0";
2339
+ env.GIT_CONFIG_COUNT = "2";
2340
+ env.GIT_CONFIG_KEY_0 = "credential.helper";
2341
+ env.GIT_CONFIG_VALUE_0 = "";
2342
+ env.GIT_CONFIG_KEY_1 = "credential.helper";
2343
+ env.GIT_CONFIG_VALUE_1 = '!f() { test "$1" = get || exit 0; token="${GITHUB_TOKEN:-${GH_TOKEN:-${RIG_GITHUB_TOKEN:-}}}"; test -n "$token" || exit 0; echo username=x-access-token; echo password="$token"; }; f';
2344
+ }
2321
2345
  function persistRuntimeSecrets(runtimeRoot, env) {
2322
2346
  const secretsPath = resolve11(runtimeRoot, "runtime-secrets.json");
2323
2347
  const persisted = {};
2324
2348
  for (const key of [
2325
2349
  "GITHUB_TOKEN",
2326
2350
  "GH_TOKEN",
2351
+ "RIG_GITHUB_TOKEN",
2327
2352
  "GREPTILE_GITHUB_TOKEN",
2328
2353
  "GREPTILE_API_KEY",
2329
2354
  "AI_REVIEW_MODE",
@@ -417,20 +417,23 @@ function hashProjectPath(workspaceDir) {
417
417
  }
418
418
  function resolveGithubCliBinaryPath() {
419
419
  const explicit = process.env.RIG_GH_BIN?.trim();
420
- if (explicit && existsSync3(explicit)) {
420
+ if (explicit && existsSync3(explicit) && !isRuntimeGatewayGhPath(explicit)) {
421
421
  return explicit;
422
422
  }
423
- const bunResolved = Bun.which("gh");
424
- if (bunResolved && existsSync3(bunResolved)) {
425
- return bunResolved;
426
- }
427
- for (const candidate of ["/opt/homebrew/bin/gh", "/usr/local/bin/gh", "/usr/bin/gh"]) {
423
+ for (const candidate of ["/usr/bin/gh", "/opt/homebrew/bin/gh", "/usr/local/bin/gh"]) {
428
424
  if (existsSync3(candidate)) {
429
425
  return candidate;
430
426
  }
431
427
  }
428
+ const bunResolved = Bun.which("gh");
429
+ if (bunResolved && existsSync3(bunResolved) && !isRuntimeGatewayGhPath(bunResolved)) {
430
+ return bunResolved;
431
+ }
432
432
  return "";
433
433
  }
434
+ function isRuntimeGatewayGhPath(candidate) {
435
+ return /\/\.rig\/bin\/gh$/.test(candidate.replace(/\\/g, "/"));
436
+ }
434
437
  async function resolveGithubCliAuthToken(ghBinary = "") {
435
438
  const gh = ghBinary || resolveGithubCliBinaryPath();
436
439
  if (!gh) {
@@ -3148,8 +3148,8 @@ function githubStatusFor(issue) {
3148
3148
  return "open";
3149
3149
  }
3150
3150
  function selectedGitHubEnv() {
3151
- const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() ?? "";
3152
- return { GH_TOKEN: token, GITHUB_TOKEN: token };
3151
+ const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() || process.env.RIG_GITHUB_TOKEN?.trim() || "";
3152
+ return { GH_TOKEN: token, GITHUB_TOKEN: token, RIG_GITHUB_TOKEN: token };
3153
3153
  }
3154
3154
  function ghSpawnOptions() {
3155
3155
  return { encoding: "utf-8", env: { ...process.env, ...selectedGitHubEnv() } };
@@ -5454,20 +5454,23 @@ function hashProjectPath(workspaceDir) {
5454
5454
  }
5455
5455
  function resolveGithubCliBinaryPath() {
5456
5456
  const explicit = process.env.RIG_GH_BIN?.trim();
5457
- if (explicit && existsSync23(explicit)) {
5457
+ if (explicit && existsSync23(explicit) && !isRuntimeGatewayGhPath(explicit)) {
5458
5458
  return explicit;
5459
5459
  }
5460
- const bunResolved = Bun.which("gh");
5461
- if (bunResolved && existsSync23(bunResolved)) {
5462
- return bunResolved;
5463
- }
5464
- for (const candidate of ["/opt/homebrew/bin/gh", "/usr/local/bin/gh", "/usr/bin/gh"]) {
5460
+ for (const candidate of ["/usr/bin/gh", "/opt/homebrew/bin/gh", "/usr/local/bin/gh"]) {
5465
5461
  if (existsSync23(candidate)) {
5466
5462
  return candidate;
5467
5463
  }
5468
5464
  }
5465
+ const bunResolved = Bun.which("gh");
5466
+ if (bunResolved && existsSync23(bunResolved) && !isRuntimeGatewayGhPath(bunResolved)) {
5467
+ return bunResolved;
5468
+ }
5469
5469
  return "";
5470
5470
  }
5471
+ function isRuntimeGatewayGhPath(candidate) {
5472
+ return /\/\.rig\/bin\/gh$/.test(candidate.replace(/\\/g, "/"));
5473
+ }
5471
5474
  async function resolveGithubCliAuthToken(ghBinary = "") {
5472
5475
  const gh = ghBinary || resolveGithubCliBinaryPath();
5473
5476
  if (!gh) {
@@ -5568,6 +5571,8 @@ async function runtimeEnv(projectRoot, runtime) {
5568
5571
  XDG_CACHE_HOME: runtime.cacheDir,
5569
5572
  XDG_STATE_HOME: runtime.stateDir,
5570
5573
  RIG_AGENT_ID: runtime.id,
5574
+ ...process.env.RIG_RUN_ID?.trim() ? { RIG_RUN_ID: process.env.RIG_RUN_ID.trim() } : {},
5575
+ ...process.env.RIG_SERVER_RUN_ID?.trim() ? { RIG_SERVER_RUN_ID: process.env.RIG_SERVER_RUN_ID.trim() } : {},
5571
5576
  RIG_TASK_ID: runtime.taskId,
5572
5577
  RIG_TASK_RUNTIME_ID: runtime.id,
5573
5578
  RIG_TASK_WORKSPACE: runtime.workspaceDir,
@@ -5631,6 +5636,10 @@ async function runtimeEnv(projectRoot, runtime) {
5631
5636
  env[key] = value;
5632
5637
  }
5633
5638
  }
5639
+ const rigGithubToken = process.env.RIG_GITHUB_TOKEN?.trim() || "";
5640
+ if (rigGithubToken && !env.GITHUB_TOKEN && !env.GH_TOKEN) {
5641
+ env.GITHUB_TOKEN = rigGithubToken;
5642
+ }
5634
5643
  const fallbackGithubToken = !env.GITHUB_TOKEN && !env.GH_TOKEN ? await resolveGithubCliAuthToken(hostGhBinary) : "";
5635
5644
  if (fallbackGithubToken) {
5636
5645
  env.GITHUB_TOKEN = fallbackGithubToken;
@@ -5641,6 +5650,13 @@ async function runtimeEnv(projectRoot, runtime) {
5641
5650
  if (!env.GH_TOKEN && env.GITHUB_TOKEN) {
5642
5651
  env.GH_TOKEN = env.GITHUB_TOKEN;
5643
5652
  }
5653
+ const gitHubToken = env.GITHUB_TOKEN || env.GH_TOKEN || rigGithubToken;
5654
+ if (gitHubToken) {
5655
+ env.RIG_GITHUB_TOKEN = gitHubToken;
5656
+ env.GITHUB_TOKEN = env.GITHUB_TOKEN || gitHubToken;
5657
+ env.GH_TOKEN = env.GH_TOKEN || gitHubToken;
5658
+ applyGitHubCredentialHelperEnv(env);
5659
+ }
5644
5660
  if (!env.GREPTILE_GITHUB_TOKEN && env.GITHUB_TOKEN) {
5645
5661
  env.GREPTILE_GITHUB_TOKEN = env.GITHUB_TOKEN;
5646
5662
  }
@@ -5736,12 +5752,21 @@ async function materializeRuntimeCertBundle(runtime) {
5736
5752
  }
5737
5753
  return targetPath;
5738
5754
  }
5755
+ function applyGitHubCredentialHelperEnv(env) {
5756
+ env.GIT_TERMINAL_PROMPT = "0";
5757
+ env.GIT_CONFIG_COUNT = "2";
5758
+ env.GIT_CONFIG_KEY_0 = "credential.helper";
5759
+ env.GIT_CONFIG_VALUE_0 = "";
5760
+ env.GIT_CONFIG_KEY_1 = "credential.helper";
5761
+ env.GIT_CONFIG_VALUE_1 = '!f() { test "$1" = get || exit 0; token="${GITHUB_TOKEN:-${GH_TOKEN:-${RIG_GITHUB_TOKEN:-}}}"; test -n "$token" || exit 0; echo username=x-access-token; echo password="$token"; }; f';
5762
+ }
5739
5763
  function persistRuntimeSecrets(runtimeRoot, env) {
5740
5764
  const secretsPath = resolve25(runtimeRoot, "runtime-secrets.json");
5741
5765
  const persisted = {};
5742
5766
  for (const key of [
5743
5767
  "GITHUB_TOKEN",
5744
5768
  "GH_TOKEN",
5769
+ "RIG_GITHUB_TOKEN",
5745
5770
  "GREPTILE_GITHUB_TOKEN",
5746
5771
  "GREPTILE_API_KEY",
5747
5772
  "AI_REVIEW_MODE",
@@ -8060,7 +8085,11 @@ async function ensureAgentRuntime(options) {
8060
8085
  mkdirSync18(runtime.binDir, { recursive: true });
8061
8086
  mkdirSync18(workspaceLayout.distDir, { recursive: true });
8062
8087
  prepareRuntimeWorkspace(options.projectRoot, workspaceDir);
8063
- await resetEphemeralTaskArtifacts(workspaceDir, options.taskId);
8088
+ if (options.preserveTaskArtifacts) {
8089
+ console.log(`[rig-agent] Preserving runtime task artifacts for resume of ${options.taskId}.`);
8090
+ } else {
8091
+ await resetEphemeralTaskArtifacts(workspaceDir, options.taskId);
8092
+ }
8064
8093
  const ctx = {
8065
8094
  runtimeId: options.id,
8066
8095
  taskId: options.taskId,
@@ -4560,8 +4560,8 @@ function githubStatusFor(issue) {
4560
4560
  return "open";
4561
4561
  }
4562
4562
  function selectedGitHubEnv() {
4563
- const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() ?? "";
4564
- return { GH_TOKEN: token, GITHUB_TOKEN: token };
4563
+ const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() || process.env.RIG_GITHUB_TOKEN?.trim() || "";
4564
+ return { GH_TOKEN: token, GITHUB_TOKEN: token, RIG_GITHUB_TOKEN: token };
4565
4565
  }
4566
4566
  function ghSpawnOptions() {
4567
4567
  return { encoding: "utf-8", env: { ...process.env, ...selectedGitHubEnv() } };
@@ -6178,20 +6178,23 @@ function hashProjectPath(workspaceDir) {
6178
6178
  }
6179
6179
  function resolveGithubCliBinaryPath() {
6180
6180
  const explicit = process.env.RIG_GH_BIN?.trim();
6181
- if (explicit && existsSync24(explicit)) {
6181
+ if (explicit && existsSync24(explicit) && !isRuntimeGatewayGhPath(explicit)) {
6182
6182
  return explicit;
6183
6183
  }
6184
- const bunResolved = Bun.which("gh");
6185
- if (bunResolved && existsSync24(bunResolved)) {
6186
- return bunResolved;
6187
- }
6188
- for (const candidate of ["/opt/homebrew/bin/gh", "/usr/local/bin/gh", "/usr/bin/gh"]) {
6184
+ for (const candidate of ["/usr/bin/gh", "/opt/homebrew/bin/gh", "/usr/local/bin/gh"]) {
6189
6185
  if (existsSync24(candidate)) {
6190
6186
  return candidate;
6191
6187
  }
6192
6188
  }
6189
+ const bunResolved = Bun.which("gh");
6190
+ if (bunResolved && existsSync24(bunResolved) && !isRuntimeGatewayGhPath(bunResolved)) {
6191
+ return bunResolved;
6192
+ }
6193
6193
  return "";
6194
6194
  }
6195
+ function isRuntimeGatewayGhPath(candidate) {
6196
+ return /\/\.rig\/bin\/gh$/.test(candidate.replace(/\\/g, "/"));
6197
+ }
6195
6198
  async function resolveGithubCliAuthToken(ghBinary = "") {
6196
6199
  const gh = ghBinary || resolveGithubCliBinaryPath();
6197
6200
  if (!gh) {
@@ -6292,6 +6295,8 @@ async function runtimeEnv(projectRoot, runtime) {
6292
6295
  XDG_CACHE_HOME: runtime.cacheDir,
6293
6296
  XDG_STATE_HOME: runtime.stateDir,
6294
6297
  RIG_AGENT_ID: runtime.id,
6298
+ ...process.env.RIG_RUN_ID?.trim() ? { RIG_RUN_ID: process.env.RIG_RUN_ID.trim() } : {},
6299
+ ...process.env.RIG_SERVER_RUN_ID?.trim() ? { RIG_SERVER_RUN_ID: process.env.RIG_SERVER_RUN_ID.trim() } : {},
6295
6300
  RIG_TASK_ID: runtime.taskId,
6296
6301
  RIG_TASK_RUNTIME_ID: runtime.id,
6297
6302
  RIG_TASK_WORKSPACE: runtime.workspaceDir,
@@ -6355,6 +6360,10 @@ async function runtimeEnv(projectRoot, runtime) {
6355
6360
  env[key] = value;
6356
6361
  }
6357
6362
  }
6363
+ const rigGithubToken = process.env.RIG_GITHUB_TOKEN?.trim() || "";
6364
+ if (rigGithubToken && !env.GITHUB_TOKEN && !env.GH_TOKEN) {
6365
+ env.GITHUB_TOKEN = rigGithubToken;
6366
+ }
6358
6367
  const fallbackGithubToken = !env.GITHUB_TOKEN && !env.GH_TOKEN ? await resolveGithubCliAuthToken(hostGhBinary) : "";
6359
6368
  if (fallbackGithubToken) {
6360
6369
  env.GITHUB_TOKEN = fallbackGithubToken;
@@ -6365,6 +6374,13 @@ async function runtimeEnv(projectRoot, runtime) {
6365
6374
  if (!env.GH_TOKEN && env.GITHUB_TOKEN) {
6366
6375
  env.GH_TOKEN = env.GITHUB_TOKEN;
6367
6376
  }
6377
+ const gitHubToken = env.GITHUB_TOKEN || env.GH_TOKEN || rigGithubToken;
6378
+ if (gitHubToken) {
6379
+ env.RIG_GITHUB_TOKEN = gitHubToken;
6380
+ env.GITHUB_TOKEN = env.GITHUB_TOKEN || gitHubToken;
6381
+ env.GH_TOKEN = env.GH_TOKEN || gitHubToken;
6382
+ applyGitHubCredentialHelperEnv(env);
6383
+ }
6368
6384
  if (!env.GREPTILE_GITHUB_TOKEN && env.GITHUB_TOKEN) {
6369
6385
  env.GREPTILE_GITHUB_TOKEN = env.GITHUB_TOKEN;
6370
6386
  }
@@ -6460,12 +6476,21 @@ async function materializeRuntimeCertBundle(runtime) {
6460
6476
  }
6461
6477
  return targetPath;
6462
6478
  }
6479
+ function applyGitHubCredentialHelperEnv(env) {
6480
+ env.GIT_TERMINAL_PROMPT = "0";
6481
+ env.GIT_CONFIG_COUNT = "2";
6482
+ env.GIT_CONFIG_KEY_0 = "credential.helper";
6483
+ env.GIT_CONFIG_VALUE_0 = "";
6484
+ env.GIT_CONFIG_KEY_1 = "credential.helper";
6485
+ env.GIT_CONFIG_VALUE_1 = '!f() { test "$1" = get || exit 0; token="${GITHUB_TOKEN:-${GH_TOKEN:-${RIG_GITHUB_TOKEN:-}}}"; test -n "$token" || exit 0; echo username=x-access-token; echo password="$token"; }; f';
6486
+ }
6463
6487
  function persistRuntimeSecrets(runtimeRoot, env) {
6464
6488
  const secretsPath = resolve27(runtimeRoot, "runtime-secrets.json");
6465
6489
  const persisted = {};
6466
6490
  for (const key of [
6467
6491
  "GITHUB_TOKEN",
6468
6492
  "GH_TOKEN",
6493
+ "RIG_GITHUB_TOKEN",
6469
6494
  "GREPTILE_GITHUB_TOKEN",
6470
6495
  "GREPTILE_API_KEY",
6471
6496
  "AI_REVIEW_MODE",
@@ -8045,7 +8070,11 @@ async function ensureAgentRuntime(options) {
8045
8070
  mkdirSync18(runtime.binDir, { recursive: true });
8046
8071
  mkdirSync18(workspaceLayout.distDir, { recursive: true });
8047
8072
  prepareRuntimeWorkspace(options.projectRoot, workspaceDir);
8048
- await resetEphemeralTaskArtifacts(workspaceDir, options.taskId);
8073
+ if (options.preserveTaskArtifacts) {
8074
+ console.log(`[rig-agent] Preserving runtime task artifacts for resume of ${options.taskId}.`);
8075
+ } else {
8076
+ await resetEphemeralTaskArtifacts(workspaceDir, options.taskId);
8077
+ }
8049
8078
  const ctx = {
8050
8079
  runtimeId: options.id,
8051
8080
  taskId: options.taskId,
@@ -198,6 +198,17 @@ async function readSourceAwareTaskStatus(projectRoot, taskId, options = {}) {
198
198
  return null;
199
199
  }
200
200
  }
201
+ function updateGithubIssueTaskBySourceIssueId(sourceIssueId, taskId, update, options = {}) {
202
+ const parsed = sourceIssueId?.trim().match(/^([^/]+)\/([^#]+)#(\d+)$/);
203
+ if (!parsed || parsed[3] !== taskId) {
204
+ return false;
205
+ }
206
+ applyGithubIssueUpdate(options.ghBinary ?? "gh", options.spawn ?? spawnSync, parsed[3], {
207
+ sourceIssueId: sourceIssueId.trim(),
208
+ taskSource: { kind: "github-issues", owner: parsed[1], repo: parsed[2] }
209
+ }, update);
210
+ return true;
211
+ }
201
212
  function updateSourceAwareTaskConfigTask(projectRoot, taskId, update, options = {}) {
202
213
  const configPath = options.configPath ?? resolve2(projectRoot, ".rig", "task-config.json");
203
214
  const rawEntry = readRawTaskEntry(configPath, taskId);
@@ -553,8 +564,8 @@ function ensureStatusLabel(bin, repo, spawnFn, label) {
553
564
  }
554
565
  }
555
566
  function selectedGitHubEnv() {
556
- const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() ?? "";
557
- return { GH_TOKEN: token, GITHUB_TOKEN: token };
567
+ const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() || process.env.RIG_GITHUB_TOKEN?.trim() || "";
568
+ return { GH_TOKEN: token, GITHUB_TOKEN: token, RIG_GITHUB_TOKEN: token };
558
569
  }
559
570
  function ghSpawnOptions() {
560
571
  return { encoding: "utf-8", env: { ...process.env, ...selectedGitHubEnv() } };
@@ -605,6 +616,7 @@ function isPlainRecord2(candidate) {
605
616
  }
606
617
  export {
607
618
  updateSourceAwareTaskConfigTask,
619
+ updateGithubIssueTaskBySourceIssueId,
608
620
  readSourceAwareTaskStatus,
609
621
  readMaterializedTaskMetadata,
610
622
  createSourceAwareTaskConfigRecordReader
@@ -884,8 +884,8 @@ function ensureStatusLabel(bin, repo, spawnFn, label) {
884
884
  }
885
885
  }
886
886
  function selectedGitHubEnv() {
887
- const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() ?? "";
888
- return { GH_TOKEN: token, GITHUB_TOKEN: token };
887
+ const token = process.env.RIG_GITHUB_SELECTED_TOKEN?.trim() || process.env.RIG_GITHUB_TOKEN?.trim() || "";
888
+ return { GH_TOKEN: token, GITHUB_TOKEN: token, RIG_GITHUB_TOKEN: token };
889
889
  }
890
890
  function ghSpawnOptions() {
891
891
  return { encoding: "utf-8", env: { ...process.env, ...selectedGitHubEnv() } };
package/dist/src/index.js CHANGED
@@ -619,6 +619,18 @@ async function waitForServerHealthy(baseUrl, authToken, timeoutMs) {
619
619
  }
620
620
  return false;
621
621
  }
622
+ function resolveRigServerSpawnPlan(projectRoot, host, authToken, which = (command) => Bun.which(command)) {
623
+ const binary = process.env.RIG_SERVER_BIN?.trim() || which("rig-server")?.trim();
624
+ const args = ["start", "--host", host, "--port", "0", "--auth-token", authToken];
625
+ if (binary) {
626
+ return { command: binary, args, cwd: projectRoot };
627
+ }
628
+ return {
629
+ command: "bun",
630
+ args: ["run", "packages/server/src/server.ts", ...args],
631
+ cwd: resolve5(import.meta.dir, "../../..")
632
+ };
633
+ }
622
634
  async function waitForPublishedServer(projectRoot, authToken, timeoutMs) {
623
635
  const deadline = Date.now() + timeoutMs;
624
636
  while (Date.now() < deadline) {
@@ -644,23 +656,13 @@ async function ensureLocalRigServerConnection(projectRoot, options = {}) {
644
656
  const host = options.host ?? "127.0.0.1";
645
657
  const startupTimeoutMs = options.startupTimeoutMs ?? 15000;
646
658
  const authToken = Buffer.from(crypto.getRandomValues(new Uint8Array(24))).toString("hex");
647
- const workspaceRoot = resolve5(import.meta.dir, "../../..");
648
659
  const bootstrapLogPath = resolveRigServerLogPath(projectRoot);
649
660
  mkdirSync2(resolveRigServerPaths(projectRoot).logsDir, { recursive: true });
650
661
  const bootstrapLogFd = openSync(bootstrapLogPath, "w");
651
662
  clearPublishedRigServerState(projectRoot);
652
- const child = spawn("bun", [
653
- "run",
654
- "packages/server/src/server.ts",
655
- "start",
656
- "--host",
657
- host,
658
- "--port",
659
- "0",
660
- "--auth-token",
661
- authToken
662
- ], {
663
- cwd: workspaceRoot,
663
+ const spawnPlan = resolveRigServerSpawnPlan(projectRoot, host, authToken);
664
+ const child = spawn(spawnPlan.command, [...spawnPlan.args], {
665
+ cwd: spawnPlan.cwd,
664
666
  env: {
665
667
  ...process.env,
666
668
  PROJECT_RIG_ROOT: projectRoot
@@ -134,6 +134,18 @@ async function waitForServerHealthy(baseUrl, authToken, timeoutMs) {
134
134
  }
135
135
  return false;
136
136
  }
137
+ function resolveRigServerSpawnPlan(projectRoot, host, authToken, which = (command) => Bun.which(command)) {
138
+ const binary = process.env.RIG_SERVER_BIN?.trim() || which("rig-server")?.trim();
139
+ const args = ["start", "--host", host, "--port", "0", "--auth-token", authToken];
140
+ if (binary) {
141
+ return { command: binary, args, cwd: projectRoot };
142
+ }
143
+ return {
144
+ command: "bun",
145
+ args: ["run", "packages/server/src/server.ts", ...args],
146
+ cwd: resolve2(import.meta.dir, "../../..")
147
+ };
148
+ }
137
149
  async function waitForPublishedServer(projectRoot, authToken, timeoutMs) {
138
150
  const deadline = Date.now() + timeoutMs;
139
151
  while (Date.now() < deadline) {
@@ -159,23 +171,13 @@ async function ensureLocalRigServerConnection(projectRoot, options = {}) {
159
171
  const host = options.host ?? "127.0.0.1";
160
172
  const startupTimeoutMs = options.startupTimeoutMs ?? 15000;
161
173
  const authToken = Buffer.from(crypto.getRandomValues(new Uint8Array(24))).toString("hex");
162
- const workspaceRoot = resolve2(import.meta.dir, "../../..");
163
174
  const bootstrapLogPath = resolveRigServerLogPath(projectRoot);
164
175
  mkdirSync(resolveRigServerPaths(projectRoot).logsDir, { recursive: true });
165
176
  const bootstrapLogFd = openSync(bootstrapLogPath, "w");
166
177
  clearPublishedRigServerState(projectRoot);
167
- const child = spawn("bun", [
168
- "run",
169
- "packages/server/src/server.ts",
170
- "start",
171
- "--host",
172
- host,
173
- "--port",
174
- "0",
175
- "--auth-token",
176
- authToken
177
- ], {
178
- cwd: workspaceRoot,
178
+ const spawnPlan = resolveRigServerSpawnPlan(projectRoot, host, authToken);
179
+ const child = spawn(spawnPlan.command, [...spawnPlan.args], {
180
+ cwd: spawnPlan.cwd,
179
181
  env: {
180
182
  ...process.env,
181
183
  PROJECT_RIG_ROOT: projectRoot
@@ -195,8 +197,12 @@ ${bootstrapLog}` : ` No bootstrap log was written.`;
195
197
  }
196
198
  return toLocalServerConnection(ready);
197
199
  }
200
+ var __testOnly = {
201
+ resolveRigServerSpawnPlan
202
+ };
198
203
  export {
199
204
  readPublishedRigServerStateSync,
200
205
  readPublishedRigServerState,
201
- ensureLocalRigServerConnection
206
+ ensureLocalRigServerConnection,
207
+ __testOnly
202
208
  };
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": 1,
3
+ "buildKey": "{\"version\":1,\"sourcePath\":\"/var/folders/zr/6js4xbjs3bgf46v76j145mlw0000gn/T/rig-native/rig-git-darwin-arm64\",\"sourceDigest\":\"5d1f9d17af5789a15328b4c4aff2b155962bd9d8e180812fa67a30c1685b2bf3\"}"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": 1,
3
+ "buildKey": "{\"version\":1,\"sourcePath\":\"/var/folders/zr/6js4xbjs3bgf46v76j145mlw0000gn/T/rig-native/rig-shell-darwin-arm64\",\"sourceDigest\":\"082addd699beb1eb87d242208741012bba54becf7e2c3cd85904c68c200be3e3\"}"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": 1,
3
+ "buildKey": "{\"version\":1,\"sourcePath\":\"/var/folders/zr/6js4xbjs3bgf46v76j145mlw0000gn/T/rig-native/rig-tools-darwin-arm64\",\"sourceDigest\":\"a0950e37e897d520196d93e5487bade084e5f0cad45c57843b4e9f16a6421da8\"}"
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/runtime",
3
- "version": "0.0.6-alpha.0",
3
+ "version": "0.0.6-alpha.10",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",
@@ -64,11 +64,12 @@
64
64
  "module": "./dist/src/index.js",
65
65
  "dependencies": {
66
66
  "@libsql/client": "^0.17.2",
67
- "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.0",
68
- "@rig/core": "npm:@h-rig/core@0.0.6-alpha.0",
69
- "@rig/hook-kit": "npm:@h-rig/hook-kit@0.0.6-alpha.0",
70
- "@rig/shared": "npm:@h-rig/shared@0.0.6-alpha.0",
71
- "@rig/validator-kit": "npm:@h-rig/validator-kit@0.0.6-alpha.0",
72
- "effect": "4.0.0-beta.78"
67
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.10",
68
+ "@rig/core": "npm:@h-rig/core@0.0.6-alpha.10",
69
+ "@rig/hook-kit": "npm:@h-rig/hook-kit@0.0.6-alpha.10",
70
+ "@rig/shared": "npm:@h-rig/shared@0.0.6-alpha.10",
71
+ "@rig/validator-kit": "npm:@h-rig/validator-kit@0.0.6-alpha.10",
72
+ "effect": "4.0.0-beta.78",
73
+ "smol-toml": "^1.6.0"
73
74
  }
74
75
  }
@@ -1 +0,0 @@
1
- {"platform":"darwin-arm64","suffix":"dylib","builtAt":"2026-06-07T22:55:24Z"}
Binary file