@h-rig/cli 0.0.6-alpha.94 → 0.0.6-alpha.95
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.
- package/README.md +6 -27
- package/bin/rig.js +16 -0
- package/package.json +14 -40
- package/dist/bin/build-rig-binaries.d.ts +0 -2
- package/dist/bin/build-rig-binaries.js +0 -119
- package/dist/bin/rig.d.ts +0 -72
- package/dist/bin/rig.js +0 -17855
- package/dist/config/rig-default-config.yml +0 -5
- package/dist/src/app/drone-ui.d.ts +0 -34
- package/dist/src/app/drone-ui.js +0 -278
- package/dist/src/commands/_async-ui.d.ts +0 -10
- package/dist/src/commands/_async-ui.js +0 -121
- package/dist/src/commands/_cli-format.d.ts +0 -56
- package/dist/src/commands/_cli-format.js +0 -319
- package/dist/src/commands/_connection-state.d.ts +0 -54
- package/dist/src/commands/_connection-state.js +0 -187
- package/dist/src/commands/_doctor-checks.d.ts +0 -46
- package/dist/src/commands/_doctor-checks.js +0 -352
- package/dist/src/commands/_help-catalog.d.ts +0 -51
- package/dist/src/commands/_help-catalog.js +0 -502
- package/dist/src/commands/_inprocess-services.d.ts +0 -33
- package/dist/src/commands/_inprocess-services.js +0 -102
- package/dist/src/commands/_json-output.d.ts +0 -11
- package/dist/src/commands/_json-output.js +0 -60
- package/dist/src/commands/_lazy-reconcile.d.ts +0 -34
- package/dist/src/commands/_lazy-reconcile.js +0 -102
- package/dist/src/commands/_parsers.d.ts +0 -15
- package/dist/src/commands/_parsers.js +0 -114
- package/dist/src/commands/_paths.d.ts +0 -11
- package/dist/src/commands/_paths.js +0 -50
- package/dist/src/commands/_pi-frontend.d.ts +0 -35
- package/dist/src/commands/_pi-frontend.js +0 -64
- package/dist/src/commands/_pi-install.d.ts +0 -42
- package/dist/src/commands/_pi-install.js +0 -167
- package/dist/src/commands/_policy.d.ts +0 -8
- package/dist/src/commands/_policy.js +0 -127
- package/dist/src/commands/_probes.d.ts +0 -1
- package/dist/src/commands/_probes.js +0 -13
- package/dist/src/commands/_run-bridge.d.ts +0 -114
- package/dist/src/commands/_run-bridge.js +0 -387
- package/dist/src/commands/_run-diagnostics.d.ts +0 -9
- package/dist/src/commands/_run-diagnostics.js +0 -51
- package/dist/src/commands/_run-driver-helpers.d.ts +0 -26
- package/dist/src/commands/_run-driver-helpers.js +0 -138
- package/dist/src/commands/_run-projection.d.ts +0 -50
- package/dist/src/commands/_run-projection.js +0 -349
- package/dist/src/commands/_run-subcommands.d.ts +0 -3
- package/dist/src/commands/_run-subcommands.js +0 -31
- package/dist/src/commands/_spinner.d.ts +0 -25
- package/dist/src/commands/_spinner.js +0 -65
- package/dist/src/commands/agent.d.ts +0 -3
- package/dist/src/commands/agent.js +0 -8837
- package/dist/src/commands/dist.d.ts +0 -28
- package/dist/src/commands/dist.js +0 -417
- package/dist/src/commands/doctor.d.ts +0 -3
- package/dist/src/commands/doctor.js +0 -480
- package/dist/src/commands/github.d.ts +0 -3
- package/dist/src/commands/github.js +0 -342
- package/dist/src/commands/inbox.d.ts +0 -28
- package/dist/src/commands/inbox.js +0 -579
- package/dist/src/commands/init.d.ts +0 -64
- package/dist/src/commands/init.js +0 -1541
- package/dist/src/commands/inspect.d.ts +0 -20
- package/dist/src/commands/inspect.js +0 -764
- package/dist/src/commands/pi.d.ts +0 -3
- package/dist/src/commands/pi.js +0 -177
- package/dist/src/commands/plugin.d.ts +0 -16
- package/dist/src/commands/plugin.js +0 -714
- package/dist/src/commands/profile-and-review.d.ts +0 -4
- package/dist/src/commands/profile-and-review.js +0 -223
- package/dist/src/commands/queue.d.ts +0 -3
- package/dist/src/commands/queue.js +0 -197
- package/dist/src/commands/remote.d.ts +0 -3
- package/dist/src/commands/remote.js +0 -1337
- package/dist/src/commands/repo-git-harness.d.ts +0 -5
- package/dist/src/commands/repo-git-harness.js +0 -271
- package/dist/src/commands/run.d.ts +0 -21
- package/dist/src/commands/run.js +0 -17847
- package/dist/src/commands/server.d.ts +0 -3
- package/dist/src/commands/server.js +0 -249
- package/dist/src/commands/setup.d.ts +0 -16
- package/dist/src/commands/setup.js +0 -644
- package/dist/src/commands/stats.d.ts +0 -15
- package/dist/src/commands/stats.js +0 -979
- package/dist/src/commands/task-run-driver.d.ts +0 -94
- package/dist/src/commands/task-run-driver.js +0 -203
- package/dist/src/commands/task.d.ts +0 -35
- package/dist/src/commands/task.js +0 -818
- package/dist/src/commands/test.d.ts +0 -3
- package/dist/src/commands/test.js +0 -46
- package/dist/src/commands/triage.d.ts +0 -11
- package/dist/src/commands/triage.js +0 -227
- package/dist/src/commands/workspace.d.ts +0 -3
- package/dist/src/commands/workspace.js +0 -130
- package/dist/src/commands.d.ts +0 -13
- package/dist/src/commands.js +0 -17979
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -17991
- package/dist/src/launcher.d.ts +0 -61
- package/dist/src/launcher.js +0 -199
- package/dist/src/operator-cli.d.ts +0 -2
- package/dist/src/operator-cli.js +0 -17847
- package/dist/src/operator-entry.d.ts +0 -1
- package/dist/src/operator-entry.js +0 -3
- package/dist/src/runner.d.ts +0 -47
- package/dist/src/runner.js +0 -267
- package/dist/src/withMutedConsole.d.ts +0 -2
- package/dist/src/withMutedConsole.js +0 -42
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
var __require = import.meta.require;
|
|
3
|
-
|
|
4
|
-
// packages/cli/src/runner.ts
|
|
5
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
6
|
-
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
7
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
8
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
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
|
-
}
|
|
19
|
-
function requireNoExtraArgs(args, usage) {
|
|
20
|
-
if (args.length > 0) {
|
|
21
|
-
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
22
|
-
Usage: ${usage}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// packages/cli/src/commands/_doctor-checks.ts
|
|
27
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
28
|
-
import { resolve as resolve3 } from "path";
|
|
29
|
-
import { isSupportedBunVersion, MIN_SUPPORTED_BUN_VERSION } from "@rig/runtime/control-plane/setup-version";
|
|
30
|
-
|
|
31
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
32
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
33
|
-
import { dirname, resolve } from "path";
|
|
34
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
35
|
-
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
36
|
-
}
|
|
37
|
-
function readJsonFile(path) {
|
|
38
|
-
if (!existsSync(path))
|
|
39
|
-
return null;
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
42
|
-
} catch (error) {
|
|
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>`." });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function readRepoConnection(projectRoot) {
|
|
47
|
-
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
48
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
49
|
-
return null;
|
|
50
|
-
const record = payload;
|
|
51
|
-
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
52
|
-
if (!selected)
|
|
53
|
-
return null;
|
|
54
|
-
return {
|
|
55
|
-
selected,
|
|
56
|
-
project: typeof record.project === "string" ? record.project : 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
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
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;
|
|
76
|
-
function cleanToken(value) {
|
|
77
|
-
const trimmed = value?.trim();
|
|
78
|
-
return trimmed ? trimmed : null;
|
|
79
|
-
}
|
|
80
|
-
function cleanString(value) {
|
|
81
|
-
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
82
|
-
}
|
|
83
|
-
function oauthClientId() {
|
|
84
|
-
return cleanToken(process.env.RIG_GITHUB_OAUTH_CLIENT_ID);
|
|
85
|
-
}
|
|
86
|
-
async function getGitHubAuthStatusInProcess(context) {
|
|
87
|
-
return { ok: true, ...resolveGitHubAuthStatus({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) }) };
|
|
88
|
-
}
|
|
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()) });
|
|
95
|
-
}
|
|
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}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// packages/cli/src/commands/_parsers.ts
|
|
122
|
-
async function loadRigConfigOrNull(projectRoot) {
|
|
123
|
-
try {
|
|
124
|
-
const { loadConfig } = await import("@rig/core/load-config");
|
|
125
|
-
return await loadConfig(projectRoot);
|
|
126
|
-
} catch {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// packages/cli/src/commands/_pi-install.ts
|
|
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";
|
|
136
|
-
async function defaultCommandRunner(command, options = {}) {
|
|
137
|
-
const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
|
|
138
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
139
|
-
new Response(proc.stdout).text(),
|
|
140
|
-
new Response(proc.stderr).text(),
|
|
141
|
-
proc.exited
|
|
142
|
-
]);
|
|
143
|
-
return { exitCode, stdout, stderr };
|
|
144
|
-
}
|
|
145
|
-
function resolvePiRigExtensionPath(homeDir) {
|
|
146
|
-
return resolve2(homeDir, ".pi", "agent", "extensions", "pi-rig");
|
|
147
|
-
}
|
|
148
|
-
function resolvePiHomeDir(inputHomeDir) {
|
|
149
|
-
return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
|
|
150
|
-
}
|
|
151
|
-
function piListContainsPiRig(output) {
|
|
152
|
-
return output.split(/\r?\n/).some((line) => {
|
|
153
|
-
const normalized = line.trim();
|
|
154
|
-
return normalized.includes(PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
async function safeRun(runner, command, options) {
|
|
158
|
-
try {
|
|
159
|
-
return await runner(command, options);
|
|
160
|
-
} catch (error) {
|
|
161
|
-
return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async function checkPiRigInstall(input = {}) {
|
|
165
|
-
const home = resolvePiHomeDir(input.homeDir);
|
|
166
|
-
const extensionPath = resolvePiRigExtensionPath(home);
|
|
167
|
-
if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
|
|
168
|
-
return {
|
|
169
|
-
extensionPath,
|
|
170
|
-
pi: { ok: true, label: "pi", detail: "fake-pi" },
|
|
171
|
-
piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
const runner = input.commandRunner ?? defaultCommandRunner;
|
|
175
|
-
const piResult = await safeRun(runner, ["pi", "--version"]);
|
|
176
|
-
const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
|
|
177
|
-
const hasPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
|
|
178
|
-
${piListResult.stderr}`);
|
|
179
|
-
const hasLegacyBridgeScaffold = !hasPiRig && (input.exists ?? existsSync2)(extensionPath);
|
|
180
|
-
return {
|
|
181
|
-
extensionPath,
|
|
182
|
-
pi: {
|
|
183
|
-
ok: piResult.exitCode === 0,
|
|
184
|
-
label: "pi",
|
|
185
|
-
detail: (piResult.stdout || piResult.stderr).trim() || undefined,
|
|
186
|
-
hint: piResult.exitCode === 0 ? undefined : "Install Pi/OMP manually or set RIG_PI_INSTALL_COMMAND before verifying with bare `rig` / Cockpit \u2192 Doctor."
|
|
187
|
-
},
|
|
188
|
-
piRig: {
|
|
189
|
-
ok: hasPiRig,
|
|
190
|
-
label: "pi-rig global extension",
|
|
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.`
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
async function buildPiSetupChecks(input = {}) {
|
|
197
|
-
const status = await checkPiRigInstall(input);
|
|
198
|
-
return [status.pi, status.piRig];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// packages/cli/src/commands/_doctor-checks.ts
|
|
202
|
-
function check(id, label, status, detail, remediation) {
|
|
203
|
-
return {
|
|
204
|
-
id,
|
|
205
|
-
label,
|
|
206
|
-
status,
|
|
207
|
-
...detail ? { detail } : {},
|
|
208
|
-
...remediation ? { remediation } : {}
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function errorMessage(error) {
|
|
212
|
-
return error instanceof Error ? error.message : String(error);
|
|
213
|
-
}
|
|
214
|
-
function isAuthenticated(payload) {
|
|
215
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
216
|
-
return false;
|
|
217
|
-
const record = payload;
|
|
218
|
-
return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
|
|
219
|
-
}
|
|
220
|
-
function loadFallbackConfig(projectRoot) {
|
|
221
|
-
const candidates = ["rig.config.ts", "rig.config.mts", "rig.config.json"];
|
|
222
|
-
for (const name of candidates) {
|
|
223
|
-
const path = resolve3(projectRoot, name);
|
|
224
|
-
if (!existsSync3(path))
|
|
225
|
-
continue;
|
|
226
|
-
try {
|
|
227
|
-
const source = readFileSync2(path, "utf8");
|
|
228
|
-
if (name.endsWith(".json"))
|
|
229
|
-
return JSON.parse(source);
|
|
230
|
-
const owner = source.match(/owner\s*:\s*["']([^"']+)["']/)?.[1];
|
|
231
|
-
const repo = source.match(/repo\s*:\s*["']([^"']+)["']/)?.[1];
|
|
232
|
-
const projectRepo = source.match(/project\s*:\s*\{[^}]*repo\s*:\s*["']([^"']+)["']/s)?.[1] ?? (owner && repo ? `${owner}/${repo}` : undefined);
|
|
233
|
-
const taskKind = source.match(/taskSource\s*:\s*\{[^}]*kind\s*:\s*["']([^"']+)["']/s)?.[1];
|
|
234
|
-
if (projectRepo || taskKind) {
|
|
235
|
-
return {
|
|
236
|
-
...projectRepo ? { project: { name: projectRepo, repo: projectRepo } } : {},
|
|
237
|
-
...taskKind ? { taskSource: { kind: taskKind, ...owner ? { owner } : {}, ...repo ? { repo } : {} } } : {}
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
} catch {
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
function githubProjectsCheck(config) {
|
|
247
|
-
const github = config?.github;
|
|
248
|
-
const projects = github?.projects;
|
|
249
|
-
if (!projects?.enabled) {
|
|
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.");
|
|
251
|
-
}
|
|
252
|
-
if (projects.projectId && projects.statusFieldId) {
|
|
253
|
-
return check("github-projects", "GitHub Projects status sync", "pass", `project ${projects.projectId}`);
|
|
254
|
-
}
|
|
255
|
-
return check("github-projects", "GitHub Projects status sync", "fail", "enabled but projectId/statusFieldId is incomplete", "Configure github.projects.projectId and github.projects.statusFieldId, or disable github.projects.enabled.");
|
|
256
|
-
}
|
|
257
|
-
function permissionAllowsPr(payload) {
|
|
258
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
259
|
-
return null;
|
|
260
|
-
const record = payload;
|
|
261
|
-
if (record.canOpenPullRequest === true || record.pullRequests === true || record.push === true || record.maintain === true || record.admin === true)
|
|
262
|
-
return true;
|
|
263
|
-
if (record.canOpenPullRequest === false || record.pullRequests === false || record.push === false)
|
|
264
|
-
return false;
|
|
265
|
-
const permissions = record.permissions;
|
|
266
|
-
if (permissions && typeof permissions === "object" && !Array.isArray(permissions)) {
|
|
267
|
-
const p = permissions;
|
|
268
|
-
if (p.push === true || p.maintain === true || p.admin === true)
|
|
269
|
-
return true;
|
|
270
|
-
if (p.push === false && p.maintain !== true && p.admin !== true)
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
function prMergeCheck(config) {
|
|
276
|
-
const pr = config?.pr;
|
|
277
|
-
const merge = config?.merge;
|
|
278
|
-
if (pr?.mode === "off" || merge?.mode === "off") {
|
|
279
|
-
return check("pr-merge", "PR/merge automation", "warn", "automatic PR or merge is disabled", "Set pr.mode and merge.mode to auto for autonomous YOLO runs.");
|
|
280
|
-
}
|
|
281
|
-
return check("pr-merge", "PR/merge automation", "pass", `pr=${pr?.mode ?? "auto"}, merge=${merge?.mode ?? "auto"}, method=${merge?.method ?? "repo-default"}`);
|
|
282
|
-
}
|
|
283
|
-
async function runRigDoctorChecks(options) {
|
|
284
|
-
const projectRoot = options.projectRoot;
|
|
285
|
-
const checks = [];
|
|
286
|
-
const which = options.which ?? ((binary) => Bun.which(binary));
|
|
287
|
-
const bunVersion = options.bunVersion ?? Bun.version;
|
|
288
|
-
const request = options.requestJson ?? ((pathname, init) => requestGitHubAuthJsonInProcess({ projectRoot }, pathname, init));
|
|
289
|
-
const loadConfig = options.loadConfig ?? loadRigConfigOrNull;
|
|
290
|
-
const progress = options.onProgress ?? (() => {});
|
|
291
|
-
progress("Checking local toolchain\u2026");
|
|
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");
|
|
294
|
-
const loadedConfig = await loadConfig(projectRoot).catch(() => null);
|
|
295
|
-
const config = loadedConfig ?? loadFallbackConfig(projectRoot);
|
|
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."));
|
|
298
|
-
const taskSourceKind = config?.taskSource?.kind;
|
|
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."));
|
|
300
|
-
const repo = readRepoConnection(projectRoot);
|
|
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."));
|
|
302
|
-
try {
|
|
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>`."));
|
|
306
|
-
} catch (error) {
|
|
307
|
-
checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig."));
|
|
308
|
-
}
|
|
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."));
|
|
316
|
-
}
|
|
317
|
-
if (taskSourceKind === "github-issues") {
|
|
318
|
-
checks.push(check("gh", "gh CLI fallback", which("gh") ? "pass" : "warn", which("gh") ?? undefined, "Install gh for local/dev GitHub fallback operations."));
|
|
319
|
-
}
|
|
320
|
-
checks.push(githubProjectsCheck(config));
|
|
321
|
-
checks.push(prMergeCheck(config));
|
|
322
|
-
progress("Checking Pi installation\u2026");
|
|
323
|
-
const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
|
|
324
|
-
ok: false,
|
|
325
|
-
label: "pi/pi-rig checks",
|
|
326
|
-
hint: errorMessage(error)
|
|
327
|
-
}]);
|
|
328
|
-
for (const pi of piChecks) {
|
|
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.")));
|
|
330
|
-
}
|
|
331
|
-
return checks;
|
|
332
|
-
}
|
|
333
|
-
function formatDoctorChecks(checks) {
|
|
334
|
-
return checks.map((entry) => {
|
|
335
|
-
const prefix = entry.status.toUpperCase();
|
|
336
|
-
const detail = entry.detail ? ` \u2014 ${entry.detail}` : "";
|
|
337
|
-
const remediation = entry.remediation && entry.status !== "pass" ? ` (${entry.remediation})` : "";
|
|
338
|
-
return `${prefix}: ${entry.label}${detail}${remediation}`;
|
|
339
|
-
}).join(`
|
|
340
|
-
`);
|
|
341
|
-
}
|
|
342
|
-
function countDoctorFailures(checks) {
|
|
343
|
-
return checks.filter((entry) => entry.status === "fail").length;
|
|
344
|
-
}
|
|
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
|
-
|
|
464
|
-
// packages/cli/src/commands/doctor.ts
|
|
465
|
-
async function executeDoctor(context, args) {
|
|
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 });
|
|
468
|
-
if (context.outputMode === "text") {
|
|
469
|
-
console.log(formatDoctorChecks(checks));
|
|
470
|
-
}
|
|
471
|
-
return {
|
|
472
|
-
ok: countDoctorFailures(checks) === 0,
|
|
473
|
-
group: "doctor",
|
|
474
|
-
command: "check",
|
|
475
|
-
details: { checks, failures: countDoctorFailures(checks) }
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
export {
|
|
479
|
-
executeDoctor
|
|
480
|
-
};
|