@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.91
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 +18 -19
- package/dist/bin/build-rig-binaries.d.ts +2 -0
- package/dist/bin/build-rig-binaries.js +22 -10
- package/dist/bin/rig.d.ts +72 -0
- package/dist/bin/rig.js +15637 -7344
- package/dist/config/rig-default-config.yml +5 -0
- package/dist/src/app/drone-ui.d.ts +34 -0
- package/dist/src/app/drone-ui.js +278 -0
- package/dist/src/commands/_async-ui.d.ts +10 -0
- package/dist/src/commands/_async-ui.js +121 -0
- package/dist/src/commands/_cli-format.d.ts +56 -0
- package/dist/src/commands/_cli-format.js +319 -0
- package/dist/src/commands/_connection-state.d.ts +54 -0
- package/dist/src/commands/_connection-state.js +75 -11
- package/dist/src/commands/_doctor-checks.d.ts +46 -0
- package/dist/src/commands/_doctor-checks.js +100 -267
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +502 -0
- package/dist/src/commands/_inprocess-services.d.ts +33 -0
- package/dist/src/commands/_inprocess-services.js +102 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +60 -0
- package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
- package/dist/src/commands/_lazy-reconcile.js +102 -0
- package/dist/src/commands/_parsers.d.ts +15 -0
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_paths.d.ts +11 -0
- package/dist/src/commands/_paths.js +1 -1
- package/dist/src/commands/_pi-frontend.d.ts +35 -0
- package/dist/src/commands/_pi-frontend.js +64 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +19 -36
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +67 -19
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-bridge.d.ts +114 -0
- package/dist/src/commands/_run-bridge.js +387 -0
- package/dist/src/commands/_run-diagnostics.d.ts +9 -0
- package/dist/src/commands/_run-diagnostics.js +51 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
- package/dist/src/commands/_run-driver-helpers.js +79 -230
- package/dist/src/commands/_run-projection.d.ts +50 -0
- package/dist/src/commands/_run-projection.js +349 -0
- package/dist/src/commands/_run-subcommands.d.ts +3 -0
- package/dist/src/commands/_run-subcommands.js +31 -0
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +8575 -236
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +44 -29
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +219 -268
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +236 -188
- package/dist/src/commands/inbox.d.ts +28 -0
- package/dist/src/commands/inbox.js +530 -111
- package/dist/src/commands/init.d.ts +64 -0
- package/dist/src/commands/init.js +912 -705
- package/dist/src/commands/inspect.d.ts +20 -0
- package/dist/src/commands/inspect.js +709 -119
- package/dist/src/commands/pi.d.ts +3 -0
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.d.ts +16 -0
- package/dist/src/commands/plugin.js +576 -29
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +112 -67
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +20 -20
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +880 -50
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +78 -28
- package/dist/src/commands/run.d.ts +21 -0
- package/dist/src/commands/run.js +17701 -661
- package/dist/src/commands/server.d.ts +3 -0
- package/dist/src/commands/server.js +166 -303
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +244 -299
- package/dist/src/commands/stats.d.ts +15 -0
- package/dist/src/commands/stats.js +979 -0
- package/dist/src/commands/task-run-driver.d.ts +94 -0
- package/dist/src/commands/task-run-driver.js +116 -1961
- package/dist/src/commands/task.d.ts +35 -0
- package/dist/src/commands/task.js +676 -1201
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/triage.d.ts +11 -0
- package/dist/src/commands/triage.js +227 -0
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +13 -0
- package/dist/src/commands.js +16792 -8055
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +16862 -8450
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +81 -13
- package/dist/src/operator-cli.d.ts +2 -0
- package/dist/src/operator-cli.js +17837 -0
- package/dist/src/operator-entry.d.ts +1 -0
- package/dist/src/operator-entry.js +3 -0
- package/dist/src/runner.d.ts +47 -0
- package/dist/src/runner.js +16 -22
- package/dist/src/withMutedConsole.d.ts +2 -0
- package/package.json +21 -8
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_operator-view.js +0 -340
- package/dist/src/commands/_preflight.js +0 -478
- package/dist/src/commands/_server-client.js +0 -382
- package/dist/src/commands/_snapshot-upload.js +0 -331
- package/dist/src/commands/_task-picker.js +0 -48
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -180
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/task-report-bug.js +0 -1083
- package/dist/src/report-bug.js +0 -260
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type RunnerContext } from "../runner";
|
|
2
|
+
import type { CommandOutcome } from "@rig/runtime";
|
|
3
|
+
export declare function executeRepo(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
|
|
4
|
+
export declare function executeGit(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
|
|
5
|
+
export declare function executeHarness(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/cli/src/runner.ts
|
|
3
3
|
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
4
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
4
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
5
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
6
|
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
class CliError extends RuntimeCliError {
|
|
9
|
+
hint;
|
|
10
|
+
constructor(message, exitCode = 1, options = {}) {
|
|
11
|
+
super(message, exitCode);
|
|
12
|
+
if (options.hint?.trim()) {
|
|
13
|
+
this.hint = options.hint.trim();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
10
17
|
function formatCommand(parts) {
|
|
11
18
|
return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
|
|
12
19
|
}
|
|
@@ -30,7 +37,7 @@ function takeOption(args, option) {
|
|
|
30
37
|
if (current === option) {
|
|
31
38
|
const next = args[index + 1];
|
|
32
39
|
if (!next || next.startsWith("-")) {
|
|
33
|
-
throw new CliError(`Missing value for ${option}`);
|
|
40
|
+
throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
|
|
34
41
|
}
|
|
35
42
|
value = next;
|
|
36
43
|
index += 1;
|
|
@@ -93,23 +100,67 @@ function withMutedConsole(mute, fn) {
|
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
// packages/cli/src/commands/_policy.ts
|
|
96
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
103
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
104
|
+
import { resolve as resolve2 } from "path";
|
|
105
|
+
|
|
106
|
+
// packages/cli/src/commands/_paths.ts
|
|
97
107
|
import { resolve } from "path";
|
|
98
|
-
import {
|
|
99
|
-
|
|
108
|
+
import { resolveMonorepoRoot } from "@rig/runtime/layout";
|
|
109
|
+
function resolveControlPlaneHostStateRoot(projectRoot) {
|
|
110
|
+
return resolve(projectRoot, ".rig");
|
|
111
|
+
}
|
|
112
|
+
function resolveControlPlaneHostLogsDir(projectRoot) {
|
|
113
|
+
return resolve(resolveControlPlaneHostStateRoot(projectRoot), "logs");
|
|
114
|
+
}
|
|
115
|
+
function resolveControlPlaneDefinitionRoot(projectRoot) {
|
|
116
|
+
return resolve(projectRoot, "rig");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// packages/cli/src/commands/_policy.ts
|
|
120
|
+
function loadPolicyFile(projectRoot) {
|
|
121
|
+
const policyPath = resolve2(resolveControlPlaneDefinitionRoot(projectRoot), "policy", "policy.json");
|
|
122
|
+
if (!existsSync(policyPath)) {
|
|
123
|
+
return { mode: "observe", rules: [] };
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const parsed = JSON.parse(readFileSync(policyPath, "utf8"));
|
|
127
|
+
const mode = parsed.mode === "off" || parsed.mode === "observe" || parsed.mode === "enforce" ? parsed.mode : "observe";
|
|
128
|
+
const rules = Array.isArray(parsed.rules) ? parsed.rules.filter((value) => Boolean(value && typeof value === "object" && !Array.isArray(value))).map((value, index) => ({
|
|
129
|
+
id: typeof value.id === "string" && value.id.trim() ? value.id.trim() : `rule-${index + 1}`,
|
|
130
|
+
reason: typeof value.reason === "string" && value.reason.trim() ? value.reason.trim() : undefined,
|
|
131
|
+
match: typeof value.match === "string" && value.match.trim() ? value.match.trim() : undefined,
|
|
132
|
+
command: typeof value.command === "string" && value.command.trim() ? value.command.trim() : undefined
|
|
133
|
+
})) : [];
|
|
134
|
+
return { mode, rules };
|
|
135
|
+
} catch {
|
|
136
|
+
return { mode: "observe", rules: [] };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function matchingRules(command, rules) {
|
|
140
|
+
return rules.filter((rule) => {
|
|
141
|
+
const rawPattern = rule.command ?? rule.match;
|
|
142
|
+
if (!rawPattern)
|
|
143
|
+
return false;
|
|
144
|
+
try {
|
|
145
|
+
return new RegExp(rawPattern, "i").test(command);
|
|
146
|
+
} catch {
|
|
147
|
+
return command.includes(rawPattern);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
100
151
|
function resolveEffectivePolicyMode(context) {
|
|
101
152
|
const envMode = process.env.RIG_BASH_MODE;
|
|
102
153
|
if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
|
|
103
154
|
return envMode;
|
|
104
155
|
}
|
|
105
|
-
return context.policyMode
|
|
156
|
+
return context.policyMode ?? loadPolicyFile(context.projectRoot).mode;
|
|
106
157
|
}
|
|
107
158
|
function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
|
|
108
159
|
if (mode === "off") {
|
|
109
160
|
return;
|
|
110
161
|
}
|
|
111
|
-
const logsDir =
|
|
112
|
-
const logFile =
|
|
162
|
+
const logsDir = resolveControlPlaneHostLogsDir(context.projectRoot);
|
|
163
|
+
const logFile = resolve2(logsDir, "controlled-bash.jsonl");
|
|
113
164
|
mkdirSync(logsDir, { recursive: true });
|
|
114
165
|
const payload = {
|
|
115
166
|
timestamp: new Date().toISOString(),
|
|
@@ -130,25 +181,24 @@ function appendControlledBashAudit(context, mode, command, args, matchedRuleIds,
|
|
|
130
181
|
async function enforceNativeCommandPolicy(context, args, options) {
|
|
131
182
|
const mode = resolveEffectivePolicyMode(context);
|
|
132
183
|
const command = formatCommand([options.commandPrefix, ...args]);
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
const action = resolveAction2(mode, decision.matchedRules);
|
|
138
|
-
const matchedRuleIds = decision.matchedRules.map((rule) => rule.id);
|
|
184
|
+
const rules = matchingRules(command, loadPolicyFile(context.projectRoot).rules);
|
|
185
|
+
const matchedRuleIds = rules.map((rule) => rule.id);
|
|
186
|
+
const action = rules.length === 0 ? "allow" : mode === "enforce" ? "block" : "warn";
|
|
139
187
|
await context.emitEvent("policy.decision", {
|
|
140
188
|
target: "command",
|
|
141
189
|
command,
|
|
142
190
|
mode,
|
|
143
191
|
allowed: action !== "block",
|
|
144
192
|
matchedRuleIds,
|
|
145
|
-
reasons:
|
|
193
|
+
reasons: rules.map((rule) => rule.reason).filter(Boolean)
|
|
146
194
|
});
|
|
147
195
|
if (options.writeAuditLog) {
|
|
148
196
|
appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
|
|
149
197
|
}
|
|
150
198
|
if (action === "block") {
|
|
151
|
-
throw new
|
|
199
|
+
throw new CliError(`Policy blocked command: ${command}`, 126, {
|
|
200
|
+
hint: "Review rig/policy/policy.json, or re-run with `--policy-mode observe` to log instead of block."
|
|
201
|
+
});
|
|
152
202
|
}
|
|
153
203
|
}
|
|
154
204
|
|
|
@@ -158,23 +208,23 @@ async function executeRepo(context, args) {
|
|
|
158
208
|
switch (command) {
|
|
159
209
|
case "sync": {
|
|
160
210
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
161
|
-
requireNoExtraArgs(remaining, "
|
|
211
|
+
requireNoExtraArgs(remaining, "rig repo sync [--task <task-id>]");
|
|
162
212
|
withMutedConsole(context.outputMode === "json", () => repoEnsure(context.projectRoot, task || undefined));
|
|
163
213
|
return { ok: true, group: "repo", command, details: { task: task || null } };
|
|
164
214
|
}
|
|
165
215
|
case "reset-baseline": {
|
|
166
216
|
const { value: keepTaskStatusFlag, rest: remaining } = takeFlag(rest, "--keep-task-status");
|
|
167
|
-
requireNoExtraArgs(remaining, "
|
|
217
|
+
requireNoExtraArgs(remaining, "rig repo reset-baseline [--keep-task-status]");
|
|
168
218
|
withMutedConsole(context.outputMode === "json", () => resetBaseline(context.projectRoot, keepTaskStatusFlag));
|
|
169
219
|
return { ok: true, group: "repo", command, details: { keepTaskStatus: keepTaskStatusFlag } };
|
|
170
220
|
}
|
|
171
221
|
default:
|
|
172
|
-
throw new
|
|
222
|
+
throw new CliError(`Unknown repo command: ${command}`, 1, { hint: "Run `rig repo --help` \u2014 commands are sync|reset-baseline." });
|
|
173
223
|
}
|
|
174
224
|
}
|
|
175
225
|
async function executeGit(context, args) {
|
|
176
226
|
if (args.length === 0) {
|
|
177
|
-
throw new
|
|
227
|
+
throw new CliError("Usage: rig git <git-flow args...>");
|
|
178
228
|
}
|
|
179
229
|
await enforceNativeCommandPolicy(context, args, {
|
|
180
230
|
commandPrefix: "rig-agent git",
|
|
@@ -187,15 +237,15 @@ async function executeGit(context, args) {
|
|
|
187
237
|
return { ok: true, group: "git", command: args[0] ?? "git" };
|
|
188
238
|
}
|
|
189
239
|
try {
|
|
190
|
-
await executeHarnessCommand(context.projectRoot,
|
|
240
|
+
await executeHarnessCommand(context.projectRoot, ["git", ...args]);
|
|
191
241
|
} catch (error) {
|
|
192
|
-
throw new
|
|
242
|
+
throw new CliError(error instanceof Error ? error.message : String(error), 2);
|
|
193
243
|
}
|
|
194
244
|
return { ok: true, group: "git", command: args[0] ?? "git" };
|
|
195
245
|
}
|
|
196
246
|
async function executeHarness(context, args) {
|
|
197
247
|
if (args.length === 0) {
|
|
198
|
-
throw new
|
|
248
|
+
throw new CliError("Usage: rig harness <harness args...>");
|
|
199
249
|
}
|
|
200
250
|
await enforceNativeCommandPolicy(context, args, {
|
|
201
251
|
commandPrefix: "rig-agent",
|
|
@@ -208,9 +258,9 @@ async function executeHarness(context, args) {
|
|
|
208
258
|
return { ok: true, group: "harness", command: args[0] ?? "harness" };
|
|
209
259
|
}
|
|
210
260
|
try {
|
|
211
|
-
await executeHarnessCommand(context.projectRoot,
|
|
261
|
+
await executeHarnessCommand(context.projectRoot, args);
|
|
212
262
|
} catch (error) {
|
|
213
|
-
throw new
|
|
263
|
+
throw new CliError(error instanceof Error ? error.message : String(error), 2);
|
|
214
264
|
}
|
|
215
265
|
return { ok: true, group: "harness", command: args[0] ?? "harness" };
|
|
216
266
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type RunnerContext } from "../runner";
|
|
2
|
+
import type { CommandOutcome } from "@rig/runtime";
|
|
3
|
+
import { type RigExtensionTask, type RunControl } from "./_run-bridge";
|
|
4
|
+
import { type RunJoinTarget, type RunProjectionRecord } from "./_run-projection";
|
|
5
|
+
export type RunTaskLike = RigExtensionTask & Record<string, unknown>;
|
|
6
|
+
export interface RunExecutorDeps {
|
|
7
|
+
readonly listRuns?: (projectRoot: string) => Promise<RunProjectionRecord[]>;
|
|
8
|
+
readonly getRun?: (projectRoot: string, runId: string) => Promise<RunProjectionRecord | null>;
|
|
9
|
+
readonly resolveJoin?: (projectRoot: string, runId: string) => Promise<RunJoinTarget | null>;
|
|
10
|
+
readonly dispatch?: (input: {
|
|
11
|
+
readonly projectRoot: string;
|
|
12
|
+
readonly taskId: string;
|
|
13
|
+
readonly title?: string | null;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
readonly runId: string;
|
|
16
|
+
}>;
|
|
17
|
+
readonly listTasks?: (projectRoot: string) => Promise<readonly RunTaskLike[]>;
|
|
18
|
+
readonly appendLocal?: (record: RunProjectionRecord, text: string) => Promise<void>;
|
|
19
|
+
readonly deliverRemote?: (projectRoot: string, runId: string, control: RunControl) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare function executeRun(context: RunnerContext, args: string[], deps?: RunExecutorDeps): Promise<CommandOutcome>;
|