@h-rig/cli 0.0.6-alpha.12 → 0.0.6-alpha.121

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 (48) hide show
  1. package/README.md +6 -28
  2. package/bin/rig.js +16 -0
  3. package/package.json +14 -27
  4. package/dist/bin/build-rig-binaries.js +0 -107
  5. package/dist/bin/rig.js +0 -9592
  6. package/dist/src/commands/_authority-runs.js +0 -111
  7. package/dist/src/commands/_connection-state.js +0 -123
  8. package/dist/src/commands/_doctor-checks.js +0 -519
  9. package/dist/src/commands/_operator-view.js +0 -340
  10. package/dist/src/commands/_parsers.js +0 -107
  11. package/dist/src/commands/_paths.js +0 -50
  12. package/dist/src/commands/_pi-install.js +0 -184
  13. package/dist/src/commands/_policy.js +0 -79
  14. package/dist/src/commands/_preflight.js +0 -478
  15. package/dist/src/commands/_probes.js +0 -13
  16. package/dist/src/commands/_run-driver-helpers.js +0 -289
  17. package/dist/src/commands/_server-client.js +0 -402
  18. package/dist/src/commands/_snapshot-upload.js +0 -331
  19. package/dist/src/commands/_task-picker.js +0 -48
  20. package/dist/src/commands/agent.js +0 -498
  21. package/dist/src/commands/browser.js +0 -890
  22. package/dist/src/commands/connect.js +0 -180
  23. package/dist/src/commands/dist.js +0 -402
  24. package/dist/src/commands/doctor.js +0 -529
  25. package/dist/src/commands/github.js +0 -294
  26. package/dist/src/commands/inbox.js +0 -160
  27. package/dist/src/commands/init.js +0 -1372
  28. package/dist/src/commands/inspect.js +0 -174
  29. package/dist/src/commands/inspector.js +0 -256
  30. package/dist/src/commands/plugin.js +0 -167
  31. package/dist/src/commands/profile-and-review.js +0 -178
  32. package/dist/src/commands/queue.js +0 -197
  33. package/dist/src/commands/remote.js +0 -507
  34. package/dist/src/commands/repo-git-harness.js +0 -221
  35. package/dist/src/commands/run.js +0 -797
  36. package/dist/src/commands/server.js +0 -386
  37. package/dist/src/commands/setup.js +0 -699
  38. package/dist/src/commands/task-report-bug.js +0 -1083
  39. package/dist/src/commands/task-run-driver.js +0 -2049
  40. package/dist/src/commands/task.js +0 -1343
  41. package/dist/src/commands/test.js +0 -39
  42. package/dist/src/commands/workspace.js +0 -123
  43. package/dist/src/commands.js +0 -9271
  44. package/dist/src/index.js +0 -9610
  45. package/dist/src/launcher.js +0 -133
  46. package/dist/src/report-bug.js +0 -260
  47. package/dist/src/runner.js +0 -273
  48. package/dist/src/withMutedConsole.js +0 -42
@@ -1,386 +0,0 @@
1
- // @bun
2
- // packages/cli/src/runner.ts
3
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
4
- import { CliError } from "@rig/runtime/control-plane/errors";
5
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
6
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
7
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
8
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
9
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
10
- function takeOption(args, option) {
11
- const rest = [];
12
- let value;
13
- for (let index = 0;index < args.length; index += 1) {
14
- const current = args[index];
15
- if (current === option) {
16
- const next = args[index + 1];
17
- if (!next || next.startsWith("-")) {
18
- throw new CliError(`Missing value for ${option}`);
19
- }
20
- value = next;
21
- index += 1;
22
- continue;
23
- }
24
- if (current !== undefined) {
25
- rest.push(current);
26
- }
27
- }
28
- return { value, rest };
29
- }
30
- function requireNoExtraArgs(args, usage) {
31
- if (args.length > 0) {
32
- throw new CliError(`Unexpected arguments: ${args.join(" ")}
33
- Usage: ${usage}`);
34
- }
35
- }
36
-
37
- // packages/cli/src/commands/_authority-runs.ts
38
- import {
39
- readAuthorityRun,
40
- readJsonlFile,
41
- resolveAuthorityRunDir,
42
- writeJsonFile
43
- } from "@rig/runtime/control-plane/authority-files";
44
-
45
- // packages/cli/src/commands/_paths.ts
46
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
47
-
48
- // packages/cli/src/commands/_authority-runs.ts
49
- function normalizeRuntimeAdapter(value) {
50
- const normalized = value?.trim().toLowerCase();
51
- if (!normalized) {
52
- return "pi";
53
- }
54
- if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
55
- return "codex";
56
- }
57
- if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
58
- return "pi";
59
- }
60
- return "claude-code";
61
- }
62
-
63
- // packages/cli/src/commands/_server-client.ts
64
- import { spawnSync } from "child_process";
65
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
66
- import { resolve as resolve2 } from "path";
67
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
68
-
69
- // packages/cli/src/commands/_connection-state.ts
70
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
71
- import { homedir } from "os";
72
- import { dirname, resolve } from "path";
73
- function resolveGlobalConnectionsPath(env = process.env) {
74
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
75
- if (explicit)
76
- return resolve(explicit);
77
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
78
- if (stateDir)
79
- return resolve(stateDir, "connections.json");
80
- return resolve(homedir(), ".rig", "connections.json");
81
- }
82
- function resolveRepoConnectionPath(projectRoot) {
83
- return resolve(projectRoot, ".rig", "state", "connection.json");
84
- }
85
- function readJsonFile(path) {
86
- if (!existsSync(path))
87
- return null;
88
- try {
89
- return JSON.parse(readFileSync(path, "utf8"));
90
- } catch (error) {
91
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
92
- }
93
- }
94
- function normalizeConnection(value) {
95
- if (!value || typeof value !== "object" || Array.isArray(value))
96
- return null;
97
- const record = value;
98
- if (record.kind === "local")
99
- return { kind: "local", mode: "auto" };
100
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
101
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
102
- return { kind: "remote", baseUrl };
103
- }
104
- return null;
105
- }
106
- function readGlobalConnections(options = {}) {
107
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
108
- const payload = readJsonFile(path);
109
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
110
- return { connections: {} };
111
- }
112
- const rawConnections = payload.connections;
113
- const connections = {};
114
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
115
- for (const [alias, raw] of Object.entries(rawConnections)) {
116
- const connection = normalizeConnection(raw);
117
- if (connection)
118
- connections[alias] = connection;
119
- }
120
- }
121
- return { connections };
122
- }
123
- function readRepoConnection(projectRoot) {
124
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
125
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
126
- return null;
127
- const record = payload;
128
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
129
- if (!selected)
130
- return null;
131
- return {
132
- selected,
133
- project: typeof record.project === "string" ? record.project : undefined,
134
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
135
- };
136
- }
137
- function resolveSelectedConnection(projectRoot, options = {}) {
138
- const repo = readRepoConnection(projectRoot);
139
- if (!repo)
140
- return null;
141
- if (repo.selected === "local")
142
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
143
- const global = readGlobalConnections(options);
144
- const connection = global.connections[repo.selected];
145
- if (!connection) {
146
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
147
- }
148
- return { alias: repo.selected, connection };
149
- }
150
-
151
- // packages/cli/src/commands/_server-client.ts
152
- var cachedGitHubBearerToken;
153
- function cleanToken(value) {
154
- const trimmed = value?.trim();
155
- return trimmed ? trimmed : null;
156
- }
157
- function readPrivateRemoteSessionToken(projectRoot) {
158
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
159
- if (!existsSync2(path))
160
- return null;
161
- try {
162
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
163
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
164
- } catch {
165
- return null;
166
- }
167
- }
168
- function readGitHubBearerTokenForRemote(projectRoot) {
169
- if (cachedGitHubBearerToken !== undefined)
170
- return cachedGitHubBearerToken;
171
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
172
- if (privateSession) {
173
- cachedGitHubBearerToken = privateSession;
174
- return cachedGitHubBearerToken;
175
- }
176
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
177
- if (envToken) {
178
- cachedGitHubBearerToken = envToken;
179
- return cachedGitHubBearerToken;
180
- }
181
- const result = spawnSync("gh", ["auth", "token"], {
182
- encoding: "utf8",
183
- timeout: 5000,
184
- stdio: ["ignore", "pipe", "ignore"]
185
- });
186
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
187
- return cachedGitHubBearerToken;
188
- }
189
- async function ensureServerForCli(projectRoot) {
190
- try {
191
- const selected = resolveSelectedConnection(projectRoot);
192
- if (selected?.connection.kind === "remote") {
193
- return {
194
- baseUrl: selected.connection.baseUrl,
195
- authToken: readGitHubBearerTokenForRemote(projectRoot),
196
- connectionKind: "remote"
197
- };
198
- }
199
- const connection = await ensureLocalRigServerConnection(projectRoot);
200
- return {
201
- baseUrl: connection.baseUrl,
202
- authToken: connection.authToken,
203
- connectionKind: "local"
204
- };
205
- } catch (error) {
206
- if (error instanceof Error) {
207
- throw new CliError2(error.message, 1);
208
- }
209
- throw error;
210
- }
211
- }
212
- function mergeHeaders(headers, authToken) {
213
- const merged = new Headers(headers);
214
- if (authToken) {
215
- merged.set("authorization", `Bearer ${authToken}`);
216
- }
217
- return merged;
218
- }
219
- function diagnosticMessage(payload) {
220
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
221
- return null;
222
- const record = payload;
223
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
224
- const messages = diagnostics.flatMap((entry) => {
225
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
226
- return [];
227
- const diagnostic = entry;
228
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
229
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
230
- return message ? [`${kind}: ${message}`] : [];
231
- });
232
- return messages.length > 0 ? messages.join("; ") : null;
233
- }
234
- async function requestServerJson(context, pathname, init = {}) {
235
- const server = await ensureServerForCli(context.projectRoot);
236
- const response = await fetch(`${server.baseUrl}${pathname}`, {
237
- ...init,
238
- headers: mergeHeaders(init.headers, server.authToken)
239
- });
240
- const text = await response.text();
241
- const payload = text.trim().length > 0 ? (() => {
242
- try {
243
- return JSON.parse(text);
244
- } catch {
245
- return null;
246
- }
247
- })() : null;
248
- if (!response.ok) {
249
- const diagnostics = diagnosticMessage(payload);
250
- const detail = diagnostics ?? (text || response.statusText);
251
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
252
- }
253
- return payload;
254
- }
255
- async function submitTaskRunViaServer(context, input) {
256
- const isTaskRun = Boolean(input.taskId);
257
- const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
258
- const payload = await requestServerJson(context, endpoint, {
259
- method: "POST",
260
- headers: {
261
- "content-type": "application/json"
262
- },
263
- body: JSON.stringify({
264
- runId: input.runId,
265
- taskId: input.taskId,
266
- title: input.title,
267
- runtimeAdapter: input.runtimeAdapter,
268
- model: input.model,
269
- runtimeMode: input.runtimeMode,
270
- interactionMode: input.interactionMode,
271
- initialPrompt: input.initialPrompt,
272
- baselineMode: input.baselineMode,
273
- prMode: input.prMode,
274
- executionTarget: "local"
275
- })
276
- });
277
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
278
- throw new CliError2("Rig server returned an invalid run submission payload.", 1);
279
- }
280
- const runId = payload.runId;
281
- if (typeof runId !== "string" || runId.trim().length === 0) {
282
- throw new CliError2("Rig server returned no runId for the submitted run.", 1);
283
- }
284
- return { runId };
285
- }
286
-
287
- // packages/cli/src/commands/server.ts
288
- async function executeServer(context, args, options) {
289
- const [command = "start", ...rest] = args;
290
- switch (command) {
291
- case "start": {
292
- let pending = rest;
293
- const hostResult = takeOption(pending, "--host");
294
- pending = hostResult.rest;
295
- const portResult = takeOption(pending, "--port");
296
- pending = portResult.rest;
297
- const pollResult = takeOption(pending, "--poll-ms");
298
- pending = pollResult.rest;
299
- const authTokenResult = takeOption(pending, "--auth-token");
300
- pending = authTokenResult.rest;
301
- requireNoExtraArgs(pending, "bun run rig server start [--host <host>] [--port <n>] [--poll-ms <n>] [--auth-token <token>]");
302
- const commandParts = ["rig-server", "start"];
303
- if (hostResult.value) {
304
- commandParts.push("--host", hostResult.value);
305
- }
306
- if (portResult.value) {
307
- commandParts.push("--port", portResult.value);
308
- }
309
- if (pollResult.value) {
310
- commandParts.push("--poll-ms", pollResult.value);
311
- }
312
- if (authTokenResult.value) {
313
- commandParts.push("--auth-token", authTokenResult.value);
314
- }
315
- await context.runCommand(commandParts);
316
- return { ok: true, group: "server", command };
317
- }
318
- case "events":
319
- throw new CliError2("server events is not supported by the CLI wrapper. Use `rig inspector stream` for bounded event streaming, or start the server with `rig server start`.", 2);
320
- case "notify-test": {
321
- let pending = rest;
322
- const eventResult = takeOption(pending, "--event");
323
- pending = eventResult.rest;
324
- requireNoExtraArgs(pending, "bun run rig server notify-test [--event <type>]");
325
- const commandParts = ["rig-server", "notify-test"];
326
- if (eventResult.value) {
327
- commandParts.push("--event", eventResult.value);
328
- }
329
- await context.runCommand(commandParts);
330
- return { ok: true, group: "server", command, details: { event: eventResult.value || "manual.test" } };
331
- }
332
- case "task-run": {
333
- let pending = rest;
334
- const taskResult = takeOption(pending, "--task");
335
- pending = taskResult.rest;
336
- const titleResult = takeOption(pending, "--title");
337
- pending = titleResult.rest;
338
- const runtimeAdapterResult = takeOption(pending, "--runtime-adapter");
339
- pending = runtimeAdapterResult.rest;
340
- const modelResult = takeOption(pending, "--model");
341
- pending = modelResult.rest;
342
- const runtimeModeResult = takeOption(pending, "--runtime-mode");
343
- pending = runtimeModeResult.rest;
344
- const interactionModeResult = takeOption(pending, "--interaction-mode");
345
- pending = interactionModeResult.rest;
346
- const initialPromptResult = takeOption(pending, "--initial-prompt");
347
- pending = initialPromptResult.rest;
348
- const dirtyBaselineResult = takeOption(pending, "--dirty-baseline");
349
- pending = dirtyBaselineResult.rest;
350
- const prResult = takeOption(pending, "--pr");
351
- pending = prResult.rest;
352
- requireNoExtraArgs(pending, "bun run rig --run-id <run-id> server task-run [--task <id>] [--title <text>] [--runtime-adapter claude-code|codex|pi] [--model <model>] [--runtime-mode <mode>] [--interaction-mode <mode>] [--initial-prompt <text>] [--dirty-baseline head|dirty-snapshot] [--pr auto|ask|off]");
353
- if (!taskResult.value && !initialPromptResult.value && !titleResult.value) {
354
- throw new CliError2("server task-run requires either --task <id> or --initial-prompt/--title for an ad hoc run.", 2);
355
- }
356
- const input = {
357
- runId: context.runId,
358
- taskId: taskResult.value ?? undefined,
359
- title: titleResult.value ?? undefined,
360
- runtimeAdapter: normalizeRuntimeAdapter(runtimeAdapterResult.value),
361
- model: modelResult.value ?? undefined,
362
- runtimeMode: runtimeModeResult.value || "full-access",
363
- interactionMode: interactionModeResult.value || "default",
364
- initialPrompt: initialPromptResult.value ?? undefined,
365
- baselineMode: dirtyBaselineResult.value === "dirty-snapshot" ? "dirty-snapshot" : "head",
366
- prMode: prResult.value === "auto" || prResult.value === "ask" || prResult.value === "off" ? prResult.value : undefined
367
- };
368
- if (process.env.RIG_SERVER_INTERNAL_EXEC === "1") {
369
- await options.executeRigOwnedTaskRun(context, input);
370
- } else {
371
- await submitTaskRunViaServer(context, input);
372
- }
373
- return {
374
- ok: true,
375
- group: "server",
376
- command,
377
- details: { runId: context.runId, taskId: taskResult.value ?? null, title: titleResult.value ?? null }
378
- };
379
- }
380
- default:
381
- throw new CliError2(`Unknown server command: ${command}`);
382
- }
383
- }
384
- export {
385
- executeServer
386
- };