@h-rig/cli 0.0.6-alpha.2 → 0.0.6-alpha.200

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