@h-rig/cli 0.0.6-alpha.7 → 0.0.6-alpha.70
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 +1 -1
- package/dist/bin/rig.js +4507 -1506
- package/dist/src/commands/_async-ui.js +152 -0
- package/dist/src/commands/_authority-runs.js +2 -3
- package/dist/src/commands/_cli-format.js +369 -0
- package/dist/src/commands/_connection-state.js +30 -11
- package/dist/src/commands/_doctor-checks.js +177 -43
- package/dist/src/commands/_help-catalog.js +485 -0
- package/dist/src/commands/_json-output.js +56 -0
- package/dist/src/commands/_operator-surface.js +220 -0
- package/dist/src/commands/_operator-view.js +595 -72
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_pi-frontend.js +411 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_policy.js +12 -5
- package/dist/src/commands/_preflight.js +187 -127
- package/dist/src/commands/_run-driver-helpers.js +75 -22
- package/dist/src/commands/_run-replay.js +142 -0
- package/dist/src/commands/_server-client.js +343 -60
- package/dist/src/commands/_snapshot-upload.js +160 -38
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/_task-picker.js +44 -16
- package/dist/src/commands/agent.js +39 -20
- package/dist/src/commands/browser.js +28 -21
- package/dist/src/commands/connect.js +146 -33
- package/dist/src/commands/dist.js +19 -12
- package/dist/src/commands/doctor.js +304 -44
- package/dist/src/commands/github.js +301 -52
- package/dist/src/commands/inbox.js +679 -72
- package/dist/src/commands/init.js +622 -118
- package/dist/src/commands/inspect.js +515 -32
- package/dist/src/commands/inspector.js +20 -13
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.js +95 -27
- package/dist/src/commands/profile-and-review.js +26 -19
- package/dist/src/commands/queue.js +32 -12
- package/dist/src/commands/remote.js +43 -36
- package/dist/src/commands/repo-git-harness.js +22 -15
- package/dist/src/commands/run.js +1162 -158
- package/dist/src/commands/server.js +373 -56
- package/dist/src/commands/setup.js +316 -62
- package/dist/src/commands/stats.js +1030 -0
- package/dist/src/commands/task-report-bug.js +29 -22
- package/dist/src/commands/task-run-driver.js +862 -129
- package/dist/src/commands/task.js +1423 -311
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.js +4446 -1499
- package/dist/src/index.js +4502 -1504
- package/dist/src/launcher.js +77 -13
- package/dist/src/report-bug.js +3 -3
- package/dist/src/runner.js +16 -22
- package/package.json +10 -5
package/dist/src/launcher.js
CHANGED
|
@@ -1,9 +1,60 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/cli/src/launcher.ts
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
|
-
import { resolve } from "path";
|
|
4
|
+
import { basename, resolve } from "path";
|
|
5
5
|
import { loadDotEnvSecrets } from "@rig/runtime/baked-secrets";
|
|
6
6
|
import { RIG_DEFINITION_DIRNAME, RIG_STATE_DIRNAME, resolveNearestRigProjectRoot } from "@rig/runtime/layout";
|
|
7
|
+
|
|
8
|
+
// packages/cli/src/commands/_json-output.ts
|
|
9
|
+
import { Schema } from "effect";
|
|
10
|
+
import {
|
|
11
|
+
RigDoctorCheckOutput,
|
|
12
|
+
RigInboxApprovalsOutput,
|
|
13
|
+
RigInboxInputsOutput,
|
|
14
|
+
RigRunListOutput,
|
|
15
|
+
RigRunShowOutput,
|
|
16
|
+
RigServerStatusOutput,
|
|
17
|
+
RigStatsOutput,
|
|
18
|
+
RigTaskListOutput,
|
|
19
|
+
RigTaskShowOutput
|
|
20
|
+
} from "@rig/contracts";
|
|
21
|
+
var CLI_OUTPUT_SCHEMAS = {
|
|
22
|
+
"task list": RigTaskListOutput,
|
|
23
|
+
"task show": RigTaskShowOutput,
|
|
24
|
+
"run list": RigRunListOutput,
|
|
25
|
+
"run show": RigRunShowOutput,
|
|
26
|
+
"server status": RigServerStatusOutput,
|
|
27
|
+
"inbox approvals": RigInboxApprovalsOutput,
|
|
28
|
+
"inbox inputs": RigInboxInputsOutput,
|
|
29
|
+
"doctor check": RigDoctorCheckOutput,
|
|
30
|
+
"stats show": RigStatsOutput
|
|
31
|
+
};
|
|
32
|
+
function isCommandOutcomeLike(value) {
|
|
33
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
34
|
+
return false;
|
|
35
|
+
const record = value;
|
|
36
|
+
return typeof record.group === "string" && typeof record.command === "string";
|
|
37
|
+
}
|
|
38
|
+
function buildCliJsonEnvelope(outcome, options = {}) {
|
|
39
|
+
if (!isCommandOutcomeLike(outcome))
|
|
40
|
+
return null;
|
|
41
|
+
const commandKey = `${outcome.group} ${outcome.command}`;
|
|
42
|
+
const schema = CLI_OUTPUT_SCHEMAS[commandKey];
|
|
43
|
+
if (!schema)
|
|
44
|
+
return null;
|
|
45
|
+
const warn = options.warn ?? ((message) => console.error(message));
|
|
46
|
+
const envelope = { v: 1, command: commandKey, data: outcome.details ?? {} };
|
|
47
|
+
try {
|
|
48
|
+
Schema.decodeUnknownSync(schema)(JSON.parse(JSON.stringify(envelope)));
|
|
49
|
+
return envelope;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
warn(`[rig] --json output for "${commandKey}" failed schema validation; printing legacy payload. ` + `(${error instanceof Error ? error.message.split(`
|
|
52
|
+
`)[0] : String(error)})`);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// packages/cli/src/launcher.ts
|
|
7
58
|
function parsePolicyMode(value) {
|
|
8
59
|
if (!value) {
|
|
9
60
|
return;
|
|
@@ -14,7 +65,7 @@ function parsePolicyMode(value) {
|
|
|
14
65
|
throw new Error(`Invalid --policy-mode value: ${value}. Use off|observe|enforce.`);
|
|
15
66
|
}
|
|
16
67
|
function hasRigProjectMarker(candidate) {
|
|
17
|
-
return existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME)) || existsSync(resolve(candidate, "rig.config.ts")) || existsSync(resolve(candidate, "rig.config.json"));
|
|
68
|
+
return existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME)) || existsSync(resolve(candidate, "rig.config.ts")) || existsSync(resolve(candidate, "rig.config.json")) || existsSync(resolve(candidate, ".git"));
|
|
18
69
|
}
|
|
19
70
|
function resolveProjectRoot({
|
|
20
71
|
envProjectRoot,
|
|
@@ -26,7 +77,9 @@ function resolveProjectRoot({
|
|
|
26
77
|
return resolve(cwd, envProjectRoot);
|
|
27
78
|
}
|
|
28
79
|
const fallbackImportDir = importDir ?? cwd;
|
|
29
|
-
const
|
|
80
|
+
const execName = basename(execPath).toLowerCase();
|
|
81
|
+
const execCandidates = execName === "rig" || execName === "rig.exe" ? [resolve(execPath, "..", "..")] : [];
|
|
82
|
+
const candidates = [cwd, ...execCandidates, resolve(fallbackImportDir, "..")];
|
|
30
83
|
for (const candidate of candidates) {
|
|
31
84
|
const nearest = resolveNearestRigProjectRoot(candidate);
|
|
32
85
|
if (hasRigProjectMarker(nearest)) {
|
|
@@ -45,14 +98,17 @@ function normalizeCliErrorCode(message, isCliError) {
|
|
|
45
98
|
return isCliError ? "CLI_ERROR" : "UNEXPECTED_ERROR";
|
|
46
99
|
}
|
|
47
100
|
function normalizeCliErrorPayload(error, CliErrorClass, options = {}) {
|
|
48
|
-
const isCliError = error instanceof CliErrorClass;
|
|
101
|
+
const isCliError = error instanceof CliErrorClass || error instanceof Error && error.name === "CliError" && typeof error.exitCode === "number";
|
|
49
102
|
const message = error instanceof Error ? error.message : String(error);
|
|
50
103
|
const exitCode = isCliError ? error.exitCode : 1;
|
|
104
|
+
const rawHint = error instanceof Error ? error.hint : undefined;
|
|
105
|
+
const hint = typeof rawHint === "string" && rawHint.trim() ? rawHint.trim() : undefined;
|
|
51
106
|
const payload = {
|
|
52
107
|
ok: false,
|
|
53
108
|
code: normalizeCliErrorCode(message, isCliError),
|
|
54
109
|
message,
|
|
55
|
-
exitCode
|
|
110
|
+
exitCode,
|
|
111
|
+
...hint ? { hint } : {}
|
|
56
112
|
};
|
|
57
113
|
if (options.debug && error instanceof Error && error.stack) {
|
|
58
114
|
return { ...payload, stack: error.stack };
|
|
@@ -95,14 +151,19 @@ async function runRigCli(module, options = {}) {
|
|
|
95
151
|
const context = await module.initializeRuntime(runtimeOptions);
|
|
96
152
|
const outcome = await module.execute(context, runIdResult.rest);
|
|
97
153
|
if (outputMode === "json") {
|
|
98
|
-
io.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
154
|
+
const envelope = buildCliJsonEnvelope(outcome, { warn: io.error });
|
|
155
|
+
if (envelope) {
|
|
156
|
+
io.log(JSON.stringify(envelope, null, 2));
|
|
157
|
+
} else {
|
|
158
|
+
io.log(JSON.stringify({
|
|
159
|
+
ok: true,
|
|
160
|
+
runId: context.runId,
|
|
161
|
+
outcome,
|
|
162
|
+
eventsFile: context.eventBus.getEventsFile(),
|
|
163
|
+
policyFile: resolve(projectRoot, "rig", "policy", "policy.json"),
|
|
164
|
+
policyMode: context.policyMode ?? policyMode ?? module.loadPolicy(projectRoot).mode
|
|
165
|
+
}, null, 2));
|
|
166
|
+
}
|
|
106
167
|
}
|
|
107
168
|
} catch (error) {
|
|
108
169
|
const payload = normalizeCliErrorPayload(error, module.CliError, { debug: debugErrors });
|
|
@@ -110,6 +171,9 @@ async function runRigCli(module, options = {}) {
|
|
|
110
171
|
io.error(JSON.stringify(payload, null, 2));
|
|
111
172
|
} else {
|
|
112
173
|
io.error(debugErrors && payload.stack ? payload.stack : payload.message);
|
|
174
|
+
if (payload.hint) {
|
|
175
|
+
io.error(`Next: ${payload.hint}`);
|
|
176
|
+
}
|
|
113
177
|
}
|
|
114
178
|
process.exit(payload.exitCode);
|
|
115
179
|
}
|
package/dist/src/report-bug.js
CHANGED
|
@@ -166,15 +166,15 @@ function buildBugReportMarkdown(input, browser, screenshots, assets) {
|
|
|
166
166
|
...input.issueId ? [
|
|
167
167
|
`- Canonical task assets live under \`artifacts/${input.issueId}/bug-report/\`.`,
|
|
168
168
|
`- Start with \`artifacts/${input.issueId}/bug-report/task.md\` and the files in \`artifacts/${input.issueId}/bug-report/assets/\`.`,
|
|
169
|
-
browserRequired ? `- Run \`
|
|
169
|
+
browserRequired ? `- Run \`rig task info --task ${input.issueId}\` to confirm browser wiring before debugging.` : `- Run \`rig task info --task ${input.issueId}\` to confirm scope and artifact links before debugging.`
|
|
170
170
|
] : [
|
|
171
|
-
"- Draft-only report: convert this into a
|
|
171
|
+
"- Draft-only report: convert this into a Rig task before assigning it to an agent run."
|
|
172
172
|
],
|
|
173
173
|
"",
|
|
174
174
|
"## Validation",
|
|
175
175
|
"",
|
|
176
176
|
"```bash",
|
|
177
|
-
...input.issueId ? [`
|
|
177
|
+
...input.issueId ? [`rig task validate --task ${input.issueId}`] : [],
|
|
178
178
|
...browserRequired ? [
|
|
179
179
|
"bun run app:check:browser:hp-next",
|
|
180
180
|
"bun run app:e2e:browser:hp-next"
|
package/dist/src/runner.js
CHANGED
|
@@ -4,12 +4,19 @@ var {$ } = globalThis.Bun;
|
|
|
4
4
|
import { existsSync, mkdirSync } from "fs";
|
|
5
5
|
import { resolve } from "path";
|
|
6
6
|
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
7
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
7
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
8
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
9
|
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
class CliError extends RuntimeCliError {
|
|
12
|
+
hint;
|
|
13
|
+
constructor(message, exitCode = 1, options = {}) {
|
|
14
|
+
super(message, exitCode);
|
|
15
|
+
if (options.hint?.trim()) {
|
|
16
|
+
this.hint = options.hint.trim();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
13
20
|
function withProjectRoot(projectRoot) {
|
|
14
21
|
$.cwd(projectRoot);
|
|
15
22
|
}
|
|
@@ -61,13 +68,6 @@ async function ensureAgentShellBinary(projectRoot, options = {}) {
|
|
|
61
68
|
}
|
|
62
69
|
async function initializeRuntime(options) {
|
|
63
70
|
const eventBus = new EventBus({ projectRoot: options.projectRoot, runId: options.runId });
|
|
64
|
-
const runtimeContext = loadRuntimeContextFromEnv() ?? undefined;
|
|
65
|
-
const plugins = await PluginManager.load({
|
|
66
|
-
projectRoot: options.projectRoot,
|
|
67
|
-
runId: eventBus.getRunId(),
|
|
68
|
-
eventBus,
|
|
69
|
-
runtimeContext
|
|
70
|
-
});
|
|
71
71
|
const context = {
|
|
72
72
|
projectRoot: options.projectRoot,
|
|
73
73
|
dryRun: options.dryRun,
|
|
@@ -75,10 +75,8 @@ async function initializeRuntime(options) {
|
|
|
75
75
|
runId: eventBus.getRunId(),
|
|
76
76
|
policyMode: options.policyMode,
|
|
77
77
|
eventBus,
|
|
78
|
-
plugins,
|
|
79
78
|
emitEvent: async (type, payload) => {
|
|
80
|
-
|
|
81
|
-
await plugins.onEvent(event);
|
|
79
|
+
await eventBus.emit(type, payload);
|
|
82
80
|
}
|
|
83
81
|
};
|
|
84
82
|
context.runCommand = async (parts) => runCommand(context, parts);
|
|
@@ -87,8 +85,7 @@ async function initializeRuntime(options) {
|
|
|
87
85
|
outputMode: context.outputMode,
|
|
88
86
|
dryRun: context.dryRun,
|
|
89
87
|
policyMode: context.policyMode ?? loadPolicy(options.projectRoot).mode,
|
|
90
|
-
policyFile: resolve(options.projectRoot, "rig/policy/policy.json")
|
|
91
|
-
plugins: context.plugins.list()
|
|
88
|
+
policyFile: resolve(options.projectRoot, "rig/policy/policy.json")
|
|
92
89
|
});
|
|
93
90
|
return context;
|
|
94
91
|
}
|
|
@@ -137,9 +134,8 @@ async function runCommand(context, parts) {
|
|
|
137
134
|
matchedRuleIds: guardDecision.matchedRules.map((r) => r.id),
|
|
138
135
|
mode: effectiveMode
|
|
139
136
|
});
|
|
140
|
-
throw new CliError(`Policy blocked command: ${formatted}`, 126);
|
|
137
|
+
throw new CliError(`Policy blocked command: ${formatted}`, 126, { hint: "Review rig/policy/policy.json, or re-run with `--policy-mode observe` to log instead of block." });
|
|
141
138
|
}
|
|
142
|
-
await context.plugins.beforeCommand({ command: commandWithEnv, formattedCommand: formatted });
|
|
143
139
|
const startedAt = new Date;
|
|
144
140
|
await context.emitEvent("command.started", {
|
|
145
141
|
command: commandWithEnv,
|
|
@@ -159,7 +155,6 @@ async function runCommand(context, parts) {
|
|
|
159
155
|
if (context.outputMode === "text") {
|
|
160
156
|
console.log(`$ ${formatted}`);
|
|
161
157
|
}
|
|
162
|
-
await context.plugins.afterCommand(dryResult);
|
|
163
158
|
await context.emitEvent("command.finished", {
|
|
164
159
|
...dryResult,
|
|
165
160
|
dryRun: true
|
|
@@ -199,7 +194,6 @@ async function runCommand(context, parts) {
|
|
|
199
194
|
stdout: context.outputMode === "json" ? stdout : undefined,
|
|
200
195
|
stderr: context.outputMode === "json" ? stderr : undefined
|
|
201
196
|
};
|
|
202
|
-
await context.plugins.afterCommand(result);
|
|
203
197
|
if (exitCode !== 0) {
|
|
204
198
|
await context.emitEvent("command.failed", {
|
|
205
199
|
...result
|
|
@@ -233,7 +227,7 @@ function takeOption(args, option) {
|
|
|
233
227
|
if (current === option) {
|
|
234
228
|
const next = args[index + 1];
|
|
235
229
|
if (!next || next.startsWith("-")) {
|
|
236
|
-
throw new CliError(`Missing value for ${option}`);
|
|
230
|
+
throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
|
|
237
231
|
}
|
|
238
232
|
value = next;
|
|
239
233
|
index += 1;
|
|
@@ -269,5 +263,5 @@ export {
|
|
|
269
263
|
initializeRuntime,
|
|
270
264
|
formatCommand,
|
|
271
265
|
ensureAgentShellBinary,
|
|
272
|
-
|
|
266
|
+
CliError
|
|
273
267
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-rig/cli",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.70",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rig package",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -23,10 +23,15 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@clack/prompts": "^1.2.0",
|
|
26
|
-
"@
|
|
27
|
-
"@rig/
|
|
28
|
-
"@rig/
|
|
29
|
-
"@rig/
|
|
26
|
+
"@earendil-works/pi-coding-agent": "0.79.0",
|
|
27
|
+
"@rig/client": "npm:@h-rig/client@0.0.6-alpha.70",
|
|
28
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.70",
|
|
29
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.70",
|
|
30
|
+
"@rig/pi-rig": "npm:@h-rig/pi-rig@0.0.6-alpha.70",
|
|
31
|
+
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.70",
|
|
32
|
+
"@rig/server": "npm:@h-rig/server@0.0.6-alpha.70",
|
|
33
|
+
"@rig/standard-plugin": "npm:@h-rig/standard-plugin@0.0.6-alpha.70",
|
|
34
|
+
"effect": "4.0.0-beta.78",
|
|
30
35
|
"picocolors": "^1.1.1"
|
|
31
36
|
}
|
|
32
37
|
}
|