@h-rig/cli 0.0.6-alpha.0
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.
- package/README.md +30 -0
- package/dist/bin/build-rig-binaries.js +107 -0
- package/dist/bin/rig.js +9330 -0
- package/dist/src/commands/_authority-runs.js +110 -0
- package/dist/src/commands/_connection-state.js +123 -0
- package/dist/src/commands/_doctor-checks.js +501 -0
- package/dist/src/commands/_operator-view.js +322 -0
- package/dist/src/commands/_parsers.js +107 -0
- package/dist/src/commands/_paths.js +50 -0
- package/dist/src/commands/_pi-install.js +184 -0
- package/dist/src/commands/_policy.js +79 -0
- package/dist/src/commands/_preflight.js +460 -0
- package/dist/src/commands/_probes.js +13 -0
- package/dist/src/commands/_run-driver-helpers.js +289 -0
- package/dist/src/commands/_server-client.js +364 -0
- package/dist/src/commands/_snapshot-upload.js +313 -0
- package/dist/src/commands/_task-picker.js +48 -0
- package/dist/src/commands/agent.js +497 -0
- package/dist/src/commands/browser.js +890 -0
- package/dist/src/commands/connect.js +180 -0
- package/dist/src/commands/dist.js +402 -0
- package/dist/src/commands/doctor.js +511 -0
- package/dist/src/commands/github.js +276 -0
- package/dist/src/commands/inbox.js +160 -0
- package/dist/src/commands/init.js +1254 -0
- package/dist/src/commands/inspect.js +174 -0
- package/dist/src/commands/inspector.js +256 -0
- package/dist/src/commands/plugin.js +167 -0
- package/dist/src/commands/profile-and-review.js +178 -0
- package/dist/src/commands/queue.js +197 -0
- package/dist/src/commands/remote.js +507 -0
- package/dist/src/commands/repo-git-harness.js +221 -0
- package/dist/src/commands/run.js +753 -0
- package/dist/src/commands/server.js +368 -0
- package/dist/src/commands/setup.js +681 -0
- package/dist/src/commands/task-report-bug.js +1083 -0
- package/dist/src/commands/task-run-driver.js +1933 -0
- package/dist/src/commands/task.js +1325 -0
- package/dist/src/commands/test.js +39 -0
- package/dist/src/commands/workspace.js +123 -0
- package/dist/src/commands.js +9012 -0
- package/dist/src/index.js +9348 -0
- package/dist/src/launcher.js +131 -0
- package/dist/src/report-bug.js +260 -0
- package/dist/src/runner.js +272 -0
- package/dist/src/withMutedConsole.js +42 -0
- package/package.json +31 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/runner.ts
|
|
3
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
4
|
+
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
5
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
6
|
+
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
7
|
+
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
8
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
9
|
+
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
10
|
+
function takeOption(args, option) {
|
|
11
|
+
const rest = [];
|
|
12
|
+
let value;
|
|
13
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
14
|
+
const current = args[index];
|
|
15
|
+
if (current === option) {
|
|
16
|
+
const next = args[index + 1];
|
|
17
|
+
if (!next || next.startsWith("-")) {
|
|
18
|
+
throw new CliError(`Missing value for ${option}`);
|
|
19
|
+
}
|
|
20
|
+
value = next;
|
|
21
|
+
index += 1;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (current !== undefined) {
|
|
25
|
+
rest.push(current);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { value, rest };
|
|
29
|
+
}
|
|
30
|
+
function requireNoExtraArgs(args, usage) {
|
|
31
|
+
if (args.length > 0) {
|
|
32
|
+
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
33
|
+
Usage: ${usage}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// packages/cli/src/commands/profile-and-review.ts
|
|
38
|
+
import {
|
|
39
|
+
setProfile,
|
|
40
|
+
setReviewProfile,
|
|
41
|
+
showProfile,
|
|
42
|
+
showReviewProfile
|
|
43
|
+
} from "@rig/runtime/control-plane/native/profile-ops";
|
|
44
|
+
|
|
45
|
+
// packages/cli/src/withMutedConsole.ts
|
|
46
|
+
function isPromise(value) {
|
|
47
|
+
if (typeof value !== "object" && typeof value !== "function") {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return value !== null && typeof value.then === "function";
|
|
51
|
+
}
|
|
52
|
+
function withMutedConsole(mute, fn) {
|
|
53
|
+
if (!mute) {
|
|
54
|
+
return fn();
|
|
55
|
+
}
|
|
56
|
+
const originalLog = console.log;
|
|
57
|
+
const originalWarn = console.warn;
|
|
58
|
+
const originalInfo = console.info;
|
|
59
|
+
const restore = () => {
|
|
60
|
+
console.log = originalLog;
|
|
61
|
+
console.warn = originalWarn;
|
|
62
|
+
console.info = originalInfo;
|
|
63
|
+
};
|
|
64
|
+
console.log = () => {};
|
|
65
|
+
console.warn = () => {};
|
|
66
|
+
console.info = () => {};
|
|
67
|
+
try {
|
|
68
|
+
const result = fn();
|
|
69
|
+
if (isPromise(result)) {
|
|
70
|
+
return result.finally(restore);
|
|
71
|
+
}
|
|
72
|
+
restore();
|
|
73
|
+
return result;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
restore();
|
|
76
|
+
throw error;
|
|
77
|
+
} finally {
|
|
78
|
+
if (console.log === originalLog) {
|
|
79
|
+
restore();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// packages/cli/src/commands/profile-and-review.ts
|
|
85
|
+
async function executeProfile(context, args) {
|
|
86
|
+
const [command = "show", ...rest] = args;
|
|
87
|
+
switch (command) {
|
|
88
|
+
case "show":
|
|
89
|
+
requireNoExtraArgs(rest, "bun run rig profile show");
|
|
90
|
+
await withMutedConsole(context.outputMode === "json", () => showProfile(context.projectRoot));
|
|
91
|
+
return { ok: true, group: "profile", command };
|
|
92
|
+
case "set": {
|
|
93
|
+
if (rest.length === 0) {
|
|
94
|
+
throw new CliError2("Usage: bun run rig profile set <claude-code|codex-cli|pi> or set [--model ...] [--runtime ...] [--plugin ...]");
|
|
95
|
+
}
|
|
96
|
+
const preset = rest[0];
|
|
97
|
+
if (preset && !preset.startsWith("-")) {
|
|
98
|
+
if (rest.length !== 1) {
|
|
99
|
+
throw new CliError2("Usage: bun run rig profile set <claude-code|codex-cli|pi>");
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
await withMutedConsole(context.outputMode === "json", () => setProfile(context.projectRoot, { preset }));
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new CliError2(error instanceof Error ? error.message : String(error), 2);
|
|
105
|
+
}
|
|
106
|
+
return { ok: true, group: "profile", command, details: { preset } };
|
|
107
|
+
}
|
|
108
|
+
let pending = rest;
|
|
109
|
+
const modelResult = takeOption(pending, "--model");
|
|
110
|
+
pending = modelResult.rest;
|
|
111
|
+
const runtimeResult = takeOption(pending, "--runtime");
|
|
112
|
+
pending = runtimeResult.rest;
|
|
113
|
+
const pluginResult = takeOption(pending, "--plugin");
|
|
114
|
+
pending = pluginResult.rest;
|
|
115
|
+
requireNoExtraArgs(pending, "bun run rig profile set [--model ...] [--runtime ...] [--plugin ...]");
|
|
116
|
+
if (!modelResult.value && !runtimeResult.value && !pluginResult.value) {
|
|
117
|
+
throw new CliError2("Provide at least one of --model, --runtime, or --plugin.");
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await withMutedConsole(context.outputMode === "json", () => setProfile(context.projectRoot, {
|
|
121
|
+
model: modelResult.value,
|
|
122
|
+
runtime: runtimeResult.value,
|
|
123
|
+
plugin: pluginResult.value
|
|
124
|
+
}));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
throw new CliError2(error instanceof Error ? error.message : String(error), 2);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
ok: true,
|
|
130
|
+
group: "profile",
|
|
131
|
+
command,
|
|
132
|
+
details: {
|
|
133
|
+
model: modelResult.value || null,
|
|
134
|
+
runtime: runtimeResult.value || null,
|
|
135
|
+
plugin: pluginResult.value || null
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
default:
|
|
140
|
+
throw new CliError2(`Unknown profile command: ${command}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function executeReview(context, args) {
|
|
144
|
+
const [command = "show", ...rest] = args;
|
|
145
|
+
switch (command) {
|
|
146
|
+
case "show":
|
|
147
|
+
requireNoExtraArgs(rest, "bun run rig review show");
|
|
148
|
+
await withMutedConsole(context.outputMode === "json", () => showReviewProfile(context.projectRoot));
|
|
149
|
+
return { ok: true, group: "review", command };
|
|
150
|
+
case "set": {
|
|
151
|
+
if (rest.length === 0) {
|
|
152
|
+
throw new CliError2("Usage: bun run rig review set <off|advisory|required> [--provider greptile]");
|
|
153
|
+
}
|
|
154
|
+
const mode = rest[0];
|
|
155
|
+
if (!mode) {
|
|
156
|
+
throw new CliError2("Usage: bun run rig review set <off|advisory|required> [--provider greptile]");
|
|
157
|
+
}
|
|
158
|
+
let pending = rest.slice(1);
|
|
159
|
+
const providerResult = takeOption(pending, "--provider");
|
|
160
|
+
pending = providerResult.rest;
|
|
161
|
+
requireNoExtraArgs(pending, "bun run rig review set <off|advisory|required> [--provider greptile]");
|
|
162
|
+
try {
|
|
163
|
+
await withMutedConsole(context.outputMode === "json", () => {
|
|
164
|
+
return setReviewProfile(context.projectRoot, mode, providerResult.value);
|
|
165
|
+
});
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new CliError2(error instanceof Error ? error.message : String(error), 2);
|
|
168
|
+
}
|
|
169
|
+
return { ok: true, group: "review", command, details: { mode, provider: providerResult.value || null } };
|
|
170
|
+
}
|
|
171
|
+
default:
|
|
172
|
+
throw new CliError2(`Unknown review command: ${command}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
executeReview,
|
|
177
|
+
executeProfile
|
|
178
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/runner.ts
|
|
3
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
4
|
+
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
5
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
6
|
+
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
7
|
+
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
8
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
9
|
+
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
10
|
+
function takeFlag(args, flag) {
|
|
11
|
+
const rest = [];
|
|
12
|
+
let value = false;
|
|
13
|
+
for (const arg of args) {
|
|
14
|
+
if (arg === flag) {
|
|
15
|
+
value = true;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
rest.push(arg);
|
|
19
|
+
}
|
|
20
|
+
return { value, rest };
|
|
21
|
+
}
|
|
22
|
+
function takeOption(args, option) {
|
|
23
|
+
const rest = [];
|
|
24
|
+
let value;
|
|
25
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
26
|
+
const current = args[index];
|
|
27
|
+
if (current === option) {
|
|
28
|
+
const next = args[index + 1];
|
|
29
|
+
if (!next || next.startsWith("-")) {
|
|
30
|
+
throw new CliError(`Missing value for ${option}`);
|
|
31
|
+
}
|
|
32
|
+
value = next;
|
|
33
|
+
index += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (current !== undefined) {
|
|
37
|
+
rest.push(current);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { value, rest };
|
|
41
|
+
}
|
|
42
|
+
function requireNoExtraArgs(args, usage) {
|
|
43
|
+
if (args.length > 0) {
|
|
44
|
+
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
45
|
+
Usage: ${usage}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// packages/cli/src/commands/queue.ts
|
|
50
|
+
import { runPriorityQueue } from "@rig/runtime/control-plane/runtime/queue";
|
|
51
|
+
|
|
52
|
+
// packages/cli/src/commands/_parsers.ts
|
|
53
|
+
function parsePositiveInt(value, option, fallback) {
|
|
54
|
+
if (!value) {
|
|
55
|
+
return fallback;
|
|
56
|
+
}
|
|
57
|
+
const parsed = Number.parseInt(value, 10);
|
|
58
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
59
|
+
throw new CliError2(`Invalid ${option} value: ${value}`);
|
|
60
|
+
}
|
|
61
|
+
return parsed;
|
|
62
|
+
}
|
|
63
|
+
function parseAction(value) {
|
|
64
|
+
if (!value || value === "validate") {
|
|
65
|
+
return "validate";
|
|
66
|
+
}
|
|
67
|
+
if (value === "verify") {
|
|
68
|
+
return "verify";
|
|
69
|
+
}
|
|
70
|
+
if (value === "pipeline") {
|
|
71
|
+
return "pipeline";
|
|
72
|
+
}
|
|
73
|
+
throw new CliError2(`Invalid --action value: ${value}. Use validate, verify, or pipeline.`);
|
|
74
|
+
}
|
|
75
|
+
function parseIsolationMode(value, allowOff) {
|
|
76
|
+
if (!value) {
|
|
77
|
+
return "worktree";
|
|
78
|
+
}
|
|
79
|
+
if (value === "worktree") {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if (allowOff && value === "off") {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
throw new CliError2(`Invalid isolation mode: ${value}. Use ${allowOff ? "off|" : ""}worktree.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// packages/cli/src/commands/_preflight.ts
|
|
89
|
+
import { ensureProjectMainFreshBeforeRun } from "@rig/runtime/control-plane/project-main-pre-run-sync";
|
|
90
|
+
|
|
91
|
+
// packages/cli/src/commands/_server-client.ts
|
|
92
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
93
|
+
|
|
94
|
+
// packages/cli/src/commands/_preflight.ts
|
|
95
|
+
async function runProjectMainSyncPreflight(context, options) {
|
|
96
|
+
if (context.dryRun) {
|
|
97
|
+
if (context.outputMode === "text" && !options.disabled) {
|
|
98
|
+
console.log("[dry-run] project-rig pre-run sync check");
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const result = await ensureProjectMainFreshBeforeRun({
|
|
103
|
+
projectRoot: context.projectRoot,
|
|
104
|
+
disabled: options.disabled,
|
|
105
|
+
runBootstrap: async () => {
|
|
106
|
+
const bootstrap = await context.runCommand(["bun", "run", "bootstrap"]);
|
|
107
|
+
if (bootstrap.exitCode !== 0) {
|
|
108
|
+
throw new CliError2(bootstrap.stderr || bootstrap.stdout || "bun run bootstrap failed during project pre-run sync", bootstrap.exitCode || 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (context.outputMode !== "text") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
switch (result.status) {
|
|
116
|
+
case "disabled":
|
|
117
|
+
console.log("Project pre-run sync skipped (--skip-project-sync).");
|
|
118
|
+
break;
|
|
119
|
+
case "skipped_not_main":
|
|
120
|
+
console.log(`Project pre-run sync skipped (current branch: ${result.branch}).`);
|
|
121
|
+
break;
|
|
122
|
+
case "up_to_date":
|
|
123
|
+
break;
|
|
124
|
+
case "local_ahead":
|
|
125
|
+
console.log(`Project pre-run sync skipped (local main ahead by ${result.localAhead} commit(s)).`);
|
|
126
|
+
break;
|
|
127
|
+
case "updated":
|
|
128
|
+
console.log(`Project pre-run sync updated local main from origin/main (+${result.remoteAhead}) and bootstrapped.`);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// packages/cli/src/commands/queue.ts
|
|
134
|
+
async function executeQueue(context, args) {
|
|
135
|
+
const [command = "run", ...rest] = args;
|
|
136
|
+
switch (command) {
|
|
137
|
+
case "run": {
|
|
138
|
+
let pending = rest;
|
|
139
|
+
const workersResult = takeOption(pending, "--workers");
|
|
140
|
+
pending = workersResult.rest;
|
|
141
|
+
const maxTasksResult = takeOption(pending, "--max-tasks");
|
|
142
|
+
pending = maxTasksResult.rest;
|
|
143
|
+
const actionResult = takeOption(pending, "--action");
|
|
144
|
+
pending = actionResult.rest;
|
|
145
|
+
const isolationResult = takeOption(pending, "--isolation");
|
|
146
|
+
pending = isolationResult.rest;
|
|
147
|
+
const noRuntimeReuseResult = takeFlag(pending, "--no-runtime-reuse");
|
|
148
|
+
pending = noRuntimeReuseResult.rest;
|
|
149
|
+
const failFastResult = takeFlag(pending, "--fail-fast");
|
|
150
|
+
pending = failFastResult.rest;
|
|
151
|
+
const skipProjectSyncResult = takeFlag(pending, "--skip-project-sync");
|
|
152
|
+
pending = skipProjectSyncResult.rest;
|
|
153
|
+
requireNoExtraArgs(pending, "bun run rig queue run [--workers <n>] [--max-tasks <n>] [--action validate|verify|pipeline] [--isolation off|worktree] [--no-runtime-reuse] [--fail-fast] [--skip-project-sync]");
|
|
154
|
+
const workers = parsePositiveInt(workersResult.value, "--workers", 2);
|
|
155
|
+
const maxTasks = parsePositiveInt(maxTasksResult.value, "--max-tasks", 10);
|
|
156
|
+
const action = parseAction(actionResult.value);
|
|
157
|
+
const isolation = parseIsolationMode(isolationResult.value, true);
|
|
158
|
+
const reuseRuntime = !noRuntimeReuseResult.value;
|
|
159
|
+
await runProjectMainSyncPreflight(context, { disabled: skipProjectSyncResult.value });
|
|
160
|
+
const summary = await runPriorityQueue(context, {
|
|
161
|
+
workers,
|
|
162
|
+
maxTasks,
|
|
163
|
+
action,
|
|
164
|
+
isolation,
|
|
165
|
+
reuseRuntime,
|
|
166
|
+
failFast: failFastResult.value
|
|
167
|
+
});
|
|
168
|
+
if (context.outputMode === "text") {
|
|
169
|
+
console.log(`Processed: ${summary.processed}`);
|
|
170
|
+
console.log(`Succeeded: ${summary.succeeded}`);
|
|
171
|
+
console.log(`Failed: ${summary.failed}`);
|
|
172
|
+
}
|
|
173
|
+
if (summary.failed > 0) {
|
|
174
|
+
throw new CliError2(`Queue finished with ${summary.failed} failed task(s).`, 3);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
ok: true,
|
|
178
|
+
group: "queue",
|
|
179
|
+
command,
|
|
180
|
+
details: {
|
|
181
|
+
workers,
|
|
182
|
+
maxTasks,
|
|
183
|
+
action,
|
|
184
|
+
isolation,
|
|
185
|
+
reuseRuntime,
|
|
186
|
+
failFast: failFastResult.value,
|
|
187
|
+
summary
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
default:
|
|
192
|
+
throw new CliError2(`Unknown queue command: ${command}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
executeQueue
|
|
197
|
+
};
|