@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.91

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 (116) 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 +15637 -7344
  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/_connection-state.d.ts +54 -0
  14. package/dist/src/commands/_connection-state.js +75 -11
  15. package/dist/src/commands/_doctor-checks.d.ts +46 -0
  16. package/dist/src/commands/_doctor-checks.js +100 -267
  17. package/dist/src/commands/_help-catalog.d.ts +51 -0
  18. package/dist/src/commands/_help-catalog.js +502 -0
  19. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  20. package/dist/src/commands/_inprocess-services.js +102 -0
  21. package/dist/src/commands/_json-output.d.ts +11 -0
  22. package/dist/src/commands/_json-output.js +60 -0
  23. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  24. package/dist/src/commands/_lazy-reconcile.js +102 -0
  25. package/dist/src/commands/_parsers.d.ts +15 -0
  26. package/dist/src/commands/_parsers.js +18 -11
  27. package/dist/src/commands/_paths.d.ts +11 -0
  28. package/dist/src/commands/_paths.js +1 -1
  29. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  30. package/dist/src/commands/_pi-frontend.js +64 -0
  31. package/dist/src/commands/_pi-install.d.ts +42 -0
  32. package/dist/src/commands/_pi-install.js +19 -36
  33. package/dist/src/commands/_policy.d.ts +8 -0
  34. package/dist/src/commands/_policy.js +67 -19
  35. package/dist/src/commands/_probes.d.ts +1 -0
  36. package/dist/src/commands/_run-bridge.d.ts +114 -0
  37. package/dist/src/commands/_run-bridge.js +387 -0
  38. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  39. package/dist/src/commands/_run-diagnostics.js +51 -0
  40. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  41. package/dist/src/commands/_run-driver-helpers.js +79 -230
  42. package/dist/src/commands/_run-projection.d.ts +50 -0
  43. package/dist/src/commands/_run-projection.js +349 -0
  44. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  45. package/dist/src/commands/_run-subcommands.js +31 -0
  46. package/dist/src/commands/_spinner.d.ts +25 -0
  47. package/dist/src/commands/_spinner.js +65 -0
  48. package/dist/src/commands/agent.d.ts +3 -0
  49. package/dist/src/commands/agent.js +8575 -236
  50. package/dist/src/commands/dist.d.ts +28 -0
  51. package/dist/src/commands/dist.js +44 -29
  52. package/dist/src/commands/doctor.d.ts +3 -0
  53. package/dist/src/commands/doctor.js +219 -268
  54. package/dist/src/commands/github.d.ts +3 -0
  55. package/dist/src/commands/github.js +236 -188
  56. package/dist/src/commands/inbox.d.ts +28 -0
  57. package/dist/src/commands/inbox.js +530 -111
  58. package/dist/src/commands/init.d.ts +64 -0
  59. package/dist/src/commands/init.js +912 -705
  60. package/dist/src/commands/inspect.d.ts +20 -0
  61. package/dist/src/commands/inspect.js +709 -119
  62. package/dist/src/commands/pi.d.ts +3 -0
  63. package/dist/src/commands/pi.js +177 -0
  64. package/dist/src/commands/plugin.d.ts +16 -0
  65. package/dist/src/commands/plugin.js +576 -29
  66. package/dist/src/commands/profile-and-review.d.ts +4 -0
  67. package/dist/src/commands/profile-and-review.js +112 -67
  68. package/dist/src/commands/queue.d.ts +3 -0
  69. package/dist/src/commands/queue.js +20 -20
  70. package/dist/src/commands/remote.d.ts +3 -0
  71. package/dist/src/commands/remote.js +880 -50
  72. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  73. package/dist/src/commands/repo-git-harness.js +78 -28
  74. package/dist/src/commands/run.d.ts +21 -0
  75. package/dist/src/commands/run.js +17701 -661
  76. package/dist/src/commands/server.d.ts +3 -0
  77. package/dist/src/commands/server.js +166 -303
  78. package/dist/src/commands/setup.d.ts +16 -0
  79. package/dist/src/commands/setup.js +244 -299
  80. package/dist/src/commands/stats.d.ts +15 -0
  81. package/dist/src/commands/stats.js +979 -0
  82. package/dist/src/commands/task-run-driver.d.ts +94 -0
  83. package/dist/src/commands/task-run-driver.js +116 -1961
  84. package/dist/src/commands/task.d.ts +35 -0
  85. package/dist/src/commands/task.js +676 -1201
  86. package/dist/src/commands/test.d.ts +3 -0
  87. package/dist/src/commands/test.js +15 -8
  88. package/dist/src/commands/triage.d.ts +11 -0
  89. package/dist/src/commands/triage.js +227 -0
  90. package/dist/src/commands/workspace.d.ts +3 -0
  91. package/dist/src/commands/workspace.js +18 -11
  92. package/dist/src/commands.d.ts +13 -0
  93. package/dist/src/commands.js +16792 -8055
  94. package/dist/src/index.d.ts +4 -0
  95. package/dist/src/index.js +16862 -8450
  96. package/dist/src/launcher.d.ts +61 -0
  97. package/dist/src/launcher.js +81 -13
  98. package/dist/src/operator-cli.d.ts +2 -0
  99. package/dist/src/operator-cli.js +17837 -0
  100. package/dist/src/operator-entry.d.ts +1 -0
  101. package/dist/src/operator-entry.js +3 -0
  102. package/dist/src/runner.d.ts +47 -0
  103. package/dist/src/runner.js +16 -22
  104. package/dist/src/withMutedConsole.d.ts +2 -0
  105. package/package.json +21 -8
  106. package/dist/src/commands/_authority-runs.js +0 -111
  107. package/dist/src/commands/_operator-view.js +0 -340
  108. package/dist/src/commands/_preflight.js +0 -478
  109. package/dist/src/commands/_server-client.js +0 -382
  110. package/dist/src/commands/_snapshot-upload.js +0 -331
  111. package/dist/src/commands/_task-picker.js +0 -48
  112. package/dist/src/commands/browser.js +0 -890
  113. package/dist/src/commands/connect.js +0 -180
  114. package/dist/src/commands/inspector.js +0 -256
  115. package/dist/src/commands/task-report-bug.js +0 -1083
  116. 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 existsSync4, readFileSync as readFileSync4 } from "fs";
21
- import { resolve as resolve4 } from "path";
27
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
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,130 +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 { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
109
- import { resolve as resolve2 } from "path";
110
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
111
- 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;
112
76
  function cleanToken(value) {
113
77
  const trimmed = value?.trim();
114
78
  return trimmed ? trimmed : null;
115
79
  }
116
- function readPrivateRemoteSessionToken(projectRoot) {
117
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
118
- if (!existsSync2(path))
119
- return null;
120
- try {
121
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
122
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
123
- } catch {
124
- return null;
125
- }
80
+ function cleanString(value) {
81
+ return typeof value === "string" && value.trim() ? value.trim() : null;
126
82
  }
127
- function readGitHubBearerTokenForRemote(projectRoot) {
128
- if (cachedGitHubBearerToken !== undefined)
129
- return cachedGitHubBearerToken;
130
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
131
- if (privateSession) {
132
- cachedGitHubBearerToken = privateSession;
133
- return cachedGitHubBearerToken;
134
- }
135
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
136
- if (envToken) {
137
- cachedGitHubBearerToken = envToken;
138
- return cachedGitHubBearerToken;
139
- }
140
- const result = spawnSync("gh", ["auth", "token"], {
141
- encoding: "utf8",
142
- timeout: 5000,
143
- stdio: ["ignore", "pipe", "ignore"]
144
- });
145
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
146
- return cachedGitHubBearerToken;
83
+ function oauthClientId() {
84
+ return cleanToken(process.env.RIG_GITHUB_OAUTH_CLIENT_ID);
147
85
  }
148
- async function ensureServerForCli(projectRoot) {
149
- try {
150
- const selected = resolveSelectedConnection(projectRoot);
151
- if (selected?.connection.kind === "remote") {
152
- return {
153
- baseUrl: selected.connection.baseUrl,
154
- authToken: readGitHubBearerTokenForRemote(projectRoot),
155
- connectionKind: "remote"
156
- };
157
- }
158
- const connection = await ensureLocalRigServerConnection(projectRoot);
159
- return {
160
- baseUrl: connection.baseUrl,
161
- authToken: connection.authToken,
162
- connectionKind: "local"
163
- };
164
- } catch (error) {
165
- if (error instanceof Error) {
166
- throw new CliError2(error.message, 1);
167
- }
168
- throw error;
169
- }
86
+ async function getGitHubAuthStatusInProcess(context) {
87
+ return { ok: true, ...resolveGitHubAuthStatus({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) }) };
170
88
  }
171
- function mergeHeaders(headers, authToken) {
172
- const merged = new Headers(headers);
173
- if (authToken) {
174
- merged.set("authorization", `Bearer ${authToken}`);
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()) });
175
95
  }
176
- return merged;
177
- }
178
- function diagnosticMessage(payload) {
179
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
180
- return null;
181
- const record = payload;
182
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
183
- const messages = diagnostics.flatMap((entry) => {
184
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
185
- return [];
186
- const diagnostic = entry;
187
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
188
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
189
- return message ? [`${kind}: ${message}`] : [];
190
- });
191
- return messages.length > 0 ? messages.join("; ") : null;
192
- }
193
- async function requestServerJson(context, pathname, init = {}) {
194
- const server = await ensureServerForCli(context.projectRoot);
195
- const response = await fetch(`${server.baseUrl}${pathname}`, {
196
- ...init,
197
- headers: mergeHeaders(init.headers, server.authToken)
198
- });
199
- const text = await response.text();
200
- const payload = text.trim().length > 0 ? (() => {
201
- try {
202
- return JSON.parse(text);
203
- } catch {
204
- return null;
205
- }
206
- })() : null;
207
- if (!response.ok) {
208
- const diagnostics = diagnosticMessage(payload);
209
- const detail = diagnostics ?? (text || response.statusText);
210
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
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) });
211
117
  }
212
- return payload;
118
+ throw new Error(`No in-process GitHub auth API for ${method} ${pathname}`);
213
119
  }
214
120
 
215
121
  // packages/cli/src/commands/_parsers.ts
@@ -223,10 +129,10 @@ async function loadRigConfigOrNull(projectRoot) {
223
129
  }
224
130
 
225
131
  // packages/cli/src/commands/_pi-install.ts
226
- import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync } from "fs";
227
- import { homedir as homedir2 } from "os";
228
- import { resolve as resolve3 } from "path";
229
- var PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
132
+ import { existsSync as existsSync2 } from "fs";
133
+ import { homedir } from "os";
134
+ import { resolve as resolve2 } from "path";
135
+ var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
230
136
  async function defaultCommandRunner(command, options = {}) {
231
137
  const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
232
138
  const [stdout, stderr, exitCode] = await Promise.all([
@@ -237,10 +143,10 @@ async function defaultCommandRunner(command, options = {}) {
237
143
  return { exitCode, stdout, stderr };
238
144
  }
239
145
  function resolvePiRigExtensionPath(homeDir) {
240
- return resolve3(homeDir, ".pi", "agent", "extensions", "pi-rig");
146
+ return resolve2(homeDir, ".pi", "agent", "extensions", "pi-rig");
241
147
  }
242
148
  function resolvePiHomeDir(inputHomeDir) {
243
- return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir2();
149
+ return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
244
150
  }
245
151
  function piListContainsPiRig(output) {
246
152
  return output.split(/\r?\n/).some((line) => {
@@ -265,27 +171,25 @@ async function checkPiRigInstall(input = {}) {
265
171
  piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
266
172
  };
267
173
  }
268
- const exists = input.exists ?? existsSync3;
269
174
  const runner = input.commandRunner ?? defaultCommandRunner;
270
175
  const piResult = await safeRun(runner, ["pi", "--version"]);
271
176
  const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
272
- const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
177
+ const hasPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
273
178
  ${piListResult.stderr}`);
274
- const legacyBridge = exists(resolve3(extensionPath, "index.ts"));
275
- const hasPiRig = listedPiRig;
179
+ const hasLegacyBridgeScaffold = !hasPiRig && (input.exists ?? existsSync2)(extensionPath);
276
180
  return {
277
181
  extensionPath,
278
182
  pi: {
279
183
  ok: piResult.exitCode === 0,
280
184
  label: "pi",
281
185
  detail: (piResult.stdout || piResult.stderr).trim() || undefined,
282
- 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."
283
187
  },
284
188
  piRig: {
285
189
  ok: hasPiRig,
286
190
  label: "pi-rig global extension",
287
- detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
288
- 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.`
289
193
  }
290
194
  };
291
195
  }
@@ -313,31 +217,14 @@ function isAuthenticated(payload) {
313
217
  const record = payload;
314
218
  return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
315
219
  }
316
- function repoSlugFromConfig(config) {
317
- const project = config?.project;
318
- if (project && typeof project === "object" && !Array.isArray(project)) {
319
- const record = project;
320
- if (typeof record.repo === "string" && /^([^/\s]+)\/([^/\s]+)$/.test(record.repo))
321
- return record.repo;
322
- if (typeof record.name === "string" && /^([^/\s]+)\/([^/\s]+)$/.test(record.name))
323
- return record.name;
324
- }
325
- const taskSource = config?.taskSource;
326
- if (taskSource && typeof taskSource === "object" && !Array.isArray(taskSource)) {
327
- const source = taskSource;
328
- if (typeof source.owner === "string" && typeof source.repo === "string")
329
- return `${source.owner}/${source.repo}`;
330
- }
331
- return null;
332
- }
333
220
  function loadFallbackConfig(projectRoot) {
334
221
  const candidates = ["rig.config.ts", "rig.config.mts", "rig.config.json"];
335
222
  for (const name of candidates) {
336
- const path = resolve4(projectRoot, name);
337
- if (!existsSync4(path))
223
+ const path = resolve3(projectRoot, name);
224
+ if (!existsSync3(path))
338
225
  continue;
339
226
  try {
340
- const source = readFileSync4(path, "utf8");
227
+ const source = readFileSync2(path, "utf8");
341
228
  if (name.endsWith(".json"))
342
229
  return JSON.parse(source);
343
230
  const owner = source.match(/owner\s*:\s*["']([^"']+)["']/)?.[1];
@@ -356,14 +243,11 @@ function loadFallbackConfig(projectRoot) {
356
243
  }
357
244
  return null;
358
245
  }
359
- function projectStatusSlug(projectRoot, config) {
360
- return readRepoConnection(projectRoot)?.project ?? repoSlugFromConfig(config);
361
- }
362
246
  function githubProjectsCheck(config) {
363
247
  const github = config?.github;
364
248
  const projects = github?.projects;
365
249
  if (!projects?.enabled) {
366
- 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.");
367
251
  }
368
252
  if (projects.projectId && projects.statusFieldId) {
369
253
  return check("github-projects", "GitHub Projects status sync", "pass", `project ${projects.projectId}`);
@@ -388,16 +272,6 @@ function permissionAllowsPr(payload) {
388
272
  }
389
273
  return null;
390
274
  }
391
- function labelsReady(payload) {
392
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
393
- return null;
394
- const record = payload;
395
- if (record.ok === true || record.ready === true || record.labelsReady === true)
396
- return true;
397
- if (record.ok === false || record.ready === false || record.labelsReady === false)
398
- return false;
399
- return null;
400
- }
401
275
  function prMergeCheck(config) {
402
276
  const pr = config?.pr;
403
277
  const merge = config?.merge;
@@ -411,89 +285,48 @@ async function runRigDoctorChecks(options) {
411
285
  const checks = [];
412
286
  const which = options.which ?? ((binary) => Bun.which(binary));
413
287
  const bunVersion = options.bunVersion ?? Bun.version;
414
- const request = options.requestJson ?? ((pathname, init) => requestServerJson({ projectRoot }, pathname, init));
288
+ const request = options.requestJson ?? ((pathname, init) => requestGitHubAuthJsonInProcess({ projectRoot }, pathname, init));
415
289
  const loadConfig = options.loadConfig ?? loadRigConfigOrNull;
290
+ const progress = options.onProgress ?? (() => {});
291
+ progress("Checking local toolchain\u2026");
416
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");
417
294
  const loadedConfig = await loadConfig(projectRoot).catch(() => null);
418
295
  const config = loadedConfig ?? loadFallbackConfig(projectRoot);
419
- const hasConfigFile = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync4(resolve4(projectRoot, name)));
420
- 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."));
296
+ const hasConfigFile = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync3(resolve3(projectRoot, name)));
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."));
421
298
  const taskSourceKind = config?.taskSource?.kind;
422
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."));
423
300
  const repo = readRepoConnection(projectRoot);
424
- 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>`."));
425
- const selected = (() => {
426
- try {
427
- return resolveSelectedConnection(projectRoot);
428
- } catch {
429
- return null;
430
- }
431
- })();
432
- 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));
433
- 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."));
434
302
  try {
435
- server = await (options.resolveServer ?? ensureServerForCli)(projectRoot);
436
- 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>`."));
437
306
  } catch (error) {
438
- 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."));
439
308
  }
440
- if (server || options.requestJson) {
441
- try {
442
- const status = await request("/api/server/status");
443
- checks.push(check("server-status", "server project status", "pass", JSON.stringify(status).slice(0, 180)));
444
- } catch (error) {
445
- checks.push(check("server-status", "server project status", "fail", errorMessage(error), "Run `rig doctor` after the selected server is reachable."));
446
- }
447
- try {
448
- const auth = await request("/api/github/auth/status");
449
- 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>`."));
450
- } catch (error) {
451
- checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig and ensure the server exposes auth status."));
452
- }
453
- try {
454
- const permissions = await request("/api/github/repo/permissions");
455
- const allowed = permissionAllowsPr(permissions);
456
- 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."));
457
- } catch (error) {
458
- 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."));
459
- }
460
- try {
461
- const labels = await request("/api/workspace/task-labels");
462
- const ready = labelsReady(labels);
463
- 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."));
464
- } catch (error) {
465
- checks.push(check("task-labels", "GitHub issue labels", "warn", errorMessage(error), "Run `rig init`/`rig doctor` after label setup is wired on the server."));
466
- }
467
- try {
468
- const projection = await request("/api/workspace/task-projection");
469
- checks.push(check("task-projection", "task projection", "pass", JSON.stringify(projection).slice(0, 180)));
470
- } catch (error) {
471
- checks.push(check("task-projection", "task projection", "warn", errorMessage(error), "Refresh task projection with `rig task list` or fix the task source."));
472
- }
473
- const slug = projectStatusSlug(projectRoot, config);
474
- if (slug) {
475
- try {
476
- const project = await request(`/api/projects/${encodeURIComponent(slug)}`);
477
- checks.push(check("remote-checkout", "server project checkout", "pass", JSON.stringify(project).slice(0, 180)));
478
- } catch (error) {
479
- 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."));
480
- }
481
- } else {
482
- checks.push(check("remote-checkout", "server project checkout", "warn", "repo slug unknown", "Set project.repo or run `rig init --repo owner/repo`."));
483
- }
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."));
484
316
  }
485
317
  if (taskSourceKind === "github-issues") {
486
318
  checks.push(check("gh", "gh CLI fallback", which("gh") ? "pass" : "warn", which("gh") ?? undefined, "Install gh for local/dev GitHub fallback operations."));
487
319
  }
488
320
  checks.push(githubProjectsCheck(config));
489
321
  checks.push(prMergeCheck(config));
322
+ progress("Checking Pi installation\u2026");
490
323
  const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
491
324
  ok: false,
492
325
  label: "pi/pi-rig checks",
493
326
  hint: errorMessage(error)
494
327
  }]);
495
328
  for (const pi of piChecks) {
496
- 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.")));
497
330
  }
498
331
  return checks;
499
332
  }
@@ -510,10 +343,128 @@ function countDoctorFailures(checks) {
510
343
  return checks.filter((entry) => entry.status === "fail").length;
511
344
  }
512
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
+
513
464
  // packages/cli/src/commands/doctor.ts
514
465
  async function executeDoctor(context, args) {
515
- requireNoExtraArgs(args, "rig doctor");
516
- 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 });
517
468
  if (context.outputMode === "text") {
518
469
  console.log(formatDoctorChecks(checks));
519
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>;