@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,221 @@
|
|
|
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 formatCommand(parts) {
|
|
11
|
+
return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
|
|
12
|
+
}
|
|
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/repo-git-harness.ts
|
|
53
|
+
import { executeHarnessCommand } from "@rig/runtime/control-plane/native/harness-cli";
|
|
54
|
+
import { repoEnsure, resetBaseline } from "@rig/runtime/control-plane/native/repo-ops";
|
|
55
|
+
|
|
56
|
+
// packages/cli/src/withMutedConsole.ts
|
|
57
|
+
function isPromise(value) {
|
|
58
|
+
if (typeof value !== "object" && typeof value !== "function") {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return value !== null && typeof value.then === "function";
|
|
62
|
+
}
|
|
63
|
+
function withMutedConsole(mute, fn) {
|
|
64
|
+
if (!mute) {
|
|
65
|
+
return fn();
|
|
66
|
+
}
|
|
67
|
+
const originalLog = console.log;
|
|
68
|
+
const originalWarn = console.warn;
|
|
69
|
+
const originalInfo = console.info;
|
|
70
|
+
const restore = () => {
|
|
71
|
+
console.log = originalLog;
|
|
72
|
+
console.warn = originalWarn;
|
|
73
|
+
console.info = originalInfo;
|
|
74
|
+
};
|
|
75
|
+
console.log = () => {};
|
|
76
|
+
console.warn = () => {};
|
|
77
|
+
console.info = () => {};
|
|
78
|
+
try {
|
|
79
|
+
const result = fn();
|
|
80
|
+
if (isPromise(result)) {
|
|
81
|
+
return result.finally(restore);
|
|
82
|
+
}
|
|
83
|
+
restore();
|
|
84
|
+
return result;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
restore();
|
|
87
|
+
throw error;
|
|
88
|
+
} finally {
|
|
89
|
+
if (console.log === originalLog) {
|
|
90
|
+
restore();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// packages/cli/src/commands/_policy.ts
|
|
96
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
97
|
+
import { resolve } from "path";
|
|
98
|
+
import { evaluate as evaluate2, loadPolicy as loadPolicy2, resolveAction as resolveAction2 } from "@rig/runtime/control-plane/runtime/guard";
|
|
99
|
+
import { resolveHarnessPaths } from "@rig/runtime/control-plane/native/utils";
|
|
100
|
+
function resolveEffectivePolicyMode(context) {
|
|
101
|
+
const envMode = process.env.RIG_BASH_MODE;
|
|
102
|
+
if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
|
|
103
|
+
return envMode;
|
|
104
|
+
}
|
|
105
|
+
return context.policyMode || loadPolicy2(context.projectRoot).mode;
|
|
106
|
+
}
|
|
107
|
+
function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
|
|
108
|
+
if (mode === "off") {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const logsDir = resolveHarnessPaths(context.projectRoot).logsDir;
|
|
112
|
+
const logFile = resolve(logsDir, "controlled-bash.jsonl");
|
|
113
|
+
mkdirSync(logsDir, { recursive: true });
|
|
114
|
+
const payload = {
|
|
115
|
+
timestamp: new Date().toISOString(),
|
|
116
|
+
mode,
|
|
117
|
+
cwd: process.cwd(),
|
|
118
|
+
pid: process.pid,
|
|
119
|
+
ppid: process.ppid,
|
|
120
|
+
argv: args,
|
|
121
|
+
command,
|
|
122
|
+
matchedRuleIds
|
|
123
|
+
};
|
|
124
|
+
if (action) {
|
|
125
|
+
payload.action = action;
|
|
126
|
+
}
|
|
127
|
+
appendFileSync(logFile, `${JSON.stringify(payload)}
|
|
128
|
+
`, "utf-8");
|
|
129
|
+
}
|
|
130
|
+
async function enforceNativeCommandPolicy(context, args, options) {
|
|
131
|
+
const mode = resolveEffectivePolicyMode(context);
|
|
132
|
+
const command = formatCommand([options.commandPrefix, ...args]);
|
|
133
|
+
const decision = evaluate2({
|
|
134
|
+
projectRoot: context.projectRoot,
|
|
135
|
+
evaluation: { type: "command", command }
|
|
136
|
+
});
|
|
137
|
+
const action = resolveAction2(mode, decision.matchedRules);
|
|
138
|
+
const matchedRuleIds = decision.matchedRules.map((rule) => rule.id);
|
|
139
|
+
await context.emitEvent("policy.decision", {
|
|
140
|
+
target: "command",
|
|
141
|
+
command,
|
|
142
|
+
mode,
|
|
143
|
+
allowed: action !== "block",
|
|
144
|
+
matchedRuleIds,
|
|
145
|
+
reasons: decision.matchedRules.map((rule) => rule.reason)
|
|
146
|
+
});
|
|
147
|
+
if (options.writeAuditLog) {
|
|
148
|
+
appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
|
|
149
|
+
}
|
|
150
|
+
if (action === "block") {
|
|
151
|
+
throw new CliError2(`Policy blocked command: ${command}`, 126);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// packages/cli/src/commands/repo-git-harness.ts
|
|
156
|
+
async function executeRepo(context, args) {
|
|
157
|
+
const [command = "sync", ...rest] = args;
|
|
158
|
+
switch (command) {
|
|
159
|
+
case "sync": {
|
|
160
|
+
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
161
|
+
requireNoExtraArgs(remaining, "bun run rig repo sync [--task <beads-id>]");
|
|
162
|
+
withMutedConsole(context.outputMode === "json", () => repoEnsure(context.projectRoot, task || undefined));
|
|
163
|
+
return { ok: true, group: "repo", command, details: { task: task || null } };
|
|
164
|
+
}
|
|
165
|
+
case "reset-baseline": {
|
|
166
|
+
const { value: keepTaskStatusFlag, rest: remaining } = takeFlag(rest, "--keep-task-status");
|
|
167
|
+
requireNoExtraArgs(remaining, "bun run rig repo reset-baseline [--keep-task-status]");
|
|
168
|
+
withMutedConsole(context.outputMode === "json", () => resetBaseline(context.projectRoot, keepTaskStatusFlag));
|
|
169
|
+
return { ok: true, group: "repo", command, details: { keepTaskStatus: keepTaskStatusFlag } };
|
|
170
|
+
}
|
|
171
|
+
default:
|
|
172
|
+
throw new CliError2(`Unknown repo command: ${command}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async function executeGit(context, args) {
|
|
176
|
+
if (args.length === 0) {
|
|
177
|
+
throw new CliError2("Usage: bun run rig git <git-flow args...>");
|
|
178
|
+
}
|
|
179
|
+
await enforceNativeCommandPolicy(context, args, {
|
|
180
|
+
commandPrefix: "rig-agent git",
|
|
181
|
+
writeAuditLog: false
|
|
182
|
+
});
|
|
183
|
+
if (context.dryRun) {
|
|
184
|
+
if (context.outputMode === "text") {
|
|
185
|
+
console.log(`[dry-run] rig git ${args.join(" ")}`);
|
|
186
|
+
}
|
|
187
|
+
return { ok: true, group: "git", command: args[0] ?? "git" };
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
await executeHarnessCommand(context.projectRoot, context.plugins, ["git", ...args]);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
throw new CliError2(error instanceof Error ? error.message : String(error), 2);
|
|
193
|
+
}
|
|
194
|
+
return { ok: true, group: "git", command: args[0] ?? "git" };
|
|
195
|
+
}
|
|
196
|
+
async function executeHarness(context, args) {
|
|
197
|
+
if (args.length === 0) {
|
|
198
|
+
throw new CliError2("Usage: bun run rig harness <harness args...>");
|
|
199
|
+
}
|
|
200
|
+
await enforceNativeCommandPolicy(context, args, {
|
|
201
|
+
commandPrefix: "rig-agent",
|
|
202
|
+
writeAuditLog: true
|
|
203
|
+
});
|
|
204
|
+
if (context.dryRun) {
|
|
205
|
+
if (context.outputMode === "text") {
|
|
206
|
+
console.log(`[dry-run] rig harness ${args.join(" ")}`);
|
|
207
|
+
}
|
|
208
|
+
return { ok: true, group: "harness", command: args[0] ?? "harness" };
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
await executeHarnessCommand(context.projectRoot, context.plugins, args);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
throw new CliError2(error instanceof Error ? error.message : String(error), 2);
|
|
214
|
+
}
|
|
215
|
+
return { ok: true, group: "harness", command: args[0] ?? "harness" };
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
executeRepo,
|
|
219
|
+
executeHarness,
|
|
220
|
+
executeGit
|
|
221
|
+
};
|