@h-rig/cli 0.0.6-alpha.100 → 0.0.6-alpha.101
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 -17875
- 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/_config-env.d.ts +0 -18
- package/dist/src/commands/_config-env.js +0 -22
- 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 -29
- package/dist/src/commands/_help-catalog.js +0 -146
- 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 -8952
- package/dist/src/commands/config.d.ts +0 -3
- package/dist/src/commands/config.js +0 -181
- 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 -1340
- 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 -17867
- 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 -632
- 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 -17999
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -18011
- 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 -17867
- 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,352 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
var __require = import.meta.require;
|
|
3
|
-
|
|
4
|
-
// packages/cli/src/commands/_doctor-checks.ts
|
|
5
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
6
|
-
import { resolve as resolve3 } from "path";
|
|
7
|
-
|
|
8
|
-
// packages/cli/src/runner.ts
|
|
9
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
10
|
-
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
11
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
12
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
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
|
-
}
|
|
23
|
-
|
|
24
|
-
// packages/cli/src/commands/_doctor-checks.ts
|
|
25
|
-
import { isSupportedBunVersion, MIN_SUPPORTED_BUN_VERSION } from "@rig/runtime/control-plane/setup-version";
|
|
26
|
-
|
|
27
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
28
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
29
|
-
import { dirname, resolve } from "path";
|
|
30
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
31
|
-
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
32
|
-
}
|
|
33
|
-
function readJsonFile(path) {
|
|
34
|
-
if (!existsSync(path))
|
|
35
|
-
return null;
|
|
36
|
-
try {
|
|
37
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
38
|
-
} catch (error) {
|
|
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>`." });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function readRepoConnection(projectRoot) {
|
|
43
|
-
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
44
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
45
|
-
return null;
|
|
46
|
-
const record = payload;
|
|
47
|
-
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
48
|
-
if (!selected)
|
|
49
|
-
return null;
|
|
50
|
-
return {
|
|
51
|
-
selected,
|
|
52
|
-
project: typeof record.project === "string" ? record.project : 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
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
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;
|
|
72
|
-
function cleanToken(value) {
|
|
73
|
-
const trimmed = value?.trim();
|
|
74
|
-
return trimmed ? trimmed : null;
|
|
75
|
-
}
|
|
76
|
-
function cleanString(value) {
|
|
77
|
-
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
78
|
-
}
|
|
79
|
-
function oauthClientId() {
|
|
80
|
-
return cleanToken(process.env.RIG_GITHUB_OAUTH_CLIENT_ID);
|
|
81
|
-
}
|
|
82
|
-
async function getGitHubAuthStatusInProcess(context) {
|
|
83
|
-
return { ok: true, ...resolveGitHubAuthStatus({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) }) };
|
|
84
|
-
}
|
|
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()) });
|
|
91
|
-
}
|
|
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) });
|
|
113
|
-
}
|
|
114
|
-
throw new Error(`No in-process GitHub auth API for ${method} ${pathname}`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// packages/cli/src/commands/_parsers.ts
|
|
118
|
-
async function loadRigConfigOrNull(projectRoot) {
|
|
119
|
-
try {
|
|
120
|
-
const { loadConfig } = await import("@rig/core/load-config");
|
|
121
|
-
return await loadConfig(projectRoot);
|
|
122
|
-
} catch {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// packages/cli/src/commands/_pi-install.ts
|
|
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";
|
|
132
|
-
async function defaultCommandRunner(command, options = {}) {
|
|
133
|
-
const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
|
|
134
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
135
|
-
new Response(proc.stdout).text(),
|
|
136
|
-
new Response(proc.stderr).text(),
|
|
137
|
-
proc.exited
|
|
138
|
-
]);
|
|
139
|
-
return { exitCode, stdout, stderr };
|
|
140
|
-
}
|
|
141
|
-
function resolvePiRigExtensionPath(homeDir) {
|
|
142
|
-
return resolve2(homeDir, ".pi", "agent", "extensions", "pi-rig");
|
|
143
|
-
}
|
|
144
|
-
function resolvePiHomeDir(inputHomeDir) {
|
|
145
|
-
return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
|
|
146
|
-
}
|
|
147
|
-
function piListContainsPiRig(output) {
|
|
148
|
-
return output.split(/\r?\n/).some((line) => {
|
|
149
|
-
const normalized = line.trim();
|
|
150
|
-
return normalized.includes(PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
async function safeRun(runner, command, options) {
|
|
154
|
-
try {
|
|
155
|
-
return await runner(command, options);
|
|
156
|
-
} catch (error) {
|
|
157
|
-
return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
async function checkPiRigInstall(input = {}) {
|
|
161
|
-
const home = resolvePiHomeDir(input.homeDir);
|
|
162
|
-
const extensionPath = resolvePiRigExtensionPath(home);
|
|
163
|
-
if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
|
|
164
|
-
return {
|
|
165
|
-
extensionPath,
|
|
166
|
-
pi: { ok: true, label: "pi", detail: "fake-pi" },
|
|
167
|
-
piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const runner = input.commandRunner ?? defaultCommandRunner;
|
|
171
|
-
const piResult = await safeRun(runner, ["pi", "--version"]);
|
|
172
|
-
const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
|
|
173
|
-
const hasPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
|
|
174
|
-
${piListResult.stderr}`);
|
|
175
|
-
const hasLegacyBridgeScaffold = !hasPiRig && (input.exists ?? existsSync2)(extensionPath);
|
|
176
|
-
return {
|
|
177
|
-
extensionPath,
|
|
178
|
-
pi: {
|
|
179
|
-
ok: piResult.exitCode === 0,
|
|
180
|
-
label: "pi",
|
|
181
|
-
detail: (piResult.stdout || piResult.stderr).trim() || undefined,
|
|
182
|
-
hint: piResult.exitCode === 0 ? undefined : "Install Pi/OMP manually or set RIG_PI_INSTALL_COMMAND before verifying with bare `rig` / Cockpit \u2192 Doctor."
|
|
183
|
-
},
|
|
184
|
-
piRig: {
|
|
185
|
-
ok: hasPiRig,
|
|
186
|
-
label: "pi-rig global extension",
|
|
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.`
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
async function buildPiSetupChecks(input = {}) {
|
|
193
|
-
const status = await checkPiRigInstall(input);
|
|
194
|
-
return [status.pi, status.piRig];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// packages/cli/src/commands/_doctor-checks.ts
|
|
198
|
-
function check(id, label, status, detail, remediation) {
|
|
199
|
-
return {
|
|
200
|
-
id,
|
|
201
|
-
label,
|
|
202
|
-
status,
|
|
203
|
-
...detail ? { detail } : {},
|
|
204
|
-
...remediation ? { remediation } : {}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function errorMessage(error) {
|
|
208
|
-
return error instanceof Error ? error.message : String(error);
|
|
209
|
-
}
|
|
210
|
-
function isAuthenticated(payload) {
|
|
211
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
212
|
-
return false;
|
|
213
|
-
const record = payload;
|
|
214
|
-
return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
|
|
215
|
-
}
|
|
216
|
-
function loadFallbackConfig(projectRoot) {
|
|
217
|
-
const candidates = ["rig.config.ts", "rig.config.mts", "rig.config.json"];
|
|
218
|
-
for (const name of candidates) {
|
|
219
|
-
const path = resolve3(projectRoot, name);
|
|
220
|
-
if (!existsSync3(path))
|
|
221
|
-
continue;
|
|
222
|
-
try {
|
|
223
|
-
const source = readFileSync2(path, "utf8");
|
|
224
|
-
if (name.endsWith(".json"))
|
|
225
|
-
return JSON.parse(source);
|
|
226
|
-
const owner = source.match(/owner\s*:\s*["']([^"']+)["']/)?.[1];
|
|
227
|
-
const repo = source.match(/repo\s*:\s*["']([^"']+)["']/)?.[1];
|
|
228
|
-
const projectRepo = source.match(/project\s*:\s*\{[^}]*repo\s*:\s*["']([^"']+)["']/s)?.[1] ?? (owner && repo ? `${owner}/${repo}` : undefined);
|
|
229
|
-
const taskKind = source.match(/taskSource\s*:\s*\{[^}]*kind\s*:\s*["']([^"']+)["']/s)?.[1];
|
|
230
|
-
if (projectRepo || taskKind) {
|
|
231
|
-
return {
|
|
232
|
-
...projectRepo ? { project: { name: projectRepo, repo: projectRepo } } : {},
|
|
233
|
-
...taskKind ? { taskSource: { kind: taskKind, ...owner ? { owner } : {}, ...repo ? { repo } : {} } } : {}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
} catch {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
function githubProjectsCheck(config) {
|
|
243
|
-
const github = config?.github;
|
|
244
|
-
const projects = github?.projects;
|
|
245
|
-
if (!projects?.enabled) {
|
|
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.");
|
|
247
|
-
}
|
|
248
|
-
if (projects.projectId && projects.statusFieldId) {
|
|
249
|
-
return check("github-projects", "GitHub Projects status sync", "pass", `project ${projects.projectId}`);
|
|
250
|
-
}
|
|
251
|
-
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.");
|
|
252
|
-
}
|
|
253
|
-
function permissionAllowsPr(payload) {
|
|
254
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
255
|
-
return null;
|
|
256
|
-
const record = payload;
|
|
257
|
-
if (record.canOpenPullRequest === true || record.pullRequests === true || record.push === true || record.maintain === true || record.admin === true)
|
|
258
|
-
return true;
|
|
259
|
-
if (record.canOpenPullRequest === false || record.pullRequests === false || record.push === false)
|
|
260
|
-
return false;
|
|
261
|
-
const permissions = record.permissions;
|
|
262
|
-
if (permissions && typeof permissions === "object" && !Array.isArray(permissions)) {
|
|
263
|
-
const p = permissions;
|
|
264
|
-
if (p.push === true || p.maintain === true || p.admin === true)
|
|
265
|
-
return true;
|
|
266
|
-
if (p.push === false && p.maintain !== true && p.admin !== true)
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
function prMergeCheck(config) {
|
|
272
|
-
const pr = config?.pr;
|
|
273
|
-
const merge = config?.merge;
|
|
274
|
-
if (pr?.mode === "off" || merge?.mode === "off") {
|
|
275
|
-
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.");
|
|
276
|
-
}
|
|
277
|
-
return check("pr-merge", "PR/merge automation", "pass", `pr=${pr?.mode ?? "auto"}, merge=${merge?.mode ?? "auto"}, method=${merge?.method ?? "repo-default"}`);
|
|
278
|
-
}
|
|
279
|
-
async function runRigDoctorChecks(options) {
|
|
280
|
-
const projectRoot = options.projectRoot;
|
|
281
|
-
const checks = [];
|
|
282
|
-
const which = options.which ?? ((binary) => Bun.which(binary));
|
|
283
|
-
const bunVersion = options.bunVersion ?? Bun.version;
|
|
284
|
-
const request = options.requestJson ?? ((pathname, init) => requestGitHubAuthJsonInProcess({ projectRoot }, pathname, init));
|
|
285
|
-
const loadConfig = options.loadConfig ?? loadRigConfigOrNull;
|
|
286
|
-
const progress = options.onProgress ?? (() => {});
|
|
287
|
-
progress("Checking local toolchain\u2026");
|
|
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");
|
|
290
|
-
const loadedConfig = await loadConfig(projectRoot).catch(() => null);
|
|
291
|
-
const config = loadedConfig ?? loadFallbackConfig(projectRoot);
|
|
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."));
|
|
294
|
-
const taskSourceKind = config?.taskSource?.kind;
|
|
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."));
|
|
296
|
-
const repo = readRepoConnection(projectRoot);
|
|
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."));
|
|
298
|
-
try {
|
|
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>`."));
|
|
302
|
-
} catch (error) {
|
|
303
|
-
checks.push(check("github-auth", "GitHub auth", "fail", errorMessage(error), "Authenticate GitHub through Rig."));
|
|
304
|
-
}
|
|
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."));
|
|
312
|
-
}
|
|
313
|
-
if (taskSourceKind === "github-issues") {
|
|
314
|
-
checks.push(check("gh", "gh CLI fallback", which("gh") ? "pass" : "warn", which("gh") ?? undefined, "Install gh for local/dev GitHub fallback operations."));
|
|
315
|
-
}
|
|
316
|
-
checks.push(githubProjectsCheck(config));
|
|
317
|
-
checks.push(prMergeCheck(config));
|
|
318
|
-
progress("Checking Pi installation\u2026");
|
|
319
|
-
const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
|
|
320
|
-
ok: false,
|
|
321
|
-
label: "pi/pi-rig checks",
|
|
322
|
-
hint: errorMessage(error)
|
|
323
|
-
}]);
|
|
324
|
-
for (const pi of piChecks) {
|
|
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.")));
|
|
326
|
-
}
|
|
327
|
-
return checks;
|
|
328
|
-
}
|
|
329
|
-
function formatDoctorChecks(checks) {
|
|
330
|
-
return checks.map((entry) => {
|
|
331
|
-
const prefix = entry.status.toUpperCase();
|
|
332
|
-
const detail = entry.detail ? ` \u2014 ${entry.detail}` : "";
|
|
333
|
-
const remediation = entry.remediation && entry.status !== "pass" ? ` (${entry.remediation})` : "";
|
|
334
|
-
return `${prefix}: ${entry.label}${detail}${remediation}`;
|
|
335
|
-
}).join(`
|
|
336
|
-
`);
|
|
337
|
-
}
|
|
338
|
-
function countDoctorFailures(checks) {
|
|
339
|
-
return checks.filter((entry) => entry.status === "fail").length;
|
|
340
|
-
}
|
|
341
|
-
function throwIfDoctorFailed(checks) {
|
|
342
|
-
const failures = countDoctorFailures(checks);
|
|
343
|
-
if (failures > 0) {
|
|
344
|
-
throw new CliError(`Doctor failed (${failures} failing check${failures === 1 ? "" : "s"}).`, 1);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
export {
|
|
348
|
-
throwIfDoctorFailed,
|
|
349
|
-
runRigDoctorChecks,
|
|
350
|
-
formatDoctorChecks,
|
|
351
|
-
countDoctorFailures
|
|
352
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { helpCatalog, type HelpCommand, type HelpGroup, type TopLevelSection } from "@rig/contracts";
|
|
2
|
-
export { helpCatalog };
|
|
3
|
-
export type { HelpCommand, HelpGroup, TopLevelSection };
|
|
4
|
-
/**
|
|
5
|
-
* Night City boot screen. Rendered only on interactive TTY launches — plain
|
|
6
|
-
* mode and --json never see it.
|
|
7
|
-
*/
|
|
8
|
-
export declare function renderRigBanner(version?: string): string;
|
|
9
|
-
export declare function renderTopLevelHelp(): string;
|
|
10
|
-
export declare function renderAdvancedHelp(): string;
|
|
11
|
-
export declare function renderGroupHelp(groupName: string): string | null;
|
|
12
|
-
export declare function listHelpGroups(): string[];
|
|
13
|
-
/**
|
|
14
|
-
* Fuzzy-match a bare word against known group subcommand names so the
|
|
15
|
-
* unknown-command error can suggest the canonical `rig <group> <cmd>`
|
|
16
|
-
* spelling. Primary groups win ties (ALL_GROUPS is primary-first).
|
|
17
|
-
*/
|
|
18
|
-
export declare function suggestGroupCommandForWord(word: string, liveGroups?: ReadonlySet<string>): string | null;
|
|
19
|
-
export type TopLevelLaunchState = {
|
|
20
|
-
/** True when the cwd resolves to an initialized Rig project. */
|
|
21
|
-
projectInitialized?: boolean;
|
|
22
|
-
/** Short description of the selected server connection, if known. */
|
|
23
|
-
selectedServer?: string | null;
|
|
24
|
-
/** CLI version for the banner footer. */
|
|
25
|
-
version?: string;
|
|
26
|
-
};
|
|
27
|
-
export declare function printTopLevelHelp(state?: TopLevelLaunchState): void;
|
|
28
|
-
export declare function printAdvancedHelp(): void;
|
|
29
|
-
export declare function printGroupHelpDocument(groupName: string): void;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/_help-catalog.ts
|
|
3
|
-
import pc from "picocolors";
|
|
4
|
-
import {
|
|
5
|
-
ADVANCED_COMMANDS,
|
|
6
|
-
ADVANCED_GROUPS,
|
|
7
|
-
ALL_GROUPS,
|
|
8
|
-
helpCatalog,
|
|
9
|
-
TOP_LEVEL_SECTIONS
|
|
10
|
-
} from "@rig/contracts";
|
|
11
|
-
function heading(title) {
|
|
12
|
-
return pc.bold(pc.cyan(title));
|
|
13
|
-
}
|
|
14
|
-
function renderRigBanner(version) {
|
|
15
|
-
const m = (s) => pc.bold(pc.magenta(s));
|
|
16
|
-
const c = (s) => pc.bold(pc.cyan(s));
|
|
17
|
-
const y = (s) => pc.yellow(s);
|
|
18
|
-
const d = (s) => pc.dim(s);
|
|
19
|
-
const lines = [
|
|
20
|
-
m(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ") + d(" \u2591\u2592\u2593\u2588 "),
|
|
21
|
-
m(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ") + d("\u2593\u2592\u2591"),
|
|
22
|
-
c(" \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557") + d(" \u2591\u2592"),
|
|
23
|
-
c(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551") + d(" \u2588\u2593\u2591"),
|
|
24
|
-
y(" \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D") + d(" \u2592\u2591"),
|
|
25
|
-
y(" \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),
|
|
26
|
-
"",
|
|
27
|
-
` ${c("\u25E2\u25E4")} ${pc.bold("OMP extension cockpit for autonomous coding agents")} ${m("//")} ${d("you are the operator")}`,
|
|
28
|
-
version ? ` ${d(`v${version} \xB7 jack in: rig`)}` : ` ${d("jack in: rig")}`
|
|
29
|
-
];
|
|
30
|
-
return lines.join(`
|
|
31
|
-
`);
|
|
32
|
-
}
|
|
33
|
-
function commandLine(command, description) {
|
|
34
|
-
const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
|
|
35
|
-
return `${pc.dim("\u2502")} ${pc.bold(commandColumn)} ${description}`;
|
|
36
|
-
}
|
|
37
|
-
function renderCommandBlock(commands) {
|
|
38
|
-
return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
39
|
-
`);
|
|
40
|
-
}
|
|
41
|
-
function renderGroup(group) {
|
|
42
|
-
const lines = [
|
|
43
|
-
`${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
|
|
44
|
-
"",
|
|
45
|
-
pc.bold("Usage"),
|
|
46
|
-
...group.usage.map((line) => ` ${line}`),
|
|
47
|
-
"",
|
|
48
|
-
pc.bold("Commands"),
|
|
49
|
-
...group.commands.map((entry) => commandLine(entry.command, entry.description))
|
|
50
|
-
];
|
|
51
|
-
if (group.examples?.length) {
|
|
52
|
-
lines.push("", pc.bold("Examples"), ...group.examples.map((line) => ` ${pc.dim("$")} ${line}`));
|
|
53
|
-
}
|
|
54
|
-
if (group.next?.length) {
|
|
55
|
-
lines.push("", pc.bold("Next steps"), ...group.next.map((line) => ` ${pc.dim("\u203A")} ${line}`));
|
|
56
|
-
}
|
|
57
|
-
if (group.advanced?.length) {
|
|
58
|
-
lines.push("", pc.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc.dim("\u203A")} ${line}`));
|
|
59
|
-
}
|
|
60
|
-
return lines.join(`
|
|
61
|
-
`);
|
|
62
|
-
}
|
|
63
|
-
function renderTopLevelHelp() {
|
|
64
|
-
return [
|
|
65
|
-
`${heading("rig")} ${pc.dim("\u2014 Rig Cockpit for autonomous coding agents")}`,
|
|
66
|
-
pc.dim("The loop: bare `rig` \u2192 Cockpit \u2192 Server target \u2192 Tasks \u2192 Task detail \u2192 Dispatch/Attach; every run uses OMP collaboration as the session substrate."),
|
|
67
|
-
"",
|
|
68
|
-
...TOP_LEVEL_SECTIONS.flatMap((section) => [
|
|
69
|
-
`${pc.bold(pc.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc.dim(section.subtitle)}`,
|
|
70
|
-
renderCommandBlock(section.commands),
|
|
71
|
-
""
|
|
72
|
-
]),
|
|
73
|
-
pc.dim("More: `rig help --advanced` for fenced legacy/diagnostic commands; `rig <group> --help` for per-group compatibility help; `rig --version` for the installed version."),
|
|
74
|
-
"",
|
|
75
|
-
pc.bold("Root options"),
|
|
76
|
-
commandLine("--workspace <path>", "Open Rig Cockpit for a workspace instead of the current directory."),
|
|
77
|
-
commandLine("--json", "Compatibility flag for fenced legacy/diagnostic subcommands."),
|
|
78
|
-
commandLine("--dry-run", "Compatibility flag for fenced legacy/diagnostic subcommands.")
|
|
79
|
-
].join(`
|
|
80
|
-
`).trimEnd();
|
|
81
|
-
}
|
|
82
|
-
function renderAdvancedHelp() {
|
|
83
|
-
return [
|
|
84
|
-
`${heading("rig advanced")} \u2014 fenced legacy compatibility, diagnostics, and internal surfaces`,
|
|
85
|
-
"",
|
|
86
|
-
pc.bold("Normal public UX"),
|
|
87
|
-
" rig, rig --workspace <path>, rig join <collab-link>, and /rig inside OMP",
|
|
88
|
-
"",
|
|
89
|
-
pc.bold("Legacy/diagnostic groups"),
|
|
90
|
-
" init, server, task, run, inbox, inspect, stats, doctor, github, setup, remote",
|
|
91
|
-
"",
|
|
92
|
-
pc.bold("Advanced commands"),
|
|
93
|
-
...ADVANCED_COMMANDS.map((entry) => commandLine(entry.command, entry.description)),
|
|
94
|
-
"",
|
|
95
|
-
pc.bold("Advanced groups"),
|
|
96
|
-
...ADVANCED_GROUPS.map((group) => commandLine(group.name, group.summary)),
|
|
97
|
-
"",
|
|
98
|
-
pc.dim("Legacy groups remain callable for old automation and diagnostics. Prefer bare `rig` and the OMP cockpit for day-to-day work.")
|
|
99
|
-
].join(`
|
|
100
|
-
`);
|
|
101
|
-
}
|
|
102
|
-
function renderGroupHelp(groupName) {
|
|
103
|
-
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
104
|
-
return group ? renderGroup(group) : null;
|
|
105
|
-
}
|
|
106
|
-
function listHelpGroups() {
|
|
107
|
-
return ALL_GROUPS.map((group) => group.name);
|
|
108
|
-
}
|
|
109
|
-
function suggestGroupCommandForWord(word, liveGroups) {
|
|
110
|
-
const normalized = word.trim().toLowerCase();
|
|
111
|
-
if (!normalized)
|
|
112
|
-
return null;
|
|
113
|
-
for (const group of ALL_GROUPS) {
|
|
114
|
-
if (liveGroups && !liveGroups.has(group.name))
|
|
115
|
-
continue;
|
|
116
|
-
for (const entry of group.commands) {
|
|
117
|
-
const firstToken = entry.command.split(/\s+/)[0] ?? "";
|
|
118
|
-
const names = firstToken.split("|").map((name) => name.trim().toLowerCase());
|
|
119
|
-
if (names.includes(normalized)) {
|
|
120
|
-
return `rig ${group.name} ${normalized}`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
function printTopLevelHelp(state = {}) {
|
|
127
|
-
console.log(renderTopLevelHelp());
|
|
128
|
-
}
|
|
129
|
-
function printAdvancedHelp() {
|
|
130
|
-
console.log(renderAdvancedHelp());
|
|
131
|
-
}
|
|
132
|
-
function printGroupHelpDocument(groupName) {
|
|
133
|
-
console.log(renderGroupHelp(groupName) ?? renderTopLevelHelp());
|
|
134
|
-
}
|
|
135
|
-
export {
|
|
136
|
-
suggestGroupCommandForWord,
|
|
137
|
-
renderTopLevelHelp,
|
|
138
|
-
renderRigBanner,
|
|
139
|
-
renderGroupHelp,
|
|
140
|
-
renderAdvancedHelp,
|
|
141
|
-
printTopLevelHelp,
|
|
142
|
-
printGroupHelpDocument,
|
|
143
|
-
printAdvancedHelp,
|
|
144
|
-
listHelpGroups,
|
|
145
|
-
helpCatalog
|
|
146
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { saveGitHubTokenForProject, type GitHubAuthStatus } from "@rig/runtime/control-plane/github/index";
|
|
2
|
-
export type GitHubAuthStatusResponse = {
|
|
3
|
-
readonly ok: true;
|
|
4
|
-
} & GitHubAuthStatus;
|
|
5
|
-
export type GitHubTokenPostResponse = Awaited<ReturnType<typeof saveGitHubTokenForProject>> & {
|
|
6
|
-
readonly authenticated: boolean;
|
|
7
|
-
readonly apiSessionToken: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function setGitHubBearerTokenForCurrentProcess(token: string | null, projectRoot?: string): void;
|
|
10
|
-
export declare function getGitHubAuthStatusInProcess(context: {
|
|
11
|
-
projectRoot: string;
|
|
12
|
-
}): Promise<GitHubAuthStatusResponse>;
|
|
13
|
-
export declare function postGitHubTokenInProcess(context: {
|
|
14
|
-
projectRoot: string;
|
|
15
|
-
}, token: string, options?: {
|
|
16
|
-
readonly selectedRepo?: string;
|
|
17
|
-
readonly projectRoot?: string;
|
|
18
|
-
}): Promise<GitHubTokenPostResponse>;
|
|
19
|
-
export declare function listGitHubProjectsInProcess(context: {
|
|
20
|
-
projectRoot: string;
|
|
21
|
-
}, owner: string, options?: {
|
|
22
|
-
readonly authToken?: string | null;
|
|
23
|
-
readonly baseUrl?: string | null;
|
|
24
|
-
}): Promise<Record<string, unknown>>;
|
|
25
|
-
export declare function getGitHubProjectStatusFieldInProcess(context: {
|
|
26
|
-
projectRoot: string;
|
|
27
|
-
}, projectId: string, options?: {
|
|
28
|
-
readonly authToken?: string | null;
|
|
29
|
-
readonly baseUrl?: string | null;
|
|
30
|
-
}): Promise<Record<string, unknown>>;
|
|
31
|
-
export declare function requestGitHubAuthJsonInProcess(context: {
|
|
32
|
-
projectRoot: string;
|
|
33
|
-
}, pathname: string, init?: RequestInit): Promise<unknown>;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/_inprocess-services.ts
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
import {
|
|
5
|
-
beginGitHubDeviceFlow,
|
|
6
|
-
checkGitHubRepoPermissions,
|
|
7
|
-
createGitHubAuthStore,
|
|
8
|
-
listGitHubProjects,
|
|
9
|
-
pollGitHubDeviceFlow,
|
|
10
|
-
resolveGitHubAuthStatus,
|
|
11
|
-
resolveProjectStatusField,
|
|
12
|
-
saveGitHubTokenForProject
|
|
13
|
-
} from "@rig/runtime/control-plane/github/index";
|
|
14
|
-
var scopedGitHubBearerTokens = new Map;
|
|
15
|
-
function cleanToken(value) {
|
|
16
|
-
const trimmed = value?.trim();
|
|
17
|
-
return trimmed ? trimmed : null;
|
|
18
|
-
}
|
|
19
|
-
function cleanString(value) {
|
|
20
|
-
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
21
|
-
}
|
|
22
|
-
function oauthClientId() {
|
|
23
|
-
return cleanToken(process.env.RIG_GITHUB_OAUTH_CLIENT_ID);
|
|
24
|
-
}
|
|
25
|
-
function tokenForProject(projectRoot, override) {
|
|
26
|
-
const scoped = scopedGitHubBearerTokens.get(resolve(projectRoot));
|
|
27
|
-
return cleanToken(override) ?? scoped ?? createGitHubAuthStore(projectRoot).readToken() ?? cleanToken(process.env.RIG_GITHUB_TOKEN);
|
|
28
|
-
}
|
|
29
|
-
function setGitHubBearerTokenForCurrentProcess(token, projectRoot) {
|
|
30
|
-
scopedGitHubBearerTokens.set(resolve(projectRoot ?? process.cwd()), cleanToken(token));
|
|
31
|
-
}
|
|
32
|
-
async function getGitHubAuthStatusInProcess(context) {
|
|
33
|
-
return { ok: true, ...resolveGitHubAuthStatus({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) }) };
|
|
34
|
-
}
|
|
35
|
-
async function postGitHubTokenInProcess(context, token, options = {}) {
|
|
36
|
-
const targetRoot = options.projectRoot?.trim() || context.projectRoot;
|
|
37
|
-
const result = await saveGitHubTokenForProject({
|
|
38
|
-
projectRoot: targetRoot,
|
|
39
|
-
token,
|
|
40
|
-
tokenSource: "manual-token",
|
|
41
|
-
selectedRepo: options.selectedRepo ?? null
|
|
42
|
-
});
|
|
43
|
-
const store = createGitHubAuthStore(targetRoot);
|
|
44
|
-
const session = store.createApiSession();
|
|
45
|
-
if (targetRoot !== context.projectRoot) {
|
|
46
|
-
store.copyToLocalProjectRoot(context.projectRoot);
|
|
47
|
-
}
|
|
48
|
-
return { ...result, authenticated: result.signedIn, apiSessionToken: session.token };
|
|
49
|
-
}
|
|
50
|
-
async function listGitHubProjectsInProcess(context, owner, options = {}) {
|
|
51
|
-
const token = tokenForProject(context.projectRoot, options.authToken);
|
|
52
|
-
if (!token)
|
|
53
|
-
return { ok: false, error: "missing-token", projects: [] };
|
|
54
|
-
const projects = await listGitHubProjects({ owner, token });
|
|
55
|
-
return { ok: true, projects };
|
|
56
|
-
}
|
|
57
|
-
async function getGitHubProjectStatusFieldInProcess(context, projectId, options = {}) {
|
|
58
|
-
const token = tokenForProject(context.projectRoot, options.authToken);
|
|
59
|
-
if (!token)
|
|
60
|
-
return { ok: false, error: "missing-token" };
|
|
61
|
-
const field = await resolveProjectStatusField({ projectId, token });
|
|
62
|
-
return { ok: true, field };
|
|
63
|
-
}
|
|
64
|
-
async function requestGitHubAuthJsonInProcess(context, pathname, init = {}) {
|
|
65
|
-
const method = (init.method ?? "GET").toUpperCase();
|
|
66
|
-
if (pathname === "/api/github/auth/status")
|
|
67
|
-
return getGitHubAuthStatusInProcess(context);
|
|
68
|
-
if (pathname === "/api/github/repo/permissions") {
|
|
69
|
-
return checkGitHubRepoPermissions({ projectRoot: context.projectRoot, oauthConfigured: Boolean(oauthClientId()) });
|
|
70
|
-
}
|
|
71
|
-
if (pathname === "/api/github/auth/device/start" && method === "POST") {
|
|
72
|
-
const clientId = oauthClientId();
|
|
73
|
-
if (!clientId)
|
|
74
|
-
return { ok: false, oauthConfigured: false, error: "RIG_GITHUB_OAUTH_CLIENT_ID is not configured." };
|
|
75
|
-
const body = init.body ? JSON.parse(String(init.body)) : {};
|
|
76
|
-
return beginGitHubDeviceFlow({
|
|
77
|
-
projectRoot: context.projectRoot,
|
|
78
|
-
clientId,
|
|
79
|
-
scope: cleanString(body.scope) ?? undefined,
|
|
80
|
-
selectedRepo: cleanString(body.repoSlug)
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (pathname === "/api/github/auth/device/poll" && method === "POST") {
|
|
84
|
-
const clientId = oauthClientId();
|
|
85
|
-
if (!clientId)
|
|
86
|
-
return { ok: false, oauthConfigured: false, error: "RIG_GITHUB_OAUTH_CLIENT_ID is not configured." };
|
|
87
|
-
const body = init.body ? JSON.parse(String(init.body)) : {};
|
|
88
|
-
const pollId = cleanString(body.pollId);
|
|
89
|
-
if (!pollId)
|
|
90
|
-
return { ok: false, status: "error", error: "pollId is required" };
|
|
91
|
-
return pollGitHubDeviceFlow({ projectRoot: context.projectRoot, clientId, pollId, selectedRepo: cleanString(body.repoSlug) });
|
|
92
|
-
}
|
|
93
|
-
throw new Error(`No in-process GitHub auth API for ${method} ${pathname}`);
|
|
94
|
-
}
|
|
95
|
-
export {
|
|
96
|
-
setGitHubBearerTokenForCurrentProcess,
|
|
97
|
-
requestGitHubAuthJsonInProcess,
|
|
98
|
-
postGitHubTokenInProcess,
|
|
99
|
-
listGitHubProjectsInProcess,
|
|
100
|
-
getGitHubProjectStatusFieldInProcess,
|
|
101
|
-
getGitHubAuthStatusInProcess
|
|
102
|
-
};
|