@h-rig/cli 0.0.6-alpha.24 → 0.0.6-alpha.241

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 (51) hide show
  1. package/README.md +6 -28
  2. package/package.json +13 -28
  3. package/dist/bin/build-rig-binaries.js +0 -107
  4. package/dist/bin/rig.js +0 -11112
  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 -1147
  11. package/dist/src/commands/_parsers.js +0 -107
  12. package/dist/src/commands/_paths.js +0 -50
  13. package/dist/src/commands/_pi-frontend.js +0 -843
  14. package/dist/src/commands/_pi-install.js +0 -185
  15. package/dist/src/commands/_pi-worker-bridge-extension.js +0 -761
  16. package/dist/src/commands/_policy.js +0 -79
  17. package/dist/src/commands/_preflight.js +0 -403
  18. package/dist/src/commands/_probes.js +0 -13
  19. package/dist/src/commands/_run-driver-helpers.js +0 -289
  20. package/dist/src/commands/_server-client.js +0 -514
  21. package/dist/src/commands/_snapshot-upload.js +0 -318
  22. package/dist/src/commands/_task-picker.js +0 -76
  23. package/dist/src/commands/agent.js +0 -499
  24. package/dist/src/commands/browser.js +0 -890
  25. package/dist/src/commands/connect.js +0 -180
  26. package/dist/src/commands/dist.js +0 -402
  27. package/dist/src/commands/doctor.js +0 -517
  28. package/dist/src/commands/github.js +0 -281
  29. package/dist/src/commands/inbox.js +0 -160
  30. package/dist/src/commands/init.js +0 -1563
  31. package/dist/src/commands/inspect.js +0 -174
  32. package/dist/src/commands/inspector.js +0 -256
  33. package/dist/src/commands/plugin.js +0 -167
  34. package/dist/src/commands/profile-and-review.js +0 -178
  35. package/dist/src/commands/queue.js +0 -198
  36. package/dist/src/commands/remote.js +0 -507
  37. package/dist/src/commands/repo-git-harness.js +0 -221
  38. package/dist/src/commands/run.js +0 -1674
  39. package/dist/src/commands/server.js +0 -373
  40. package/dist/src/commands/setup.js +0 -687
  41. package/dist/src/commands/task-report-bug.js +0 -1083
  42. package/dist/src/commands/task-run-driver.js +0 -2600
  43. package/dist/src/commands/task.js +0 -2178
  44. package/dist/src/commands/test.js +0 -39
  45. package/dist/src/commands/workspace.js +0 -123
  46. package/dist/src/commands.js +0 -10791
  47. package/dist/src/index.js +0 -11130
  48. package/dist/src/launcher.js +0 -133
  49. package/dist/src/report-bug.js +0 -260
  50. package/dist/src/runner.js +0 -273
  51. 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 connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect 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
- };
@@ -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
- };