@h-rig/cli 0.0.6-alpha.13 → 0.0.6-alpha.130

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,294 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/github.ts
3
- import { spawnSync as spawnSync2 } 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 { spawnSync } from "child_process";
36
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
37
- import { resolve as resolve2 } from "path";
38
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
39
-
40
- // packages/cli/src/commands/_connection-state.ts
41
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
42
- import { homedir } from "os";
43
- import { dirname, resolve } from "path";
44
- function resolveGlobalConnectionsPath(env = process.env) {
45
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
46
- if (explicit)
47
- return resolve(explicit);
48
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
49
- if (stateDir)
50
- return resolve(stateDir, "connections.json");
51
- return resolve(homedir(), ".rig", "connections.json");
52
- }
53
- function resolveRepoConnectionPath(projectRoot) {
54
- return resolve(projectRoot, ".rig", "state", "connection.json");
55
- }
56
- function readJsonFile(path) {
57
- if (!existsSync(path))
58
- return null;
59
- try {
60
- return JSON.parse(readFileSync(path, "utf8"));
61
- } catch (error) {
62
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
63
- }
64
- }
65
- function normalizeConnection(value) {
66
- if (!value || typeof value !== "object" || Array.isArray(value))
67
- return null;
68
- const record = value;
69
- if (record.kind === "local")
70
- return { kind: "local", mode: "auto" };
71
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
72
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
73
- return { kind: "remote", baseUrl };
74
- }
75
- return null;
76
- }
77
- function readGlobalConnections(options = {}) {
78
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
79
- const payload = readJsonFile(path);
80
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
81
- return { connections: {} };
82
- }
83
- const rawConnections = payload.connections;
84
- const connections = {};
85
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
86
- for (const [alias, raw] of Object.entries(rawConnections)) {
87
- const connection = normalizeConnection(raw);
88
- if (connection)
89
- connections[alias] = connection;
90
- }
91
- }
92
- return { connections };
93
- }
94
- function readRepoConnection(projectRoot) {
95
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
96
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
97
- return null;
98
- const record = payload;
99
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
100
- if (!selected)
101
- return null;
102
- return {
103
- selected,
104
- project: typeof record.project === "string" ? record.project : undefined,
105
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
106
- };
107
- }
108
- function resolveSelectedConnection(projectRoot, options = {}) {
109
- const repo = readRepoConnection(projectRoot);
110
- if (!repo)
111
- return null;
112
- if (repo.selected === "local")
113
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
114
- const global = readGlobalConnections(options);
115
- const connection = global.connections[repo.selected];
116
- if (!connection) {
117
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
118
- }
119
- return { alias: repo.selected, connection };
120
- }
121
-
122
- // packages/cli/src/commands/_server-client.ts
123
- var cachedGitHubBearerToken;
124
- function cleanToken(value) {
125
- const trimmed = value?.trim();
126
- return trimmed ? trimmed : null;
127
- }
128
- function readPrivateRemoteSessionToken(projectRoot) {
129
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
130
- if (!existsSync2(path))
131
- return null;
132
- try {
133
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
134
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
135
- } catch {
136
- return null;
137
- }
138
- }
139
- function readGitHubBearerTokenForRemote(projectRoot) {
140
- if (cachedGitHubBearerToken !== undefined)
141
- return cachedGitHubBearerToken;
142
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
143
- if (privateSession) {
144
- cachedGitHubBearerToken = privateSession;
145
- return cachedGitHubBearerToken;
146
- }
147
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
148
- if (envToken) {
149
- cachedGitHubBearerToken = envToken;
150
- return cachedGitHubBearerToken;
151
- }
152
- const result = spawnSync("gh", ["auth", "token"], {
153
- encoding: "utf8",
154
- timeout: 5000,
155
- stdio: ["ignore", "pipe", "ignore"]
156
- });
157
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
158
- return cachedGitHubBearerToken;
159
- }
160
- async function ensureServerForCli(projectRoot) {
161
- try {
162
- const selected = resolveSelectedConnection(projectRoot);
163
- if (selected?.connection.kind === "remote") {
164
- return {
165
- baseUrl: selected.connection.baseUrl,
166
- authToken: readGitHubBearerTokenForRemote(projectRoot),
167
- connectionKind: "remote"
168
- };
169
- }
170
- const connection = await ensureLocalRigServerConnection(projectRoot);
171
- return {
172
- baseUrl: connection.baseUrl,
173
- authToken: connection.authToken,
174
- connectionKind: "local"
175
- };
176
- } catch (error) {
177
- if (error instanceof Error) {
178
- throw new CliError2(error.message, 1);
179
- }
180
- throw error;
181
- }
182
- }
183
- function mergeHeaders(headers, authToken) {
184
- const merged = new Headers(headers);
185
- if (authToken) {
186
- merged.set("authorization", `Bearer ${authToken}`);
187
- }
188
- return merged;
189
- }
190
- function diagnosticMessage(payload) {
191
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
192
- return null;
193
- const record = payload;
194
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
195
- const messages = diagnostics.flatMap((entry) => {
196
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
197
- return [];
198
- const diagnostic = entry;
199
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
200
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
201
- return message ? [`${kind}: ${message}`] : [];
202
- });
203
- return messages.length > 0 ? messages.join("; ") : null;
204
- }
205
- async function requestServerJson(context, pathname, init = {}) {
206
- const server = await ensureServerForCli(context.projectRoot);
207
- const response = await fetch(`${server.baseUrl}${pathname}`, {
208
- ...init,
209
- headers: mergeHeaders(init.headers, server.authToken)
210
- });
211
- const text = await response.text();
212
- const payload = text.trim().length > 0 ? (() => {
213
- try {
214
- return JSON.parse(text);
215
- } catch {
216
- return null;
217
- }
218
- })() : null;
219
- if (!response.ok) {
220
- const diagnostics = diagnosticMessage(payload);
221
- const detail = diagnostics ?? (text || response.statusText);
222
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
223
- }
224
- return payload;
225
- }
226
- async function getGitHubAuthStatusViaServer(context) {
227
- const payload = await requestServerJson(context, "/api/github/auth/status");
228
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
229
- }
230
- async function postGitHubTokenViaServer(context, token, options = {}) {
231
- const payload = await requestServerJson(context, "/api/github/auth/token", {
232
- method: "POST",
233
- headers: { "content-type": "application/json" },
234
- body: JSON.stringify({ token, selectedRepo: options.selectedRepo, projectRoot: options.projectRoot })
235
- });
236
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
237
- }
238
-
239
- // packages/cli/src/commands/github.ts
240
- function printPayload(context, payload, fallback) {
241
- if (context.outputMode === "json")
242
- console.log(JSON.stringify(payload, null, 2));
243
- else
244
- console.log(fallback);
245
- }
246
- function readGhToken() {
247
- const result = spawnSync2("gh", ["auth", "token"], { encoding: "utf8" });
248
- if (result.status !== 0) {
249
- const detail = result.stderr?.trim() || result.stdout?.trim() || "gh auth token failed";
250
- throw new CliError2(`Could not import GitHub token from gh: ${detail}`, 1);
251
- }
252
- const token = result.stdout.trim();
253
- if (!token)
254
- throw new CliError2("gh auth token returned an empty token.", 1);
255
- return token;
256
- }
257
- async function executeGithub(context, args) {
258
- const [group, command, ...rest] = args;
259
- if (group !== "auth") {
260
- throw new CliError2("Usage: rig github auth <status|import-gh|token>", 1);
261
- }
262
- switch (command) {
263
- case "status": {
264
- if (rest.length > 0)
265
- throw new CliError2("Usage: rig github auth status", 1);
266
- const status = await getGitHubAuthStatusViaServer(context);
267
- printPayload(context, status, `GitHub auth: ${status.authenticated ? "authenticated" : "unauthenticated"}`);
268
- return { ok: true, group: "github", command: "auth status", details: status };
269
- }
270
- case "token": {
271
- const parsed = takeOption(rest, "--token");
272
- if (parsed.rest.length > 0)
273
- throw new CliError2("Usage: rig github auth token --token <token>", 1);
274
- const token = parsed.value?.trim();
275
- if (!token)
276
- throw new CliError2("Missing --token value.", 1);
277
- const result = await postGitHubTokenViaServer(context, token);
278
- printPayload(context, result, "GitHub token stored on the selected Rig server.");
279
- return { ok: true, group: "github", command: "auth token", details: result };
280
- }
281
- case "import-gh": {
282
- if (rest.length > 0)
283
- throw new CliError2("Usage: rig github auth import-gh", 1);
284
- const result = await postGitHubTokenViaServer(context, readGhToken());
285
- printPayload(context, result, "GitHub token imported from gh and stored on the selected Rig server.");
286
- return { ok: true, group: "github", command: "auth import-gh", details: result };
287
- }
288
- default:
289
- throw new CliError2("Usage: rig github auth <status|import-gh|token>", 1);
290
- }
291
- }
292
- export {
293
- executeGithub
294
- };
@@ -1,160 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/inbox.ts
3
- import { writeFileSync } from "fs";
4
- import { resolve } from "path";
5
-
6
- // packages/cli/src/runner.ts
7
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
8
- import { CliError } from "@rig/runtime/control-plane/errors";
9
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
10
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
11
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
12
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
13
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
14
- function takeOption(args, option) {
15
- const rest = [];
16
- let value;
17
- for (let index = 0;index < args.length; index += 1) {
18
- const current = args[index];
19
- if (current === option) {
20
- const next = args[index + 1];
21
- if (!next || next.startsWith("-")) {
22
- throw new CliError(`Missing value for ${option}`);
23
- }
24
- value = next;
25
- index += 1;
26
- continue;
27
- }
28
- if (current !== undefined) {
29
- rest.push(current);
30
- }
31
- }
32
- return { value, rest };
33
- }
34
- function requireNoExtraArgs(args, usage) {
35
- if (args.length > 0) {
36
- throw new CliError(`Unexpected arguments: ${args.join(" ")}
37
- Usage: ${usage}`);
38
- }
39
- }
40
-
41
- // packages/cli/src/commands/inbox.ts
42
- import {
43
- listAuthorityRuns,
44
- readJsonlFile,
45
- resolveAuthorityRunDir
46
- } from "@rig/runtime/control-plane/authority-files";
47
- async function executeInbox(context, args) {
48
- const [command = "approvals", ...rest] = args;
49
- switch (command) {
50
- case "approvals": {
51
- let pending = rest;
52
- const run = takeOption(pending, "--run");
53
- pending = run.rest;
54
- const task = takeOption(pending, "--task");
55
- pending = task.rest;
56
- requireNoExtraArgs(pending, "bun run rig inbox approvals [--run <id>] [--task <id>]");
57
- const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!run.value || entry.runId === run.value) && (!task.value || entry.taskId === task.value));
58
- const approvals = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "approvals.jsonl")).map((record) => ({
59
- runId: entry.runId,
60
- record
61
- })));
62
- if (context.outputMode === "text") {
63
- for (const approval of approvals) {
64
- console.log(JSON.stringify(approval));
65
- }
66
- }
67
- return { ok: true, group: "inbox", command, details: { approvals } };
68
- }
69
- case "approve": {
70
- let pending = rest;
71
- const run = takeOption(pending, "--run");
72
- pending = run.rest;
73
- const request = takeOption(pending, "--request");
74
- pending = request.rest;
75
- const decision = takeOption(pending, "--decision");
76
- pending = decision.rest;
77
- const note = takeOption(pending, "--note");
78
- pending = note.rest;
79
- requireNoExtraArgs(pending, "bun run rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
80
- if (!run.value || !request.value || !decision.value) {
81
- throw new CliError2("approve requires --run, --request, and --decision.");
82
- }
83
- if (decision.value !== "approve" && decision.value !== "reject") {
84
- throw new CliError2("decision must be approve or reject.");
85
- }
86
- const approvalsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
87
- const approvals = readJsonlFile(approvalsPath);
88
- const resolvedAt = new Date().toISOString();
89
- const next = approvals.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", decision: decision.value, note: note.value ?? null, resolvedAt } : entry);
90
- writeFileSync(approvalsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
91
- `)}
92
- `, "utf8");
93
- return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, decision: decision.value } };
94
- }
95
- case "inputs": {
96
- let pending = rest;
97
- const run = takeOption(pending, "--run");
98
- pending = run.rest;
99
- const task = takeOption(pending, "--task");
100
- pending = task.rest;
101
- requireNoExtraArgs(pending, "bun run rig inbox inputs [--run <id>] [--task <id>]");
102
- const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!run.value || entry.runId === run.value) && (!task.value || entry.taskId === task.value));
103
- const requests = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "user-input.jsonl")).map((record) => ({
104
- runId: entry.runId,
105
- record
106
- })));
107
- if (context.outputMode === "text") {
108
- for (const request of requests) {
109
- console.log(JSON.stringify(request));
110
- }
111
- }
112
- return { ok: true, group: "inbox", command, details: { requests } };
113
- }
114
- case "respond": {
115
- let pending = rest;
116
- const run = takeOption(pending, "--run");
117
- pending = run.rest;
118
- const request = takeOption(pending, "--request");
119
- pending = request.rest;
120
- const answers = [];
121
- const remaining = [];
122
- for (let index = 0;index < pending.length; index += 1) {
123
- const current = pending[index];
124
- if (current === "--answer") {
125
- const next2 = pending[index + 1];
126
- if (!next2 || next2.startsWith("-")) {
127
- throw new CliError2("Missing value for --answer");
128
- }
129
- answers.push(next2);
130
- index += 1;
131
- continue;
132
- }
133
- if (current !== undefined) {
134
- remaining.push(current);
135
- }
136
- }
137
- requireNoExtraArgs(remaining, "bun run rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
138
- if (!run.value || !request.value || answers.length === 0) {
139
- throw new CliError2("respond requires --run, --request, and at least one --answer.");
140
- }
141
- const parsedAnswers = Object.fromEntries(answers.map((entry) => {
142
- const [key, ...restValue] = entry.split("=");
143
- return [key, restValue.join("=")];
144
- }));
145
- const requestsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
146
- const requests = readJsonlFile(requestsPath);
147
- const resolvedAt = new Date().toISOString();
148
- const next = requests.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", answers: parsedAnswers, respondedAt: resolvedAt, resolvedAt } : entry);
149
- writeFileSync(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
150
- `)}
151
- `, "utf8");
152
- return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, answers: parsedAnswers } };
153
- }
154
- default:
155
- throw new CliError2(`Unknown inbox command: ${command}`);
156
- }
157
- }
158
- export {
159
- executeInbox
160
- };