@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
@@ -2,34 +2,31 @@
2
2
  var __require = import.meta.require;
3
3
 
4
4
  // packages/cli/src/commands/_doctor-checks.ts
5
- import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
6
- import { resolve as resolve4 } from "path";
5
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
6
+ import { resolve as resolve3 } 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
 
17
24
  // packages/cli/src/commands/_doctor-checks.ts
18
25
  import { isSupportedBunVersion, MIN_SUPPORTED_BUN_VERSION } from "@rig/runtime/control-plane/setup-version";
19
26
 
20
27
  // packages/cli/src/commands/_connection-state.ts
21
28
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
22
- import { homedir } from "os";
23
29
  import { dirname, resolve } from "path";
24
- function resolveGlobalConnectionsPath(env = process.env) {
25
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
26
- if (explicit)
27
- return resolve(explicit);
28
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
29
- if (stateDir)
30
- return resolve(stateDir, "connections.json");
31
- return resolve(homedir(), ".rig", "connections.json");
32
- }
33
30
  function resolveRepoConnectionPath(projectRoot) {
34
31
  return resolve(projectRoot, ".rig", "state", "connection.json");
35
32
  }
@@ -39,37 +36,8 @@ function readJsonFile(path) {
39
36
  try {
40
37
  return JSON.parse(readFileSync(path, "utf8"));
41
38
  } catch (error) {
42
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
43
- }
44
- }
45
- function normalizeConnection(value) {
46
- if (!value || typeof value !== "object" || Array.isArray(value))
47
- return null;
48
- const record = value;
49
- if (record.kind === "local")
50
- return { kind: "local", mode: "auto" };
51
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
52
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
53
- return { kind: "remote", baseUrl };
39
+ 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>`." });
54
40
  }
55
- return null;
56
- }
57
- function readGlobalConnections(options = {}) {
58
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
59
- const payload = readJsonFile(path);
60
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
61
- return { connections: {} };
62
- }
63
- const rawConnections = payload.connections;
64
- const connections = {};
65
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
66
- for (const [alias, raw] of Object.entries(rawConnections)) {
67
- const connection = normalizeConnection(raw);
68
- if (connection)
69
- connections[alias] = connection;
70
- }
71
- }
72
- return { connections };
73
41
  }
74
42
  function readRepoConnection(projectRoot) {
75
43
  const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
@@ -82,130 +50,68 @@ function readRepoConnection(projectRoot) {
82
50
  return {
83
51
  selected,
84
52
  project: typeof record.project === "string" ? record.project : undefined,
85
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
53
+ linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
54
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
55
+ serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
56
+ serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
86
57
  };
87
58
  }
88
- function resolveSelectedConnection(projectRoot, options = {}) {
89
- const repo = readRepoConnection(projectRoot);
90
- if (!repo)
91
- return null;
92
- if (repo.selected === "local")
93
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
94
- const global = readGlobalConnections(options);
95
- const connection = global.connections[repo.selected];
96
- if (!connection) {
97
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
98
- }
99
- return { alias: repo.selected, connection };
100
- }
101
59
 
102
- // packages/cli/src/commands/_server-client.ts
103
- import { spawnSync } from "child_process";
104
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
105
- import { resolve as resolve2 } from "path";
106
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
107
- var cachedGitHubBearerToken;
60
+ // packages/cli/src/commands/_inprocess-services.ts
61
+ import {
62
+ beginGitHubDeviceFlow,
63
+ checkGitHubRepoPermissions,
64
+ createGitHubAuthStore,
65
+ listGitHubProjects,
66
+ pollGitHubDeviceFlow,
67
+ resolveGitHubAuthStatus,
68
+ resolveProjectStatusField,
69
+ saveGitHubTokenForProject
70
+ } from "@rig/runtime/control-plane/github/index";
71
+ var scopedGitHubBearerTokens = new Map;
108
72
  function cleanToken(value) {
109
73
  const trimmed = value?.trim();
110
74
  return trimmed ? trimmed : null;
111
75
  }
112
- function readPrivateRemoteSessionToken(projectRoot) {
113
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
114
- if (!existsSync2(path))
115
- return null;
116
- try {
117
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
118
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
119
- } catch {
120
- return null;
121
- }
76
+ function cleanString(value) {
77
+ return typeof value === "string" && value.trim() ? value.trim() : null;
122
78
  }
123
- function readGitHubBearerTokenForRemote(projectRoot) {
124
- if (cachedGitHubBearerToken !== undefined)
125
- return cachedGitHubBearerToken;
126
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
127
- if (privateSession) {
128
- cachedGitHubBearerToken = privateSession;
129
- return cachedGitHubBearerToken;
130
- }
131
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
132
- if (envToken) {
133
- cachedGitHubBearerToken = envToken;
134
- return cachedGitHubBearerToken;
135
- }
136
- const result = spawnSync("gh", ["auth", "token"], {
137
- encoding: "utf8",
138
- timeout: 5000,
139
- stdio: ["ignore", "pipe", "ignore"]
140
- });
141
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
142
- return cachedGitHubBearerToken;
79
+ function oauthClientId() {
80
+ return cleanToken(process.env.RIG_GITHUB_OAUTH_CLIENT_ID);
143
81
  }
144
- async function ensureServerForCli(projectRoot) {
145
- try {
146
- const selected = resolveSelectedConnection(projectRoot);
147
- if (selected?.connection.kind === "remote") {
148
- return {
149
- baseUrl: selected.connection.baseUrl,
150
- authToken: readGitHubBearerTokenForRemote(projectRoot),
151
- connectionKind: "remote"
152
- };
153
- }
154
- const connection = await ensureLocalRigServerConnection(projectRoot);
155
- return {
156
- baseUrl: connection.baseUrl,
157
- authToken: connection.authToken,
158
- connectionKind: "local"
159
- };
160
- } catch (error) {
161
- if (error instanceof Error) {
162
- throw new CliError2(error.message, 1);
163
- }
164
- throw error;
165
- }
82
+ async function getGitHubAuthStatusInProcess(context) {
83
+ return { ok: true, ...resolveGitHubAuthStatus({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) }) };
166
84
  }
167
- function mergeHeaders(headers, authToken) {
168
- const merged = new Headers(headers);
169
- if (authToken) {
170
- merged.set("authorization", `Bearer ${authToken}`);
85
+ async function requestGitHubAuthJsonInProcess(context, pathname, init = {}) {
86
+ const method = (init.method ?? "GET").toUpperCase();
87
+ if (pathname === "/api/github/auth/status")
88
+ return getGitHubAuthStatusInProcess(context);
89
+ if (pathname === "/api/github/repo/permissions") {
90
+ return checkGitHubRepoPermissions({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) });
171
91
  }
172
- return merged;
173
- }
174
- function diagnosticMessage(payload) {
175
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
176
- return null;
177
- const record = payload;
178
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
179
- const messages = diagnostics.flatMap((entry) => {
180
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
181
- return [];
182
- const diagnostic = entry;
183
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
184
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
185
- return message ? [`${kind}: ${message}`] : [];
186
- });
187
- return messages.length > 0 ? messages.join("; ") : null;
188
- }
189
- async function requestServerJson(context, pathname, init = {}) {
190
- const server = await ensureServerForCli(context.projectRoot);
191
- const response = await fetch(`${server.baseUrl}${pathname}`, {
192
- ...init,
193
- headers: mergeHeaders(init.headers, server.authToken)
194
- });
195
- const text = await response.text();
196
- const payload = text.trim().length > 0 ? (() => {
197
- try {
198
- return JSON.parse(text);
199
- } catch {
200
- return null;
201
- }
202
- })() : null;
203
- if (!response.ok) {
204
- const diagnostics = diagnosticMessage(payload);
205
- const detail = diagnostics ?? (text || response.statusText);
206
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
92
+ if (pathname === "/api/github/auth/device/start" && method === "POST") {
93
+ const clientId = oauthClientId();
94
+ if (!clientId)
95
+ return { ok: false, oauthConfigured: false, error: "RIG_GITHUB_OAUTH_CLIENT_ID is not configured." };
96
+ const body = init.body ? JSON.parse(String(init.body)) : {};
97
+ return beginGitHubDeviceFlow({
98
+ projectRoot: context.projectRoot,
99
+ clientId,
100
+ scope: cleanString(body.scope) ?? undefined,
101
+ selectedRepo: cleanString(body.repoSlug)
102
+ });
103
+ }
104
+ if (pathname === "/api/github/auth/device/poll" && method === "POST") {
105
+ const clientId = oauthClientId();
106
+ if (!clientId)
107
+ return { ok: false, oauthConfigured: false, error: "RIG_GITHUB_OAUTH_CLIENT_ID is not configured." };
108
+ const body = init.body ? JSON.parse(String(init.body)) : {};
109
+ const pollId = cleanString(body.pollId);
110
+ if (!pollId)
111
+ return { ok: false, status: "error", error: "pollId is required" };
112
+ return pollGitHubDeviceFlow({ projectRoot: context.projectRoot, clientId, pollId, selectedRepo: cleanString(body.repoSlug) });
207
113
  }
208
- return payload;
114
+ throw new Error(`No in-process GitHub auth API for ${method} ${pathname}`);
209
115
  }
210
116
 
211
117
  // packages/cli/src/commands/_parsers.ts
@@ -219,10 +125,10 @@ async function loadRigConfigOrNull(projectRoot) {
219
125
  }
220
126
 
221
127
  // packages/cli/src/commands/_pi-install.ts
222
- import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync } from "fs";
223
- import { homedir as homedir2 } from "os";
224
- import { resolve as resolve3 } from "path";
225
- var PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
128
+ import { existsSync as existsSync2 } from "fs";
129
+ import { homedir } from "os";
130
+ import { resolve as resolve2 } from "path";
131
+ var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
226
132
  async function defaultCommandRunner(command, options = {}) {
227
133
  const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
228
134
  const [stdout, stderr, exitCode] = await Promise.all([
@@ -233,10 +139,10 @@ async function defaultCommandRunner(command, options = {}) {
233
139
  return { exitCode, stdout, stderr };
234
140
  }
235
141
  function resolvePiRigExtensionPath(homeDir) {
236
- return resolve3(homeDir, ".pi", "agent", "extensions", "pi-rig");
142
+ return resolve2(homeDir, ".pi", "agent", "extensions", "pi-rig");
237
143
  }
238
144
  function resolvePiHomeDir(inputHomeDir) {
239
- return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir2();
145
+ return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
240
146
  }
241
147
  function piListContainsPiRig(output) {
242
148
  return output.split(/\r?\n/).some((line) => {
@@ -261,27 +167,25 @@ async function checkPiRigInstall(input = {}) {
261
167
  piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
262
168
  };
263
169
  }
264
- const exists = input.exists ?? existsSync3;
265
170
  const runner = input.commandRunner ?? defaultCommandRunner;
266
171
  const piResult = await safeRun(runner, ["pi", "--version"]);
267
172
  const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
268
- const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
173
+ const hasPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
269
174
  ${piListResult.stderr}`);
270
- const legacyBridge = exists(resolve3(extensionPath, "index.ts"));
271
- const hasPiRig = listedPiRig;
175
+ const hasLegacyBridgeScaffold = !hasPiRig && (input.exists ?? existsSync2)(extensionPath);
272
176
  return {
273
177
  extensionPath,
274
178
  pi: {
275
179
  ok: piResult.exitCode === 0,
276
180
  label: "pi",
277
181
  detail: (piResult.stdout || piResult.stderr).trim() || undefined,
278
- hint: piResult.exitCode === 0 ? undefined : "Install Pi or run `rig init --yes` to install/update the Pi runtime."
182
+ hint: piResult.exitCode === 0 ? undefined : "Install Pi/OMP manually or set RIG_PI_INSTALL_COMMAND before verifying with bare `rig` / Cockpit \u2192 Doctor."
279
183
  },
280
184
  piRig: {
281
185
  ok: hasPiRig,
282
186
  label: "pi-rig global extension",
283
- detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
284
- hint: hasPiRig ? undefined : "Run `rig init --yes` to install/enable the global pi-rig package with `pi install`."
187
+ detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : hasLegacyBridgeScaffold ? `legacy bridge scaffold at ${extensionPath}` : undefined,
188
+ hint: hasPiRig ? undefined : `Install the Rig OMP extension with \`pi install ${PI_RIG_PACKAGE_NAME}\`, then verify with bare \`rig\` / Cockpit \u2192 Doctor.`
285
189
  }
286
190
  };
287
191
  }
@@ -309,31 +213,14 @@ function isAuthenticated(payload) {
309
213
  const record = payload;
310
214
  return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
311
215
  }
312
- function repoSlugFromConfig(config) {
313
- const project = config?.project;
314
- if (project && typeof project === "object" && !Array.isArray(project)) {
315
- const record = project;
316
- if (typeof record.repo === "string" && /^([^/\s]+)\/([^/\s]+)$/.test(record.repo))
317
- return record.repo;
318
- if (typeof record.name === "string" && /^([^/\s]+)\/([^/\s]+)$/.test(record.name))
319
- return record.name;
320
- }
321
- const taskSource = config?.taskSource;
322
- if (taskSource && typeof taskSource === "object" && !Array.isArray(taskSource)) {
323
- const source = taskSource;
324
- if (typeof source.owner === "string" && typeof source.repo === "string")
325
- return `${source.owner}/${source.repo}`;
326
- }
327
- return null;
328
- }
329
216
  function loadFallbackConfig(projectRoot) {
330
217
  const candidates = ["rig.config.ts", "rig.config.mts", "rig.config.json"];
331
218
  for (const name of candidates) {
332
- const path = resolve4(projectRoot, name);
333
- if (!existsSync4(path))
219
+ const path = resolve3(projectRoot, name);
220
+ if (!existsSync3(path))
334
221
  continue;
335
222
  try {
336
- const source = readFileSync4(path, "utf8");
223
+ const source = readFileSync2(path, "utf8");
337
224
  if (name.endsWith(".json"))
338
225
  return JSON.parse(source);
339
226
  const owner = source.match(/owner\s*:\s*["']([^"']+)["']/)?.[1];
@@ -352,14 +239,11 @@ function loadFallbackConfig(projectRoot) {
352
239
  }
353
240
  return null;
354
241
  }
355
- function projectStatusSlug(projectRoot, config) {
356
- return readRepoConnection(projectRoot)?.project ?? repoSlugFromConfig(config);
357
- }
358
242
  function githubProjectsCheck(config) {
359
243
  const github = config?.github;
360
244
  const projects = github?.projects;
361
245
  if (!projects?.enabled) {
362
- 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.");
246
+ 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.");
363
247
  }
364
248
  if (projects.projectId && projects.statusFieldId) {
365
249
  return check("github-projects", "GitHub Projects status sync", "pass", `project ${projects.projectId}`);
@@ -384,16 +268,6 @@ function permissionAllowsPr(payload) {
384
268
  }
385
269
  return null;
386
270
  }
387
- function labelsReady(payload) {
388
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
389
- return null;
390
- const record = payload;
391
- if (record.ok === true || record.ready === true || record.labelsReady === true)
392
- return true;
393
- if (record.ok === false || record.ready === false || record.labelsReady === false)
394
- return false;
395
- return null;
396
- }
397
271
  function prMergeCheck(config) {
398
272
  const pr = config?.pr;
399
273
  const merge = config?.merge;
@@ -407,89 +281,48 @@ async function runRigDoctorChecks(options) {
407
281
  const checks = [];
408
282
  const which = options.which ?? ((binary) => Bun.which(binary));
409
283
  const bunVersion = options.bunVersion ?? Bun.version;
410
- const request = options.requestJson ?? ((pathname, init) => requestServerJson({ projectRoot }, pathname, init));
284
+ const request = options.requestJson ?? ((pathname, init) => requestGitHubAuthJsonInProcess({ projectRoot }, pathname, init));
411
285
  const loadConfig = options.loadConfig ?? loadRigConfigOrNull;
286
+ const progress = options.onProgress ?? (() => {});
287
+ progress("Checking local toolchain\u2026");
412
288
  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`)."));
289
+ progress("Loading rig.config\u2026");
413
290
  const loadedConfig = await loadConfig(projectRoot).catch(() => null);
414
291
  const config = loadedConfig ?? loadFallbackConfig(projectRoot);
415
- const hasConfigFile = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync4(resolve4(projectRoot, name)));
416
- 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."));
292
+ const hasConfigFile = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync3(resolve3(projectRoot, name)));
293
+ 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."));
417
294
  const taskSourceKind = config?.taskSource?.kind;
418
295
  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."));
419
296
  const repo = readRepoConnection(projectRoot);
420
- 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>`."));
421
- const selected = (() => {
422
- try {
423
- return resolveSelectedConnection(projectRoot);
424
- } catch {
425
- return null;
426
- }
427
- })();
428
- 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));
429
- let server = null;
297
+ 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."));
430
298
  try {
431
- server = await (options.resolveServer ?? ensureServerForCli)(projectRoot);
432
- checks.push(check("server", "Rig server reachable", "pass", `${server.connectionKind} ${server.baseUrl}`));
299
+ progress("Checking GitHub auth\u2026");
300
+ const auth = await request("/api/github/auth/status");
301
+ 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>`."));
433
302
  } catch (error) {
434
- checks.push(check("server", "Rig server reachable", "fail", errorMessage(error), "Start the local Rig server or fix the selected remote connection."));
303
+ checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig."));
435
304
  }
436
- if (server || options.requestJson) {
437
- try {
438
- const status = await request("/api/server/status");
439
- checks.push(check("server-status", "server project status", "pass", JSON.stringify(status).slice(0, 180)));
440
- } catch (error) {
441
- checks.push(check("server-status", "server project status", "fail", errorMessage(error), "Run `rig doctor` after the selected server is reachable."));
442
- }
443
- try {
444
- const auth = await request("/api/github/auth/status");
445
- 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>`."));
446
- } catch (error) {
447
- checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig and ensure the server exposes auth status."));
448
- }
449
- try {
450
- const permissions = await request("/api/github/repo/permissions");
451
- const allowed = permissionAllowsPr(permissions);
452
- 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."));
453
- } catch (error) {
454
- 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."));
455
- }
456
- try {
457
- const labels = await request("/api/workspace/task-labels");
458
- const ready = labelsReady(labels);
459
- 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."));
460
- } catch (error) {
461
- checks.push(check("task-labels", "GitHub issue labels", "warn", errorMessage(error), "Run `rig init`/`rig doctor` after label setup is wired on the server."));
462
- }
463
- try {
464
- const projection = await request("/api/workspace/task-projection");
465
- checks.push(check("task-projection", "task projection", "pass", JSON.stringify(projection).slice(0, 180)));
466
- } catch (error) {
467
- checks.push(check("task-projection", "task projection", "warn", errorMessage(error), "Refresh task projection with `rig task list` or fix the task source."));
468
- }
469
- const slug = projectStatusSlug(projectRoot, config);
470
- if (slug) {
471
- try {
472
- const project = await request(`/api/projects/${encodeURIComponent(slug)}`);
473
- checks.push(check("remote-checkout", "server project checkout", "pass", JSON.stringify(project).slice(0, 180)));
474
- } catch (error) {
475
- 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."));
476
- }
477
- } else {
478
- checks.push(check("remote-checkout", "server project checkout", "warn", "repo slug unknown", "Set project.repo or run `rig init --repo owner/repo`."));
479
- }
305
+ try {
306
+ progress("Checking GitHub repo permissions\u2026");
307
+ const permissions = await request("/api/github/repo/permissions");
308
+ const allowed = permissionAllowsPr(permissions);
309
+ 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."));
310
+ } catch (error) {
311
+ checks.push(check("github-repo-permissions", "GitHub repo PR permissions", "warn", errorMessage(error), "Ensure the token can open PRs."));
480
312
  }
481
313
  if (taskSourceKind === "github-issues") {
482
314
  checks.push(check("gh", "gh CLI fallback", which("gh") ? "pass" : "warn", which("gh") ?? undefined, "Install gh for local/dev GitHub fallback operations."));
483
315
  }
484
316
  checks.push(githubProjectsCheck(config));
485
317
  checks.push(prMergeCheck(config));
318
+ progress("Checking Pi installation\u2026");
486
319
  const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
487
320
  ok: false,
488
321
  label: "pi/pi-rig checks",
489
322
  hint: errorMessage(error)
490
323
  }]);
491
324
  for (const pi of piChecks) {
492
- 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.")));
325
+ 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.")));
493
326
  }
494
327
  return checks;
495
328
  }
@@ -508,7 +341,7 @@ function countDoctorFailures(checks) {
508
341
  function throwIfDoctorFailed(checks) {
509
342
  const failures = countDoctorFailures(checks);
510
343
  if (failures > 0) {
511
- throw new CliError2(`Doctor failed (${failures} failing check${failures === 1 ? "" : "s"}).`, 1);
344
+ throw new CliError(`Doctor failed (${failures} failing check${failures === 1 ? "" : "s"}).`, 1);
512
345
  }
513
346
  }
514
347
  export {
@@ -0,0 +1,51 @@
1
+ export type HelpCommand = {
2
+ command: string;
3
+ description: string;
4
+ primary?: boolean;
5
+ };
6
+ export type HelpGroup = {
7
+ name: string;
8
+ summary: string;
9
+ usage: string[];
10
+ commands: HelpCommand[];
11
+ examples?: string[];
12
+ next?: string[];
13
+ advanced?: string[];
14
+ };
15
+ export type TopLevelSection = {
16
+ title: string;
17
+ subtitle: string;
18
+ commands: HelpCommand[];
19
+ };
20
+ /** Catalog DATA for the app's help view — the view builds its own layout
21
+ * from these; the render* functions below remain for plain/script output. */
22
+ export declare function helpCatalog(): {
23
+ sections: readonly TopLevelSection[];
24
+ groups: readonly HelpGroup[];
25
+ };
26
+ /**
27
+ * Night City boot screen. Rendered only on interactive TTY launches — plain
28
+ * mode and --json never see it.
29
+ */
30
+ export declare function renderRigBanner(version?: string): string;
31
+ export declare function renderTopLevelHelp(): string;
32
+ export declare function renderAdvancedHelp(): string;
33
+ export declare function renderGroupHelp(groupName: string): string | null;
34
+ export declare function listHelpGroups(): string[];
35
+ /**
36
+ * Fuzzy-match a bare word against known group subcommand names so the
37
+ * unknown-command error can suggest the canonical `rig <group> <cmd>`
38
+ * spelling. Primary groups win ties (ALL_GROUPS is primary-first).
39
+ */
40
+ export declare function suggestGroupCommandForWord(word: string, liveGroups?: ReadonlySet<string>): string | null;
41
+ export type TopLevelLaunchState = {
42
+ /** True when the cwd resolves to an initialized Rig project. */
43
+ projectInitialized?: boolean;
44
+ /** Short description of the selected server connection, if known. */
45
+ selectedServer?: string | null;
46
+ /** CLI version for the banner footer. */
47
+ version?: string;
48
+ };
49
+ export declare function printTopLevelHelp(state?: TopLevelLaunchState): void;
50
+ export declare function printAdvancedHelp(): void;
51
+ export declare function printGroupHelpDocument(groupName: string): void;