@h-rig/cli 0.0.6-alpha.1 → 0.0.6-alpha.100

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 (120) hide show
  1. package/README.md +18 -19
  2. package/dist/bin/build-rig-binaries.d.ts +2 -0
  3. package/dist/bin/build-rig-binaries.js +22 -10
  4. package/dist/bin/rig.d.ts +72 -0
  5. package/dist/bin/rig.js +15742 -7203
  6. package/dist/config/rig-default-config.yml +5 -0
  7. package/dist/src/app/drone-ui.d.ts +34 -0
  8. package/dist/src/app/drone-ui.js +278 -0
  9. package/dist/src/commands/_async-ui.d.ts +10 -0
  10. package/dist/src/commands/_async-ui.js +121 -0
  11. package/dist/src/commands/_cli-format.d.ts +56 -0
  12. package/dist/src/commands/_cli-format.js +319 -0
  13. package/dist/src/commands/_config-env.d.ts +18 -0
  14. package/dist/src/commands/_config-env.js +22 -0
  15. package/dist/src/commands/_connection-state.d.ts +54 -0
  16. package/dist/src/commands/_connection-state.js +75 -11
  17. package/dist/src/commands/_doctor-checks.d.ts +46 -0
  18. package/dist/src/commands/_doctor-checks.js +95 -244
  19. package/dist/src/commands/_help-catalog.d.ts +29 -0
  20. package/dist/src/commands/_help-catalog.js +146 -0
  21. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  22. package/dist/src/commands/_inprocess-services.js +102 -0
  23. package/dist/src/commands/_json-output.d.ts +11 -0
  24. package/dist/src/commands/_json-output.js +60 -0
  25. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  26. package/dist/src/commands/_lazy-reconcile.js +102 -0
  27. package/dist/src/commands/_parsers.d.ts +15 -0
  28. package/dist/src/commands/_parsers.js +18 -11
  29. package/dist/src/commands/_paths.d.ts +11 -0
  30. package/dist/src/commands/_paths.js +1 -1
  31. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  32. package/dist/src/commands/_pi-frontend.js +64 -0
  33. package/dist/src/commands/_pi-install.d.ts +42 -0
  34. package/dist/src/commands/_pi-install.js +19 -36
  35. package/dist/src/commands/_policy.d.ts +8 -0
  36. package/dist/src/commands/_policy.js +67 -19
  37. package/dist/src/commands/_probes.d.ts +1 -0
  38. package/dist/src/commands/_run-bridge.d.ts +114 -0
  39. package/dist/src/commands/_run-bridge.js +387 -0
  40. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  41. package/dist/src/commands/_run-diagnostics.js +51 -0
  42. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  43. package/dist/src/commands/_run-driver-helpers.js +79 -230
  44. package/dist/src/commands/_run-projection.d.ts +50 -0
  45. package/dist/src/commands/_run-projection.js +349 -0
  46. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  47. package/dist/src/commands/_run-subcommands.js +31 -0
  48. package/dist/src/commands/_spinner.d.ts +25 -0
  49. package/dist/src/commands/_spinner.js +65 -0
  50. package/dist/src/commands/agent.d.ts +3 -0
  51. package/dist/src/commands/agent.js +8690 -235
  52. package/dist/src/commands/config.d.ts +3 -0
  53. package/dist/src/commands/config.js +181 -0
  54. package/dist/src/commands/dist.d.ts +28 -0
  55. package/dist/src/commands/dist.js +44 -29
  56. package/dist/src/commands/doctor.d.ts +3 -0
  57. package/dist/src/commands/doctor.js +214 -245
  58. package/dist/src/commands/github.d.ts +3 -0
  59. package/dist/src/commands/github.js +237 -171
  60. package/dist/src/commands/inbox.d.ts +28 -0
  61. package/dist/src/commands/inbox.js +530 -111
  62. package/dist/src/commands/init.d.ts +64 -0
  63. package/dist/src/commands/init.js +941 -654
  64. package/dist/src/commands/inspect.d.ts +20 -0
  65. package/dist/src/commands/inspect.js +709 -119
  66. package/dist/src/commands/pi.d.ts +3 -0
  67. package/dist/src/commands/pi.js +177 -0
  68. package/dist/src/commands/plugin.d.ts +16 -0
  69. package/dist/src/commands/plugin.js +576 -29
  70. package/dist/src/commands/profile-and-review.d.ts +4 -0
  71. package/dist/src/commands/profile-and-review.js +112 -67
  72. package/dist/src/commands/queue.d.ts +3 -0
  73. package/dist/src/commands/queue.js +20 -20
  74. package/dist/src/commands/remote.d.ts +3 -0
  75. package/dist/src/commands/remote.js +883 -50
  76. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  77. package/dist/src/commands/repo-git-harness.js +78 -28
  78. package/dist/src/commands/run.d.ts +21 -0
  79. package/dist/src/commands/run.js +17732 -618
  80. package/dist/src/commands/server.d.ts +3 -0
  81. package/dist/src/commands/server.js +166 -285
  82. package/dist/src/commands/setup.d.ts +16 -0
  83. package/dist/src/commands/setup.js +230 -267
  84. package/dist/src/commands/stats.d.ts +15 -0
  85. package/dist/src/commands/stats.js +632 -0
  86. package/dist/src/commands/task-run-driver.d.ts +94 -0
  87. package/dist/src/commands/task-run-driver.js +120 -1856
  88. package/dist/src/commands/task.d.ts +35 -0
  89. package/dist/src/commands/task.js +676 -1183
  90. package/dist/src/commands/test.d.ts +3 -0
  91. package/dist/src/commands/test.js +15 -8
  92. package/dist/src/commands/triage.d.ts +11 -0
  93. package/dist/src/commands/triage.js +227 -0
  94. package/dist/src/commands/workspace.d.ts +3 -0
  95. package/dist/src/commands/workspace.js +18 -11
  96. package/dist/src/commands.d.ts +13 -0
  97. package/dist/src/commands.js +16760 -7779
  98. package/dist/src/index.d.ts +4 -0
  99. package/dist/src/index.js +16880 -8223
  100. package/dist/src/launcher.d.ts +61 -0
  101. package/dist/src/launcher.js +81 -13
  102. package/dist/src/operator-cli.d.ts +2 -0
  103. package/dist/src/operator-cli.js +17867 -0
  104. package/dist/src/operator-entry.d.ts +1 -0
  105. package/dist/src/operator-entry.js +3 -0
  106. package/dist/src/runner.d.ts +47 -0
  107. package/dist/src/runner.js +19 -24
  108. package/dist/src/withMutedConsole.d.ts +2 -0
  109. package/package.json +21 -7
  110. package/dist/src/commands/_authority-runs.js +0 -110
  111. package/dist/src/commands/_operator-view.js +0 -322
  112. package/dist/src/commands/_preflight.js +0 -460
  113. package/dist/src/commands/_server-client.js +0 -364
  114. package/dist/src/commands/_snapshot-upload.js +0 -313
  115. package/dist/src/commands/_task-picker.js +0 -48
  116. package/dist/src/commands/browser.js +0 -890
  117. package/dist/src/commands/connect.js +0 -180
  118. package/dist/src/commands/inspector.js +0 -256
  119. package/dist/src/commands/task-report-bug.js +0 -1083
  120. package/dist/src/report-bug.js +0 -260
@@ -3,12 +3,19 @@ var __require = import.meta.require;
3
3
 
4
4
  // packages/cli/src/runner.ts
5
5
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
6
- import { CliError } from "@rig/runtime/control-plane/errors";
6
+ import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
7
7
  import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
8
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
9
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
10
8
  import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
11
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
9
+
10
+ class CliError extends RuntimeCliError {
11
+ hint;
12
+ constructor(message, exitCode = 1, options = {}) {
13
+ super(message, exitCode);
14
+ if (options.hint?.trim()) {
15
+ this.hint = options.hint.trim();
16
+ }
17
+ }
18
+ }
12
19
  function requireNoExtraArgs(args, usage) {
13
20
  if (args.length > 0) {
14
21
  throw new CliError(`Unexpected arguments: ${args.join(" ")}
@@ -17,23 +24,13 @@ Usage: ${usage}`);
17
24
  }
18
25
 
19
26
  // packages/cli/src/commands/_doctor-checks.ts
20
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
27
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
21
28
  import { resolve as resolve3 } from "path";
22
29
  import { isSupportedBunVersion, MIN_SUPPORTED_BUN_VERSION } from "@rig/runtime/control-plane/setup-version";
23
30
 
24
31
  // packages/cli/src/commands/_connection-state.ts
25
32
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
26
- import { homedir } from "os";
27
33
  import { dirname, resolve } from "path";
28
- function resolveGlobalConnectionsPath(env = process.env) {
29
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
30
- if (explicit)
31
- return resolve(explicit);
32
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
33
- if (stateDir)
34
- return resolve(stateDir, "connections.json");
35
- return resolve(homedir(), ".rig", "connections.json");
36
- }
37
34
  function resolveRepoConnectionPath(projectRoot) {
38
35
  return resolve(projectRoot, ".rig", "state", "connection.json");
39
36
  }
@@ -43,37 +40,8 @@ function readJsonFile(path) {
43
40
  try {
44
41
  return JSON.parse(readFileSync(path, "utf8"));
45
42
  } catch (error) {
46
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
47
- }
48
- }
49
- function normalizeConnection(value) {
50
- if (!value || typeof value !== "object" || Array.isArray(value))
51
- return null;
52
- const record = value;
53
- if (record.kind === "local")
54
- return { kind: "local", mode: "auto" };
55
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
56
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
57
- return { kind: "remote", baseUrl };
58
- }
59
- return null;
60
- }
61
- function readGlobalConnections(options = {}) {
62
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
63
- const payload = readJsonFile(path);
64
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
65
- return { connections: {} };
66
- }
67
- const rawConnections = payload.connections;
68
- const connections = {};
69
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
70
- for (const [alias, raw] of Object.entries(rawConnections)) {
71
- const connection = normalizeConnection(raw);
72
- if (connection)
73
- connections[alias] = connection;
74
- }
43
+ 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>`." });
75
44
  }
76
- return { connections };
77
45
  }
78
46
  function readRepoConnection(projectRoot) {
79
47
  const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
@@ -86,112 +54,68 @@ function readRepoConnection(projectRoot) {
86
54
  return {
87
55
  selected,
88
56
  project: typeof record.project === "string" ? record.project : undefined,
89
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
57
+ linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
58
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
59
+ serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
60
+ serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
90
61
  };
91
62
  }
92
- function resolveSelectedConnection(projectRoot, options = {}) {
93
- const repo = readRepoConnection(projectRoot);
94
- if (!repo)
95
- return null;
96
- if (repo.selected === "local")
97
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
98
- const global = readGlobalConnections(options);
99
- const connection = global.connections[repo.selected];
100
- if (!connection) {
101
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
102
- }
103
- return { alias: repo.selected, connection };
104
- }
105
63
 
106
- // packages/cli/src/commands/_server-client.ts
107
- import { spawnSync } from "child_process";
108
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
109
- var cachedGitHubBearerToken;
64
+ // packages/cli/src/commands/_inprocess-services.ts
65
+ import {
66
+ beginGitHubDeviceFlow,
67
+ checkGitHubRepoPermissions,
68
+ createGitHubAuthStore,
69
+ listGitHubProjects,
70
+ pollGitHubDeviceFlow,
71
+ resolveGitHubAuthStatus,
72
+ resolveProjectStatusField,
73
+ saveGitHubTokenForProject
74
+ } from "@rig/runtime/control-plane/github/index";
75
+ var scopedGitHubBearerTokens = new Map;
110
76
  function cleanToken(value) {
111
77
  const trimmed = value?.trim();
112
78
  return trimmed ? trimmed : null;
113
79
  }
114
- function readGitHubBearerTokenForRemote() {
115
- if (cachedGitHubBearerToken !== undefined)
116
- return cachedGitHubBearerToken;
117
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
118
- if (envToken) {
119
- cachedGitHubBearerToken = envToken;
120
- return cachedGitHubBearerToken;
121
- }
122
- const result = spawnSync("gh", ["auth", "token"], {
123
- encoding: "utf8",
124
- timeout: 5000,
125
- stdio: ["ignore", "pipe", "ignore"]
126
- });
127
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
128
- return cachedGitHubBearerToken;
129
- }
130
- async function ensureServerForCli(projectRoot) {
131
- try {
132
- const selected = resolveSelectedConnection(projectRoot);
133
- if (selected?.connection.kind === "remote") {
134
- return {
135
- baseUrl: selected.connection.baseUrl,
136
- authToken: readGitHubBearerTokenForRemote(),
137
- connectionKind: "remote"
138
- };
139
- }
140
- const connection = await ensureLocalRigServerConnection(projectRoot);
141
- return {
142
- baseUrl: connection.baseUrl,
143
- authToken: connection.authToken,
144
- connectionKind: "local"
145
- };
146
- } catch (error) {
147
- if (error instanceof Error) {
148
- throw new CliError2(error.message, 1);
149
- }
150
- throw error;
151
- }
80
+ function cleanString(value) {
81
+ return typeof value === "string" && value.trim() ? value.trim() : null;
152
82
  }
153
- function mergeHeaders(headers, authToken) {
154
- const merged = new Headers(headers);
155
- if (authToken) {
156
- merged.set("authorization", `Bearer ${authToken}`);
157
- }
158
- return merged;
83
+ function oauthClientId() {
84
+ return cleanToken(process.env.RIG_GITHUB_OAUTH_CLIENT_ID);
159
85
  }
160
- function diagnosticMessage(payload) {
161
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
162
- return null;
163
- const record = payload;
164
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
165
- const messages = diagnostics.flatMap((entry) => {
166
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
167
- return [];
168
- const diagnostic = entry;
169
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
170
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
171
- return message ? [`${kind}: ${message}`] : [];
172
- });
173
- return messages.length > 0 ? messages.join("; ") : null;
86
+ async function getGitHubAuthStatusInProcess(context) {
87
+ return { ok: true, ...resolveGitHubAuthStatus({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) }) };
174
88
  }
175
- async function requestServerJson(context, pathname, init = {}) {
176
- const server = await ensureServerForCli(context.projectRoot);
177
- const response = await fetch(`${server.baseUrl}${pathname}`, {
178
- ...init,
179
- headers: mergeHeaders(init.headers, server.authToken)
180
- });
181
- const text = await response.text();
182
- const payload = text.trim().length > 0 ? (() => {
183
- try {
184
- return JSON.parse(text);
185
- } catch {
186
- return null;
187
- }
188
- })() : null;
189
- if (!response.ok) {
190
- const diagnostics = diagnosticMessage(payload);
191
- const detail = diagnostics ?? (text || response.statusText);
192
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
89
+ async function requestGitHubAuthJsonInProcess(context, pathname, init = {}) {
90
+ const method = (init.method ?? "GET").toUpperCase();
91
+ if (pathname === "/api/github/auth/status")
92
+ return getGitHubAuthStatusInProcess(context);
93
+ if (pathname === "/api/github/repo/permissions") {
94
+ return checkGitHubRepoPermissions({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) });
193
95
  }
194
- return payload;
96
+ if (pathname === "/api/github/auth/device/start" && method === "POST") {
97
+ const clientId = oauthClientId();
98
+ if (!clientId)
99
+ return { ok: false, oauthConfigured: false, error: "RIG_GITHUB_OAUTH_CLIENT_ID is not configured." };
100
+ const body = init.body ? JSON.parse(String(init.body)) : {};
101
+ return beginGitHubDeviceFlow({
102
+ projectRoot: context.projectRoot,
103
+ clientId,
104
+ scope: cleanString(body.scope) ?? undefined,
105
+ selectedRepo: cleanString(body.repoSlug)
106
+ });
107
+ }
108
+ if (pathname === "/api/github/auth/device/poll" && method === "POST") {
109
+ const clientId = oauthClientId();
110
+ if (!clientId)
111
+ return { ok: false, oauthConfigured: false, error: "RIG_GITHUB_OAUTH_CLIENT_ID is not configured." };
112
+ const body = init.body ? JSON.parse(String(init.body)) : {};
113
+ const pollId = cleanString(body.pollId);
114
+ if (!pollId)
115
+ return { ok: false, status: "error", error: "pollId is required" };
116
+ return pollGitHubDeviceFlow({ projectRoot: context.projectRoot, clientId, pollId, selectedRepo: cleanString(body.repoSlug) });
117
+ }
118
+ throw new Error(`No in-process GitHub auth API for ${method} ${pathname}`);
195
119
  }
196
120
 
197
121
  // packages/cli/src/commands/_parsers.ts
@@ -205,10 +129,10 @@ async function loadRigConfigOrNull(projectRoot) {
205
129
  }
206
130
 
207
131
  // packages/cli/src/commands/_pi-install.ts
208
- import { existsSync as existsSync2, readFileSync as readFileSync2, rmSync } from "fs";
209
- import { homedir as homedir2 } from "os";
132
+ import { existsSync as existsSync2 } from "fs";
133
+ import { homedir } from "os";
210
134
  import { resolve as resolve2 } from "path";
211
- var PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
135
+ var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
212
136
  async function defaultCommandRunner(command, options = {}) {
213
137
  const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
214
138
  const [stdout, stderr, exitCode] = await Promise.all([
@@ -222,7 +146,7 @@ function resolvePiRigExtensionPath(homeDir) {
222
146
  return resolve2(homeDir, ".pi", "agent", "extensions", "pi-rig");
223
147
  }
224
148
  function resolvePiHomeDir(inputHomeDir) {
225
- return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir2();
149
+ return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
226
150
  }
227
151
  function piListContainsPiRig(output) {
228
152
  return output.split(/\r?\n/).some((line) => {
@@ -247,27 +171,25 @@ async function checkPiRigInstall(input = {}) {
247
171
  piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
248
172
  };
249
173
  }
250
- const exists = input.exists ?? existsSync2;
251
174
  const runner = input.commandRunner ?? defaultCommandRunner;
252
175
  const piResult = await safeRun(runner, ["pi", "--version"]);
253
176
  const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
254
- const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
177
+ const hasPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
255
178
  ${piListResult.stderr}`);
256
- const legacyBridge = exists(resolve2(extensionPath, "index.ts"));
257
- const hasPiRig = listedPiRig;
179
+ const hasLegacyBridgeScaffold = !hasPiRig && (input.exists ?? existsSync2)(extensionPath);
258
180
  return {
259
181
  extensionPath,
260
182
  pi: {
261
183
  ok: piResult.exitCode === 0,
262
184
  label: "pi",
263
185
  detail: (piResult.stdout || piResult.stderr).trim() || undefined,
264
- hint: piResult.exitCode === 0 ? undefined : "Install Pi or run `rig init --yes` to install/update the Pi runtime."
186
+ hint: piResult.exitCode === 0 ? undefined : "Install Pi/OMP manually or set RIG_PI_INSTALL_COMMAND before verifying with bare `rig` / Cockpit \u2192 Doctor."
265
187
  },
266
188
  piRig: {
267
189
  ok: hasPiRig,
268
190
  label: "pi-rig global extension",
269
- detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
270
- hint: hasPiRig ? undefined : "Run `rig init --yes` to install/enable the global pi-rig package with `pi install`."
191
+ detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : hasLegacyBridgeScaffold ? `legacy bridge scaffold at ${extensionPath}` : undefined,
192
+ hint: hasPiRig ? undefined : `Install the Rig OMP extension with \`pi install ${PI_RIG_PACKAGE_NAME}\`, then verify with bare \`rig\` / Cockpit \u2192 Doctor.`
271
193
  }
272
194
  };
273
195
  }
@@ -295,23 +217,6 @@ function isAuthenticated(payload) {
295
217
  const record = payload;
296
218
  return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
297
219
  }
298
- function repoSlugFromConfig(config) {
299
- const project = config?.project;
300
- if (project && typeof project === "object" && !Array.isArray(project)) {
301
- const record = project;
302
- if (typeof record.repo === "string" && /^([^/\s]+)\/([^/\s]+)$/.test(record.repo))
303
- return record.repo;
304
- if (typeof record.name === "string" && /^([^/\s]+)\/([^/\s]+)$/.test(record.name))
305
- return record.name;
306
- }
307
- const taskSource = config?.taskSource;
308
- if (taskSource && typeof taskSource === "object" && !Array.isArray(taskSource)) {
309
- const source = taskSource;
310
- if (typeof source.owner === "string" && typeof source.repo === "string")
311
- return `${source.owner}/${source.repo}`;
312
- }
313
- return null;
314
- }
315
220
  function loadFallbackConfig(projectRoot) {
316
221
  const candidates = ["rig.config.ts", "rig.config.mts", "rig.config.json"];
317
222
  for (const name of candidates) {
@@ -319,7 +224,7 @@ function loadFallbackConfig(projectRoot) {
319
224
  if (!existsSync3(path))
320
225
  continue;
321
226
  try {
322
- const source = readFileSync3(path, "utf8");
227
+ const source = readFileSync2(path, "utf8");
323
228
  if (name.endsWith(".json"))
324
229
  return JSON.parse(source);
325
230
  const owner = source.match(/owner\s*:\s*["']([^"']+)["']/)?.[1];
@@ -338,14 +243,11 @@ function loadFallbackConfig(projectRoot) {
338
243
  }
339
244
  return null;
340
245
  }
341
- function projectStatusSlug(projectRoot, config) {
342
- return readRepoConnection(projectRoot)?.project ?? repoSlugFromConfig(config);
343
- }
344
246
  function githubProjectsCheck(config) {
345
247
  const github = config?.github;
346
248
  const projects = github?.projects;
347
249
  if (!projects?.enabled) {
348
- return check("github-projects", "GitHub Projects status sync", "warn", "disabled or not configured", "Run `rig init --github-project <project>` or configure github.projects when Project status sync should be authoritative.");
250
+ return check("github-projects", "GitHub Projects status sync", "warn", "disabled or not configured", "Current OMP flow does not require GitHub Projects status sync; configure github.projects manually when Project status sync should be authoritative.");
349
251
  }
350
252
  if (projects.projectId && projects.statusFieldId) {
351
253
  return check("github-projects", "GitHub Projects status sync", "pass", `project ${projects.projectId}`);
@@ -370,16 +272,6 @@ function permissionAllowsPr(payload) {
370
272
  }
371
273
  return null;
372
274
  }
373
- function labelsReady(payload) {
374
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
375
- return null;
376
- const record = payload;
377
- if (record.ok === true || record.ready === true || record.labelsReady === true)
378
- return true;
379
- if (record.ok === false || record.ready === false || record.labelsReady === false)
380
- return false;
381
- return null;
382
- }
383
275
  function prMergeCheck(config) {
384
276
  const pr = config?.pr;
385
277
  const merge = config?.merge;
@@ -393,89 +285,48 @@ async function runRigDoctorChecks(options) {
393
285
  const checks = [];
394
286
  const which = options.which ?? ((binary) => Bun.which(binary));
395
287
  const bunVersion = options.bunVersion ?? Bun.version;
396
- const request = options.requestJson ?? ((pathname, init) => requestServerJson({ projectRoot }, pathname, init));
288
+ const request = options.requestJson ?? ((pathname, init) => requestGitHubAuthJsonInProcess({ projectRoot }, pathname, init));
397
289
  const loadConfig = options.loadConfig ?? loadRigConfigOrNull;
290
+ const progress = options.onProgress ?? (() => {});
291
+ progress("Checking local toolchain\u2026");
398
292
  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`)."));
293
+ progress("Loading rig.config\u2026");
399
294
  const loadedConfig = await loadConfig(projectRoot).catch(() => null);
400
295
  const config = loadedConfig ?? loadFallbackConfig(projectRoot);
401
296
  const hasConfigFile = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync3(resolve3(projectRoot, name)));
402
- checks.push(config ? check("config", "rig.config loadable", "pass") : check("config", "rig.config loadable", hasConfigFile ? "fail" : "fail", hasConfigFile ? "config file exists but failed to load" : "missing rig.config.ts/json", "Run `rig init` or fix the config error."));
297
+ checks.push(config ? check("config", "rig.config loadable", "pass") : check("config", "rig.config loadable", hasConfigFile ? "fail" : "fail", hasConfigFile ? "config file exists but failed to load" : "missing rig.config.ts/json", "Create/fix rig.config.ts or use the OMP cockpit Start tab to scaffold one."));
403
298
  const taskSourceKind = config?.taskSource?.kind;
404
299
  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."));
405
300
  const repo = readRepoConnection(projectRoot);
406
- 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>`."));
407
- const selected = (() => {
408
- try {
409
- return resolveSelectedConnection(projectRoot);
410
- } catch {
411
- return null;
412
- }
413
- })();
414
- 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));
415
- let server = null;
301
+ checks.push(repo ? check("project-link", "repo selected for local setup", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --repo owner/repo` if this project should use GitHub Issues.") : check("project-link", "repo selected for local setup", "warn", "missing .rig/state/connection.json", "Current UX can run without this compatibility file; `rig init` recreates it for GitHub-backed projects."));
416
302
  try {
417
- server = await (options.resolveServer ?? ensureServerForCli)(projectRoot);
418
- checks.push(check("server", "Rig server reachable", "pass", `${server.connectionKind} ${server.baseUrl}`));
303
+ progress("Checking GitHub auth\u2026");
304
+ const auth = await request("/api/github/auth/status");
305
+ 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>`."));
419
306
  } catch (error) {
420
- checks.push(check("server", "Rig server reachable", "fail", errorMessage(error), "Start the local Rig server or fix the selected remote connection."));
307
+ checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig."));
421
308
  }
422
- if (server || options.requestJson) {
423
- try {
424
- const status = await request("/api/server/status");
425
- checks.push(check("server-status", "server project status", "pass", JSON.stringify(status).slice(0, 180)));
426
- } catch (error) {
427
- checks.push(check("server-status", "server project status", "fail", errorMessage(error), "Run `rig doctor` after the selected server is reachable."));
428
- }
429
- try {
430
- const auth = await request("/api/github/auth/status");
431
- 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>`."));
432
- } catch (error) {
433
- checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig and ensure the server exposes auth status."));
434
- }
435
- try {
436
- const permissions = await request("/api/github/repo/permissions");
437
- const allowed = permissionAllowsPr(permissions);
438
- 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."));
439
- } catch (error) {
440
- 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."));
441
- }
442
- try {
443
- const labels = await request("/api/workspace/task-labels");
444
- const ready = labelsReady(labels);
445
- 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."));
446
- } catch (error) {
447
- checks.push(check("task-labels", "GitHub issue labels", "warn", errorMessage(error), "Run `rig init`/`rig doctor` after label setup is wired on the server."));
448
- }
449
- try {
450
- const projection = await request("/api/workspace/task-projection");
451
- checks.push(check("task-projection", "task projection", "pass", JSON.stringify(projection).slice(0, 180)));
452
- } catch (error) {
453
- checks.push(check("task-projection", "task projection", "warn", errorMessage(error), "Refresh task projection with `rig task list` or fix the task source."));
454
- }
455
- const slug = projectStatusSlug(projectRoot, config);
456
- if (slug) {
457
- try {
458
- const project = await request(`/api/projects/${encodeURIComponent(slug)}`);
459
- checks.push(check("remote-checkout", "server project checkout", "pass", JSON.stringify(project).slice(0, 180)));
460
- } catch (error) {
461
- checks.push(check("remote-checkout", "server project checkout", "warn", errorMessage(error), "Run `rig init --yes --repo owner/repo` to register/link the server project checkout."));
462
- }
463
- } else {
464
- checks.push(check("remote-checkout", "server project checkout", "warn", "repo slug unknown", "Set project.repo or run `rig init --repo owner/repo`."));
465
- }
309
+ try {
310
+ progress("Checking GitHub repo permissions\u2026");
311
+ const permissions = await request("/api/github/repo/permissions");
312
+ const allowed = permissionAllowsPr(permissions);
313
+ 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."));
314
+ } catch (error) {
315
+ checks.push(check("github-repo-permissions", "GitHub repo PR permissions", "warn", errorMessage(error), "Ensure the token can open PRs."));
466
316
  }
467
317
  if (taskSourceKind === "github-issues") {
468
318
  checks.push(check("gh", "gh CLI fallback", which("gh") ? "pass" : "warn", which("gh") ?? undefined, "Install gh for local/dev GitHub fallback operations."));
469
319
  }
470
320
  checks.push(githubProjectsCheck(config));
471
321
  checks.push(prMergeCheck(config));
322
+ progress("Checking Pi installation\u2026");
472
323
  const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
473
324
  ok: false,
474
325
  label: "pi/pi-rig checks",
475
326
  hint: errorMessage(error)
476
327
  }]);
477
328
  for (const pi of piChecks) {
478
- checks.push(check(pi.label === "pi" ? "pi" : "pi-rig", pi.label, pi.ok ? "pass" : "warn", pi.detail, pi.hint ?? (pi.ok ? undefined : "Run `rig init --yes` to install/update Pi and enable pi-rig.")));
329
+ checks.push(check(pi.label === "pi" ? "pi" : "pi-rig", pi.label, pi.ok ? "pass" : "warn", pi.detail, pi.hint ?? (pi.ok ? undefined : "Install Pi/OMP and the Rig extension, then use bare `rig` or Cockpit \u2192 Doctor to verify.")));
479
330
  }
480
331
  return checks;
481
332
  }
@@ -492,10 +343,128 @@ function countDoctorFailures(checks) {
492
343
  return checks.filter((entry) => entry.status === "fail").length;
493
344
  }
494
345
 
346
+ // packages/cli/src/commands/_async-ui.ts
347
+ import pc from "picocolors";
348
+
349
+ // packages/cli/src/commands/_spinner.ts
350
+ var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
351
+ function createTtySpinner(input) {
352
+ const output = input.output ?? process.stdout;
353
+ const isTty = output.isTTY === true;
354
+ const frames = input.frames && input.frames.length > 0 ? input.frames : SPINNER_FRAMES;
355
+ let label = input.label;
356
+ let frame = 0;
357
+ let paused = false;
358
+ let stopped = false;
359
+ let lastPrintedLabel = "";
360
+ const render = () => {
361
+ if (stopped || paused)
362
+ return;
363
+ if (!isTty) {
364
+ if (label !== lastPrintedLabel) {
365
+ output.write(`${label}
366
+ `);
367
+ lastPrintedLabel = label;
368
+ }
369
+ return;
370
+ }
371
+ frame = (frame + 1) % frames.length;
372
+ const glyph = frames[frame] ?? frames[0] ?? "";
373
+ output.write(`\r\x1B[2K${input.styleFrame ? input.styleFrame(glyph) : glyph} ${label}`);
374
+ };
375
+ const clearLine = () => {
376
+ if (isTty)
377
+ output.write("\r\x1B[2K");
378
+ };
379
+ render();
380
+ const timer = isTty ? setInterval(render, input.intervalMs ?? 16) : null;
381
+ return {
382
+ setLabel(next) {
383
+ label = next;
384
+ render();
385
+ },
386
+ pause() {
387
+ paused = true;
388
+ clearLine();
389
+ },
390
+ resume() {
391
+ if (stopped)
392
+ return;
393
+ paused = false;
394
+ render();
395
+ },
396
+ stop(finalLine) {
397
+ if (stopped)
398
+ return;
399
+ stopped = true;
400
+ if (timer)
401
+ clearInterval(timer);
402
+ clearLine();
403
+ if (finalLine)
404
+ output.write(`${finalLine}
405
+ `);
406
+ }
407
+ };
408
+ }
409
+
410
+ // packages/cli/src/commands/_async-ui.ts
411
+ var FRAMES = ["\u25D0", "\u25D3", "\u25D1", "\u25D2"];
412
+ var DONE_SYMBOL = pc.green("\u25C7");
413
+ var FAIL_SYMBOL = pc.red("\u25A0");
414
+ var activeUpdate = null;
415
+ async function withSpinner(label, work, options = {}) {
416
+ if (options.outputMode === "json") {
417
+ return work(() => {
418
+ return;
419
+ });
420
+ }
421
+ if (activeUpdate) {
422
+ activeUpdate(label);
423
+ return work(activeUpdate);
424
+ }
425
+ const output = options.output ?? process.stderr;
426
+ const isTty = output.isTTY === true;
427
+ let lastLabel = label;
428
+ if (!isTty) {
429
+ output.write(`${label}
430
+ `);
431
+ const update2 = (next) => {
432
+ lastLabel = next;
433
+ };
434
+ activeUpdate = update2;
435
+ try {
436
+ return await work(update2);
437
+ } finally {
438
+ activeUpdate = null;
439
+ }
440
+ }
441
+ const spinner = createTtySpinner({
442
+ label,
443
+ output,
444
+ frames: FRAMES,
445
+ styleFrame: (frame) => pc.cyan(frame)
446
+ });
447
+ const update = (next) => {
448
+ lastLabel = next;
449
+ spinner.setLabel(next);
450
+ };
451
+ activeUpdate = update;
452
+ try {
453
+ const result = await work(update);
454
+ spinner.stop(options.doneLabel ? `${DONE_SYMBOL} ${options.doneLabel}` : undefined);
455
+ return result;
456
+ } catch (error) {
457
+ spinner.stop(`${FAIL_SYMBOL} ${lastLabel}`);
458
+ throw error;
459
+ } finally {
460
+ activeUpdate = null;
461
+ }
462
+ }
463
+
495
464
  // packages/cli/src/commands/doctor.ts
496
465
  async function executeDoctor(context, args) {
497
- requireNoExtraArgs(args, "rig doctor");
498
- const checks = await runRigDoctorChecks({ projectRoot: context.projectRoot });
466
+ requireNoExtraArgs(args, "legacy diagnostic: rig doctor");
467
+ const checks = await withSpinner("Running doctor checks\u2026", (update) => runRigDoctorChecks({ projectRoot: context.projectRoot, onProgress: update }), { outputMode: context.outputMode });
499
468
  if (context.outputMode === "text") {
500
469
  console.log(formatDoctorChecks(checks));
501
470
  }
@@ -0,0 +1,3 @@
1
+ import { type RunnerContext } from "../runner";
2
+ import type { CommandOutcome } from "@rig/runtime";
3
+ export declare function executeGithub(context: RunnerContext, args: string[]): Promise<CommandOutcome>;