@h-rig/cli 0.0.6-alpha.9 → 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 (114) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/build-rig-binaries.d.ts +2 -0
  3. package/dist/bin/rig.d.ts +2 -0
  4. package/dist/bin/rig.js +11052 -6668
  5. package/dist/src/app/board.d.ts +23 -0
  6. package/dist/src/app/board.js +1786 -0
  7. package/dist/src/app/drone-ui.d.ts +37 -0
  8. package/dist/src/app/drone-ui.js +294 -0
  9. package/dist/src/app/theme.d.ts +47 -0
  10. package/dist/src/app/theme.js +150 -0
  11. package/dist/src/commands/_async-ui.d.ts +13 -0
  12. package/dist/src/commands/_async-ui.js +223 -0
  13. package/dist/src/commands/_authority-runs.d.ts +22 -0
  14. package/dist/src/commands/_authority-runs.js +2 -3
  15. package/dist/src/commands/_cli-format.d.ts +49 -0
  16. package/dist/src/commands/_cli-format.js +447 -0
  17. package/dist/src/commands/_connection-state.d.ts +44 -0
  18. package/dist/src/commands/_connection-state.js +30 -11
  19. package/dist/src/commands/_doctor-checks.d.ts +52 -0
  20. package/dist/src/commands/_doctor-checks.js +180 -44
  21. package/dist/src/commands/_help-catalog.d.ts +51 -0
  22. package/dist/src/commands/_help-catalog.js +442 -0
  23. package/dist/src/commands/_json-output.d.ts +11 -0
  24. package/dist/src/commands/_json-output.js +56 -0
  25. package/dist/src/commands/_operator-surface.d.ts +34 -0
  26. package/dist/src/commands/_operator-surface.js +220 -0
  27. package/dist/src/commands/_operator-view.d.ts +30 -0
  28. package/dist/src/commands/_operator-view.js +803 -73
  29. package/dist/src/commands/_parsers.d.ts +15 -0
  30. package/dist/src/commands/_parsers.js +18 -11
  31. package/dist/src/commands/_paths.d.ts +11 -0
  32. package/dist/src/commands/_pi-frontend.d.ts +27 -0
  33. package/dist/src/commands/_pi-frontend.js +742 -0
  34. package/dist/src/commands/_pi-install.d.ts +42 -0
  35. package/dist/src/commands/_pi-install.js +5 -4
  36. package/dist/src/commands/_policy.d.ts +8 -0
  37. package/dist/src/commands/_policy.js +12 -5
  38. package/dist/src/commands/_preflight.d.ts +22 -0
  39. package/dist/src/commands/_preflight.js +190 -128
  40. package/dist/src/commands/_probes.d.ts +1 -0
  41. package/dist/src/commands/_run-driver-helpers.d.ts +99 -0
  42. package/dist/src/commands/_run-driver-helpers.js +75 -22
  43. package/dist/src/commands/_run-replay.d.ts +24 -0
  44. package/dist/src/commands/_run-replay.js +142 -0
  45. package/dist/src/commands/_server-client.d.ts +186 -0
  46. package/dist/src/commands/_server-client.js +360 -61
  47. package/dist/src/commands/_snapshot-upload.d.ts +39 -0
  48. package/dist/src/commands/_snapshot-upload.js +163 -39
  49. package/dist/src/commands/_spinner.d.ts +25 -0
  50. package/dist/src/commands/_spinner.js +65 -0
  51. package/dist/src/commands/_task-picker.d.ts +9 -0
  52. package/dist/src/commands/_task-picker.js +172 -19
  53. package/dist/src/commands/agent.d.ts +3 -0
  54. package/dist/src/commands/agent.js +39 -20
  55. package/dist/src/commands/browser.d.ts +65 -0
  56. package/dist/src/commands/browser.js +334 -51
  57. package/dist/src/commands/connect.d.ts +7 -0
  58. package/dist/src/commands/connect.js +272 -33
  59. package/dist/src/commands/dist.d.ts +28 -0
  60. package/dist/src/commands/dist.js +19 -12
  61. package/dist/src/commands/doctor.d.ts +3 -0
  62. package/dist/src/commands/doctor.js +378 -45
  63. package/dist/src/commands/github.d.ts +3 -0
  64. package/dist/src/commands/github.js +375 -53
  65. package/dist/src/commands/inbox.d.ts +30 -0
  66. package/dist/src/commands/inbox.js +760 -70
  67. package/dist/src/commands/init.d.ts +74 -0
  68. package/dist/src/commands/init.js +963 -119
  69. package/dist/src/commands/inspect.d.ts +3 -0
  70. package/dist/src/commands/inspect.js +588 -32
  71. package/dist/src/commands/inspector.d.ts +3 -0
  72. package/dist/src/commands/inspector.js +20 -13
  73. package/dist/src/commands/pi.d.ts +3 -0
  74. package/dist/src/commands/pi.js +177 -0
  75. package/dist/src/commands/plugin.d.ts +16 -0
  76. package/dist/src/commands/plugin.js +95 -27
  77. package/dist/src/commands/profile-and-review.d.ts +4 -0
  78. package/dist/src/commands/profile-and-review.js +26 -19
  79. package/dist/src/commands/queue.d.ts +3 -0
  80. package/dist/src/commands/queue.js +32 -12
  81. package/dist/src/commands/remote.d.ts +3 -0
  82. package/dist/src/commands/remote.js +43 -36
  83. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  84. package/dist/src/commands/repo-git-harness.js +22 -15
  85. package/dist/src/commands/run.d.ts +3 -0
  86. package/dist/src/commands/run.js +1379 -159
  87. package/dist/src/commands/server.d.ts +7 -0
  88. package/dist/src/commands/server.js +502 -57
  89. package/dist/src/commands/setup.d.ts +16 -0
  90. package/dist/src/commands/setup.js +390 -63
  91. package/dist/src/commands/stats.d.ts +12 -0
  92. package/dist/src/commands/stats.js +1051 -0
  93. package/dist/src/commands/task-report-bug.d.ts +19 -0
  94. package/dist/src/commands/task-report-bug.js +260 -62
  95. package/dist/src/commands/task-run-driver.d.ts +132 -0
  96. package/dist/src/commands/task-run-driver.js +886 -130
  97. package/dist/src/commands/task.d.ts +14 -0
  98. package/dist/src/commands/task.js +1644 -314
  99. package/dist/src/commands/test.d.ts +3 -0
  100. package/dist/src/commands/test.js +15 -8
  101. package/dist/src/commands/workspace.d.ts +3 -0
  102. package/dist/src/commands/workspace.js +18 -11
  103. package/dist/src/commands.d.ts +29 -0
  104. package/dist/src/commands.js +10967 -6637
  105. package/dist/src/index.d.ts +4 -0
  106. package/dist/src/index.js +10168 -5787
  107. package/dist/src/launcher.d.ts +61 -0
  108. package/dist/src/launcher.js +77 -13
  109. package/dist/src/report-bug.d.ts +44 -0
  110. package/dist/src/report-bug.js +3 -3
  111. package/dist/src/runner.d.ts +47 -0
  112. package/dist/src/runner.js +16 -22
  113. package/dist/src/withMutedConsole.d.ts +2 -0
  114. package/package.json +13 -6
@@ -7,12 +7,19 @@ import { resolve as resolve6 } from "path";
7
7
 
8
8
  // packages/cli/src/runner.ts
9
9
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
10
- import { CliError } from "@rig/runtime/control-plane/errors";
10
+ import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
11
11
  import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
12
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
13
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
14
12
  import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
15
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
13
+
14
+ class CliError extends RuntimeCliError {
15
+ hint;
16
+ constructor(message, exitCode = 1, options = {}) {
17
+ super(message, exitCode);
18
+ if (options.hint?.trim()) {
19
+ this.hint = options.hint.trim();
20
+ }
21
+ }
22
+ }
16
23
  function requireNoExtraArgs(args, usage) {
17
24
  if (args.length > 0) {
18
25
  throw new CliError(`Unexpected arguments: ${args.join(" ")}
@@ -102,7 +109,8 @@ function resolveControlPlaneDefinitionRoot(projectRoot) {
102
109
  import { existsSync, readFileSync, rmSync } from "fs";
103
110
  import { homedir } from "os";
104
111
  import { resolve as resolve2 } from "path";
105
- var PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
112
+ var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
113
+ var LEGACY_PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
106
114
  async function defaultCommandRunner(command, options = {}) {
107
115
  const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
108
116
  const [stdout, stderr, exitCode] = await Promise.all([
@@ -121,7 +129,7 @@ function resolvePiHomeDir(inputHomeDir) {
121
129
  function piListContainsPiRig(output) {
122
130
  return output.split(/\r?\n/).some((line) => {
123
131
  const normalized = line.trim();
124
- return normalized.includes(PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
132
+ return normalized.includes(PI_RIG_PACKAGE_NAME) || normalized.includes(LEGACY_PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
125
133
  });
126
134
  }
127
135
  async function safeRun(runner, command, options) {
@@ -197,9 +205,14 @@ function readJsonFile(path) {
197
205
  try {
198
206
  return JSON.parse(readFileSync2(path, "utf8"));
199
207
  } catch (error) {
200
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
208
+ throw new CliError(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1, { hint: "Fix or delete that file, then re-select a server with `rig server use <alias|local>`." });
201
209
  }
202
210
  }
211
+ function writeJsonFile(path, value) {
212
+ mkdirSync(dirname(path), { recursive: true });
213
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
214
+ `, "utf8");
215
+ }
203
216
  function normalizeConnection(value) {
204
217
  if (!value || typeof value !== "object" || Array.isArray(value))
205
218
  return null;
@@ -240,29 +253,47 @@ function readRepoConnection(projectRoot) {
240
253
  return {
241
254
  selected,
242
255
  project: typeof record.project === "string" ? record.project : undefined,
243
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
256
+ linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
257
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
244
258
  };
245
259
  }
260
+ function writeRepoConnection(projectRoot, state) {
261
+ writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
262
+ }
246
263
  function resolveSelectedConnection(projectRoot, options = {}) {
247
264
  const repo = readRepoConnection(projectRoot);
248
265
  if (!repo)
249
266
  return null;
250
267
  if (repo.selected === "local")
251
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
268
+ return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
252
269
  const global = readGlobalConnections(options);
253
270
  const connection = global.connections[repo.selected];
254
271
  if (!connection) {
255
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
272
+ throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
256
273
  }
257
- return { alias: repo.selected, connection };
274
+ return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
275
+ }
276
+ function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
277
+ const repo = readRepoConnection(projectRoot);
278
+ if (!repo)
279
+ return;
280
+ writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
258
281
  }
259
282
 
260
283
  // packages/cli/src/commands/_server-client.ts
261
- import { spawnSync } from "child_process";
262
284
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
263
285
  import { resolve as resolve4 } from "path";
264
286
  import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
265
- var cachedGitHubBearerToken;
287
+ var scopedGitHubBearerTokens = new Map;
288
+ var serverPhaseListener = null;
289
+ function setServerPhaseListener(listener) {
290
+ const previous = serverPhaseListener;
291
+ serverPhaseListener = listener;
292
+ return previous;
293
+ }
294
+ function reportServerPhase(label) {
295
+ serverPhaseListener?.(label);
296
+ }
266
297
  function cleanToken(value) {
267
298
  const trimmed = value?.trim();
268
299
  return trimmed ? trimmed : null;
@@ -279,49 +310,80 @@ function readPrivateRemoteSessionToken(projectRoot) {
279
310
  }
280
311
  }
281
312
  function readGitHubBearerTokenForRemote(projectRoot) {
282
- if (cachedGitHubBearerToken !== undefined)
283
- return cachedGitHubBearerToken;
313
+ const scopedKey = resolve4(projectRoot);
314
+ if (scopedGitHubBearerTokens.has(scopedKey))
315
+ return scopedGitHubBearerTokens.get(scopedKey) ?? null;
284
316
  const privateSession = readPrivateRemoteSessionToken(projectRoot);
285
- if (privateSession) {
286
- cachedGitHubBearerToken = privateSession;
287
- return cachedGitHubBearerToken;
288
- }
289
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
290
- if (envToken) {
291
- cachedGitHubBearerToken = envToken;
292
- return cachedGitHubBearerToken;
293
- }
294
- const result = spawnSync("gh", ["auth", "token"], {
295
- encoding: "utf8",
296
- timeout: 5000,
297
- stdio: ["ignore", "pipe", "ignore"]
298
- });
299
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
300
- return cachedGitHubBearerToken;
317
+ if (privateSession)
318
+ return privateSession;
319
+ return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
320
+ }
321
+ function readStoredGitHubAuthToken(projectRoot) {
322
+ const path = resolve4(projectRoot, ".rig", "state", "github-auth.json");
323
+ if (!existsSync3(path))
324
+ return null;
325
+ try {
326
+ const parsed = JSON.parse(readFileSync3(path, "utf8"));
327
+ return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
328
+ } catch {
329
+ return null;
330
+ }
331
+ }
332
+ function readLocalConnectionFallbackToken(projectRoot) {
333
+ return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
301
334
  }
302
335
  async function ensureServerForCli(projectRoot) {
303
336
  try {
304
337
  const selected = resolveSelectedConnection(projectRoot);
305
338
  if (selected?.connection.kind === "remote") {
339
+ reportServerPhase(`Connecting to ${selected.alias}\u2026`);
340
+ const authToken = readGitHubBearerTokenForRemote(projectRoot);
341
+ const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
306
342
  return {
307
343
  baseUrl: selected.connection.baseUrl,
308
- authToken: readGitHubBearerTokenForRemote(projectRoot),
309
- connectionKind: "remote"
344
+ authToken,
345
+ connectionKind: "remote",
346
+ serverProjectRoot
310
347
  };
311
348
  }
349
+ reportServerPhase("Starting local Rig server\u2026");
312
350
  const connection = await ensureLocalRigServerConnection(projectRoot);
313
351
  return {
314
352
  baseUrl: connection.baseUrl,
315
- authToken: connection.authToken,
316
- connectionKind: "local"
353
+ authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
354
+ connectionKind: "local",
355
+ serverProjectRoot: resolve4(projectRoot)
317
356
  };
318
357
  } catch (error) {
319
358
  if (error instanceof Error) {
320
- throw new CliError2(error.message, 1);
359
+ throw new CliError(error.message, 1);
321
360
  }
322
361
  throw error;
323
362
  }
324
363
  }
364
+ async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
365
+ const repo = readRepoConnection(projectRoot);
366
+ const slug = repo?.project?.trim();
367
+ if (!slug)
368
+ return null;
369
+ try {
370
+ const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
371
+ headers: mergeHeaders(undefined, authToken)
372
+ });
373
+ if (!response.ok)
374
+ return null;
375
+ const payload = await response.json();
376
+ const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
377
+ const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
378
+ const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
379
+ const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
380
+ if (path)
381
+ writeRepoServerProjectRoot(projectRoot, path);
382
+ return path;
383
+ } catch {
384
+ return null;
385
+ }
386
+ }
325
387
  function mergeHeaders(headers, authToken) {
326
388
  const merged = new Headers(headers);
327
389
  if (authToken) {
@@ -344,12 +406,65 @@ function diagnosticMessage(payload) {
344
406
  });
345
407
  return messages.length > 0 ? messages.join("; ") : null;
346
408
  }
409
+ var serverReachabilityCache = new Map;
410
+ async function probeServerReachability(baseUrl, authToken) {
411
+ try {
412
+ const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
413
+ headers: mergeHeaders(undefined, authToken),
414
+ signal: AbortSignal.timeout(1500)
415
+ });
416
+ return response.ok;
417
+ } catch {
418
+ return false;
419
+ }
420
+ }
421
+ function cachedServerReachability(projectRoot, baseUrl, authToken) {
422
+ const key = resolve4(projectRoot);
423
+ const cached = serverReachabilityCache.get(key);
424
+ if (cached)
425
+ return cached;
426
+ const probe = probeServerReachability(baseUrl, authToken);
427
+ serverReachabilityCache.set(key, probe);
428
+ return probe;
429
+ }
430
+ function describeSelectedServer(projectRoot, server) {
431
+ try {
432
+ const selected = resolveSelectedConnection(projectRoot);
433
+ if (selected) {
434
+ return {
435
+ alias: selected.alias,
436
+ target: selected.connection.kind === "remote" ? selected.connection.baseUrl : server.baseUrl
437
+ };
438
+ }
439
+ } catch {}
440
+ return { alias: server.connectionKind === "remote" ? "remote" : "local", target: server.baseUrl };
441
+ }
442
+ async function buildServerFailureContext(projectRoot, server) {
443
+ const { alias, target } = describeSelectedServer(projectRoot, server);
444
+ const reachable = await cachedServerReachability(projectRoot, server.baseUrl, server.authToken);
445
+ const reachability = reachable ? "server is reachable" : "server is unreachable";
446
+ return {
447
+ contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
448
+ hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
449
+ };
450
+ }
347
451
  async function requestServerJson(context, pathname, init = {}) {
348
452
  const server = await ensureServerForCli(context.projectRoot);
349
- const response = await fetch(`${server.baseUrl}${pathname}`, {
350
- ...init,
351
- headers: mergeHeaders(init.headers, server.authToken)
352
- });
453
+ const headers = mergeHeaders(init.headers, server.authToken);
454
+ if (server.serverProjectRoot)
455
+ headers.set("x-rig-project-root", server.serverProjectRoot);
456
+ reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
457
+ let response;
458
+ try {
459
+ response = await fetch(`${server.baseUrl}${pathname}`, {
460
+ ...init,
461
+ headers
462
+ });
463
+ } catch (error) {
464
+ const failure = await buildServerFailureContext(context.projectRoot, server);
465
+ throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
466
+ ${failure.contextLine}`, 1, { hint: failure.hint });
467
+ }
353
468
  const text = await response.text();
354
469
  const payload = text.trim().length > 0 ? (() => {
355
470
  try {
@@ -360,11 +475,26 @@ async function requestServerJson(context, pathname, init = {}) {
360
475
  })() : null;
361
476
  if (!response.ok) {
362
477
  const diagnostics = diagnosticMessage(payload);
363
- const detail = diagnostics ?? (text || response.statusText);
364
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
478
+ const rawDetail = diagnostics ?? (text || response.statusText);
479
+ const detail = diagnostics ? rawDetail : rawDetail.split(`
480
+ `).map((line) => line.trim()).find((line) => line.length > 0)?.slice(0, 200) ?? response.statusText;
481
+ const failure = await buildServerFailureContext(context.projectRoot, server);
482
+ throw new CliError(`Rig server request failed (${response.status}): ${detail}
483
+ ${failure.contextLine}`, 1, { hint: failure.hint });
365
484
  }
366
485
  return payload;
367
486
  }
487
+ var RESUMABLE_RUN_STATUSES = new Set([
488
+ "created",
489
+ "preparing",
490
+ "running",
491
+ "validating",
492
+ "reviewing",
493
+ "stopped",
494
+ "failed",
495
+ "needs-attention",
496
+ "needs_attention"
497
+ ]);
368
498
 
369
499
  // packages/cli/src/commands/_doctor-checks.ts
370
500
  function check(id, label, status, detail, remediation) {
@@ -485,7 +615,10 @@ async function runRigDoctorChecks(options) {
485
615
  const bunVersion = options.bunVersion ?? Bun.version;
486
616
  const request = options.requestJson ?? ((pathname, init) => requestServerJson({ projectRoot }, pathname, init));
487
617
  const loadConfig = options.loadConfig ?? loadRigConfigOrNull;
618
+ const progress = options.onProgress ?? (() => {});
619
+ progress("Checking local toolchain\u2026");
488
620
  checks.push(check("bun", `bun >= ${MIN_SUPPORTED_BUN_VERSION}`, isSupportedBunVersion(bunVersion) ? "pass" : "fail", `found ${bunVersion}`, `Install Bun ${MIN_SUPPORTED_BUN_VERSION} or newer.`), check("git", "git", which("git") ? "pass" : "fail", which("git") ?? undefined, "Install git and ensure it is on PATH."), check("jq", "jq", which("jq") ? "pass" : "warn", which("jq") ?? undefined, "Install jq (for example `brew install jq`)."));
621
+ progress("Loading rig.config\u2026");
489
622
  const loadedConfig = await loadConfig(projectRoot).catch(() => null);
490
623
  const config = loadedConfig ?? loadFallbackConfig(projectRoot);
491
624
  const hasConfigFile = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync4(resolve5(projectRoot, name)));
@@ -493,7 +626,7 @@ async function runRigDoctorChecks(options) {
493
626
  const taskSourceKind = config?.taskSource?.kind;
494
627
  checks.push(taskSourceKind ? check("task-source", "task source configured", "pass", taskSourceKind) : check("task-source", "task source configured", "fail", "missing taskSource", "Configure taskSource in rig.config.ts."));
495
628
  const repo = readRepoConnection(projectRoot);
496
- checks.push(repo ? check("project-link", "repo selected Rig connection", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to link this checkout to a GitHub repo slug.") : check("project-link", "repo selected Rig connection", "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig connect use <alias|local>`."));
629
+ checks.push(repo ? check("project-link", "repo selected Rig server", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to link this checkout to a GitHub repo slug.") : check("project-link", "repo selected Rig server", "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
497
630
  const selected = (() => {
498
631
  try {
499
632
  return resolveSelectedConnection(projectRoot);
@@ -501,9 +634,10 @@ async function runRigDoctorChecks(options) {
501
634
  return null;
502
635
  }
503
636
  })();
504
- checks.push(selected ? check("connection", "selected server connection", "pass", selected.connection.kind === "remote" ? selected.connection.baseUrl : "local auto") : check("connection", "selected server connection", repo ? "fail" : "warn", repo ? "selected alias is missing" : "will auto-start local server", repo ? "Run `rig connect list` and `rig connect use <alias|local>`." : undefined));
637
+ checks.push(selected ? check("connection", "selected server connection", "pass", selected.connection.kind === "remote" ? selected.connection.baseUrl : "local auto") : check("connection", "selected server", repo ? "fail" : "warn", repo ? "selected alias is missing" : "will auto-start local server", repo ? "Run `rig server list` and `rig server use <alias|local>`." : undefined));
505
638
  let server = null;
506
639
  try {
640
+ progress("Connecting to the selected Rig server\u2026");
507
641
  server = await (options.resolveServer ?? ensureServerForCli)(projectRoot);
508
642
  checks.push(check("server", "Rig server reachable", "pass", `${server.connectionKind} ${server.baseUrl}`));
509
643
  } catch (error) {
@@ -511,18 +645,21 @@ async function runRigDoctorChecks(options) {
511
645
  }
512
646
  if (server || options.requestJson) {
513
647
  try {
648
+ progress("Checking server status\u2026");
514
649
  const status = await request("/api/server/status");
515
650
  checks.push(check("server-status", "server project status", "pass", JSON.stringify(status).slice(0, 180)));
516
651
  } catch (error) {
517
652
  checks.push(check("server-status", "server project status", "fail", errorMessage(error), "Run `rig doctor` after the selected server is reachable."));
518
653
  }
519
654
  try {
655
+ progress("Checking GitHub auth\u2026");
520
656
  const auth = await request("/api/github/auth/status");
521
657
  checks.push(isAuthenticated(auth) ? check("github-auth", "GitHub auth", "pass") : check("github-auth", "GitHub auth", "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
522
658
  } catch (error) {
523
659
  checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig and ensure the server exposes auth status."));
524
660
  }
525
661
  try {
662
+ progress("Checking GitHub repo permissions\u2026");
526
663
  const permissions = await request("/api/github/repo/permissions");
527
664
  const allowed = permissionAllowsPr(permissions);
528
665
  checks.push(allowed === true ? check("github-repo-permissions", "GitHub repo PR permissions", "pass", JSON.stringify(permissions).slice(0, 180)) : allowed === false ? check("github-repo-permissions", "GitHub repo PR permissions", "fail", JSON.stringify(permissions).slice(0, 180), "Grant the selected GitHub token permission to push branches, open PRs, and merge according to repo rules.") : check("github-repo-permissions", "GitHub repo PR permissions", "warn", JSON.stringify(permissions).slice(0, 180), "Confirm the selected token can push branches and open PRs."));
@@ -530,6 +667,7 @@ async function runRigDoctorChecks(options) {
530
667
  checks.push(check("github-repo-permissions", "GitHub repo PR permissions", "warn", errorMessage(error), "Ensure the server exposes repo permission checks and the token can open PRs."));
531
668
  }
532
669
  try {
670
+ progress("Checking GitHub issue labels\u2026");
533
671
  const labels = await request("/api/workspace/task-labels");
534
672
  const ready = labelsReady(labels);
535
673
  checks.push(ready === false ? check("task-labels", "GitHub issue labels", "fail", JSON.stringify(labels).slice(0, 180), "Let Rig create required labels or create the configured lifecycle labels manually.") : check("task-labels", "GitHub issue labels", ready === true ? "pass" : "warn", JSON.stringify(labels).slice(0, 180), "Confirm required Rig lifecycle labels exist."));
@@ -537,6 +675,7 @@ async function runRigDoctorChecks(options) {
537
675
  checks.push(check("task-labels", "GitHub issue labels", "warn", errorMessage(error), "Run `rig init`/`rig doctor` after label setup is wired on the server."));
538
676
  }
539
677
  try {
678
+ progress("Checking task projection\u2026");
540
679
  const projection = await request("/api/workspace/task-projection");
541
680
  checks.push(check("task-projection", "task projection", "pass", JSON.stringify(projection).slice(0, 180)));
542
681
  } catch (error) {
@@ -545,6 +684,7 @@ async function runRigDoctorChecks(options) {
545
684
  const slug = projectStatusSlug(projectRoot, config);
546
685
  if (slug) {
547
686
  try {
687
+ progress("Checking server project checkout\u2026");
548
688
  const project = await request(`/api/projects/${encodeURIComponent(slug)}`);
549
689
  checks.push(check("remote-checkout", "server project checkout", "pass", JSON.stringify(project).slice(0, 180)));
550
690
  } catch (error) {
@@ -559,6 +699,7 @@ async function runRigDoctorChecks(options) {
559
699
  }
560
700
  checks.push(githubProjectsCheck(config));
561
701
  checks.push(prMergeCheck(config));
702
+ progress("Checking Pi installation\u2026");
562
703
  const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
563
704
  ok: false,
564
705
  label: "pi/pi-rig checks",
@@ -582,12 +723,204 @@ function countDoctorFailures(checks) {
582
723
  return checks.filter((entry) => entry.status === "fail").length;
583
724
  }
584
725
 
726
+ // packages/cli/src/commands/_async-ui.ts
727
+ import pc from "picocolors";
728
+
729
+ // packages/cli/src/commands/_spinner.ts
730
+ var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
731
+ function createTtySpinner(input) {
732
+ const output = input.output ?? process.stdout;
733
+ const isTty = output.isTTY === true;
734
+ const frames = input.frames && input.frames.length > 0 ? input.frames : SPINNER_FRAMES;
735
+ let label = input.label;
736
+ let frame = 0;
737
+ let paused = false;
738
+ let stopped = false;
739
+ let lastPrintedLabel = "";
740
+ const render = () => {
741
+ if (stopped || paused)
742
+ return;
743
+ if (!isTty) {
744
+ if (label !== lastPrintedLabel) {
745
+ output.write(`${label}
746
+ `);
747
+ lastPrintedLabel = label;
748
+ }
749
+ return;
750
+ }
751
+ frame = (frame + 1) % frames.length;
752
+ const glyph = frames[frame] ?? frames[0] ?? "";
753
+ output.write(`\r\x1B[2K${input.styleFrame ? input.styleFrame(glyph) : glyph} ${label}`);
754
+ };
755
+ const clearLine = () => {
756
+ if (isTty)
757
+ output.write("\r\x1B[2K");
758
+ };
759
+ render();
760
+ const timer = isTty ? setInterval(render, input.intervalMs ?? 120) : null;
761
+ return {
762
+ setLabel(next) {
763
+ label = next;
764
+ render();
765
+ },
766
+ pause() {
767
+ paused = true;
768
+ clearLine();
769
+ },
770
+ resume() {
771
+ if (stopped)
772
+ return;
773
+ paused = false;
774
+ render();
775
+ },
776
+ stop(finalLine) {
777
+ if (stopped)
778
+ return;
779
+ stopped = true;
780
+ if (timer)
781
+ clearInterval(timer);
782
+ clearLine();
783
+ if (finalLine)
784
+ output.write(`${finalLine}
785
+ `);
786
+ }
787
+ };
788
+ }
789
+
790
+ // packages/cli/src/app/theme.ts
791
+ var RIG_PALETTE = {
792
+ ink: "#f2f3f6",
793
+ ink2: "#aeb0ba",
794
+ ink3: "#6c6e79",
795
+ ink4: "#44464f",
796
+ accent: "#ccff4d",
797
+ accentDim: "#a9d63f",
798
+ cyan: "#56d8ff",
799
+ red: "#ff5d5d",
800
+ yellow: "#ffd24d"
801
+ };
802
+ function hexToRgb(hex) {
803
+ const value = hex.replace("#", "");
804
+ return [
805
+ Number.parseInt(value.slice(0, 2), 16),
806
+ Number.parseInt(value.slice(2, 4), 16),
807
+ Number.parseInt(value.slice(4, 6), 16)
808
+ ];
809
+ }
810
+ function fg(hex) {
811
+ const [r, g, b] = hexToRgb(hex);
812
+ return (text) => `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
813
+ }
814
+ var ink = fg(RIG_PALETTE.ink);
815
+ var ink2 = fg(RIG_PALETTE.ink2);
816
+ var ink3 = fg(RIG_PALETTE.ink3);
817
+ var ink4 = fg(RIG_PALETTE.ink4);
818
+ var accent = fg(RIG_PALETTE.accent);
819
+ var accentDim = fg(RIG_PALETTE.accentDim);
820
+ var cyan = fg(RIG_PALETTE.cyan);
821
+ var red = fg(RIG_PALETTE.red);
822
+ var yellow = fg(RIG_PALETTE.yellow);
823
+ function bold(text) {
824
+ return `\x1B[1m${text}\x1B[22m`;
825
+ }
826
+ var DRONE_ART = [
827
+ " .-=-. .-=-. ",
828
+ " ( !!! ) ( !!! ) ",
829
+ " '-=-'._ _.'-=-' ",
830
+ " '._ _.' ",
831
+ " '=$$$$$$$=.' ",
832
+ " =$$$$$$$$$$$= ",
833
+ " $$$@@@@@@@@@@$$$ ",
834
+ " $$$@@ @@$$$ ",
835
+ " $$@ ? @$$$ ",
836
+ " $$$@ '-' @$$$ ",
837
+ " $$$@@ @@$$$ ",
838
+ " $$$@@@@@@@@@@$$$ ",
839
+ " =$$$$$$$$$$$= ",
840
+ " '=$$$$$$$=.' ",
841
+ " _.' '._ ",
842
+ " .-=-.' '.-=-. ",
843
+ " ( !!! ) ( !!! ) ",
844
+ " '-=-' '-=-' "
845
+ ];
846
+ var EYE_FRAMES = ["@", "o", "."];
847
+ var DRONE_WIDTH = DRONE_ART[0].length;
848
+ var DRONE_HEIGHT = DRONE_ART.length;
849
+ var MICRO_BLADES = ["---", "\\\\\\", "|||", "///"];
850
+ function microDroneFrame(tick) {
851
+ const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
852
+ const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
853
+ return `(${blade})${eye}(${blade})`;
854
+ }
855
+ var MICRO_DRONE_FRAMES = Array.from({ length: 12 }, (_, index) => microDroneFrame(index));
856
+ function renderMicroDroneFrame(tick) {
857
+ const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
858
+ const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
859
+ return `${ink4("(")}${cyan(blade)}${ink4(")")}${bold(accent(eye))}${ink4("(")}${cyan(blade)}${ink4(")")}`;
860
+ }
861
+
862
+ // packages/cli/src/commands/_async-ui.ts
863
+ var DONE_SYMBOL = pc.green("\u25C7");
864
+ var FAIL_SYMBOL = pc.red("\u25A0");
865
+ var activeUpdate = null;
866
+ async function withSpinner(label, work, options = {}) {
867
+ if (options.outputMode === "json") {
868
+ return work(() => {});
869
+ }
870
+ if (activeUpdate) {
871
+ const outer = activeUpdate;
872
+ outer(label);
873
+ return work(outer);
874
+ }
875
+ const output = options.output ?? process.stderr;
876
+ const isTty = output.isTTY === true;
877
+ let lastLabel = label;
878
+ if (!isTty) {
879
+ output.write(`${label}
880
+ `);
881
+ const update2 = (next) => {
882
+ lastLabel = next;
883
+ };
884
+ activeUpdate = update2;
885
+ const previousListener2 = setServerPhaseListener(update2);
886
+ try {
887
+ return await work(update2);
888
+ } finally {
889
+ activeUpdate = null;
890
+ setServerPhaseListener(previousListener2);
891
+ }
892
+ }
893
+ const spinner = createTtySpinner({
894
+ label,
895
+ output,
896
+ frames: MICRO_DRONE_FRAMES,
897
+ styleFrame: (frame) => renderMicroDroneFrame(Math.max(0, MICRO_DRONE_FRAMES.indexOf(frame)))
898
+ });
899
+ const update = (next) => {
900
+ lastLabel = next;
901
+ spinner.setLabel(next);
902
+ };
903
+ activeUpdate = update;
904
+ const previousListener = setServerPhaseListener(update);
905
+ try {
906
+ const result = await work(update);
907
+ spinner.stop(options.doneLabel ? `${DONE_SYMBOL} ${options.doneLabel}` : undefined);
908
+ return result;
909
+ } catch (error) {
910
+ spinner.stop(`${FAIL_SYMBOL} ${lastLabel}`);
911
+ throw error;
912
+ } finally {
913
+ activeUpdate = null;
914
+ setServerPhaseListener(previousListener);
915
+ }
916
+ }
917
+
585
918
  // packages/cli/src/commands/setup.ts
586
919
  async function executeSetup(context, args) {
587
920
  const [command = "check", ...rest] = args;
588
921
  switch (command) {
589
922
  case "bootstrap":
590
- requireNoExtraArgs(rest, "bun run rig setup bootstrap");
923
+ requireNoExtraArgs(rest, "rig setup bootstrap");
591
924
  {
592
925
  const hostBash = Bun.which("bash") || "/bin/bash";
593
926
  const env = { ...process.env };
@@ -605,32 +938,26 @@ async function executeSetup(context, args) {
605
938
  });
606
939
  const exitCode = await proc.exited;
607
940
  if (exitCode !== 0) {
608
- throw new CliError2(`Command failed (${exitCode}): ${hostBash} ./bootstrap.sh`, exitCode);
941
+ throw new CliError(`Command failed (${exitCode}): ${hostBash} ./bootstrap.sh`, exitCode);
609
942
  }
610
943
  }
611
944
  return { ok: true, group: "setup", command };
612
945
  case "check":
613
- requireNoExtraArgs(rest, `bun run rig setup ${command}`);
946
+ requireNoExtraArgs(rest, `rig setup ${command}`);
614
947
  {
615
- const checks = await withMutedConsole(context.outputMode === "json", () => runSetupCheck(context.projectRoot));
948
+ const checks = await withMutedConsole(context.outputMode === "json", () => runSetupCheck(context.projectRoot, context.outputMode));
616
949
  return { ok: true, group: "setup", command, details: { checks, failures: countDoctorFailures(checks) } };
617
950
  }
618
951
  case "setup":
619
- requireNoExtraArgs(rest, "bun run rig setup setup");
952
+ requireNoExtraArgs(rest, "rig setup setup");
620
953
  withMutedConsole(context.outputMode === "json", () => runSetupInit(context.projectRoot));
621
954
  return { ok: true, group: "setup", command };
622
955
  case "preflight":
623
- requireNoExtraArgs(rest, "bun run rig setup preflight");
624
- await withMutedConsole(context.outputMode === "json", () => runSetupPreflight(context.projectRoot));
625
- return { ok: true, group: "setup", command };
626
- case "install-agent-shell":
627
- requireNoExtraArgs(rest, "bun run rig setup install-agent-shell");
628
- if (context.outputMode === "text") {
629
- console.log("install-agent-shell is deprecated. Runtime shells now use compiled rig-agent directly.");
630
- }
956
+ requireNoExtraArgs(rest, "rig setup preflight");
957
+ await withMutedConsole(context.outputMode === "json", () => runSetupPreflight(context.projectRoot, context.outputMode));
631
958
  return { ok: true, group: "setup", command };
632
959
  default:
633
- throw new CliError2(`Unknown setup command: ${command}`);
960
+ throw new CliError(`Unknown setup command: ${command}`, 1, { hint: "Run `rig setup --help` \u2014 commands are bootstrap|check|preflight." });
634
961
  }
635
962
  }
636
963
  function formatTaskSourceKinds(kinds) {
@@ -664,17 +991,17 @@ function runSetupInit(projectRoot) {
664
991
  }
665
992
  console.log("Harness directories ready.");
666
993
  }
667
- async function runSetupCheck(projectRoot) {
668
- const doctorChecks = await runRigDoctorChecks({ projectRoot });
994
+ async function runSetupCheck(projectRoot, outputMode = "text") {
995
+ const doctorChecks = await withSpinner("Running setup checks\u2026", (update) => runRigDoctorChecks({ projectRoot, onProgress: update }), { outputMode });
669
996
  console.log(formatDoctorChecks(doctorChecks));
670
997
  const failures = countDoctorFailures(doctorChecks);
671
998
  if (failures > 0) {
672
- throw new CliError2(`Setup check failed (${failures} failing doctor check${failures === 1 ? "" : "s"}).`, 1);
999
+ throw new CliError(`Setup check failed (${failures} failing doctor check${failures === 1 ? "" : "s"}).`, 1, { hint: "Run `rig doctor` for the full check list with remediations." });
673
1000
  }
674
1001
  return doctorChecks;
675
1002
  }
676
- async function runSetupPreflight(projectRoot) {
677
- await runSetupCheck(projectRoot);
1003
+ async function runSetupPreflight(projectRoot, outputMode = "text") {
1004
+ await runSetupCheck(projectRoot, outputMode);
678
1005
  const validationRoot = resolve6(resolveControlPlaneDefinitionRoot(projectRoot), "validation");
679
1006
  if (existsSync5(validationRoot)) {
680
1007
  const validators = readdirSync(validationRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory());