@h-rig/cli 0.0.6-alpha.22 → 0.0.6-alpha.221

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 (49) hide show
  1. package/README.md +6 -28
  2. package/package.json +9 -29
  3. package/dist/bin/build-rig-binaries.js +0 -107
  4. package/dist/bin/rig.js +0 -10655
  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 -731
  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/_policy.js +0 -79
  15. package/dist/src/commands/_preflight.js +0 -483
  16. package/dist/src/commands/_probes.js +0 -13
  17. package/dist/src/commands/_run-driver-helpers.js +0 -289
  18. package/dist/src/commands/_server-client.js +0 -435
  19. package/dist/src/commands/_snapshot-upload.js +0 -318
  20. package/dist/src/commands/_task-picker.js +0 -76
  21. package/dist/src/commands/agent.js +0 -499
  22. package/dist/src/commands/browser.js +0 -890
  23. package/dist/src/commands/connect.js +0 -180
  24. package/dist/src/commands/dist.js +0 -402
  25. package/dist/src/commands/doctor.js +0 -517
  26. package/dist/src/commands/github.js +0 -281
  27. package/dist/src/commands/inbox.js +0 -160
  28. package/dist/src/commands/init.js +0 -1563
  29. package/dist/src/commands/inspect.js +0 -174
  30. package/dist/src/commands/inspector.js +0 -256
  31. package/dist/src/commands/plugin.js +0 -167
  32. package/dist/src/commands/profile-and-review.js +0 -178
  33. package/dist/src/commands/queue.js +0 -198
  34. package/dist/src/commands/remote.js +0 -507
  35. package/dist/src/commands/repo-git-harness.js +0 -221
  36. package/dist/src/commands/run.js +0 -1258
  37. package/dist/src/commands/server.js +0 -373
  38. package/dist/src/commands/setup.js +0 -687
  39. package/dist/src/commands/task-report-bug.js +0 -1083
  40. package/dist/src/commands/task-run-driver.js +0 -2554
  41. package/dist/src/commands/task.js +0 -1842
  42. package/dist/src/commands/test.js +0 -39
  43. package/dist/src/commands/workspace.js +0 -123
  44. package/dist/src/commands.js +0 -10334
  45. package/dist/src/index.js +0 -10673
  46. package/dist/src/launcher.js +0 -133
  47. package/dist/src/report-bug.js +0 -260
  48. package/dist/src/runner.js +0 -273
  49. package/dist/src/withMutedConsole.js +0 -42
@@ -1,499 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/agent.ts
3
- import { resolve as resolve2 } from "path";
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 takeFlag(args, flag) {
14
- const rest = [];
15
- let value = false;
16
- for (const arg of args) {
17
- if (arg === flag) {
18
- value = true;
19
- continue;
20
- }
21
- rest.push(arg);
22
- }
23
- return { value, rest };
24
- }
25
- function takeOption(args, option) {
26
- const rest = [];
27
- let value;
28
- for (let index = 0;index < args.length; index += 1) {
29
- const current = args[index];
30
- if (current === option) {
31
- const next = args[index + 1];
32
- if (!next || next.startsWith("-")) {
33
- throw new CliError(`Missing value for ${option}`);
34
- }
35
- value = next;
36
- index += 1;
37
- continue;
38
- }
39
- if (current !== undefined) {
40
- rest.push(current);
41
- }
42
- }
43
- return { value, rest };
44
- }
45
- function requireNoExtraArgs(args, usage) {
46
- if (args.length > 0) {
47
- throw new CliError(`Unexpected arguments: ${args.join(" ")}
48
- Usage: ${usage}`);
49
- }
50
- }
51
-
52
- // packages/cli/src/commands/agent.ts
53
- import {
54
- agentId,
55
- cleanupAgentRuntime,
56
- ensureAgentRuntime,
57
- listAgentRuntimes,
58
- runInAgentRuntime
59
- } from "@rig/runtime/control-plane/runtime/isolation";
60
-
61
- // packages/cli/src/commands/_authority-runs.ts
62
- import { existsSync } from "fs";
63
- import { resolve } from "path";
64
- import {
65
- readAuthorityRun,
66
- readJsonlFile,
67
- resolveAuthorityRunDir,
68
- writeJsonFile
69
- } from "@rig/runtime/control-plane/authority-files";
70
-
71
- // packages/cli/src/commands/_paths.ts
72
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
73
- function resolveControlPlaneMonorepoRoot(projectRoot) {
74
- return resolveMonorepoRoot(projectRoot);
75
- }
76
-
77
- // packages/cli/src/commands/_authority-runs.ts
78
- var RIG_WORKSPACE_ID = "rig-local-workspace";
79
- function normalizeRuntimeAdapter(value) {
80
- const normalized = value?.trim().toLowerCase();
81
- if (!normalized) {
82
- return "pi";
83
- }
84
- if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
85
- return "codex";
86
- }
87
- if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
88
- return "pi";
89
- }
90
- return "claude-code";
91
- }
92
- function readLatestBeadRecord(projectRoot, taskId) {
93
- const issuesPath = resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".beads", "issues.jsonl");
94
- if (!existsSync(issuesPath)) {
95
- return null;
96
- }
97
- let latest = null;
98
- for (const issue of readJsonlFile(issuesPath)) {
99
- if (!issue || typeof issue !== "object") {
100
- continue;
101
- }
102
- const record = issue;
103
- if (record.id === taskId) {
104
- latest = record;
105
- }
106
- }
107
- return latest;
108
- }
109
- function resolveTaskTitleForAuthorityRun(projectRoot, taskId) {
110
- try {
111
- const record = readLatestBeadRecord(projectRoot, taskId);
112
- const title = record && typeof record.title === "string" ? record.title.trim() : "";
113
- if (title) {
114
- return title;
115
- }
116
- } catch {}
117
- return null;
118
- }
119
- function upsertAgentAuthorityRun(projectRoot, input) {
120
- const current = readAuthorityRun(projectRoot, input.runId);
121
- const existing = current;
122
- const createdAt = existing?.createdAt ?? input.createdAt;
123
- const runtimeMode = typeof existing?.runtimeMode === "string" ? existing.runtimeMode : "full-access";
124
- const interactionMode = typeof existing?.interactionMode === "string" ? existing.interactionMode : "default";
125
- const runMode = typeof existing?.runMode === "string" ? existing.runMode : "autonomous";
126
- const runtimeAdapter = normalizeRuntimeAdapter(input.runtimeAdapter ?? existing?.runtimeAdapter ?? "claude-code");
127
- const title = resolveTaskTitleForAuthorityRun(projectRoot, input.taskId) ?? input.taskId;
128
- const next = {
129
- ...existing ?? {},
130
- runId: input.runId,
131
- projectRoot,
132
- workspaceId: existing?.workspaceId ?? RIG_WORKSPACE_ID,
133
- taskId: input.taskId,
134
- threadId: existing?.threadId ?? null,
135
- mode: "local",
136
- runtimeAdapter,
137
- status: input.status,
138
- createdAt,
139
- startedAt: input.startedAt ?? existing?.startedAt ?? null,
140
- completedAt: input.completedAt ?? existing?.completedAt ?? null,
141
- endpointId: existing?.endpointId ?? null,
142
- hostId: existing?.hostId ?? null,
143
- worktreePath: input.worktreePath ?? existing?.worktreePath ?? null,
144
- artifactRoot: input.artifactRoot ?? existing?.artifactRoot ?? null,
145
- logRoot: input.logRoot ?? existing?.logRoot ?? null,
146
- sessionPath: input.sessionPath ?? existing?.sessionPath ?? null,
147
- sessionLogPath: input.sessionLogPath ?? existing?.sessionLogPath ?? null,
148
- pid: input.pid ?? existing?.pid ?? null,
149
- updatedAt: input.createdAt,
150
- title,
151
- model: typeof existing?.model === "string" ? existing.model : null,
152
- runtimeMode,
153
- interactionMode,
154
- runMode,
155
- initialPrompt: typeof existing?.initialPrompt === "string" ? existing.initialPrompt : null
156
- };
157
- if (input.errorText !== undefined) {
158
- next.errorText = input.errorText;
159
- } else if ("errorText" in next) {
160
- delete next.errorText;
161
- }
162
- writeJsonFile(resolve(resolveAuthorityRunDir(projectRoot, input.runId), "run.json"), next);
163
- return next;
164
- }
165
-
166
- // packages/cli/src/withMutedConsole.ts
167
- function isPromise(value) {
168
- if (typeof value !== "object" && typeof value !== "function") {
169
- return false;
170
- }
171
- return value !== null && typeof value.then === "function";
172
- }
173
- function withMutedConsole(mute, fn) {
174
- if (!mute) {
175
- return fn();
176
- }
177
- const originalLog = console.log;
178
- const originalWarn = console.warn;
179
- const originalInfo = console.info;
180
- const restore = () => {
181
- console.log = originalLog;
182
- console.warn = originalWarn;
183
- console.info = originalInfo;
184
- };
185
- console.log = () => {};
186
- console.warn = () => {};
187
- console.info = () => {};
188
- try {
189
- const result = fn();
190
- if (isPromise(result)) {
191
- return result.finally(restore);
192
- }
193
- restore();
194
- return result;
195
- } catch (error) {
196
- restore();
197
- throw error;
198
- } finally {
199
- if (console.log === originalLog) {
200
- restore();
201
- }
202
- }
203
- }
204
-
205
- // packages/cli/src/commands/_parsers.ts
206
- function parseIsolationMode(value, allowOff) {
207
- if (!value) {
208
- return "worktree";
209
- }
210
- if (value === "worktree") {
211
- return value;
212
- }
213
- if (allowOff && value === "off") {
214
- return value;
215
- }
216
- throw new CliError2(`Invalid isolation mode: ${value}. Use ${allowOff ? "off|" : ""}worktree.`);
217
- }
218
-
219
- // packages/cli/src/commands/_preflight.ts
220
- import { ensureProjectMainFreshBeforeRun } from "@rig/runtime/control-plane/project-main-pre-run-sync";
221
-
222
- // packages/cli/src/commands/_server-client.ts
223
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
224
- var scopedGitHubBearerTokens = new Map;
225
-
226
- // packages/cli/src/commands/_preflight.ts
227
- async function runProjectMainSyncPreflight(context, options) {
228
- if (context.dryRun) {
229
- if (context.outputMode === "text" && !options.disabled) {
230
- console.log("[dry-run] project-rig pre-run sync check");
231
- }
232
- return;
233
- }
234
- const result = await ensureProjectMainFreshBeforeRun({
235
- projectRoot: context.projectRoot,
236
- disabled: options.disabled,
237
- runBootstrap: async () => {
238
- const bootstrap = await context.runCommand(["bun", "run", "bootstrap"]);
239
- if (bootstrap.exitCode !== 0) {
240
- throw new CliError2(bootstrap.stderr || bootstrap.stdout || "bun run bootstrap failed during project pre-run sync", bootstrap.exitCode || 1);
241
- }
242
- }
243
- });
244
- if (context.outputMode !== "text") {
245
- return;
246
- }
247
- switch (result.status) {
248
- case "disabled":
249
- console.log("Project pre-run sync skipped (--skip-project-sync).");
250
- break;
251
- case "skipped_not_main":
252
- console.log(`Project pre-run sync skipped (current branch: ${result.branch}).`);
253
- break;
254
- case "up_to_date":
255
- break;
256
- case "local_ahead":
257
- console.log(`Project pre-run sync skipped (local main ahead by ${result.localAhead} commit(s)).`);
258
- break;
259
- case "updated":
260
- console.log(`Project pre-run sync updated local main from origin/main (+${result.remoteAhead}) and bootstrapped.`);
261
- break;
262
- }
263
- }
264
-
265
- // packages/cli/src/commands/agent.ts
266
- function splitAtDoubleDash(args) {
267
- const separatorIndex = args.indexOf("--");
268
- if (separatorIndex === -1) {
269
- return { options: args, commandParts: [] };
270
- }
271
- return {
272
- options: args.slice(0, separatorIndex),
273
- commandParts: args.slice(separatorIndex + 1)
274
- };
275
- }
276
- async function attachEventBusToProvisionedRuntime(context, workspaceDir) {
277
- const previousWorkspace = process.env.RIG_TASK_WORKSPACE;
278
- process.env.RIG_TASK_WORKSPACE = workspaceDir;
279
- try {
280
- await context.eventBus.attachRuntimeWorkspace(context.projectRoot);
281
- } finally {
282
- if (previousWorkspace === undefined) {
283
- delete process.env.RIG_TASK_WORKSPACE;
284
- } else {
285
- process.env.RIG_TASK_WORKSPACE = previousWorkspace;
286
- }
287
- }
288
- }
289
- async function executeAgent(context, args) {
290
- const [command = "list", ...rest] = args;
291
- switch (command) {
292
- case "list": {
293
- requireNoExtraArgs(rest, "bun run rig agent list");
294
- const runtimes = await listAgentRuntimes(context.projectRoot);
295
- if (context.outputMode === "text") {
296
- if (runtimes.length === 0) {
297
- console.log("No agent runtimes.");
298
- } else {
299
- for (const runtime of runtimes) {
300
- console.log(`${runtime.id} (${runtime.mode}) workspace=${runtime.workspaceDir} created=${runtime.createdAt}`);
301
- }
302
- }
303
- }
304
- return { ok: true, group: "agent", command, details: { runtimes } };
305
- }
306
- case "prepare": {
307
- let pending = rest;
308
- const idResult = takeOption(pending, "--id");
309
- pending = idResult.rest;
310
- const modeResult = takeOption(pending, "--mode");
311
- pending = modeResult.rest;
312
- const taskResult = takeOption(pending, "--task");
313
- pending = taskResult.rest;
314
- requireNoExtraArgs(pending, "bun run rig agent prepare --task <id> [--id <id>] [--mode worktree]");
315
- const mode = parseIsolationMode(modeResult.value, false);
316
- const id = idResult.value || agentId("agent");
317
- const taskId = taskResult.value?.trim();
318
- if (!taskId) {
319
- throw new CliError2("Usage: bun run rig agent prepare --task <id> [--id <id>] [--mode worktree]");
320
- }
321
- const runtime = await withMutedConsole(context.outputMode === "json", () => ensureAgentRuntime({
322
- projectRoot: context.projectRoot,
323
- id,
324
- taskId,
325
- mode
326
- }));
327
- await attachEventBusToProvisionedRuntime(context, runtime.workspaceDir);
328
- if (context.outputMode === "text") {
329
- console.log(`Prepared runtime ${runtime.id} (${runtime.mode})`);
330
- console.log(`Workspace: ${runtime.workspaceDir}`);
331
- }
332
- return { ok: true, group: "agent", command, details: { runtime } };
333
- }
334
- case "run": {
335
- const { options, commandParts } = splitAtDoubleDash(rest);
336
- if (commandParts.length === 0) {
337
- throw new CliError2("Usage: bun run rig agent run [--id <id>] [--mode worktree] [--skip-project-sync] -- <command...>");
338
- }
339
- let pending = options;
340
- const idResult = takeOption(pending, "--id");
341
- pending = idResult.rest;
342
- const modeResult = takeOption(pending, "--mode");
343
- pending = modeResult.rest;
344
- const taskResult = takeOption(pending, "--task");
345
- pending = taskResult.rest;
346
- const skipProjectSyncResult = takeFlag(pending, "--skip-project-sync");
347
- pending = skipProjectSyncResult.rest;
348
- requireNoExtraArgs(pending, "bun run rig agent run --task <id> [--id <id>] [--mode worktree] [--skip-project-sync] -- <command...>");
349
- const mode = parseIsolationMode(modeResult.value, false);
350
- const id = idResult.value || agentId("agent-run");
351
- const taskId = taskResult.value?.trim();
352
- if (!taskId) {
353
- throw new CliError2("Usage: bun run rig agent run --task <id> [--id <id>] [--mode worktree] [--skip-project-sync] -- <command...>");
354
- }
355
- await runProjectMainSyncPreflight(context, { disabled: skipProjectSyncResult.value });
356
- const createdAt = new Date().toISOString();
357
- upsertAgentAuthorityRun(context.projectRoot, {
358
- runId: id,
359
- taskId,
360
- createdAt,
361
- runtimeAdapter: process.env.RIG_RUNTIME_ADAPTER || "claude-code",
362
- status: "preparing",
363
- startedAt: createdAt
364
- });
365
- try {
366
- const runtime = await withMutedConsole(context.outputMode === "json", () => ensureAgentRuntime({
367
- projectRoot: context.projectRoot,
368
- id,
369
- taskId,
370
- mode
371
- }));
372
- await attachEventBusToProvisionedRuntime(context, runtime.workspaceDir);
373
- const runningAt = new Date().toISOString();
374
- upsertAgentAuthorityRun(context.projectRoot, {
375
- runId: runtime.id,
376
- taskId,
377
- createdAt: runningAt,
378
- runtimeAdapter: process.env.RIG_RUNTIME_ADAPTER || "claude-code",
379
- status: "running",
380
- startedAt: createdAt,
381
- worktreePath: runtime.workspaceDir,
382
- artifactRoot: resolve2(runtime.workspaceDir, "artifacts", taskId),
383
- logRoot: runtime.logsDir,
384
- sessionPath: resolve2(runtime.sessionDir, "session.json"),
385
- sessionLogPath: resolve2(runtime.logsDir, "agent-stdout.log"),
386
- pid: process.pid
387
- });
388
- const result = await runInAgentRuntime({
389
- projectRoot: context.projectRoot,
390
- runtime,
391
- command: commandParts,
392
- inheritStdio: context.outputMode === "text"
393
- });
394
- if (result.exitCode !== 0) {
395
- const failedAt = new Date().toISOString();
396
- upsertAgentAuthorityRun(context.projectRoot, {
397
- runId: runtime.id,
398
- taskId,
399
- createdAt: failedAt,
400
- runtimeAdapter: process.env.RIG_RUNTIME_ADAPTER || "claude-code",
401
- status: "failed",
402
- startedAt: createdAt,
403
- completedAt: failedAt,
404
- worktreePath: runtime.workspaceDir,
405
- artifactRoot: resolve2(runtime.workspaceDir, "artifacts", taskId),
406
- logRoot: runtime.logsDir,
407
- sessionPath: resolve2(runtime.sessionDir, "session.json"),
408
- sessionLogPath: resolve2(runtime.logsDir, "agent-stdout.log"),
409
- pid: process.pid,
410
- errorText: result.stderr ? result.stderr.trim() : `Agent runtime command failed (${result.exitCode})`
411
- });
412
- throw new CliError2(`Agent runtime command failed (${result.exitCode}) in ${runtime.id}${result.stderr ? `
413
- ${result.stderr.trim()}` : ""}`, result.exitCode);
414
- }
415
- const completedAt = new Date().toISOString();
416
- upsertAgentAuthorityRun(context.projectRoot, {
417
- runId: runtime.id,
418
- taskId,
419
- createdAt: completedAt,
420
- runtimeAdapter: process.env.RIG_RUNTIME_ADAPTER || "claude-code",
421
- status: "completed",
422
- startedAt: createdAt,
423
- completedAt,
424
- worktreePath: runtime.workspaceDir,
425
- artifactRoot: resolve2(runtime.workspaceDir, "artifacts", taskId),
426
- logRoot: runtime.logsDir,
427
- sessionPath: resolve2(runtime.sessionDir, "session.json"),
428
- sessionLogPath: resolve2(runtime.logsDir, "agent-stdout.log"),
429
- pid: process.pid
430
- });
431
- return {
432
- ok: true,
433
- group: "agent",
434
- command,
435
- details: {
436
- runtimeId: runtime.id,
437
- mode: runtime.mode,
438
- command: commandParts,
439
- exitCode: result.exitCode,
440
- sandboxBackend: result.sandboxBackend,
441
- sandboxEnabled: result.sandboxEnabled,
442
- stdout: result.stdout,
443
- stderr: result.stderr
444
- }
445
- };
446
- } catch (error) {
447
- const failedAt = new Date().toISOString();
448
- upsertAgentAuthorityRun(context.projectRoot, {
449
- runId: id,
450
- taskId,
451
- createdAt: failedAt,
452
- runtimeAdapter: process.env.RIG_RUNTIME_ADAPTER || "claude-code",
453
- status: "failed",
454
- startedAt: createdAt,
455
- completedAt: failedAt,
456
- errorText: error instanceof Error ? error.message : String(error)
457
- });
458
- throw error;
459
- }
460
- }
461
- case "cleanup": {
462
- let pending = rest;
463
- const allResult = takeFlag(pending, "--all");
464
- pending = allResult.rest;
465
- const idResult = takeOption(pending, "--id");
466
- pending = idResult.rest;
467
- requireNoExtraArgs(pending, "bun run rig agent cleanup (--id <id> | --all)");
468
- if (!allResult.value && !idResult.value) {
469
- throw new CliError2("Provide --id <id> or --all.");
470
- }
471
- const runtimes = await listAgentRuntimes(context.projectRoot);
472
- const targets = allResult.value ? runtimes.map((runtime) => runtime.id) : [idResult.value];
473
- for (const id of targets) {
474
- await cleanupAgentRuntime({
475
- projectRoot: context.projectRoot,
476
- id
477
- });
478
- }
479
- if (context.outputMode === "text") {
480
- console.log(`Cleaned runtimes: ${targets.join(", ")}`);
481
- }
482
- return {
483
- ok: true,
484
- group: "agent",
485
- command,
486
- details: {
487
- cleaned: targets,
488
- count: targets.length,
489
- all: allResult.value
490
- }
491
- };
492
- }
493
- default:
494
- throw new CliError2(`Unknown agent command: ${command}`);
495
- }
496
- }
497
- export {
498
- executeAgent
499
- };