@h-rig/cli 0.0.6-alpha.20 → 0.0.6-alpha.201

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