@h-rig/cli 0.0.6-alpha.28 → 0.0.6-alpha.280
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 -28
- package/package.json +11 -28
- package/dist/bin/build-rig-binaries.js +0 -107
- package/dist/bin/rig.js +0 -11739
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_cli-format.js +0 -369
- package/dist/src/commands/_connection-state.js +0 -123
- package/dist/src/commands/_doctor-checks.js +0 -507
- package/dist/src/commands/_help-catalog.js +0 -364
- package/dist/src/commands/_operator-surface.js +0 -204
- package/dist/src/commands/_operator-view.js +0 -1147
- package/dist/src/commands/_parsers.js +0 -107
- package/dist/src/commands/_paths.js +0 -50
- package/dist/src/commands/_pi-frontend.js +0 -843
- package/dist/src/commands/_pi-install.js +0 -185
- package/dist/src/commands/_pi-worker-bridge-extension.js +0 -761
- package/dist/src/commands/_policy.js +0 -79
- package/dist/src/commands/_preflight.js +0 -403
- package/dist/src/commands/_probes.js +0 -13
- package/dist/src/commands/_run-driver-helpers.js +0 -289
- package/dist/src/commands/_server-client.js +0 -514
- package/dist/src/commands/_snapshot-upload.js +0 -318
- package/dist/src/commands/_task-picker.js +0 -76
- package/dist/src/commands/agent.js +0 -499
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -289
- package/dist/src/commands/dist.js +0 -402
- package/dist/src/commands/doctor.js +0 -517
- package/dist/src/commands/github.js +0 -281
- package/dist/src/commands/inbox.js +0 -482
- package/dist/src/commands/init.js +0 -1563
- package/dist/src/commands/inspect.js +0 -174
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/plugin.js +0 -167
- package/dist/src/commands/profile-and-review.js +0 -178
- package/dist/src/commands/queue.js +0 -198
- package/dist/src/commands/remote.js +0 -507
- package/dist/src/commands/repo-git-harness.js +0 -221
- package/dist/src/commands/run.js +0 -1808
- package/dist/src/commands/server.js +0 -572
- package/dist/src/commands/setup.js +0 -687
- package/dist/src/commands/task-report-bug.js +0 -1083
- package/dist/src/commands/task-run-driver.js +0 -2600
- package/dist/src/commands/task.js +0 -2606
- package/dist/src/commands/test.js +0 -39
- package/dist/src/commands/workspace.js +0 -123
- package/dist/src/commands.js +0 -11418
- package/dist/src/index.js +0 -11757
- package/dist/src/launcher.js +0 -133
- package/dist/src/report-bug.js +0 -260
- package/dist/src/runner.js +0 -273
- package/dist/src/withMutedConsole.js +0 -42
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/github.ts
|
|
3
|
-
import { spawnSync } from "child_process";
|
|
4
|
-
|
|
5
|
-
// packages/cli/src/runner.ts
|
|
6
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
7
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
8
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
9
|
-
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
10
|
-
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
11
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
12
|
-
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
13
|
-
function takeOption(args, option) {
|
|
14
|
-
const rest = [];
|
|
15
|
-
let value;
|
|
16
|
-
for (let index = 0;index < args.length; index += 1) {
|
|
17
|
-
const current = args[index];
|
|
18
|
-
if (current === option) {
|
|
19
|
-
const next = args[index + 1];
|
|
20
|
-
if (!next || next.startsWith("-")) {
|
|
21
|
-
throw new CliError(`Missing value for ${option}`);
|
|
22
|
-
}
|
|
23
|
-
value = next;
|
|
24
|
-
index += 1;
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
if (current !== undefined) {
|
|
28
|
-
rest.push(current);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return { value, rest };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// packages/cli/src/commands/_server-client.ts
|
|
35
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
36
|
-
import { resolve as resolve2 } from "path";
|
|
37
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
38
|
-
|
|
39
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
40
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
41
|
-
import { homedir } from "os";
|
|
42
|
-
import { dirname, resolve } from "path";
|
|
43
|
-
function resolveGlobalConnectionsPath(env = process.env) {
|
|
44
|
-
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
45
|
-
if (explicit)
|
|
46
|
-
return resolve(explicit);
|
|
47
|
-
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
48
|
-
if (stateDir)
|
|
49
|
-
return resolve(stateDir, "connections.json");
|
|
50
|
-
return resolve(homedir(), ".rig", "connections.json");
|
|
51
|
-
}
|
|
52
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
53
|
-
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
54
|
-
}
|
|
55
|
-
function readJsonFile(path) {
|
|
56
|
-
if (!existsSync(path))
|
|
57
|
-
return null;
|
|
58
|
-
try {
|
|
59
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
60
|
-
} catch (error) {
|
|
61
|
-
throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function normalizeConnection(value) {
|
|
65
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
66
|
-
return null;
|
|
67
|
-
const record = value;
|
|
68
|
-
if (record.kind === "local")
|
|
69
|
-
return { kind: "local", mode: "auto" };
|
|
70
|
-
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
71
|
-
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
72
|
-
return { kind: "remote", baseUrl };
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
function readGlobalConnections(options = {}) {
|
|
77
|
-
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
78
|
-
const payload = readJsonFile(path);
|
|
79
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
80
|
-
return { connections: {} };
|
|
81
|
-
}
|
|
82
|
-
const rawConnections = payload.connections;
|
|
83
|
-
const connections = {};
|
|
84
|
-
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
85
|
-
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
86
|
-
const connection = normalizeConnection(raw);
|
|
87
|
-
if (connection)
|
|
88
|
-
connections[alias] = connection;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return { connections };
|
|
92
|
-
}
|
|
93
|
-
function readRepoConnection(projectRoot) {
|
|
94
|
-
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
95
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
96
|
-
return null;
|
|
97
|
-
const record = payload;
|
|
98
|
-
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
99
|
-
if (!selected)
|
|
100
|
-
return null;
|
|
101
|
-
return {
|
|
102
|
-
selected,
|
|
103
|
-
project: typeof record.project === "string" ? record.project : undefined,
|
|
104
|
-
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
108
|
-
const repo = readRepoConnection(projectRoot);
|
|
109
|
-
if (!repo)
|
|
110
|
-
return null;
|
|
111
|
-
if (repo.selected === "local")
|
|
112
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
113
|
-
const global = readGlobalConnections(options);
|
|
114
|
-
const connection = global.connections[repo.selected];
|
|
115
|
-
if (!connection) {
|
|
116
|
-
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
117
|
-
}
|
|
118
|
-
return { alias: repo.selected, connection };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// packages/cli/src/commands/_server-client.ts
|
|
122
|
-
var scopedGitHubBearerTokens = new Map;
|
|
123
|
-
function cleanToken(value) {
|
|
124
|
-
const trimmed = value?.trim();
|
|
125
|
-
return trimmed ? trimmed : null;
|
|
126
|
-
}
|
|
127
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
128
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
129
|
-
if (!existsSync2(path))
|
|
130
|
-
return null;
|
|
131
|
-
try {
|
|
132
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
133
|
-
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
134
|
-
} catch {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
139
|
-
const scopedKey = resolve2(projectRoot);
|
|
140
|
-
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
141
|
-
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
142
|
-
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
143
|
-
if (privateSession)
|
|
144
|
-
return privateSession;
|
|
145
|
-
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
146
|
-
}
|
|
147
|
-
async function ensureServerForCli(projectRoot) {
|
|
148
|
-
try {
|
|
149
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
150
|
-
if (selected?.connection.kind === "remote") {
|
|
151
|
-
return {
|
|
152
|
-
baseUrl: selected.connection.baseUrl,
|
|
153
|
-
authToken: readGitHubBearerTokenForRemote(projectRoot),
|
|
154
|
-
connectionKind: "remote"
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
158
|
-
return {
|
|
159
|
-
baseUrl: connection.baseUrl,
|
|
160
|
-
authToken: connection.authToken,
|
|
161
|
-
connectionKind: "local"
|
|
162
|
-
};
|
|
163
|
-
} catch (error) {
|
|
164
|
-
if (error instanceof Error) {
|
|
165
|
-
throw new CliError2(error.message, 1);
|
|
166
|
-
}
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function mergeHeaders(headers, authToken) {
|
|
171
|
-
const merged = new Headers(headers);
|
|
172
|
-
if (authToken) {
|
|
173
|
-
merged.set("authorization", `Bearer ${authToken}`);
|
|
174
|
-
}
|
|
175
|
-
return merged;
|
|
176
|
-
}
|
|
177
|
-
function diagnosticMessage(payload) {
|
|
178
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
179
|
-
return null;
|
|
180
|
-
const record = payload;
|
|
181
|
-
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
182
|
-
const messages = diagnostics.flatMap((entry) => {
|
|
183
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
184
|
-
return [];
|
|
185
|
-
const diagnostic = entry;
|
|
186
|
-
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
187
|
-
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
188
|
-
return message ? [`${kind}: ${message}`] : [];
|
|
189
|
-
});
|
|
190
|
-
return messages.length > 0 ? messages.join("; ") : null;
|
|
191
|
-
}
|
|
192
|
-
async function requestServerJson(context, pathname, init = {}) {
|
|
193
|
-
const server = await ensureServerForCli(context.projectRoot);
|
|
194
|
-
const response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
195
|
-
...init,
|
|
196
|
-
headers: mergeHeaders(init.headers, server.authToken)
|
|
197
|
-
});
|
|
198
|
-
const text = await response.text();
|
|
199
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
200
|
-
try {
|
|
201
|
-
return JSON.parse(text);
|
|
202
|
-
} catch {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
})() : null;
|
|
206
|
-
if (!response.ok) {
|
|
207
|
-
const diagnostics = diagnosticMessage(payload);
|
|
208
|
-
const detail = diagnostics ?? (text || response.statusText);
|
|
209
|
-
throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
|
|
210
|
-
}
|
|
211
|
-
return payload;
|
|
212
|
-
}
|
|
213
|
-
async function getGitHubAuthStatusViaServer(context) {
|
|
214
|
-
const payload = await requestServerJson(context, "/api/github/auth/status");
|
|
215
|
-
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
216
|
-
}
|
|
217
|
-
async function postGitHubTokenViaServer(context, token, options = {}) {
|
|
218
|
-
const payload = await requestServerJson(context, "/api/github/auth/token", {
|
|
219
|
-
method: "POST",
|
|
220
|
-
headers: { "content-type": "application/json" },
|
|
221
|
-
body: JSON.stringify({ token, selectedRepo: options.selectedRepo, projectRoot: options.projectRoot })
|
|
222
|
-
});
|
|
223
|
-
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// packages/cli/src/commands/github.ts
|
|
227
|
-
function printPayload(context, payload, fallback) {
|
|
228
|
-
if (context.outputMode === "json")
|
|
229
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
230
|
-
else
|
|
231
|
-
console.log(fallback);
|
|
232
|
-
}
|
|
233
|
-
function readGhToken() {
|
|
234
|
-
const result = spawnSync("gh", ["auth", "token"], { encoding: "utf8" });
|
|
235
|
-
if (result.status !== 0) {
|
|
236
|
-
const detail = result.stderr?.trim() || result.stdout?.trim() || "gh auth token failed";
|
|
237
|
-
throw new CliError2(`Could not import GitHub token from gh: ${detail}`, 1);
|
|
238
|
-
}
|
|
239
|
-
const token = result.stdout.trim();
|
|
240
|
-
if (!token)
|
|
241
|
-
throw new CliError2("gh auth token returned an empty token.", 1);
|
|
242
|
-
return token;
|
|
243
|
-
}
|
|
244
|
-
async function executeGithub(context, args) {
|
|
245
|
-
const [group, command, ...rest] = args;
|
|
246
|
-
if (group !== "auth") {
|
|
247
|
-
throw new CliError2("Usage: rig github auth <status|import-gh|token>", 1);
|
|
248
|
-
}
|
|
249
|
-
switch (command) {
|
|
250
|
-
case "status": {
|
|
251
|
-
if (rest.length > 0)
|
|
252
|
-
throw new CliError2("Usage: rig github auth status", 1);
|
|
253
|
-
const status = await getGitHubAuthStatusViaServer(context);
|
|
254
|
-
printPayload(context, status, `GitHub auth: ${status.authenticated ? "authenticated" : "unauthenticated"}`);
|
|
255
|
-
return { ok: true, group: "github", command: "auth status", details: status };
|
|
256
|
-
}
|
|
257
|
-
case "token": {
|
|
258
|
-
const parsed = takeOption(rest, "--token");
|
|
259
|
-
if (parsed.rest.length > 0)
|
|
260
|
-
throw new CliError2("Usage: rig github auth token --token <token>", 1);
|
|
261
|
-
const token = parsed.value?.trim();
|
|
262
|
-
if (!token)
|
|
263
|
-
throw new CliError2("Missing --token value.", 1);
|
|
264
|
-
const result = await postGitHubTokenViaServer(context, token);
|
|
265
|
-
printPayload(context, result, "GitHub token stored on the selected Rig server.");
|
|
266
|
-
return { ok: true, group: "github", command: "auth token", details: result };
|
|
267
|
-
}
|
|
268
|
-
case "import-gh": {
|
|
269
|
-
if (rest.length > 0)
|
|
270
|
-
throw new CliError2("Usage: rig github auth import-gh", 1);
|
|
271
|
-
const result = await postGitHubTokenViaServer(context, readGhToken());
|
|
272
|
-
printPayload(context, result, "GitHub token imported from gh and stored on the selected Rig server.");
|
|
273
|
-
return { ok: true, group: "github", command: "auth import-gh", details: result };
|
|
274
|
-
}
|
|
275
|
-
default:
|
|
276
|
-
throw new CliError2("Usage: rig github auth <status|import-gh|token>", 1);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
export {
|
|
280
|
-
executeGithub
|
|
281
|
-
};
|