@h-rig/cli 0.0.6-alpha.19 → 0.0.6-alpha.190

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 +7 -28
  2. package/bin/rig-run.js +19 -0
  3. package/bin/rig.js +19 -0
  4. package/package.json +15 -27
  5. package/dist/bin/build-rig-binaries.js +0 -107
  6. package/dist/bin/rig.js +0 -10233
  7. package/dist/src/commands/_authority-runs.js +0 -111
  8. package/dist/src/commands/_connection-state.js +0 -123
  9. package/dist/src/commands/_doctor-checks.js +0 -506
  10. package/dist/src/commands/_operator-surface.js +0 -204
  11. package/dist/src/commands/_operator-view.js +0 -496
  12. package/dist/src/commands/_parsers.js +0 -107
  13. package/dist/src/commands/_paths.js +0 -50
  14. package/dist/src/commands/_pi-install.js +0 -184
  15. package/dist/src/commands/_policy.js +0 -79
  16. package/dist/src/commands/_preflight.js +0 -482
  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 -56
  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 -516
  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 -1562
  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 -972
  38. package/dist/src/commands/server.js +0 -373
  39. package/dist/src/commands/setup.js +0 -686
  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 -1523
  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 -9912
  46. package/dist/src/index.js +0 -10251
  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,318 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_snapshot-upload.ts
3
- import { mkdir, readdir, readFile, writeFile } from "fs/promises";
4
- import { dirname as dirname2, resolve as resolve3, relative, sep } from "path";
5
-
6
- // packages/cli/src/commands/_server-client.ts
7
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
8
- import { resolve as resolve2 } from "path";
9
-
10
- // packages/cli/src/runner.ts
11
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
12
- import { CliError } from "@rig/runtime/control-plane/errors";
13
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
14
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
15
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
16
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
17
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
18
-
19
- // packages/cli/src/commands/_server-client.ts
20
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
21
-
22
- // packages/cli/src/commands/_connection-state.ts
23
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
24
- import { homedir } from "os";
25
- import { dirname, resolve } from "path";
26
- function resolveGlobalConnectionsPath(env = process.env) {
27
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
28
- if (explicit)
29
- return resolve(explicit);
30
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
31
- if (stateDir)
32
- return resolve(stateDir, "connections.json");
33
- return resolve(homedir(), ".rig", "connections.json");
34
- }
35
- function resolveRepoConnectionPath(projectRoot) {
36
- return resolve(projectRoot, ".rig", "state", "connection.json");
37
- }
38
- function readJsonFile(path) {
39
- if (!existsSync(path))
40
- return null;
41
- try {
42
- return JSON.parse(readFileSync(path, "utf8"));
43
- } catch (error) {
44
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
45
- }
46
- }
47
- function normalizeConnection(value) {
48
- if (!value || typeof value !== "object" || Array.isArray(value))
49
- return null;
50
- const record = value;
51
- if (record.kind === "local")
52
- return { kind: "local", mode: "auto" };
53
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
54
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
55
- return { kind: "remote", baseUrl };
56
- }
57
- return null;
58
- }
59
- function readGlobalConnections(options = {}) {
60
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
61
- const payload = readJsonFile(path);
62
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
63
- return { connections: {} };
64
- }
65
- const rawConnections = payload.connections;
66
- const connections = {};
67
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
68
- for (const [alias, raw] of Object.entries(rawConnections)) {
69
- const connection = normalizeConnection(raw);
70
- if (connection)
71
- connections[alias] = connection;
72
- }
73
- }
74
- return { connections };
75
- }
76
- function readRepoConnection(projectRoot) {
77
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
78
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
79
- return null;
80
- const record = payload;
81
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
82
- if (!selected)
83
- return null;
84
- return {
85
- selected,
86
- project: typeof record.project === "string" ? record.project : undefined,
87
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
88
- };
89
- }
90
- function resolveSelectedConnection(projectRoot, options = {}) {
91
- const repo = readRepoConnection(projectRoot);
92
- if (!repo)
93
- return null;
94
- if (repo.selected === "local")
95
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
96
- const global = readGlobalConnections(options);
97
- const connection = global.connections[repo.selected];
98
- if (!connection) {
99
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
100
- }
101
- return { alias: repo.selected, connection };
102
- }
103
-
104
- // packages/cli/src/commands/_server-client.ts
105
- var scopedGitHubBearerTokens = new Map;
106
- function cleanToken(value) {
107
- const trimmed = value?.trim();
108
- return trimmed ? trimmed : null;
109
- }
110
- function readPrivateRemoteSessionToken(projectRoot) {
111
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
112
- if (!existsSync2(path))
113
- return null;
114
- try {
115
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
116
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
117
- } catch {
118
- return null;
119
- }
120
- }
121
- function readGitHubBearerTokenForRemote(projectRoot) {
122
- const scopedKey = resolve2(projectRoot);
123
- if (scopedGitHubBearerTokens.has(scopedKey))
124
- return scopedGitHubBearerTokens.get(scopedKey) ?? null;
125
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
126
- if (privateSession)
127
- return privateSession;
128
- return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
129
- }
130
- async function ensureServerForCli(projectRoot) {
131
- try {
132
- const selected = resolveSelectedConnection(projectRoot);
133
- if (selected?.connection.kind === "remote") {
134
- return {
135
- baseUrl: selected.connection.baseUrl,
136
- authToken: readGitHubBearerTokenForRemote(projectRoot),
137
- connectionKind: "remote"
138
- };
139
- }
140
- const connection = await ensureLocalRigServerConnection(projectRoot);
141
- return {
142
- baseUrl: connection.baseUrl,
143
- authToken: connection.authToken,
144
- connectionKind: "local"
145
- };
146
- } catch (error) {
147
- if (error instanceof Error) {
148
- throw new CliError2(error.message, 1);
149
- }
150
- throw error;
151
- }
152
- }
153
- function mergeHeaders(headers, authToken) {
154
- const merged = new Headers(headers);
155
- if (authToken) {
156
- merged.set("authorization", `Bearer ${authToken}`);
157
- }
158
- return merged;
159
- }
160
- function diagnosticMessage(payload) {
161
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
162
- return null;
163
- const record = payload;
164
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
165
- const messages = diagnostics.flatMap((entry) => {
166
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
167
- return [];
168
- const diagnostic = entry;
169
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
170
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
171
- return message ? [`${kind}: ${message}`] : [];
172
- });
173
- return messages.length > 0 ? messages.join("; ") : null;
174
- }
175
- async function requestServerJson(context, pathname, init = {}) {
176
- const server = await ensureServerForCli(context.projectRoot);
177
- const response = await fetch(`${server.baseUrl}${pathname}`, {
178
- ...init,
179
- headers: mergeHeaders(init.headers, server.authToken)
180
- });
181
- const text = await response.text();
182
- const payload = text.trim().length > 0 ? (() => {
183
- try {
184
- return JSON.parse(text);
185
- } catch {
186
- return null;
187
- }
188
- })() : null;
189
- if (!response.ok) {
190
- const diagnostics = diagnosticMessage(payload);
191
- const detail = diagnostics ?? (text || response.statusText);
192
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
193
- }
194
- return payload;
195
- }
196
-
197
- // packages/cli/src/commands/_snapshot-upload.ts
198
- var UPLOADED_SNAPSHOT_PR_MARKER = "<!-- rig:uploaded-snapshot -->";
199
- var SNAPSHOT_ARCHIVE_VERSION = 1;
200
- var SNAPSHOT_ARCHIVE_CONTENT_TYPE = "application/vnd.rig.snapshot+json";
201
- var DEFAULT_EXCLUDED_DIRECTORIES = new Set([
202
- ".git",
203
- ".rig",
204
- "node_modules",
205
- ".turbo",
206
- ".next",
207
- ".cache",
208
- "coverage",
209
- "dist",
210
- "build",
211
- "out"
212
- ]);
213
- function toPosixPath(path) {
214
- return path.split(sep).join("/");
215
- }
216
- function assertManifestPath(root, relativePath) {
217
- if (!relativePath || relativePath.startsWith("/") || relativePath.includes("\x00")) {
218
- throw new Error(`Invalid snapshot path: ${relativePath}`);
219
- }
220
- const resolved = resolve3(root, relativePath);
221
- const relativeToRoot = relative(root, resolved);
222
- if (relativeToRoot.startsWith("..") || relativeToRoot === ".." || resolve3(relativeToRoot) === resolved) {
223
- throw new Error(`Snapshot path escapes project root: ${relativePath}`);
224
- }
225
- return resolved;
226
- }
227
- async function buildSnapshotUploadManifest(projectRoot, options = {}) {
228
- const root = resolve3(projectRoot);
229
- const excludedDirectories = [...new Set([
230
- ...DEFAULT_EXCLUDED_DIRECTORIES,
231
- ...options.excludedDirectories ?? []
232
- ])];
233
- const excludedSet = new Set(excludedDirectories);
234
- const files = [];
235
- async function visit(dir) {
236
- const entries = await readdir(dir, { withFileTypes: true });
237
- for (const entry of entries) {
238
- if (entry.isDirectory() && excludedSet.has(entry.name))
239
- continue;
240
- const fullPath = resolve3(dir, entry.name);
241
- if (entry.isDirectory()) {
242
- await visit(fullPath);
243
- continue;
244
- }
245
- if (!entry.isFile())
246
- continue;
247
- files.push(toPosixPath(relative(root, fullPath)));
248
- }
249
- }
250
- await visit(root);
251
- files.sort();
252
- return { root, files, excludedDirectories };
253
- }
254
- async function createSnapshotUploadArchive(projectRoot, options = {}) {
255
- const manifest = await buildSnapshotUploadManifest(projectRoot, options);
256
- const files = await Promise.all(manifest.files.map(async (path) => {
257
- const fullPath = assertManifestPath(manifest.root, path);
258
- return {
259
- path,
260
- contentBase64: (await readFile(fullPath)).toString("base64")
261
- };
262
- }));
263
- return {
264
- version: SNAPSHOT_ARCHIVE_VERSION,
265
- root: manifest.root,
266
- files,
267
- excludedDirectories: manifest.excludedDirectories,
268
- createdAt: (options.now?.() ?? new Date).toISOString()
269
- };
270
- }
271
- function encodeSnapshotUploadArchive(archive) {
272
- return Buffer.from(JSON.stringify(archive), "utf8").toString("base64");
273
- }
274
- async function writeSnapshotUploadArchive(projectRoot, outputPath, options = {}) {
275
- const archive = await createSnapshotUploadArchive(projectRoot, options);
276
- const target = resolve3(outputPath);
277
- await mkdir(dirname2(target), { recursive: true });
278
- await writeFile(target, JSON.stringify(archive, null, 2), "utf8");
279
- return archive;
280
- }
281
- async function uploadSnapshotArchiveViaServer(context, input) {
282
- const payload = await requestServerJson(context, `/api/projects/${encodeURIComponent(input.repoSlug)}/upload-snapshot`, {
283
- method: "POST",
284
- headers: { "content-type": "application/json" },
285
- body: JSON.stringify({
286
- archiveContentBase64: encodeSnapshotUploadArchive(input.archive),
287
- contentType: SNAPSHOT_ARCHIVE_CONTENT_TYPE,
288
- baseDir: input.baseDir
289
- })
290
- });
291
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
292
- }
293
- function appendUploadedSnapshotPrNotice(body) {
294
- if (body.includes(UPLOADED_SNAPSHOT_PR_MARKER))
295
- return body;
296
- const prefix = body.trimEnd();
297
- const notice = [
298
- UPLOADED_SNAPSHOT_PR_MARKER,
299
- "This PR was seeded from an uploaded local working-tree snapshot. Review local snapshot provenance before merging if repository policy requires it."
300
- ].join(`
301
- `);
302
- return prefix.length > 0 ? `${prefix}
303
-
304
- ${notice}
305
- ` : `${notice}
306
- `;
307
- }
308
- export {
309
- writeSnapshotUploadArchive,
310
- uploadSnapshotArchiveViaServer,
311
- encodeSnapshotUploadArchive,
312
- createSnapshotUploadArchive,
313
- buildSnapshotUploadManifest,
314
- appendUploadedSnapshotPrNotice,
315
- UPLOADED_SNAPSHOT_PR_MARKER,
316
- SNAPSHOT_ARCHIVE_VERSION,
317
- SNAPSHOT_ARCHIVE_CONTENT_TYPE
318
- };
@@ -1,56 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_operator-surface.ts
3
- import { createInterface as createPromptInterface } from "readline/promises";
4
- function taskId(task) {
5
- return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
6
- }
7
- function taskTitle(task) {
8
- return typeof task.title === "string" && task.title.trim() ? task.title : "Untitled task";
9
- }
10
- function taskStatus(task) {
11
- return typeof task.status === "string" && task.status.trim() ? task.status : "unknown";
12
- }
13
- function renderTaskPickerRows(tasks) {
14
- return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
15
- }
16
- async function promptForTaskSelection(question) {
17
- const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
18
- try {
19
- return await rl.question(question);
20
- } finally {
21
- rl.close();
22
- }
23
- }
24
-
25
- // packages/cli/src/commands/_task-picker.ts
26
- function taskId2(task) {
27
- return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
28
- }
29
- async function selectTaskWithTextPicker(tasks, io = {}) {
30
- if (tasks.length === 0)
31
- return null;
32
- if (tasks.length === 1)
33
- return tasks[0];
34
- const isTty = io.isTty ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
35
- if (!isTty) {
36
- throw new Error("task run requires an interactive terminal to pick a task; pass --task <id>, --next, or --detach with a task id.");
37
- }
38
- const prompt = io.prompt ?? promptForTaskSelection;
39
- const renderer = io.renderer ?? { writeLine: (line) => process.stdout.write(`${line}
40
- `) };
41
- renderer.writeLine("Select Rig task:");
42
- for (const row of renderTaskPickerRows(tasks))
43
- renderer.writeLine(` ${row}`);
44
- const answer = (await prompt(`Task [1-${tasks.length}] or id: `)).trim();
45
- if (!answer)
46
- return null;
47
- if (/^\d+$/.test(answer)) {
48
- const index = Number.parseInt(answer, 10) - 1;
49
- return tasks[index] ?? null;
50
- }
51
- return tasks.find((task) => taskId2(task) === answer) ?? null;
52
- }
53
- export {
54
- selectTaskWithTextPicker,
55
- renderTaskPickerRows
56
- };