@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.90
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/build-rig-binaries.d.ts +2 -0
- package/dist/bin/rig.d.ts +2 -0
- package/dist/bin/rig.js +11052 -6668
- package/dist/src/app/board.d.ts +23 -0
- package/dist/src/app/board.js +1786 -0
- package/dist/src/app/drone-ui.d.ts +37 -0
- package/dist/src/app/drone-ui.js +294 -0
- package/dist/src/app/theme.d.ts +47 -0
- package/dist/src/app/theme.js +150 -0
- package/dist/src/commands/_async-ui.d.ts +13 -0
- package/dist/src/commands/_async-ui.js +223 -0
- package/dist/src/commands/_authority-runs.d.ts +22 -0
- package/dist/src/commands/_authority-runs.js +2 -3
- package/dist/src/commands/_cli-format.d.ts +49 -0
- package/dist/src/commands/_cli-format.js +447 -0
- package/dist/src/commands/_connection-state.d.ts +44 -0
- package/dist/src/commands/_connection-state.js +30 -11
- package/dist/src/commands/_doctor-checks.d.ts +52 -0
- package/dist/src/commands/_doctor-checks.js +180 -44
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +442 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +56 -0
- package/dist/src/commands/_operator-surface.d.ts +34 -0
- package/dist/src/commands/_operator-surface.js +220 -0
- package/dist/src/commands/_operator-view.d.ts +30 -0
- package/dist/src/commands/_operator-view.js +803 -73
- 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/_pi-frontend.d.ts +27 -0
- package/dist/src/commands/_pi-frontend.js +742 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +5 -4
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +12 -5
- package/dist/src/commands/_preflight.d.ts +22 -0
- package/dist/src/commands/_preflight.js +190 -128
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +99 -0
- package/dist/src/commands/_run-driver-helpers.js +75 -22
- package/dist/src/commands/_run-replay.d.ts +24 -0
- package/dist/src/commands/_run-replay.js +142 -0
- package/dist/src/commands/_server-client.d.ts +186 -0
- package/dist/src/commands/_server-client.js +360 -61
- package/dist/src/commands/_snapshot-upload.d.ts +39 -0
- package/dist/src/commands/_snapshot-upload.js +163 -39
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/_task-picker.d.ts +9 -0
- package/dist/src/commands/_task-picker.js +172 -19
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +39 -20
- package/dist/src/commands/browser.d.ts +65 -0
- package/dist/src/commands/browser.js +334 -51
- package/dist/src/commands/connect.d.ts +7 -0
- package/dist/src/commands/connect.js +272 -33
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +19 -12
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +378 -45
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +375 -53
- package/dist/src/commands/inbox.d.ts +30 -0
- package/dist/src/commands/inbox.js +760 -70
- package/dist/src/commands/init.d.ts +74 -0
- package/dist/src/commands/init.js +963 -119
- package/dist/src/commands/inspect.d.ts +3 -0
- package/dist/src/commands/inspect.js +588 -32
- package/dist/src/commands/inspector.d.ts +3 -0
- package/dist/src/commands/inspector.js +20 -13
- 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 +95 -27
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +26 -19
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +32 -12
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +43 -36
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +22 -15
- package/dist/src/commands/run.d.ts +3 -0
- package/dist/src/commands/run.js +1379 -159
- package/dist/src/commands/server.d.ts +7 -0
- package/dist/src/commands/server.js +502 -57
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +390 -63
- package/dist/src/commands/stats.d.ts +12 -0
- package/dist/src/commands/stats.js +1051 -0
- package/dist/src/commands/task-report-bug.d.ts +19 -0
- package/dist/src/commands/task-report-bug.js +260 -62
- package/dist/src/commands/task-run-driver.d.ts +132 -0
- package/dist/src/commands/task-run-driver.js +886 -130
- package/dist/src/commands/task.d.ts +14 -0
- package/dist/src/commands/task.js +1644 -314
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +29 -0
- package/dist/src/commands.js +10967 -6637
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +10168 -5787
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +77 -13
- package/dist/src/report-bug.d.ts +44 -0
- package/dist/src/report-bug.js +3 -3
- 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 +13 -6
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { RunnerContext } from "./runner";
|
|
2
|
+
export type PolicyModeValue = "off" | "observe" | "enforce";
|
|
3
|
+
export interface ResolveProjectRootOptions {
|
|
4
|
+
readonly envProjectRoot?: string;
|
|
5
|
+
readonly execPath?: string;
|
|
6
|
+
readonly importDir?: string;
|
|
7
|
+
readonly cwd?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CliIo {
|
|
10
|
+
readonly log: (message: string) => void;
|
|
11
|
+
readonly error: (message: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface RigCliRunOptions {
|
|
14
|
+
readonly argv?: readonly string[];
|
|
15
|
+
readonly io?: CliIo;
|
|
16
|
+
readonly envProjectRoot?: string;
|
|
17
|
+
readonly execPath?: string;
|
|
18
|
+
readonly importDir?: string;
|
|
19
|
+
readonly cwd?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RigCliModule {
|
|
22
|
+
readonly CliError: new (message: string, exitCode?: number) => Error & {
|
|
23
|
+
exitCode: number;
|
|
24
|
+
};
|
|
25
|
+
execute: (context: RunnerContext, args: string[]) => Promise<unknown>;
|
|
26
|
+
initializeRuntime: (options: {
|
|
27
|
+
projectRoot: string;
|
|
28
|
+
dryRun: boolean;
|
|
29
|
+
outputMode: "json" | "text";
|
|
30
|
+
runId?: string | undefined;
|
|
31
|
+
policyMode?: PolicyModeValue | undefined;
|
|
32
|
+
}) => Promise<RunnerContext>;
|
|
33
|
+
loadPolicy(projectRoot: string): {
|
|
34
|
+
mode: PolicyModeValue;
|
|
35
|
+
};
|
|
36
|
+
takeFlag(args: string[], flag: string): {
|
|
37
|
+
value: boolean;
|
|
38
|
+
rest: string[];
|
|
39
|
+
};
|
|
40
|
+
takeOption(args: string[], option: string): {
|
|
41
|
+
value?: string;
|
|
42
|
+
rest: string[];
|
|
43
|
+
};
|
|
44
|
+
withProjectRoot(projectRoot: string): void;
|
|
45
|
+
}
|
|
46
|
+
export declare function parsePolicyMode(value: string | undefined): PolicyModeValue | undefined;
|
|
47
|
+
export declare function resolveProjectRoot({ envProjectRoot, execPath, importDir, cwd, }: ResolveProjectRootOptions): string;
|
|
48
|
+
export interface CliErrorPayload {
|
|
49
|
+
readonly ok: false;
|
|
50
|
+
readonly code: string;
|
|
51
|
+
readonly message: string;
|
|
52
|
+
readonly exitCode: number;
|
|
53
|
+
/** Remediation hint (next command to run); rendered as `Next: <hint>`. */
|
|
54
|
+
readonly hint?: string;
|
|
55
|
+
readonly stack?: string;
|
|
56
|
+
}
|
|
57
|
+
export declare function normalizeCliErrorPayload(error: unknown, CliErrorClass: RigCliModule["CliError"], options?: {
|
|
58
|
+
readonly debug?: boolean;
|
|
59
|
+
}): CliErrorPayload;
|
|
60
|
+
export declare function runRigCli(module: RigCliModule, options?: RigCliRunOptions): Promise<void>;
|
|
61
|
+
export declare function hydrateProcessEnvFromDotEnv(projectRoot: string): void;
|
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
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type BrowserBugEnvironment = "local" | "shared-dev" | "staging" | "production" | "custom";
|
|
2
|
+
export type BrowserBugReportInput = {
|
|
3
|
+
projectRoot: string;
|
|
4
|
+
outputRoot: string;
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
browserRequired?: boolean;
|
|
8
|
+
environment: BrowserBugEnvironment | string;
|
|
9
|
+
preset: string;
|
|
10
|
+
profile: string;
|
|
11
|
+
attachUrl: string;
|
|
12
|
+
stateDir: string;
|
|
13
|
+
mode: string;
|
|
14
|
+
viewport: string;
|
|
15
|
+
summary: string;
|
|
16
|
+
steps: string[];
|
|
17
|
+
expected: string;
|
|
18
|
+
actual: string;
|
|
19
|
+
evidence: string[];
|
|
20
|
+
screenshots?: string[];
|
|
21
|
+
assets?: string[];
|
|
22
|
+
issueId?: string;
|
|
23
|
+
slug?: string;
|
|
24
|
+
overwrite: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type BrowserBugReportResult = {
|
|
27
|
+
slug: string;
|
|
28
|
+
reportDir: string;
|
|
29
|
+
taskPath: string;
|
|
30
|
+
browserPath: string | null;
|
|
31
|
+
manifestPath: string;
|
|
32
|
+
assetDir: string;
|
|
33
|
+
screenshotDir: string;
|
|
34
|
+
copiedAssets: string[];
|
|
35
|
+
copiedScreenshots: string[];
|
|
36
|
+
};
|
|
37
|
+
export declare function slugifyBugTitle(value: string): string;
|
|
38
|
+
export declare function defaultBrowserBugProfile(title: string): string;
|
|
39
|
+
export declare function defaultBrowserBugOptions(environment: string): {
|
|
40
|
+
preset: string;
|
|
41
|
+
attachUrl: string;
|
|
42
|
+
stateDir: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function createBugReportFiles(input: BrowserBugReportInput): BrowserBugReportResult;
|
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"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
2
|
+
import type { PolicyMode } from "@rig/runtime/control-plane/runtime/guard-types";
|
|
3
|
+
import type { RunnerContext } from "@rig/runtime/control-plane/runtime/runner-context";
|
|
4
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
5
|
+
import type { CommandExecutionResult, OutputMode } from "@rig/runtime/control-plane/runtime/types";
|
|
6
|
+
export type { RunnerContext } from "@rig/runtime/control-plane/runtime/runner-context";
|
|
7
|
+
/**
|
|
8
|
+
* CLI-side error with an optional remediation hint. The hint is rendered on
|
|
9
|
+
* its own line as `Next: <hint>` (and carried in the --json error payload),
|
|
10
|
+
* so every failure names the next command to run. Extends the runtime
|
|
11
|
+
* CliError so `instanceof` checks against either class keep working.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CliError extends RuntimeCliError {
|
|
14
|
+
readonly hint?: string;
|
|
15
|
+
constructor(message: string, exitCode?: number, options?: {
|
|
16
|
+
readonly hint?: string;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare function withProjectRoot(projectRoot: string): void;
|
|
20
|
+
export declare function formatCommand(parts: string[]): string;
|
|
21
|
+
type AgentShellBuild = typeof buildBinary;
|
|
22
|
+
type AgentShellMaterializationOptions = {
|
|
23
|
+
readonly env?: Record<string, string | undefined>;
|
|
24
|
+
readonly cwd?: string;
|
|
25
|
+
readonly moduleDir?: string;
|
|
26
|
+
readonly build?: AgentShellBuild;
|
|
27
|
+
};
|
|
28
|
+
export declare function resolveAgentMaterializationSourceRoot(projectRoot: string, options?: AgentShellMaterializationOptions): string;
|
|
29
|
+
export declare function ensureAgentShellBinary(projectRoot: string, options?: AgentShellMaterializationOptions): Promise<string>;
|
|
30
|
+
export declare function initializeRuntime(options: {
|
|
31
|
+
projectRoot: string;
|
|
32
|
+
dryRun: boolean;
|
|
33
|
+
outputMode: OutputMode;
|
|
34
|
+
runId?: string;
|
|
35
|
+
policyMode?: PolicyMode;
|
|
36
|
+
}): Promise<RunnerContext>;
|
|
37
|
+
export declare function runCommand(context: RunnerContext, parts: string[]): Promise<CommandExecutionResult>;
|
|
38
|
+
export declare function takeFlag(args: string[], flag: string): {
|
|
39
|
+
value: boolean;
|
|
40
|
+
rest: string[];
|
|
41
|
+
};
|
|
42
|
+
export declare function takeOption(args: string[], option: string): {
|
|
43
|
+
value: string | undefined;
|
|
44
|
+
rest: string[];
|
|
45
|
+
};
|
|
46
|
+
export declare function requireNoExtraArgs(args: string[], usage: string): void;
|
|
47
|
+
export declare function requireTask(taskId: string | undefined, usage: string): string;
|
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.90",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rig package",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"types": "./dist/src/index.d.ts",
|
|
13
14
|
"import": "./dist/src/index.js"
|
|
14
15
|
}
|
|
15
16
|
},
|
|
@@ -18,15 +19,21 @@
|
|
|
18
19
|
},
|
|
19
20
|
"main": "./dist/src/index.js",
|
|
20
21
|
"module": "./dist/src/index.js",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
21
23
|
"bin": {
|
|
22
24
|
"rig": "./dist/bin/rig.js"
|
|
23
25
|
},
|
|
24
26
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@rig/
|
|
28
|
-
"@rig/
|
|
29
|
-
"@rig/
|
|
27
|
+
"@earendil-works/pi-coding-agent": "0.79.0",
|
|
28
|
+
"@earendil-works/pi-tui": "^0.79.0",
|
|
29
|
+
"@rig/client": "npm:@h-rig/client@0.0.6-alpha.90",
|
|
30
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.90",
|
|
31
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.90",
|
|
32
|
+
"@rig/pi-rig": "npm:@h-rig/pi-rig@0.0.6-alpha.90",
|
|
33
|
+
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.90",
|
|
34
|
+
"@rig/server": "npm:@h-rig/server@0.0.6-alpha.90",
|
|
35
|
+
"@rig/standard-plugin": "npm:@h-rig/standard-plugin@0.0.6-alpha.90",
|
|
36
|
+
"effect": "4.0.0-beta.78",
|
|
30
37
|
"picocolors": "^1.1.1"
|
|
31
38
|
}
|
|
32
39
|
}
|