@h-rig/cli 0.0.6-alpha.89 → 0.0.6-alpha.90

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 (231) hide show
  1. package/dist/bin/build-rig-binaries.js +8 -40
  2. package/dist/bin/rig.js +12519 -26675
  3. package/dist/src/app/board.js +74 -693
  4. package/dist/src/app/drone-ui.js +1 -1
  5. package/dist/src/app/theme.js +0 -1
  6. package/dist/src/commands/_async-ui.js +1 -1
  7. package/dist/src/commands/_authority-runs.d.ts +1 -1
  8. package/dist/src/commands/_authority-runs.js +12 -2
  9. package/dist/src/commands/_cli-format.d.ts +1 -10
  10. package/dist/src/commands/_cli-format.js +2 -5
  11. package/dist/src/commands/_connection-state.d.ts +1 -11
  12. package/dist/src/commands/_connection-state.js +5 -50
  13. package/dist/src/commands/_doctor-checks.js +40 -501
  14. package/dist/src/commands/_help-catalog.js +17 -99
  15. package/dist/src/commands/_json-output.js +0 -4
  16. package/dist/src/commands/_operator-view.js +54 -575
  17. package/dist/src/commands/_pi-frontend.d.ts +0 -27
  18. package/dist/src/commands/_pi-frontend.js +52 -576
  19. package/dist/src/commands/_preflight.js +66 -553
  20. package/dist/src/commands/_server-client.d.ts +0 -33
  21. package/dist/src/commands/_server-client.js +46 -541
  22. package/dist/src/commands/_snapshot-upload.js +42 -503
  23. package/dist/src/commands/_spinner.js +1 -1
  24. package/dist/src/commands/agent.js +12 -2
  25. package/dist/src/commands/browser.js +1 -1
  26. package/dist/src/commands/connect.js +15 -626
  27. package/dist/src/commands/doctor.js +41 -502
  28. package/dist/src/commands/github.js +51 -584
  29. package/dist/src/commands/inbox.js +41 -502
  30. package/dist/src/commands/init.js +74 -561
  31. package/dist/src/commands/inspect.js +41 -502
  32. package/dist/src/commands/run.js +54 -578
  33. package/dist/src/commands/server.js +163 -692
  34. package/dist/src/commands/setup.js +46 -507
  35. package/dist/src/commands/stats.js +58 -601
  36. package/dist/src/commands/task-run-driver.js +58 -509
  37. package/dist/src/commands/task.js +110 -729
  38. package/dist/src/commands.js +237 -1112
  39. package/dist/src/index.js +244 -1123
  40. package/dist/src/launcher.js +0 -4
  41. package/package.json +9 -13
  42. package/dist/src/app-opentui/adapters/command.d.ts +0 -2
  43. package/dist/src/app-opentui/adapters/command.js +0 -329
  44. package/dist/src/app-opentui/adapters/common.d.ts +0 -56
  45. package/dist/src/app-opentui/adapters/common.js +0 -153
  46. package/dist/src/app-opentui/adapters/doctor.d.ts +0 -9
  47. package/dist/src/app-opentui/adapters/doctor.js +0 -1217
  48. package/dist/src/app-opentui/adapters/family.d.ts +0 -62
  49. package/dist/src/app-opentui/adapters/family.js +0 -14855
  50. package/dist/src/app-opentui/adapters/fleet.d.ts +0 -14
  51. package/dist/src/app-opentui/adapters/fleet.js +0 -1335
  52. package/dist/src/app-opentui/adapters/inbox.d.ts +0 -43
  53. package/dist/src/app-opentui/adapters/inbox.js +0 -1944
  54. package/dist/src/app-opentui/adapters/init.d.ts +0 -11
  55. package/dist/src/app-opentui/adapters/init.js +0 -2818
  56. package/dist/src/app-opentui/adapters/inspect.d.ts +0 -52
  57. package/dist/src/app-opentui/adapters/inspect.js +0 -1455
  58. package/dist/src/app-opentui/adapters/pi-attach.d.ts +0 -32
  59. package/dist/src/app-opentui/adapters/pi-attach.js +0 -2101
  60. package/dist/src/app-opentui/adapters/pi.d.ts +0 -23
  61. package/dist/src/app-opentui/adapters/pi.js +0 -363
  62. package/dist/src/app-opentui/adapters/plugin.d.ts +0 -84
  63. package/dist/src/app-opentui/adapters/plugin.js +0 -544
  64. package/dist/src/app-opentui/adapters/repo.d.ts +0 -37
  65. package/dist/src/app-opentui/adapters/repo.js +0 -186
  66. package/dist/src/app-opentui/adapters/run-detail.d.ts +0 -27
  67. package/dist/src/app-opentui/adapters/run-detail.js +0 -1441
  68. package/dist/src/app-opentui/adapters/server.d.ts +0 -48
  69. package/dist/src/app-opentui/adapters/server.js +0 -1561
  70. package/dist/src/app-opentui/adapters/tasks.d.ts +0 -64
  71. package/dist/src/app-opentui/adapters/tasks.js +0 -4524
  72. package/dist/src/app-opentui/adapters/workspace.d.ts +0 -49
  73. package/dist/src/app-opentui/adapters/workspace.js +0 -333
  74. package/dist/src/app-opentui/autocomplete.d.ts +0 -20
  75. package/dist/src/app-opentui/autocomplete.js +0 -578
  76. package/dist/src/app-opentui/bootstrap.d.ts +0 -11
  77. package/dist/src/app-opentui/bootstrap.js +0 -27833
  78. package/dist/src/app-opentui/command-palette.d.ts +0 -3
  79. package/dist/src/app-opentui/command-palette.js +0 -1038
  80. package/dist/src/app-opentui/command-pty-host.d.ts +0 -62
  81. package/dist/src/app-opentui/command-pty-host.js +0 -248
  82. package/dist/src/app-opentui/drone.d.ts +0 -12
  83. package/dist/src/app-opentui/drone.js +0 -230
  84. package/dist/src/app-opentui/events.d.ts +0 -7
  85. package/dist/src/app-opentui/events.js +0 -28
  86. package/dist/src/app-opentui/fleet-stats.d.ts +0 -32
  87. package/dist/src/app-opentui/fleet-stats.js +0 -114
  88. package/dist/src/app-opentui/focus-manager.d.ts +0 -14
  89. package/dist/src/app-opentui/focus-manager.js +0 -24
  90. package/dist/src/app-opentui/index.d.ts +0 -8
  91. package/dist/src/app-opentui/index.js +0 -5260
  92. package/dist/src/app-opentui/intent.d.ts +0 -3
  93. package/dist/src/app-opentui/intent.js +0 -365
  94. package/dist/src/app-opentui/keymap.d.ts +0 -21
  95. package/dist/src/app-opentui/keymap.js +0 -1377
  96. package/dist/src/app-opentui/launch-routing.d.ts +0 -16
  97. package/dist/src/app-opentui/launch-routing.js +0 -55
  98. package/dist/src/app-opentui/layout.d.ts +0 -22
  99. package/dist/src/app-opentui/layout.js +0 -51
  100. package/dist/src/app-opentui/list-search.d.ts +0 -36
  101. package/dist/src/app-opentui/list-search.js +0 -130
  102. package/dist/src/app-opentui/pi-host-child.d.ts +0 -2
  103. package/dist/src/app-opentui/pi-host-child.js +0 -1299
  104. package/dist/src/app-opentui/pi-pty-host.d.ts +0 -28
  105. package/dist/src/app-opentui/pi-pty-host.js +0 -10
  106. package/dist/src/app-opentui/react/App.d.ts +0 -9
  107. package/dist/src/app-opentui/react/App.js +0 -3866
  108. package/dist/src/app-opentui/react/Backdrop.d.ts +0 -5
  109. package/dist/src/app-opentui/react/Backdrop.js +0 -823
  110. package/dist/src/app-opentui/react/ChromeHost.d.ts +0 -5
  111. package/dist/src/app-opentui/react/ChromeHost.js +0 -1539
  112. package/dist/src/app-opentui/react/SceneFrameView.d.ts +0 -7
  113. package/dist/src/app-opentui/react/SceneFrameView.js +0 -579
  114. package/dist/src/app-opentui/react/context.d.ts +0 -17
  115. package/dist/src/app-opentui/react/context.js +0 -37
  116. package/dist/src/app-opentui/react/launch.d.ts +0 -2
  117. package/dist/src/app-opentui/react/launch.js +0 -4897
  118. package/dist/src/app-opentui/react/nav.d.ts +0 -18
  119. package/dist/src/app-opentui/react/nav.js +0 -54
  120. package/dist/src/app-opentui/react/scroll.d.ts +0 -12
  121. package/dist/src/app-opentui/react/scroll.js +0 -21
  122. package/dist/src/app-opentui/react/syntax.d.ts +0 -2
  123. package/dist/src/app-opentui/react/syntax.js +0 -65
  124. package/dist/src/app-opentui/registry.d.ts +0 -4
  125. package/dist/src/app-opentui/registry.js +0 -22876
  126. package/dist/src/app-opentui/remote-link.d.ts +0 -10
  127. package/dist/src/app-opentui/remote-link.js +0 -47
  128. package/dist/src/app-opentui/render/ascii-fleet.d.ts +0 -15
  129. package/dist/src/app-opentui/render/ascii-fleet.js +0 -82
  130. package/dist/src/app-opentui/render/constants.d.ts +0 -30
  131. package/dist/src/app-opentui/render/constants.js +0 -64
  132. package/dist/src/app-opentui/render/graphics.d.ts +0 -40
  133. package/dist/src/app-opentui/render/graphics.js +0 -713
  134. package/dist/src/app-opentui/render/hover.d.ts +0 -11
  135. package/dist/src/app-opentui/render/hover.js +0 -34
  136. package/dist/src/app-opentui/render/native-host.d.ts +0 -37
  137. package/dist/src/app-opentui/render/native-host.js +0 -180
  138. package/dist/src/app-opentui/render/panel-layout.d.ts +0 -38
  139. package/dist/src/app-opentui/render/panel-layout.js +0 -48
  140. package/dist/src/app-opentui/render/panels.d.ts +0 -12
  141. package/dist/src/app-opentui/render/panels.js +0 -288
  142. package/dist/src/app-opentui/render/preloader.d.ts +0 -10
  143. package/dist/src/app-opentui/render/preloader.js +0 -166
  144. package/dist/src/app-opentui/render/scene.d.ts +0 -68
  145. package/dist/src/app-opentui/render/scene.js +0 -300
  146. package/dist/src/app-opentui/render/terminal-handoff.d.ts +0 -16
  147. package/dist/src/app-opentui/render/terminal-handoff.js +0 -14
  148. package/dist/src/app-opentui/render/text.d.ts +0 -29
  149. package/dist/src/app-opentui/render/text.js +0 -177
  150. package/dist/src/app-opentui/render/type-bar.d.ts +0 -15
  151. package/dist/src/app-opentui/render/type-bar.js +0 -212
  152. package/dist/src/app-opentui/runtime-resources.d.ts +0 -16
  153. package/dist/src/app-opentui/runtime-resources.js +0 -62
  154. package/dist/src/app-opentui/runtime.d.ts +0 -45
  155. package/dist/src/app-opentui/runtime.js +0 -5232
  156. package/dist/src/app-opentui/scenes/command.d.ts +0 -3
  157. package/dist/src/app-opentui/scenes/command.js +0 -118
  158. package/dist/src/app-opentui/scenes/doctor.d.ts +0 -3
  159. package/dist/src/app-opentui/scenes/doctor.js +0 -296
  160. package/dist/src/app-opentui/scenes/error.d.ts +0 -2
  161. package/dist/src/app-opentui/scenes/error.js +0 -277
  162. package/dist/src/app-opentui/scenes/family-domains/agent.d.ts +0 -2
  163. package/dist/src/app-opentui/scenes/family-domains/agent.js +0 -349
  164. package/dist/src/app-opentui/scenes/family-domains/browser.d.ts +0 -2
  165. package/dist/src/app-opentui/scenes/family-domains/browser.js +0 -196
  166. package/dist/src/app-opentui/scenes/family-domains/dist.d.ts +0 -2
  167. package/dist/src/app-opentui/scenes/family-domains/dist.js +0 -244
  168. package/dist/src/app-opentui/scenes/family-domains/git.d.ts +0 -2
  169. package/dist/src/app-opentui/scenes/family-domains/git.js +0 -196
  170. package/dist/src/app-opentui/scenes/family-domains/github.d.ts +0 -2
  171. package/dist/src/app-opentui/scenes/family-domains/github.js +0 -275
  172. package/dist/src/app-opentui/scenes/family-domains/harness.d.ts +0 -2
  173. package/dist/src/app-opentui/scenes/family-domains/harness.js +0 -153
  174. package/dist/src/app-opentui/scenes/family-domains/index.d.ts +0 -4
  175. package/dist/src/app-opentui/scenes/family-domains/index.js +0 -1680
  176. package/dist/src/app-opentui/scenes/family-domains/kit.d.ts +0 -76
  177. package/dist/src/app-opentui/scenes/family-domains/kit.js +0 -306
  178. package/dist/src/app-opentui/scenes/family-domains/profile.d.ts +0 -2
  179. package/dist/src/app-opentui/scenes/family-domains/profile.js +0 -213
  180. package/dist/src/app-opentui/scenes/family-domains/queue.d.ts +0 -2
  181. package/dist/src/app-opentui/scenes/family-domains/queue.js +0 -147
  182. package/dist/src/app-opentui/scenes/family-domains/remote.d.ts +0 -2
  183. package/dist/src/app-opentui/scenes/family-domains/remote.js +0 -519
  184. package/dist/src/app-opentui/scenes/family-domains/review.d.ts +0 -2
  185. package/dist/src/app-opentui/scenes/family-domains/review.js +0 -281
  186. package/dist/src/app-opentui/scenes/family-domains/setup.d.ts +0 -2
  187. package/dist/src/app-opentui/scenes/family-domains/setup.js +0 -268
  188. package/dist/src/app-opentui/scenes/family-domains/stats.d.ts +0 -2
  189. package/dist/src/app-opentui/scenes/family-domains/stats.js +0 -371
  190. package/dist/src/app-opentui/scenes/family.d.ts +0 -3
  191. package/dist/src/app-opentui/scenes/family.js +0 -2199
  192. package/dist/src/app-opentui/scenes/fleet.d.ts +0 -3
  193. package/dist/src/app-opentui/scenes/fleet.js +0 -766
  194. package/dist/src/app-opentui/scenes/handoff.d.ts +0 -2
  195. package/dist/src/app-opentui/scenes/handoff.js +0 -455
  196. package/dist/src/app-opentui/scenes/help.d.ts +0 -3
  197. package/dist/src/app-opentui/scenes/help.js +0 -725
  198. package/dist/src/app-opentui/scenes/inbox.d.ts +0 -3
  199. package/dist/src/app-opentui/scenes/inbox.js +0 -427
  200. package/dist/src/app-opentui/scenes/init.d.ts +0 -3
  201. package/dist/src/app-opentui/scenes/init.js +0 -181
  202. package/dist/src/app-opentui/scenes/inspect.d.ts +0 -3
  203. package/dist/src/app-opentui/scenes/inspect.js +0 -794
  204. package/dist/src/app-opentui/scenes/main.d.ts +0 -3
  205. package/dist/src/app-opentui/scenes/main.js +0 -332
  206. package/dist/src/app-opentui/scenes/pi.d.ts +0 -3
  207. package/dist/src/app-opentui/scenes/pi.js +0 -509
  208. package/dist/src/app-opentui/scenes/plugin.d.ts +0 -3
  209. package/dist/src/app-opentui/scenes/plugin.js +0 -487
  210. package/dist/src/app-opentui/scenes/repo.d.ts +0 -3
  211. package/dist/src/app-opentui/scenes/repo.js +0 -425
  212. package/dist/src/app-opentui/scenes/run-detail.d.ts +0 -3
  213. package/dist/src/app-opentui/scenes/run-detail.js +0 -467
  214. package/dist/src/app-opentui/scenes/server.d.ts +0 -3
  215. package/dist/src/app-opentui/scenes/server.js +0 -378
  216. package/dist/src/app-opentui/scenes/tasks.d.ts +0 -3
  217. package/dist/src/app-opentui/scenes/tasks.js +0 -768
  218. package/dist/src/app-opentui/scenes/workspace.d.ts +0 -3
  219. package/dist/src/app-opentui/scenes/workspace.js +0 -427
  220. package/dist/src/app-opentui/selectable.d.ts +0 -19
  221. package/dist/src/app-opentui/selectable.js +0 -80
  222. package/dist/src/app-opentui/state.d.ts +0 -4
  223. package/dist/src/app-opentui/state.js +0 -399
  224. package/dist/src/app-opentui/surface-catalog.d.ts +0 -20
  225. package/dist/src/app-opentui/surface-catalog.js +0 -542
  226. package/dist/src/app-opentui/theme.d.ts +0 -59
  227. package/dist/src/app-opentui/theme.js +0 -142
  228. package/dist/src/app-opentui/types.d.ts +0 -313
  229. package/dist/src/app-opentui/types.js +0 -1
  230. package/dist/src/commands/_server-events.d.ts +0 -26
  231. package/dist/src/commands/_server-events.js +0 -715
@@ -110,7 +110,7 @@ function createTtySpinner(input) {
110
110
  output.write("\r\x1B[2K");
111
111
  };
112
112
  render();
113
- const timer = isTty ? setInterval(render, input.intervalMs ?? 16) : null;
113
+ const timer = isTty ? setInterval(render, input.intervalMs ?? 120) : null;
114
114
  return {
115
115
  setLabel(next) {
116
116
  label = next;
@@ -306,8 +306,18 @@ import {
306
306
  import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
307
307
 
308
308
  // packages/cli/src/commands/_authority-runs.ts
309
- function normalizeRuntimeAdapter(_value) {
310
- return "pi";
309
+ function normalizeRuntimeAdapter(value) {
310
+ const normalized = value?.trim().toLowerCase();
311
+ if (!normalized) {
312
+ return "pi";
313
+ }
314
+ if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
315
+ return "codex";
316
+ }
317
+ if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
318
+ return "pi";
319
+ }
320
+ return "claude-code";
311
321
  }
312
322
 
313
323
  // packages/cli/src/commands/_preflight.ts
@@ -384,28 +394,12 @@ function readRepoConnection(projectRoot) {
384
394
  selected,
385
395
  project: typeof record.project === "string" ? record.project : undefined,
386
396
  linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
387
- serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
388
- serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
389
- serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
397
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
390
398
  };
391
399
  }
392
400
  function writeRepoConnection(projectRoot, state) {
393
401
  writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
394
402
  }
395
- function rootAllowedForSelection(repo, connection) {
396
- const root = repo.serverProjectRoot?.trim();
397
- if (!root)
398
- return;
399
- if (connection.kind === "remote") {
400
- if (repo.serverProjectRootAlias !== repo.selected)
401
- return;
402
- if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
403
- return;
404
- } else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
405
- return;
406
- }
407
- return root;
408
- }
409
403
  function resolveSelectedConnection(projectRoot, options = {}) {
410
404
  const repo = readRepoConnection(projectRoot);
411
405
  if (!repo)
@@ -417,46 +411,18 @@ function resolveSelectedConnection(projectRoot, options = {}) {
417
411
  if (!connection) {
418
412
  throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
419
413
  }
420
- return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
421
- }
422
- function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
423
- const repo = readRepoConnection(projectRoot);
424
- if (!repo)
425
- return;
426
- let inferred = metadata;
427
- if (!inferred.alias || !inferred.baseUrl) {
428
- try {
429
- const selected = resolveSelectedConnection(projectRoot);
430
- if (selected?.connection.kind === "remote") {
431
- inferred = {
432
- alias: inferred.alias ?? selected.alias,
433
- baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
434
- };
435
- }
436
- } catch {}
437
- }
438
- writeRepoConnection(projectRoot, {
439
- ...repo,
440
- ...metadata.project ? { project: metadata.project } : {},
441
- serverProjectRoot,
442
- ...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
443
- ...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
444
- });
414
+ return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
445
415
  }
446
- function clearRepoServerProjectRoot(projectRoot) {
416
+ function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
447
417
  const repo = readRepoConnection(projectRoot);
448
418
  if (!repo)
449
419
  return;
450
- writeRepoConnection(projectRoot, {
451
- selected: repo.selected,
452
- ...repo.project ? { project: repo.project } : {},
453
- ...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
454
- });
420
+ writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
455
421
  }
456
422
 
457
423
  // packages/cli/src/commands/_server-client.ts
458
- import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
459
- import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
424
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
425
+ import { resolve as resolve2 } from "path";
460
426
  import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
461
427
  var scopedGitHubBearerTokens = new Map;
462
428
  var serverPhaseListener = null;
@@ -472,21 +438,17 @@ function cleanToken(value) {
472
438
  const trimmed = value?.trim();
473
439
  return trimmed ? trimmed : null;
474
440
  }
475
- function readRemoteAuthState(projectRoot) {
441
+ function readPrivateRemoteSessionToken(projectRoot) {
476
442
  const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
477
443
  if (!existsSync2(path))
478
444
  return null;
479
445
  try {
480
446
  const parsed = JSON.parse(readFileSync2(path, "utf8"));
481
- return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
447
+ return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
482
448
  } catch {
483
449
  return null;
484
450
  }
485
451
  }
486
- function readPrivateRemoteSessionToken(projectRoot) {
487
- const parsed = readRemoteAuthState(projectRoot);
488
- return parsed ? cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined) : null;
489
- }
490
452
  function readGitHubBearerTokenForRemote(projectRoot) {
491
453
  const scopedKey = resolve2(projectRoot);
492
454
  if (scopedGitHubBearerTokens.has(scopedKey))
@@ -497,415 +459,18 @@ function readGitHubBearerTokenForRemote(projectRoot) {
497
459
  return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
498
460
  }
499
461
  function readStoredGitHubAuthToken(projectRoot) {
500
- const parsed = readRemoteAuthState(projectRoot);
501
- return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
502
- }
503
- function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
504
- if (!/^[^/]+\/[^/]+$/.test(repoSlug))
505
- return null;
506
- const repo = readRepoConnection(projectRoot);
507
- const auth = readRemoteAuthState(projectRoot);
508
- const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
509
- const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
510
- if (Number.isFinite(authUpdatedAt) && Number.isFinite(repoLinkedAt) && authUpdatedAt + 1000 < repoLinkedAt)
511
- return null;
512
- const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
513
- if (!checkoutBaseDir)
514
- return null;
515
- return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
516
- }
517
- function readLocalConnectionFallbackToken(projectRoot) {
518
- return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
519
- }
520
- function normalizeRepoSlug(value) {
521
- const slug = value?.trim();
522
- return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
523
- }
524
- function readProjectLinkSlug(projectRoot) {
525
- const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
462
+ const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
526
463
  if (!existsSync2(path))
527
464
  return null;
528
465
  try {
529
466
  const parsed = JSON.parse(readFileSync2(path, "utf8"));
530
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
531
- return null;
532
- return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
467
+ return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
533
468
  } catch {
534
469
  return null;
535
470
  }
536
471
  }
537
- function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
538
- const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
539
- mkdirSync2(dirname2(path), { recursive: true });
540
- writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
541
- `, "utf8");
542
- }
543
- function remoteLinkRepairCommand(repoSlug) {
544
- return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
545
- }
546
- function formatRemoteProjectLinkHint(resolution) {
547
- const repair = remoteLinkRepairCommand(resolution.repoSlug);
548
- if (resolution.status === "auth_required") {
549
- return `Authenticate the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}, then run \`${repair}\`. Use \`rig github auth import-gh\` or \`rig init --repair --server remote --github-auth device${resolution.repoSlug ? ` --repo ${resolution.repoSlug}` : ""}\`.`;
550
- }
551
- if (resolution.status === "missing_project") {
552
- return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
553
- }
554
- if (resolution.status === "not_remote")
555
- return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
556
- return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
557
- }
558
- function remoteProjectLinkFailure(input) {
559
- const partial = {
560
- status: input.status,
561
- alias: input.alias,
562
- baseUrl: input.baseUrl,
563
- repoSlug: input.repoSlug
564
- };
565
- return {
566
- ok: false,
567
- ...input,
568
- hint: formatRemoteProjectLinkHint(partial),
569
- next: remoteLinkRepairCommand(input.repoSlug)
570
- };
571
- }
572
- function remoteProjectLinkSuccess(input) {
573
- return {
574
- ok: true,
575
- status: input.status,
576
- alias: input.alias,
577
- baseUrl: input.baseUrl,
578
- repoSlug: input.repoSlug,
579
- serverProjectRoot: input.serverProjectRoot,
580
- source: input.source,
581
- prepared: input.prepared ?? input.status === "prepared",
582
- validated: input.validated ?? false,
583
- message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
584
- hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
585
- next: "rig task list"
586
- };
587
- }
588
- function localCheckoutPathCandidate(projectRoot, candidate) {
589
- try {
590
- const local = resolve2(projectRoot);
591
- const resolved = resolve2(candidate);
592
- return resolved === local || resolved.startsWith(`${local}/`);
593
- } catch {
594
- return false;
595
- }
596
- }
597
- async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
598
- const requestUrl = new URL(`${baseUrl}${pathname}`);
599
- if (authToken && queryAuthFallbackEnabled())
600
- requestUrl.searchParams.set("rt", authToken);
601
- const response = await fetch(requestUrl, {
602
- ...init,
603
- headers: mergeHeaders(init.headers, authToken)
604
- });
605
- const text = await response.text();
606
- const payload = text.trim().length > 0 ? (() => {
607
- try {
608
- return JSON.parse(text);
609
- } catch {
610
- return null;
611
- }
612
- })() : null;
613
- return { ok: response.ok, status: response.status, payload, text };
614
- }
615
- function payloadError(payload, fallback) {
616
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
617
- const record = payload;
618
- const value = record.error ?? record.message ?? record.reason;
619
- if (typeof value === "string" && value.trim())
620
- return value.trim();
621
- }
622
- return fallback;
623
- }
624
- function checkoutPathsFromProjectPayload(payload) {
625
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
626
- return [];
627
- const project = payload.project;
628
- if (!project || typeof project !== "object" || Array.isArray(project))
629
- return [];
630
- const checkouts = project.checkouts;
631
- if (!Array.isArray(checkouts))
632
- return [];
633
- return [...checkouts].reverse().flatMap((entry) => {
634
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
635
- return [];
636
- const path = entry.path;
637
- return typeof path === "string" && path.trim() ? [path.trim()] : [];
638
- });
639
- }
640
- function checkoutPathFromPreparePayload(payload) {
641
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
642
- return null;
643
- const checkout = payload.checkout;
644
- if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
645
- return null;
646
- const path = checkout.path;
647
- return typeof path === "string" && path.trim() ? path.trim() : null;
648
- }
649
- async function validateAndPersistRemoteRoot(input) {
650
- const candidate = input.candidate.trim();
651
- if (!candidate || !isAbsolute(candidate)) {
652
- return remoteProjectLinkFailure({
653
- status: "invalid_root",
654
- alias: input.alias,
655
- baseUrl: input.baseUrl,
656
- repoSlug: input.repoSlug,
657
- message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
658
- });
659
- }
660
- if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
661
- return remoteProjectLinkFailure({
662
- status: "invalid_root",
663
- alias: input.alias,
664
- baseUrl: input.baseUrl,
665
- repoSlug: input.repoSlug,
666
- message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
667
- });
668
- }
669
- let response;
670
- try {
671
- response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
672
- method: "POST",
673
- headers: { "content-type": "application/json" },
674
- body: JSON.stringify({ projectRoot: candidate })
675
- });
676
- } catch (error) {
677
- return remoteProjectLinkFailure({
678
- status: "error",
679
- alias: input.alias,
680
- baseUrl: input.baseUrl,
681
- repoSlug: input.repoSlug,
682
- message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
683
- });
684
- }
685
- if (response.status === 401 || response.status === 403) {
686
- return remoteProjectLinkFailure({
687
- status: "auth_required",
688
- alias: input.alias,
689
- baseUrl: input.baseUrl,
690
- repoSlug: input.repoSlug,
691
- statusCode: response.status,
692
- message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
693
- });
694
- }
695
- if (!response.ok) {
696
- return remoteProjectLinkFailure({
697
- status: "invalid_root",
698
- alias: input.alias,
699
- baseUrl: input.baseUrl,
700
- repoSlug: input.repoSlug,
701
- statusCode: response.status,
702
- message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
703
- });
704
- }
705
- const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
706
- if (record.ok !== true) {
707
- return remoteProjectLinkFailure({
708
- status: "invalid_root",
709
- alias: input.alias,
710
- baseUrl: input.baseUrl,
711
- repoSlug: input.repoSlug,
712
- message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
713
- });
714
- }
715
- const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
716
- writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
717
- writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
718
- const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
719
- return remoteProjectLinkSuccess({
720
- status,
721
- alias: input.alias,
722
- baseUrl: input.baseUrl,
723
- repoSlug: input.repoSlug,
724
- serverProjectRoot: accepted,
725
- source: input.source,
726
- prepared: input.prepared,
727
- validated: true,
728
- message: status === "ready" ? `Remote project link already points to ${accepted} and was validated on ${input.alias}.` : input.prepared ? `Prepared and linked remote checkout ${accepted} for ${input.repoSlug}.` : `Backfilled remote checkout ${accepted} for ${input.repoSlug}.`
729
- });
730
- }
731
- async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
732
- let selected;
733
- try {
734
- selected = resolveSelectedConnection(projectRoot);
735
- } catch (error) {
736
- return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
737
- }
738
- if (!selected || selected.connection.kind !== "remote") {
739
- return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
740
- }
741
- const repo = readRepoConnection(projectRoot);
742
- const explicitRepoRequested = options.repoSlug !== undefined;
743
- const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
744
- const repoProjectSlug = normalizeRepoSlug(repo?.project);
745
- const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
746
- const alias = selected.alias;
747
- const baseUrl = selected.connection.baseUrl;
748
- const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
749
- const mode = options.mode ?? "backfill-only";
750
- if (explicitRepoRequested && !explicitRepoSlug) {
751
- return remoteProjectLinkFailure({
752
- status: "missing_project",
753
- alias,
754
- baseUrl,
755
- message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
756
- });
757
- }
758
- if (!repoSlug) {
759
- return remoteProjectLinkFailure({
760
- status: "missing_project",
761
- alias,
762
- baseUrl,
763
- message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
764
- });
765
- }
766
- const skippedCandidates = [];
767
- const storedRoot = selected.serverProjectRoot?.trim() || null;
768
- const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
769
- if (storedRoot && storedRootMatchesResolvedRepo) {
770
- if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
771
- clearRepoServerProjectRoot(projectRoot);
772
- skippedCandidates.push(storedRoot);
773
- } else {
774
- const storedResult = await validateAndPersistRemoteRoot({
775
- projectRoot,
776
- alias,
777
- baseUrl,
778
- authToken,
779
- repoSlug,
780
- candidate: storedRoot,
781
- source: "stored",
782
- status: "ready"
783
- });
784
- if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
785
- return storedResult;
786
- clearRepoServerProjectRoot(projectRoot);
787
- skippedCandidates.push(storedRoot);
788
- }
789
- } else if (storedRoot) {
790
- skippedCandidates.push(storedRoot);
791
- }
792
- const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
793
- if (authCandidate) {
794
- const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
795
- if (authResult.ok || authResult.status === "auth_required")
796
- return authResult;
797
- }
798
- let registryResponse;
799
- try {
800
- registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
801
- } catch (error) {
802
- return remoteProjectLinkFailure({
803
- status: "error",
804
- alias,
805
- baseUrl,
806
- repoSlug,
807
- message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
808
- });
809
- }
810
- if (registryResponse.status === 401 || registryResponse.status === 403) {
811
- return remoteProjectLinkFailure({
812
- status: "auth_required",
813
- alias,
814
- baseUrl,
815
- repoSlug,
816
- statusCode: registryResponse.status,
817
- message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
818
- });
819
- }
820
- if (registryResponse.ok) {
821
- const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
822
- for (const candidate of candidates) {
823
- const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
824
- if (result.ok || result.status === "auth_required")
825
- return result;
826
- skippedCandidates.push(candidate);
827
- }
828
- if (mode === "backfill-only") {
829
- return remoteProjectLinkFailure({
830
- status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
831
- alias,
832
- baseUrl,
833
- repoSlug,
834
- message: candidates.length > 0 ? `Remote registry has checkout candidates for ${repoSlug}, but none validated for ${alias}.` : `Remote registry has ${repoSlug}, but no server checkout path is linked yet.`,
835
- skippedCandidates
836
- });
837
- }
838
- } else if (registryResponse.status === 404) {
839
- if (mode === "backfill-only") {
840
- return remoteProjectLinkFailure({
841
- status: "project_not_registered",
842
- alias,
843
- baseUrl,
844
- repoSlug,
845
- statusCode: registryResponse.status,
846
- message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
847
- });
848
- }
849
- } else {
850
- return remoteProjectLinkFailure({
851
- status: "error",
852
- alias,
853
- baseUrl,
854
- repoSlug,
855
- statusCode: registryResponse.status,
856
- message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
857
- skippedCandidates
858
- });
859
- }
860
- let prepareResponse;
861
- try {
862
- prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
863
- method: "POST",
864
- headers: { "content-type": "application/json" },
865
- body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
866
- });
867
- } catch (error) {
868
- return remoteProjectLinkFailure({
869
- status: "error",
870
- alias,
871
- baseUrl,
872
- repoSlug,
873
- message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
874
- });
875
- }
876
- if (prepareResponse.status === 401 || prepareResponse.status === 403) {
877
- return remoteProjectLinkFailure({
878
- status: "auth_required",
879
- alias,
880
- baseUrl,
881
- repoSlug,
882
- statusCode: prepareResponse.status,
883
- message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
884
- });
885
- }
886
- if (!prepareResponse.ok) {
887
- return remoteProjectLinkFailure({
888
- status: "error",
889
- alias,
890
- baseUrl,
891
- repoSlug,
892
- statusCode: prepareResponse.status,
893
- message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
894
- skippedCandidates
895
- });
896
- }
897
- const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
898
- if (!preparedPath) {
899
- return remoteProjectLinkFailure({
900
- status: "invalid_root",
901
- alias,
902
- baseUrl,
903
- repoSlug,
904
- message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
905
- skippedCandidates
906
- });
907
- }
908
- return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
472
+ function readLocalConnectionFallbackToken(projectRoot) {
473
+ return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
909
474
  }
910
475
  async function ensureServerForCli(projectRoot) {
911
476
  try {
@@ -913,12 +478,12 @@ async function ensureServerForCli(projectRoot) {
913
478
  if (selected?.connection.kind === "remote") {
914
479
  reportServerPhase(`Connecting to ${selected.alias}\u2026`);
915
480
  const authToken = readGitHubBearerTokenForRemote(projectRoot);
916
- const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
481
+ const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
917
482
  return {
918
483
  baseUrl: selected.connection.baseUrl,
919
484
  authToken,
920
485
  connectionKind: "remote",
921
- serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
486
+ serverProjectRoot
922
487
  };
923
488
  }
924
489
  reportServerPhase("Starting local Rig server\u2026");
@@ -936,6 +501,29 @@ async function ensureServerForCli(projectRoot) {
936
501
  throw error;
937
502
  }
938
503
  }
504
+ async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
505
+ const repo = readRepoConnection(projectRoot);
506
+ const slug = repo?.project?.trim();
507
+ if (!slug)
508
+ return null;
509
+ try {
510
+ const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
511
+ headers: mergeHeaders(undefined, authToken)
512
+ });
513
+ if (!response.ok)
514
+ return null;
515
+ const payload = await response.json();
516
+ const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
517
+ const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
518
+ const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
519
+ const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
520
+ if (path)
521
+ writeRepoServerProjectRoot(projectRoot, path);
522
+ return path;
523
+ } catch {
524
+ return null;
525
+ }
526
+ }
939
527
  function appendTaskFilterParams(url, filters) {
940
528
  if (filters.assignee)
941
529
  url.searchParams.set("assignee", filters.assignee);
@@ -946,23 +534,10 @@ function appendTaskFilterParams(url, filters) {
946
534
  if (filters.limit !== undefined)
947
535
  url.searchParams.set("limit", String(filters.limit));
948
536
  }
949
- function mergeCookie(existing, name, value) {
950
- const encoded = `${name}=${encodeURIComponent(value)}`;
951
- if (!existing?.trim())
952
- return encoded;
953
- const parts = existing.split(";").map((part) => part.trim()).filter((part) => part && !part.startsWith(`${name}=`));
954
- return [...parts, encoded].join("; ");
955
- }
956
- function queryAuthFallbackEnabled(env = process.env) {
957
- return env.RIG_ENABLE_QUERY_AUTH_FALLBACK === "1" || env.RIG_QUERY_AUTH_FALLBACK === "1";
958
- }
959
537
  function mergeHeaders(headers, authToken) {
960
538
  const merged = new Headers(headers);
961
539
  if (authToken) {
962
- const bearer = `Bearer ${authToken}`;
963
- merged.set("authorization", bearer);
964
- merged.set("x-auth", bearer);
965
- merged.set("cookie", mergeCookie(merged.get("cookie"), "rig_auth", authToken));
540
+ merged.set("authorization", `Bearer ${authToken}`);
966
541
  }
967
542
  return merged;
968
543
  }
@@ -1023,41 +598,15 @@ async function buildServerFailureContext(projectRoot, server) {
1023
598
  hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
1024
599
  };
1025
600
  }
1026
- function isLoopbackRemoteBaseUrl(baseUrl) {
1027
- try {
1028
- const host = new URL(baseUrl).hostname.toLowerCase();
1029
- return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
1030
- } catch {
1031
- return false;
1032
- }
1033
- }
1034
- function canUseRemoteWithoutProjectRoot(pathname) {
1035
- return pathname === "/health" || pathname === "/api/health" || pathname === "/api/server/status" || pathname === "/api/server/project-root" || pathname.startsWith("/api/github/auth/") || pathname === "/api/projects" || pathname.startsWith("/api/projects/");
1036
- }
1037
601
  async function requestServerJson(context, pathname, init = {}) {
1038
602
  const server = await ensureServerForCli(context.projectRoot);
1039
- const requestUrl = new URL(`${server.baseUrl}${pathname}`);
1040
- let scopedServerProjectRoot = server.serverProjectRoot;
1041
- if (server.connectionKind === "remote" && !scopedServerProjectRoot && !canUseRemoteWithoutProjectRoot(requestUrl.pathname) && (server.authToken || !isLoopbackRemoteBaseUrl(server.baseUrl))) {
1042
- const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: server.authToken });
1043
- if (link.ok && link.serverProjectRoot) {
1044
- scopedServerProjectRoot = link.serverProjectRoot;
1045
- } else {
1046
- const repo = readRepoConnection(context.projectRoot);
1047
- const target = link.alias && link.baseUrl ? `${link.alias} (${link.baseUrl})` : server.baseUrl;
1048
- throw new CliError(`Remote server ${target} is selected for ${link.repoSlug ?? repo?.project ?? "this repo"}, but this checkout has no server-host project root link. ${link.message}`, 1, { hint: link.hint });
1049
- }
1050
- }
1051
603
  const headers = mergeHeaders(init.headers, server.authToken);
1052
- if (scopedServerProjectRoot)
1053
- headers.set("x-rig-project-root", scopedServerProjectRoot);
1054
- if (server.connectionKind === "remote" && server.authToken && queryAuthFallbackEnabled()) {
1055
- requestUrl.searchParams.set("rt", server.authToken);
1056
- }
604
+ if (server.serverProjectRoot)
605
+ headers.set("x-rig-project-root", server.serverProjectRoot);
1057
606
  reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
1058
607
  let response;
1059
608
  try {
1060
- response = await fetch(requestUrl, {
609
+ response = await fetch(`${server.baseUrl}${pathname}`, {
1061
610
  ...init,
1062
611
  headers
1063
612
  });
@@ -1261,14 +810,6 @@ function permissionAllowsPr(payload) {
1261
810
  function isNotFoundError(error) {
1262
811
  return /\b(404|not found)\b/i.test(message(error));
1263
812
  }
1264
- function isLoopbackBaseUrl(baseUrl) {
1265
- try {
1266
- const host = new URL(baseUrl).hostname.toLowerCase();
1267
- return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
1268
- } catch {
1269
- return false;
1270
- }
1271
- }
1272
813
  function projectCheckoutReady(payload) {
1273
814
  if (!payload || typeof payload !== "object" || Array.isArray(payload))
1274
815
  return null;
@@ -1322,38 +863,25 @@ async function runFastTaskRunPreflight(context, options = {}) {
1322
863
  }
1323
864
  }
1324
865
  const repo = readRepoConnection(context.projectRoot);
1325
- const remoteWithoutProjectLink = selectedServer?.connectionKind === "remote" && !repo?.project;
1326
- let remoteRootBlocked = false;
1327
- checks.push(repo ? preflightCheck("project-link", "project linked to selected server", repo.project ? "pass" : remoteWithoutProjectLink ? "fail" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : " (missing project link)"}`, remoteWithoutProjectLink ? "Run `rig server repair-link --repo owner/repo` or `rig init --repo owner/repo --server remote` to restore the remote project link." : "Run `rig init --yes --repo owner/repo` to record the GitHub repo slug.") : preflightCheck("project-link", "project linked to selected server", legacyServerCompatibility ? "warn" : "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
1328
- if (selectedServer?.connectionKind === "remote" && repo?.project && !selectedServer.serverProjectRoot) {
1329
- const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: selectedServer.authToken });
1330
- const loopbackDevRemote = !selectedServer.authToken && isLoopbackBaseUrl(selectedServer.baseUrl);
1331
- checks.push(preflightCheck("remote-project-root-link", "remote server checkout/root linked", link.ok ? "pass" : loopbackDevRemote ? "warn" : "fail", link.ok ? `${link.repoSlug} -> ${link.serverProjectRoot}` : link.message, link.ok ? undefined : loopbackDevRemote ? "Loopback development remotes may continue without x-rig-project-root; production remotes must run `rig server repair-link`." : link.hint));
1332
- remoteRootBlocked = !link.ok && !loopbackDevRemote;
1333
- }
866
+ checks.push(repo ? preflightCheck("project-link", "project linked to Rig server", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to record the GitHub repo slug.") : preflightCheck("project-link", "project linked to Rig server", legacyServerCompatibility ? "warn" : "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
1334
867
  try {
1335
868
  const auth = await request("/api/github/auth/status");
1336
869
  checks.push(isAuthenticated(auth) ? preflightCheck("github-auth", "GitHub auth valid", "pass") : preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
1337
870
  } catch (error) {
1338
871
  checks.push(preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix GitHub auth on the selected Rig server."));
1339
872
  }
1340
- if (!remoteRootBlocked) {
1341
- try {
1342
- const projection = await request("/api/workspace/task-projection");
1343
- checks.push(preflightCheck("task-projection", "task projection ready", "pass", JSON.stringify(projection).slice(0, 120)));
1344
- } catch (error) {
1345
- checks.push(preflightCheck("task-projection", "task projection ready", "warn", message(error), "Refresh task projection with `rig task list` before launching."));
1346
- }
1347
- try {
1348
- const permissions = await request("/api/github/repo/permissions");
1349
- const allowed = permissionAllowsPr(permissions);
1350
- checks.push(allowed === false ? preflightCheck("github-repo-permissions", "GitHub PR permissions", "fail", JSON.stringify(permissions).slice(0, 120), "Grant the selected GitHub token permission to push branches and open PRs.") : preflightCheck("github-repo-permissions", "GitHub PR permissions", allowed === true ? "pass" : "warn", JSON.stringify(permissions).slice(0, 120), "Confirm the selected token can push branches and open PRs."));
1351
- } catch (error) {
1352
- checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", message(error), "Ensure the selected token can push branches and open PRs."));
1353
- }
1354
- } else {
1355
- checks.push(preflightCheck("task-projection", "task projection ready", "warn", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
1356
- checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
873
+ try {
874
+ const projection = await request("/api/workspace/task-projection");
875
+ checks.push(preflightCheck("task-projection", "task projection ready", "pass", JSON.stringify(projection).slice(0, 120)));
876
+ } catch (error) {
877
+ checks.push(preflightCheck("task-projection", "task projection ready", "warn", message(error), "Refresh task projection with `rig task list` before launching."));
878
+ }
879
+ try {
880
+ const permissions = await request("/api/github/repo/permissions");
881
+ const allowed = permissionAllowsPr(permissions);
882
+ checks.push(allowed === false ? preflightCheck("github-repo-permissions", "GitHub PR permissions", "fail", JSON.stringify(permissions).slice(0, 120), "Grant the selected GitHub token permission to push branches and open PRs.") : preflightCheck("github-repo-permissions", "GitHub PR permissions", allowed === true ? "pass" : "warn", JSON.stringify(permissions).slice(0, 120), "Confirm the selected token can push branches and open PRs."));
883
+ } catch (error) {
884
+ checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", message(error), "Ensure the selected token can push branches and open PRs."));
1357
885
  }
1358
886
  if (repo?.project) {
1359
887
  try {
@@ -1365,24 +893,19 @@ async function runFastTaskRunPreflight(context, options = {}) {
1365
893
  }
1366
894
  }
1367
895
  if (taskId) {
1368
- if (!remoteRootBlocked) {
1369
- try {
1370
- const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
1371
- const found = Array.isArray(tasks) && tasks.some((task) => taskMatchesId(task, taskId));
1372
- checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
1373
- } catch (error) {
1374
- checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
1375
- }
1376
- try {
1377
- const runs = await request("/api/runs?limit=200");
1378
- const duplicate = activeDuplicateRun(runs, taskId);
1379
- checks.push(duplicate ? preflightCheck("duplicate-active-run", "one active run per task", "fail", String(duplicate.runId ?? taskId), "Attach to or stop the existing run before starting another one for this task.") : preflightCheck("duplicate-active-run", "one active run per task", "pass", taskId));
1380
- } catch (error) {
1381
- checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", message(error), "Could not list active runs; the server will still reject conflicting runs if configured."));
1382
- }
1383
- } else {
1384
- checks.push(preflightCheck("issue", "task/issue accessible", "fail", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
1385
- checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
896
+ try {
897
+ const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
898
+ const found = Array.isArray(tasks) && tasks.some((task) => taskMatchesId(task, taskId));
899
+ checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
900
+ } catch (error) {
901
+ checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
902
+ }
903
+ try {
904
+ const runs = await request("/api/runs?limit=200");
905
+ const duplicate = activeDuplicateRun(runs, taskId);
906
+ checks.push(duplicate ? preflightCheck("duplicate-active-run", "one active run per task", "fail", String(duplicate.runId ?? taskId), "Attach to or stop the existing run before starting another one for this task.") : preflightCheck("duplicate-active-run", "one active run per task", "pass", taskId));
907
+ } catch (error) {
908
+ checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", message(error), "Could not list active runs; the server will still reject conflicting runs if configured."));
1386
909
  }
1387
910
  }
1388
911
  if ((options.runtimeAdapter ?? "pi") === "pi") {
@@ -1794,19 +1317,11 @@ async function withSpinner(label, work, options = {}) {
1794
1317
  }
1795
1318
 
1796
1319
  // packages/cli/src/commands/_pi-frontend.ts
1797
- import { existsSync as existsSync3, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync3, rmSync, writeFileSync as writeFileSync3 } from "fs";
1320
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, mkdtempSync, readFileSync as readFileSync3, rmSync, writeFileSync as writeFileSync2 } from "fs";
1798
1321
  import { homedir as homedir2, tmpdir } from "os";
1799
1322
  import { join } from "path";
1800
1323
  import { main as runPiMain } from "@earendil-works/pi-coding-agent";
1801
1324
  import createPiRigExtension from "@rig/pi-rig";
1802
- var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
1803
-
1804
- class OperatorTranscriptUnavailableError extends Error {
1805
- constructor(message2) {
1806
- super(message2);
1807
- this.name = "OperatorTranscriptUnavailableError";
1808
- }
1809
- }
1810
1325
  function setTemporaryEnv(updates) {
1811
1326
  const previous = new Map;
1812
1327
  for (const [key, value] of Object.entries(updates)) {
@@ -1834,27 +1349,10 @@ function buildOperatorPiEnv(input) {
1834
1349
  ...input.serverProjectRoot ? { RIG_PROJECT_ROOT: input.serverProjectRoot } : {}
1835
1350
  };
1836
1351
  }
1837
- function shouldRequireOperatorTranscript(status) {
1838
- return typeof status === "string" && TERMINAL_RUN_STATUSES.has(status.trim().toLowerCase());
1839
- }
1840
- function missingOperatorTranscriptMessage(runId, status) {
1841
- const shortRun = runId.trim().slice(0, 8) || "unknown";
1842
- const statusText = typeof status === "string" && status.trim() ? status.trim() : "terminal";
1843
- return `Run ${shortRun} is ${statusText}, but no worker Pi session transcript is recorded for this run. It likely failed before Pi started or predates full-session capture. Use \`rig run show ${runId}\` and \`rig run logs ${runId}\` for the lifecycle details.`;
1844
- }
1845
- function statusFromRunDetails(run) {
1846
- if (!run || typeof run !== "object" || Array.isArray(run))
1847
- return;
1848
- const record = run;
1849
- if (typeof record.status === "string")
1850
- return record.status;
1851
- const nested = record.run;
1852
- return nested && typeof nested === "object" && !Array.isArray(nested) ? nested.status : undefined;
1853
- }
1854
1352
  async function prepareOperatorConsole(context, runId, tempSessionDir) {
1855
1353
  const server = await ensureServerForCli(context.projectRoot);
1856
1354
  const localCwd = join(homedir2(), ".rig", "drones", runId.slice(0, 8));
1857
- mkdirSync3(localCwd, { recursive: true });
1355
+ mkdirSync2(localCwd, { recursive: true });
1858
1356
  trustDroneCwd(localCwd);
1859
1357
  installRigPiTheme();
1860
1358
  let sessionFileArg = [];
@@ -1876,17 +1374,10 @@ async function prepareOperatorConsole(context, runId, tempSessionDir) {
1876
1374
  return line;
1877
1375
  }).join(`
1878
1376
  `);
1879
- writeFileSync3(localSessionPath, content);
1377
+ writeFileSync2(localSessionPath, content);
1880
1378
  sessionFileArg = ["--session", localSessionPath];
1881
1379
  }
1882
1380
  } catch {}
1883
- if (sessionFileArg.length === 0) {
1884
- const run = await getRunDetailsViaServer(context, runId).catch(() => null);
1885
- const status = statusFromRunDetails(run);
1886
- if (shouldRequireOperatorTranscript(status)) {
1887
- throw new OperatorTranscriptUnavailableError(missingOperatorTranscriptMessage(runId, status));
1888
- }
1889
- }
1890
1381
  return { server, sessionFileArg };
1891
1382
  }
1892
1383
  var RIG_PI_THEME = {
@@ -1966,12 +1457,12 @@ var RIG_PI_THEME = {
1966
1457
  function trustDroneCwd(localCwd) {
1967
1458
  try {
1968
1459
  const agentDir = join(homedir2(), ".pi", "agent");
1969
- mkdirSync3(agentDir, { recursive: true });
1460
+ mkdirSync2(agentDir, { recursive: true });
1970
1461
  const trustPath = join(agentDir, "trust.json");
1971
1462
  const store = existsSync3(trustPath) ? JSON.parse(readFileSync3(trustPath, "utf8")) : {};
1972
1463
  if (store[localCwd] !== true) {
1973
1464
  store[localCwd] = true;
1974
- writeFileSync3(trustPath, `${JSON.stringify(store, null, "\t")}
1465
+ writeFileSync2(trustPath, `${JSON.stringify(store, null, "\t")}
1975
1466
  `);
1976
1467
  }
1977
1468
  } catch {}
@@ -1979,38 +1470,15 @@ function trustDroneCwd(localCwd) {
1979
1470
  function installRigPiTheme() {
1980
1471
  try {
1981
1472
  const themesDir = join(homedir2(), ".pi", "agent", "themes");
1982
- mkdirSync3(themesDir, { recursive: true });
1473
+ mkdirSync2(themesDir, { recursive: true });
1983
1474
  const themePath = join(themesDir, "rig.json");
1984
1475
  const next = `${JSON.stringify(RIG_PI_THEME, null, "\t")}
1985
1476
  `;
1986
1477
  if (!existsSync3(themePath) || readFileSync3(themePath, "utf8") !== next) {
1987
- writeFileSync3(themePath, next);
1478
+ writeFileSync2(themePath, next);
1988
1479
  }
1989
1480
  } catch {}
1990
1481
  }
1991
- async function runWithProcessExitGuard(body) {
1992
- const realExit = process.exit;
1993
- let exitCode = 0;
1994
- let signalQuit = () => {};
1995
- const quit = new Promise((resolve3) => {
1996
- signalQuit = resolve3;
1997
- });
1998
- const guardedExit = (code) => {
1999
- exitCode = typeof code === "number" ? code : 0;
2000
- signalQuit();
2001
- return;
2002
- };
2003
- process.exit = guardedExit;
2004
- try {
2005
- await Promise.race([Promise.resolve().then(body), quit]);
2006
- } finally {
2007
- process.exit = realExit;
2008
- }
2009
- return exitCode;
2010
- }
2011
- function runPiMainReturningOnQuit(args, options) {
2012
- return runWithProcessExitGuard(() => runPiMain(args, options));
2013
- }
2014
1482
  async function attachRunBundledPiFrontend(context, input) {
2015
1483
  const tempSessionDir = mkdtempSync(join(tmpdir(), "rig-pi-frontend-sessions-"));
2016
1484
  const { server, sessionFileArg } = await withSpinner(`Opening Pi console for run ${input.runId}\u2026`, () => prepareOperatorConsole(context, input.runId, tempSessionDir), { outputMode: context.outputMode });
@@ -2026,20 +1494,15 @@ async function attachRunBundledPiFrontend(context, input) {
2026
1494
  };
2027
1495
  let detached = false;
2028
1496
  try {
2029
- const piArgs = [
2030
- "--offline",
1497
+ await runPiMain([
2031
1498
  "--no-extensions",
2032
1499
  "--no-skills",
2033
1500
  "--no-prompt-templates",
2034
1501
  "--no-context-files",
2035
1502
  ...sessionFileArg
2036
- ];
2037
- const piOptions = { extensionFactories: [piRigExtensionFactory] };
2038
- if (input.returnOnQuit) {
2039
- await runPiMainReturningOnQuit(piArgs, piOptions);
2040
- } else {
2041
- await runPiMain(piArgs, piOptions);
2042
- }
1503
+ ], {
1504
+ extensionFactories: [piRigExtensionFactory]
1505
+ });
2043
1506
  detached = true;
2044
1507
  } finally {
2045
1508
  restoreEnv();
@@ -2061,7 +1524,7 @@ async function attachRunBundledPiFrontend(context, input) {
2061
1524
  }
2062
1525
 
2063
1526
  // packages/cli/src/commands/_operator-view.ts
2064
- var TERMINAL_RUN_STATUSES2 = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
1527
+ var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
2065
1528
  function runStatusFromPayload(payload) {
2066
1529
  const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
2067
1530
  return String(run.status ?? "unknown").toLowerCase();
@@ -2139,7 +1602,7 @@ async function attachRunOperatorView(context, input) {
2139
1602
  }
2140
1603
  const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
2141
1604
  let timelineCursor = snapshot.timelineCursor;
2142
- while (!detached && !TERMINAL_RUN_STATUSES2.has(runStatusFromPayload(snapshot.run))) {
1605
+ while (!detached && !TERMINAL_RUN_STATUSES.has(runStatusFromPayload(snapshot.run))) {
2143
1606
  await Bun.sleep(pollMs);
2144
1607
  snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
2145
1608
  timelineCursor = snapshot.timelineCursor;
@@ -2422,13 +1885,12 @@ var PRIMARY_GROUPS = [
2422
1885
  {
2423
1886
  name: "server",
2424
1887
  summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
2425
- usage: ["rig server <status|list|add|use|repair-link|start> [options]"],
1888
+ usage: ["rig server <status|list|add|use|start> [options]"],
2426
1889
  commands: [
2427
- { command: "status", description: "Show the selected server and remote project-root link for this repo.", primary: true },
1890
+ { command: "status", description: "Show the selected server for this repo.", primary: true },
2428
1891
  { command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
2429
1892
  { command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
2430
1893
  { command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
2431
- { command: "repair-link [--prepare|--backfill-only] [--repo owner/repo]", description: "Backfill or prepare the selected remote's server-host checkout link.", primary: true },
2432
1894
  { command: "list", description: "List saved local/remote server aliases.", primary: true },
2433
1895
  { command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
2434
1896
  ],
@@ -2436,7 +1898,6 @@ var PRIMARY_GROUPS = [
2436
1898
  "rig server status",
2437
1899
  "rig server add prod https://where.rig-does.work",
2438
1900
  "rig server use prod",
2439
- "rig server repair-link --repo owner/repo",
2440
1901
  "rig server use local",
2441
1902
  "rig server start --port 3773"
2442
1903
  ],
@@ -2611,62 +2072,30 @@ var PRIMARY_GROUPS = [
2611
2072
  }
2612
2073
  ];
2613
2074
  var ADVANCED_GROUPS = [
2614
- {
2615
- name: "setup",
2616
- summary: "Bootstrap/check local setup.",
2617
- usage: ["rig setup <bootstrap|check|preflight>"],
2618
- commands: [
2619
- { command: "bootstrap", description: "Bootstrap local setup dependencies.", primary: true },
2620
- { command: "check", description: "Check local setup state (toolchain, deps, config).", primary: true },
2621
- { command: "preflight", description: "Run preflight checks before a run.", primary: true }
2622
- ]
2623
- },
2624
- {
2625
- name: "profile",
2626
- summary: "Runtime profile/model defaults.",
2627
- usage: ["rig profile <show|set>"],
2628
- commands: [
2629
- { command: "show", description: "Show the active execution profile.", primary: true },
2630
- { command: "set [--model <model>] [--runtime <runtime>] [--plugin <plugin>]", description: "Set model/runtime/plugin profile defaults.", primary: true }
2631
- ]
2632
- },
2075
+ { name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
2076
+ { name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
2633
2077
  {
2634
2078
  name: "review",
2635
2079
  summary: "Inspect or change completion review gate policy.",
2636
2080
  usage: ["rig review <show|set>"],
2637
2081
  commands: [
2638
2082
  { command: "show", description: "Show current review gate settings." },
2639
- { command: "set <off|advisory|required> [--provider <provider>]", description: "Change review strictness/provider (e.g. --provider greptile)." }
2083
+ { command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider." }
2640
2084
  ],
2641
2085
  examples: ["rig review show", "rig review set required --provider greptile"],
2642
2086
  next: ["Use `rig inbox approvals` for blocked run handoffs."]
2643
2087
  },
2644
2088
  {
2645
2089
  name: "browser",
2646
- summary: "Browser workstation actions for browser-required tasks: launch, check, CDP probe, profile reset, and app-specific smokes.",
2647
- usage: ["rig browser <help|explain|demo|hp-next|cdp-probe|profile-persistence|profile-lock-check|smoke-test> [options]"],
2090
+ summary: "Browser/app diagnostics for browser-required tasks.",
2091
+ usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
2648
2092
  commands: [
2649
- { command: "help", description: "Rich browser command help (canonical: `rig browser help`).", primary: true },
2650
- { command: "explain", description: "Explain the browser-required task contract and runtime helper commands.", primary: true },
2651
- { command: "demo [--port <n>] [--profile <name>] [--state-dir <path>] [--target-url <url>] [--keep-open] [--no-build]", description: "Run a guided real browser/agent demo flow.", primary: true },
2652
- { command: "hp-next dev", description: "Start hp-next Rig Browser in dev/watch mode.", primary: true },
2653
- { command: "hp-next start", description: "Build/start the hp-next browser workstation without watch mode.", primary: true },
2654
- { command: "hp-next check", description: "Validate the hp-next CDP endpoint on the configured port.", primary: true },
2655
- { command: "hp-next e2e", description: "Run hp-next browser e2e smoke checks through Rig Browser.", primary: true },
2656
- { command: "hp-next reset", description: "Reset the hp-next browser profile when stale browser state is suspected.", primary: true },
2657
- { command: "cdp-probe", description: "Run an isolated CDP attach/evaluate/layout probe." },
2658
- { command: "profile-persistence", description: "Verify a named browser profile persists browser state." },
2659
- { command: "profile-lock-check", description: "Verify concurrent launches reject the same profile." },
2660
- { command: "smoke-test", description: "Run the browser package smoke test." }
2661
- ],
2662
- examples: [
2663
- "rig browser help",
2664
- "rig browser hp-next check",
2665
- "rig browser hp-next e2e",
2666
- "rig browser cdp-probe",
2667
- "rig browser profile-lock-check"
2668
- ],
2669
- next: ["Inside a task run, use rig-browser-launch, rig-browser-check, and rig-browser-attach-info from the worker PATH."]
2093
+ { command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
2094
+ { command: "explain", description: "Explain the browser-required task contract." },
2095
+ { command: "demo", description: "Run browser demo flows against a local page." },
2096
+ { command: "app", description: "Launch the Rig Browser workstation app." },
2097
+ { command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
2098
+ ]
2670
2099
  },
2671
2100
  {
2672
2101
  name: "pi",
@@ -2681,60 +2110,12 @@ var ADVANCED_GROUPS = [
2681
2110
  examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
2682
2111
  next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
2683
2112
  },
2684
- {
2685
- name: "queue",
2686
- summary: "Run task queues locally.",
2687
- usage: ["rig queue run [--workers <n>] [--max-tasks <n>] [--action validate|verify|pipeline] [--isolation off|worktree] [--no-runtime-reuse] [--fail-fast] [--skip-project-sync]"],
2688
- commands: [
2689
- { command: "run [--workers <n>] [--max-tasks <n>] [--action validate|verify|pipeline] [--isolation off|worktree] [--no-runtime-reuse] [--fail-fast] [--skip-project-sync]", description: "Process queue work: drain matching tasks with N workers, optional per-task action and isolation.", primary: true }
2690
- ]
2691
- },
2692
- {
2693
- name: "agent",
2694
- summary: "Runtime agent workspace helpers.",
2695
- usage: ["rig agent <list|prepare|run|cleanup>"],
2696
- commands: [
2697
- { command: "list", description: "List prepared agent runtimes.", primary: true },
2698
- { command: "prepare [--id <id>] [--mode <mode>] [--task <task>]", description: "Prepare an isolated agent runtime workspace.", primary: true },
2699
- { command: "run [--id <id>] [--mode <mode>] [--task <task>] [--skip-project-sync]", description: "Prepare (if needed) and run an agent in its workspace.", primary: true },
2700
- { command: "cleanup [--all] [--id <id>]", description: "Remove prepared agent workspaces.", primary: true }
2701
- ]
2702
- },
2113
+ { name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
2114
+ { name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
2703
2115
  { name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
2704
- {
2705
- name: "dist",
2706
- summary: "Build/install packaged Rig CLI.",
2707
- usage: ["rig dist <build|install|doctor|rebuild-agent>"],
2708
- commands: [
2709
- { command: "build [--output-dir <dir>]", description: "Build the distributable Rig CLI.", primary: true },
2710
- { command: "install [--scope <scope>] [--path <path>]", description: "Install the built CLI to a scope/path.", primary: true },
2711
- { command: "doctor", description: "Diagnose the dist toolchain and install state.", primary: true },
2712
- { command: "rebuild-agent", description: "Rebuild the agent runtime image, pruning stale images.", primary: true }
2713
- ]
2714
- },
2116
+ { name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
2715
2117
  { name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
2716
- {
2717
- name: "remote",
2718
- summary: "Compatibility remote orchestration controls.",
2719
- usage: ["rig remote <status|tasks|watch|pause|resume|continue|stop|refresh|add-iterations|remove-iterations|endpoint ...>"],
2720
- commands: [
2721
- { command: "status [--remote <alias>]", description: "Show the remote orchestration state.", primary: true },
2722
- { command: "tasks [--remote <alias>]", description: "List the remote's tracked tasks.", primary: true },
2723
- { command: "watch [--remote <alias>] [--seconds <n>] [--event <type>]", description: "Stream remote orchestration events.", primary: true },
2724
- { command: "pause [--remote <alias>]", description: "Pause the running remote orchestration.", primary: true },
2725
- { command: "resume [--remote <alias>] [--max-workers <n>] [--max-iterations <n>] [--direct-merge]", description: "Resume the remote with optional tuning.", primary: true },
2726
- { command: "continue [--remote <alias>]", description: "Continue a paused remote orchestration.", primary: true },
2727
- { command: "stop [--remote <alias>]", description: "Stop the remote orchestration.", primary: true },
2728
- { command: "refresh [--remote <alias>]", description: "Refresh remote state.", primary: true },
2729
- { command: "add-iterations [--count <n>] [--remote <alias>]", description: "Grant the remote more iterations.", primary: true },
2730
- { command: "remove-iterations [--count <n>] [--remote <alias>]", description: "Reduce the remote's iteration budget.", primary: true },
2731
- { command: "endpoint list", description: "List configured remote endpoints.", primary: true },
2732
- { command: "endpoint add --alias <alias> --host <host> --port <n> [--token <token>]", description: "Register a remote endpoint.", primary: true },
2733
- { command: "endpoint remove --alias <alias>", description: "Remove a remote endpoint.", primary: true },
2734
- { command: "endpoint test [--alias <alias>]", description: "Test connectivity to a remote endpoint.", primary: true },
2735
- { command: "endpoint doctor", description: "Diagnose remote endpoint configuration.", primary: true }
2736
- ]
2737
- },
2118
+ { name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
2738
2119
  { name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
2739
2120
  { name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
2740
2121
  { name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }